DIR : /home/kozerus/public_html/jkwii/js/jsdoit/gravity_face/index.js
/home/kozerus/public_html/jkwii/js/jsdoit/gravity_face
var IS_ANDROID, IS_IPHONE, SCREEN_HEIGHT, SCREEN_WIDTH, root, stage, tick;
if (!(typeof root !== "undefined" && root !== null)) {
root = {};
}
SCREEN_WIDTH = 480;
SCREEN_HEIGHT = 480;
root.canvasZoom = 1;
stage = null;
IS_IPHONE = navigator.userAgent.match(/iPhone/i) !== null;
IS_ANDROID = navigator.userAgent.match(/Android/i) !== null;
/*
マウス座標の zoom による変動に対応
*/
createjs.Stage.prototype._updatePointerPosition = function(id, pageX, pageY) {
var h, o, rect, w, _ref, _ref1, _ref2, _ref3;
rect = this._getElementRect(this.canvas);
pageX -= rect.left * root.canvasZoom;
pageY -= rect.top * root.canvasZoom;
w = SCREEN_WIDTH * root.canvasZoom;
h = SCREEN_HEIGHT * root.canvasZoom;
pageX /= (rect.right - rect.left) / w * root.canvasZoom;
pageY /= (rect.bottom - rect.top) / h * root.canvasZoom;
o = this._getPointerData(id);
if ((o.inBounds = pageX >= 0 && pageY >= 0 && pageX <= w - 1 && pageY <= h - 1)) {
o.x = pageX / root.canvasZoom;
o.y = pageY / root.canvasZoom;
} else if (this.mouseMoveOutside) {
o.x = (_ref = pageX < 0) != null ? _ref : {
0: ((_ref1 = pageX > w - 1) != null ? _ref1 : w - {
1: pageX
}) / root.canvasZoom
};
o.y = (_ref2 = pageY < 0) != null ? _ref2 : {
0: ((_ref3 = pageY > h - 1) != null ? _ref3 : h - {
1: pageY
}) / root.canvasZoom
};
}
o.rawX = pageX;
o.rawY = pageY;
if (id === this._primaryPointerID) {
this.mouseX = o.x;
this.mouseY = o.y;
return this.mouseInBounds = o.inBounds;
}
};
window.onload = function() {
var canvas, zoomController;
canvas = document.getElementById("canvas");
stage = new createjs.Stage(canvas);
zoomController = new ZoomController();
if (createjs.Touch.isSupported()) {
createjs.Touch.enable(stage, false, false);
}
this._emo = new EmoticonRoot();
stage.addChild(this._emo);
this._emo.init();
createjs.Ticker.setFPS(20);
createjs.Ticker.addListener(window);
};
tick = function() {
this._emo.update();
stage.update();
};
/* ----------------------------------------------------------------------
端末にあわせて拡大率を制御
*/
var ZoomController,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
ZoomController = (function() {
function ZoomController() {
this._onResize = __bind(this._onResize, this);
this.init();
}
ZoomController.prototype.init = function() {
//window.addEventListener("onorientationchange", this._onResize);
//window.addEventListener("resize", this._onResize);
this._onResize();
};
ZoomController.prototype._onResize = function(e) {
var h, isFullscr, para, w;
w = document.body.scrollWidth;
h = document.body.scrollHeight;
if (w > h) {
w = h;
}
if (IS_IPHONE || IS_ANDROID) {
if (w >= 980) {
w = 980; // Fullscreen 表示
} else if(parent.document !== undefined) {
w = 320; // Smart Phone 表示
} else {
w = 465; // デフォルト表示
}
} else {
w = 465; // PC表示
}
root.canvasZoom = w / SCREEN_WIDTH;
return canvas.style.zoom = root.canvasZoom;
};
return ZoomController;
})();
/* ----------------------------------------------------------------------
Math
*/
var MyMath;
if (!(typeof MyMath !== "undefined" && MyMath !== null)) {
MyMath = {};
}
MyMath.getDistance = function(ptA, ptB) {
var distance, nX, nY;
nX = ptB.x - ptA.x;
nY = ptB.y - ptA.y;
distance = Math.sqrt(nX * nX + nY * nY);
return distance;
};
MyMath.getMidpoint = function(ptA, ptB) {
var xx, yy;
xx = (ptB.x - ptA.x) * 0.5 + ptA.x;
yy = (ptB.y - ptA.y) * 0.5 + ptA.y;
return new createjs.Point(xx, yy);
};
MyMath.getAngle = function(beginPoint, endPoint) {
var degree, radian;
radian = MyMath.getRadian(beginPoint, endPoint);
degree = radian * 180 / 3.1415;
return degree;
};
MyMath.getRadian = function(beginPoint, endPoint) {
var nX, nY, radian;
nX = endPoint.x - beginPoint.x;
nY = endPoint.y - beginPoint.y;
radian = Math.atan2(nY, nX);
return radian;
};
MyMath.abs = function(v) {
if (v > 0) {
return v;
} else {
return -v;
}
};
/* ----------------------------------------------------------------------
EventDispatcher
*/
var EventDispatcher;
EventDispatcher = (function() {
function EventDispatcher() {}
EventDispatcher.init = function(obj) {
obj.__event = {};
obj.addEventListener = this.__addEventListener;
obj.removeEventListener = this.__removeEventListener;
return obj.dispatchEvent = this.__dispatchEvent;
};
EventDispatcher.__addEventListener = function(type, object) {
if (!(this.__event[type] != null)) {
this.__event[type] = [];
}
this.removeEventListener(type, object);
this.__event[type].push(object);
};
EventDispatcher.__removeEventListener = function(type, object) {
var i, listener, _arr, _i, _len;
_arr = this.__event[type];
if (_arr === void 0) {
return;
}
_len = _arr.length;
for (i = _i = 0; 0 <= _len ? _i < _len : _i > _len; i = 0 <= _len ? ++_i : --_i) {
listener = _arr[i];
if (listener === object) {
_arr.splice(i, 1);
return;
}
}
};
EventDispatcher.__dispatchEvent = function(eventObj) {
var i, listener, type, _i, _len;
if (eventObj.target === null) {
eventObj.target = this;
}
type = eventObj.type;
if (!(this.__event[type] != null)) {
return;
}
_len = this.__event[type].length;
for (i = _i = 0; 0 <= _len ? _i < _len : _i > _len; i = 0 <= _len ? ++_i : --_i) {
listener = this.__event[type][i];
if (typeof listener === "object") {
listener[type].apply(listener, new Array(eventObj));
return;
} else {
listener(eventObj);
return;
}
}
};
return EventDispatcher;
})();
/* ----------------------------------------------------------------------
Point 制御
*/
var verlet;
if (!(typeof verlet !== "undefined" && verlet !== null)) {
verlet = {};
}
verlet.VerletPoint = (function() {
VerletPoint.TYPE_EMO = "type_emoticon";
VerletPoint.TYPE_BOUND = "type_bound";
function VerletPoint(myX, myY, gRate) {
if (gRate == null) {
gRate = 1;
}
this.x = this._oldX = myX;
this.y = this._oldY = myY;
this._gRate = gRate;
this.isCrossFixX = false;
this.isCrossFixY = false;
}
VerletPoint.prototype.update = function(rect, type, crossPt) {
var boundRate, diffX, diffY, friction, gX, gY, revisionX, revisionY, tempX, tempY, vX, vY;
if (rect == null) {
rect = null;
}
if (type == null) {
type = this.TYPE_BOUND;
}
tempX = this.x;
tempY = this.y;
gX = GravityStatus.gravityX * this._gRate;
gY = GravityStatus.gravityY * this._gRate;
vX = this._getVx();
vY = this._getVy();
diffX = vX + gX;
diffY = vY + gY;
this.x += diffX;
this.y += diffY;
if ((rect != null)) {
boundRate = 0;
friction = 1;
switch (type) {
case this.TYPE_EMO:
boundRate = 0.6;
friction = 1;
break;
case this.TYPE_BOUND:
boundRate = 1;
friction = 1;
}
revisionX = 0;
revisionY = 0;
if (crossPt != null) {
crossPt.isCrossFixX = false;
}
if (crossPt != null) {
crossPt.isCrossFixY = false;
}
if (this.y < rect.y) {
this.x -= diffX * GravityStatus.frictionX;
tempY = rect.y;
this.y = tempY - diffY * boundRate + revisionY;
if (crossPt != null) {
crossPt.isCrossFixY = true;
}
} else if (this.y > rect.height + rect.y) {
this.x -= diffX * GravityStatus.frictionX;
tempY = rect.height + rect.y;
this.y = tempY - diffY * boundRate - revisionY;
if (crossPt != null) {
crossPt.isCrossFixY = true;
}
} else if (this.x < rect.x) {
this.y -= diffY * GravityStatus.frictionY;
tempX = rect.x;
this.x = tempX - diffX * boundRate + revisionX;
if (crossPt != null) {
crossPt.isCrossFixX = true;
}
} else if (this.x > rect.width + rect.x) {
this.y -= diffY * GravityStatus.frictionY;
tempX = rect.width + rect.x;
this.x = tempX - diffX * boundRate - revisionX;
if (crossPt != null) {
crossPt.isCrossFixX = true;
}
}
}
this._oldX = tempX;
return this._oldY = tempY;
};
VerletPoint.prototype.changeState = function(myX, myY, gRate) {
if (gRate == null) {
gRate = 1;
}
this.x = this._oldX = myX;
this.y = this._oldY = myY;
return this._gRate = gRate;
};
VerletPoint.prototype.setPosition = function(x, y) {
this.x = this._oldX = x;
return this.y = this._oldY = y;
};
VerletPoint.prototype.setVelocity = function(vx, vy) {
this._oldX = this.x - vx;
return this._oldY = this.y - vy;
};
VerletPoint.prototype._getVx = function() {
return this.x - this._oldX;
};
VerletPoint.prototype._getVy = function() {
return this.y - this._oldY;
};
VerletPoint.prototype.render = function(g) {
g.beginFill("#000000");
g.drawCircle(this._x, this._y, 2);
return g.endFill();
};
return VerletPoint;
})();
/* ----------------------------------------------------------------------
Stick 制御
*/
var verlet;
if (!(typeof verlet !== "undefined" && verlet !== null)) {
verlet = {};
}
verlet.VerletStick = (function() {
function VerletStick(ptA, ptB, offsetRate, len) {
if (offsetRate == null) {
offsetRate = 0.5;
}
if (len == null) {
len = -1;
}
this._pointA = ptA;
this._pointB = ptB;
this._offsetRate = offsetRate;
if (len === -1) {
this._length = MyMath.getDistance(this._pointA, this._pointB);
} else {
this._length = len;
}
}
VerletStick.prototype.update = function() {
var diff, dist, dx, dy, offsetX, offsetY;
dx = this._pointB.x - this._pointA.x;
dy = this._pointB.y - this._pointA.y;
dist = Math.sqrt(dx * dx + dy * dy);
diff = this._length - dist;
offsetX = (diff * dx / dist) * this._offsetRate;
offsetY = (diff * dy / dist) * this._offsetRate;
this._pointA.x -= offsetX;
this._pointA.y -= offsetY;
this._pointB.x += offsetX;
return this._pointB.y += offsetY;
};
VerletStick.prototype.render = function(g) {
g.setStrokeStyle(0.5);
g.beginStroke("#000000");
g.moveTo(this._pointA.x, this._pointA.y);
return g.lineTo(this._pointB.x, this._pointB.y);
};
return VerletStick;
})();
/* ----------------------------------------------------------------------
EmoticonRoot
*/
var EmoticonRoot,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
EmoticonRoot = (function(_super) {
__extends(EmoticonRoot, _super);
function EmoticonRoot() {
this._sleep = __bind(this._sleep, this);
this._whistle = __bind(this._whistle, this);
this._crash = __bind(this._crash, this);
this.initialize();
this.IS_DEBUG_WIRE = false;
this._emoticon = null;
this._effect = null;
this._background = null;
this._gravityController = null;
}
EmoticonRoot.prototype.init = function() {
var effectRect, emoRect, margin;
margin = 10;
emoRect = new createjs.Rectangle(margin, margin, SCREEN_WIDTH - margin * 2, SCREEN_HEIGHT - margin * 2);
margin = 0;
effectRect = new createjs.Rectangle(margin, margin, SCREEN_WIDTH - margin * 2, SCREEN_HEIGHT - margin * 2);
this._background = new Background();
this.addChild(this._background);
this._background.init();
this._gravityController = new GravityController();
this._gravityController.init();
this.addChild(this._gravityController);
this._emoticon = new Emoticon();
this.addChild(this._emoticon);
this._emoticon.init(emoRect, this._crash, this._whistle, this._sleep);
this._effect = new Effect();
this.addChild(this._effect);
return this._effect.init(effectRect);
};
EmoticonRoot.prototype._crash = function(obj) {
this._emoticon.crash(obj);
return this._effect.crash(obj, {
x: this._emoticon.x,
y: this._emoticon.y
});
};
EmoticonRoot.prototype._whistle = function() {
return this._effect.whistle({
x: this._emoticon.x,
y: this._emoticon.y
});
};
EmoticonRoot.prototype._sleep = function(e) {
return this._effect.sleep({
x: this._emoticon.x,
y: this._emoticon.y
}, e.scale);
};
EmoticonRoot.prototype.update = function() {
var _ref, _ref1, _ref2;
this._gravityController.update();
if ((_ref = this._background) != null) {
_ref.update();
}
if ((_ref1 = this._emoticon) != null) {
_ref1.update();
}
if ((_ref2 = this._effect) != null) {
_ref2.update();
}
};
return EmoticonRoot;
})(createjs.Container);
/* ----------------------------------------------------------------------
Emoticon
*/
var Emoticon,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Emoticon = (function(_super) {
__extends(Emoticon, _super);
function Emoticon() {
this._sleep = __bind(this._sleep, this);
this._whistle = __bind(this._whistle, this);
this.initialize();
this._crashCallback = null;
this._whistleCallback = null;
this._sleepCallback = null;
this._face = null;
this._pts = [];
this._sticks = [];
this._wireCanvas = null;
this._stageRect = null;
this._contourTfs = [];
this._status = null;
this._hitRect = null;
this._dragPt = null;
this._mousePt = null;
this._canvas = null;
}
Emoticon.prototype.init = function(stageRect, crashCallback, whistleCallback, sleepCallback) {
var contourTf, i, initX, initY, pt1, pt2, pt3, pt4, pt5, pt6, pt7, pt8, r, scale, scope, _i, _ref,
_this = this;
this._stageRect = stageRect;
this._crashCallback = crashCallback;
this._whistleCallback = whistleCallback;
this._sleepCallback = sleepCallback;
this._status = new EmoticonStatus({
emoRadius: 50 * 0.7
});
this._status.addEventListener("CRASH", function(e) {
if ((_this._crashCallback != null)) {
return _this._crashCallback(e.obj);
}
});
this._status.addEventListener("STAGGER", function(e) {
return _this._stagger();
});
this._status.addEventListener("ZERO_GRAVITY", function(e) {
return _this._face.zeroGravity();
});
this._status.addEventListener("FALL", function(e) {
return _this._face.fall();
});
this._canvas = new createjs.Shape();
this.addChild(this._canvas);
scale = 0.7;
initX = 200;
initY = 300;
pt1 = this._makePoint("pt1", 50 * scale + initX, 0 + initY);
pt2 = this._makePoint("pt2", 85 * scale + initX, 15 * scale + initY);
pt3 = this._makePoint("pt3", 100 * scale + initX, 50 * scale + initY);
pt4 = this._makePoint("pt4", 85 * scale + initX, 85 * scale + initY);
pt5 = this._makePoint("pt5", 50 * scale + initX, 100 * scale + initY);
pt6 = this._makePoint("pt6", 15 * scale + initX, 85 * scale + initY);
pt7 = this._makePoint("pt7", 0 * scale + initX, 50 * scale + initY);
pt8 = this._makePoint("pt8", 15 * scale + initX, 15 * scale + initY);
this._makeStick(pt1, pt2);
this._makeStick(pt2, pt3);
this._makeStick(pt3, pt4);
this._makeStick(pt4, pt5);
this._makeStick(pt5, pt6);
this._makeStick(pt6, pt7);
this._makeStick(pt7, pt8);
this._makeStick(pt8, pt1);
this._makeStick(pt1, pt5, 0.35);
this._makeStick(pt2, pt6, 0.35);
this._makeStick(pt3, pt7, 0.35);
this._makeStick(pt4, pt8, 0.35);
this._makeStick(pt1, pt3, 0.45);
this._makeStick(pt2, pt4, 0.45);
this._makeStick(pt3, pt5, 0.45);
this._makeStick(pt4, pt6, 0.45);
this._makeStick(pt5, pt7, 0.45);
this._makeStick(pt6, pt8, 0.45);
this._makeStick(pt7, pt1, 0.45);
this._makeStick(pt8, pt2, 0.45);
this._face = new FaceController();
this.addChild(this._face);
this._face.init();
this._face.addEventListener("WHISTLE", this._whistle);
this._face.addEventListener("SLEEP", this._sleep);
for (i = _i = 0, _ref = this._pts.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
contourTf = new createjs.Text(" ─", "14px sans-serif");
contourTf.textAlign = "left";
contourTf.textBaseline = "middle";
this._contourTfs.push(contourTf);
this.addChild(contourTf);
}
if (this.IS_DEBUG_WIRE) {
this._wireCanvas = new createjs.Shape();
this.addChild(this._wireCanvas);
this._wireCanvas.alpha = 0.5;
}
this._hitRect = new createjs.Shape();
this._hitRect.graphics.beginFill("#FFF");
r = IS_IPHONE || IS_ANDROID ? 250 : 150;
this._hitRect.graphics.drawCircle(0, 0, r);
this._hitRect.alpha = 0.01;
this.addChild(this._hitRect);
scope = this;
return this._hitRect.onPress = function(pressEvent) {
scope._onMousePress(pressEvent);
pressEvent.onMouseMove = function(mouseMoveEvent) {
return scope._onMouseMove(mouseMoveEvent);
};
return pressEvent.onMouseUp = function(mouseUpEvent) {
scope._onMouseUp(mouseUpEvent);
this.onMouseMove = null;
return this.onMouseUp = null;
};
};
};
Emoticon.prototype._whistle = function() {
if ((this._whistleCallback != null)) {
return this._whistleCallback({});
}
};
Emoticon.prototype._sleep = function(e) {
if ((this._sleepCallback != null)) {
return this._sleepCallback({
scale: e.obj.scale
});
}
};
Emoticon.prototype.update = function() {
var g, i, j, len, rot, tf, _i, _j, _ref;
this._updatePoints();
this._revisionDistance(this._pts[0], this._pts[4], 1, 1);
this._revisionDistance(this._pts[1], this._pts[5], 1, 1);
this._revisionDistance(this._pts[2], this._pts[6], 1, 1);
this._revisionDistance(this._pts[3], this._pts[7], 1, 1);
this._updateSticks(this._sticks);
this._status.update(this._stageRect);
this._face.scaleX = this._status.scaleX;
this._face.rotation = this._status.rotation + 22.5;
if ((this._dragPt != null)) {
this._dragPt.x = this._mousePt.x;
this._dragPt.y = this._mousePt.y;
}
rot = this._status.rotation;
len = this._contourTfs.length;
for (i = _i = 0; 0 <= len ? _i < len : _i > len; i = 0 <= len ? ++_i : --_i) {
tf = this._contourTfs[i];
tf.x = this._pts[i].x - this._status.x;
tf.y = this._pts[i].y - this._status.y;
tf.rotation = rot;
j = i + 1;
if (j > len - 1) {
j = j - len;
}
tf.rotation = MyMath.getAngle(this._pts[i], this._pts[j]);
tf.scaleX = MyMath.getDistance(this._pts[i], this._pts[j]) / 24;
}
g = this._canvas.graphics;
g.clear();
g.beginFill("#F6F6F6");
g.beginStroke();
g.moveTo(this._pts[0].x, this._pts[0].y);
for (i = _j = 1, _ref = this._pts.length; 1 <= _ref ? _j < _ref : _j > _ref; i = 1 <= _ref ? ++_j : --_j) {
g.lineTo(this._pts[i].x, this._pts[i].y);
}
g.closePath();
this.x = this._status.x;
this.y = this._status.y;
this._canvas.x = -this.x;
this._canvas.y = -this.y;
if ((this._wireCanvas != null)) {
this._wireCanvas.graphics.clear();
this._renderPoints();
return this._renderSticks();
}
};
Emoticon.prototype._makePoint = function(name, xpos, ypos, gRate) {
var point;
if (gRate == null) {
gRate = 0.8;
}
point = new verlet.VerletPoint(xpos, ypos, gRate);
this._status.addPt(name, point);
this._pts.push(point);
return point;
};
Emoticon.prototype._makeStick = function(pointA, pointB, offsetRate, length) {
var stick;
if (length == null) {
length = -1;
}
stick = new verlet.VerletStick(pointA, pointB, offsetRate, length);
this._sticks.push(stick);
return stick;
};
Emoticon.prototype._updatePoints = function() {
var crossIndex, crossPt, i, pt, _i, _ref, _results;
_results = [];
for (i = _i = 0, _ref = this._pts.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
pt = this._pts[i];
crossIndex = i + 4;
if (crossIndex >= this._pts.length) {
crossIndex -= this._pts.length;
}
crossPt = this._pts[crossIndex];
_results.push(this._pts[i].update(this._stageRect, verlet.VerletPoint.TYPE_EMO, crossPt));
}
return _results;
};
Emoticon.prototype._updateSticks = function(arr) {
var i, stick, _i, _ref, _results;
_results = [];
for (i = _i = 0, _ref = arr.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
stick = arr[i];
_results.push(stick.update());
}
return _results;
};
Emoticon.prototype._revisionDistance = function(ptA, ptB, thresholdX, thresholdY) {
var dx, dy;
if (thresholdX == null) {
thresholdX = null;
}
if (thresholdY == null) {
thresholdY = null;
}
if (thresholdX !== null) {
dx = ptA.x - ptB.x;
if (dx < 0) {
dx = -dx;
}
dx = dx - thresholdX;
if (dx < 0) {
ptA.x -= dx / 2;
ptB.x += dx / 2;
}
}
if (thresholdY !== null) {
dy = ptA.y - ptB.y;
if (dy < 0) {
dy = -dy;
}
dy = dy - thresholdY;
if (dy < 0) {
ptA.y -= dy / 2;
return ptB.y += dy / 2;
}
}
};
Emoticon.prototype.crash = function(obj) {
var radian, velocity;
velocity = obj.velocity;
radian = obj.radian;
if (velocity < 20) {
velocity = 20;
}
return this._face.crash();
};
Emoticon.prototype._onMousePress = function(e) {
var nearObj;
this._mousePt = this._getMousePt(e);
nearObj = this._getNearestPt(this._mousePt);
this._dragPt = nearObj.pt;
this._face["catch"]();
return;
};
Emoticon.prototype._onMouseMove = function(e) {
this._mousePt = this._getMousePt(e);
};
Emoticon.prototype._onMouseUp = function(e) {
this._dragPt = null;
};
Emoticon.prototype._getMousePt = function(e) {
var pt;
pt = {};
pt.x = e.stageX;
pt.y = e.stageY;
return pt;
};
Emoticon.prototype._updateDragPt = function(e) {
this._mousePt = this._getMousePt(e);
this._dragPt.x = mousePt.x;
return this._dragPt.y = mousePt.y;
};
Emoticon.prototype._getNearestPt = function(mousePt) {
var distance, i, index, nearestDis, nearstPt, _i, _ref;
index = 0;
nearestDis = 9999;
nearstPt = null;
for (i = _i = 0, _ref = this._pts.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
distance = MyMath.getDistance(this._pts[i], mousePt);
if (distance < nearestDis) {
nearestDis = distance;
nearstPt = this._pts[i];
index = i;
}
}
return {
index: index,
pt: nearstPt,
distance: nearestDis
};
};
Emoticon.prototype._stagger = function() {
return this._face.stagger();
};
Emoticon.prototype._renderPoints = function() {
var i, _i, _ref, _results;
if ((this._wireCanvas != null)) {
_results = [];
for (i = _i = 0, _ref = this._pts.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
_results.push(this._pts[i].render(this._wireCanvas.graphics));
}
return _results;
}
};
Emoticon.prototype._renderSticks = function() {
var i, stick, _i, _ref, _results;
if ((this._wireCanvas != null)) {
_results = [];
for (i = _i = 0, _ref = this._sticks.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
stick = this._sticks[i];
_results.push(stick.render(this._wireCanvas.graphics));
}
return _results;
}
};
return Emoticon;
})(createjs.Container);
/* ----------------------------------------------------------------------
表情制御
*/
var FaceController,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
FaceController = (function(_super) {
__extends(FaceController, _super);
function FaceController() {
this.initialize();
EventDispatcher.init(this);
this._tf = null;
this._eyeR = null;
this._eyeL = null;
this._mouth = null;
this._isMouthAnimation = false;
this._isEyeAnimation = false;
this._whistleTimer = null;
this._blinkTimer = null;
this._sleepCount = 0;
}
FaceController.prototype.init = function() {
this._eyeL = new createjs.Container();
this.addChild(this._eyeL);
this._eyeL.tf = this._createTf("・");
this._eyeL.addChild(this._eyeL.tf);
this._eyeL.x = -19;
this._eyeR = new createjs.Container();
this.addChild(this._eyeR);
this._eyeR.tf = this._createTf("・");
this._eyeR.addChild(this._eyeR.tf);
this._eyeR.x = 19;
this._mouth = new createjs.Container();
this.addChild(this._mouth);
this._mouth.tf = this._createTf("-");
this._mouth.addChild(this._mouth.tf);
return this._mouth.y = 4;
};
FaceController.prototype._createTf = function(str) {
var tf;
tf = new createjs.Text(str, "20px sans-serif");
tf.textAlign = "center";
tf.textBaseline = "middle";
tf.name = Math.random();
return tf;
};
FaceController.prototype.crash = function() {
var _this = this;
this._isMouthAnimation = true;
this._isEyeAnimation = true;
this._sleepCount = 0;
this._crashEye(this._eyeL);
this._crashEye(this._eyeR);
this._setTf(this._mouth, "皿");
return createjs.Tween.get(this._mouth.tf, {
override: true
}).wait(1000).set({
text: "~"
}).wait(1000).call(function() {
return _this._reset();
});
};
FaceController.prototype._crashEye = function(tar) {
this._setTf(tar, "×");
return createjs.Tween.get(tar.tf, {
override: true
}).wait(1000).set({
text: "・"
}).wait(400).set({
text: "-"
}).wait(100).set({
text: "・"
}).wait(100).set({
text: "-"
}).wait(100).set({
text: "・"
});
};
FaceController.prototype.stagger = function() {
var _this = this;
this._isMouthAnimation = true;
this._isEyeAnimation = true;
this._sleepCount = 0;
this._staggerEye(this._eyeL);
this._staggerEye(this._eyeR);
this._setTf(this._mouth, "~");
return createjs.Tween.get(this._mouth.tf, {
override: true
}).wait(2500).call(function() {
return _this._reset();
});
};
FaceController.prototype._staggerEye = function(tar) {
this._setTf(tar, "@");
return createjs.Tween.get(tar.tf, {
override: true
}).to({
rotation: -360 * 4
}, 2300, createjs.Ease.sineOut).to({
scaleX: 0.2,
scaleY: 0.2
}, 200, createjs.Ease.sineOut).set({
text: "・",
scaleX: 1,
scaleY: 1
});
};
FaceController.prototype["catch"] = function() {
var _this = this;
this._isMouthAnimation = true;
this._isEyeAnimation = true;
this._sleepCount = 0;
this._catchEye(this._eyeL);
this._catchEye(this._eyeR);
this._setTf(this._mouth, "o");
return createjs.Tween.get(this._mouth.tf, {
override: true
}).wait(1000).set({
text: "-"
}).wait(600).call(function() {
return _this._reset();
});
};
FaceController.prototype._catchEye = function(tar) {
this._setTf(tar, "*");
return createjs.Tween.get(tar.tf, {
override: true
}).wait(1000).set({
text: "-"
}).wait(100).set({
text: "・"
}).wait(400).set({
text: "-"
}).wait(100).set({
text: "・"
});
};
FaceController.prototype.fall = function() {
var _this = this;
this._isMouthAnimation = true;
this._isEyeAnimation = true;
this._sleepCount = 0;
this._fallEye(this._eyeL);
this._fallEye(this._eyeR);
this._setTf(this._mouth, "益");
return createjs.Tween.get(this._mouth.tf, {
override: true
}).wait(1200).set({
text: "-"
}).call(function() {
return _this._reset();
});
};
FaceController.prototype._fallEye = function(tar) {
this._setTf(tar, "◉");
return createjs.Tween.get(tar.tf, {
override: true
}).wait(1000).to({
scaleX: 0.3,
scaleY: 0.3
}, 200, createjs.Ease.sineOut).set({
text: "・",
scaleX: 1,
scaleY: 1
});
};
FaceController.prototype._blink = function() {
var _this = this;
if (this._isEyeAnimation) {
return;
}
this._blinkEye(this._eyeL);
this._blinkEye(this._eyeR);
if ((this._blinkTimer != null)) {
clearTimeout(this._blinkTimer);
}
return this._blinkTimer = setTimeout(function() {
return _this._blink();
}, Math.random() * 3000 + 1000);
};
FaceController.prototype._blinkEye = function(tar) {
this._setTf(tar, "-");
return createjs.Tween.get(tar.tf, {
override: true
}).wait(200).set({
text: "・"
});
};
FaceController.prototype._whistle = function() {
var endWait, isReplay, loopCount,
_this = this;
this._sleepCount++;
if (this._sleepCount > 5) {
this._sleep();
return;
}
if (this._isMouthAnimation) {
return;
}
this._isMouthAnimation = true;
this._setTf(this._eyeL, "・");
this._setTf(this._eyeR, "・");
this._setTf(this._mouth, "ε");
loopCount = Math.random() * 3 + 1;
if (Math.random() > 0.4) {
isReplay = true;
endWait = 750;
} else {
isReplay = false;
endWait = 1000;
}
return createjs.Tween.get(this._mouth.tf, {
override: true
}).wait(250).to({
scaleX: 1.6,
scaleY: 1.6
}, 250, createjs.Ease.cubicIn).call(function() {
return _this.dispatchEvent({
type: "WHISTLE",
obj: {}
});
}).to({
scaleX: 1,
scaleY: 1
}, 250, createjs.Ease.cubicOut).wait(500).to({
scaleX: 1.6,
scaleY: 1.6
}, 250, createjs.Ease.cubicIn).call(function() {
return _this.dispatchEvent({
type: "WHISTLE",
obj: {}
});
}).to({
scaleX: 1.2,
scaleY: 1.2
}, 150, createjs.Ease.cubicOut).to({
scaleX: 1.6,
scaleY: 1.6
}, 150, createjs.Ease.cubicIn).call(function() {
return _this.dispatchEvent({
type: "WHISTLE",
obj: {}
});
}).to({
scaleX: 1,
scaleY: 1
}, 250, createjs.Ease.cubicOut).wait(endWait).call(function() {
if (isReplay) {
return _this._replayWhistle();
} else {
return _this._reset();
}
});
};
FaceController.prototype._replayWhistle = function() {
this._isMouthAnimation = false;
return this._whistle();
};
FaceController.prototype._sleep = function() {
var _this = this;
this._isMouthAnimation = true;
this._isEyeAnimation = true;
if (this._sleepCount !== -1) {
this._sleepEye(this._eyeL);
this._sleepEye(this._eyeR);
}
this._sleepCount = 0;
this._setTf(this._mouth, "_");
return createjs.Tween.get(this._mouth.tf, {
override: true
}).wait(500).call(function() {
return _this.dispatchEvent({
type: "SLEEP",
obj: {
scale: 1
}
});
}).wait(200).call(function() {
return _this.dispatchEvent({
type: "SLEEP",
obj: {
scale: 0.7
}
});
}).wait(200).call(function() {
return _this.dispatchEvent({
type: "SLEEP",
obj: {
scale: 0.4
}
});
}).wait(2000).call(function() {
_this._sleepCount = -1;
return _this._sleep();
});
};
FaceController.prototype._sleepEye = function(tar) {
this._setTf(tar, "u", 0.2);
return createjs.Tween.get(tar.tf, {
override: true
}).to({
scaleX: 1,
scaleY: 1
}, 500, createjs.Ease.sineOut);
};
FaceController.prototype.zeroGravity = function() {
var _this = this;
this._isMouthAnimation = true;
this._isEyeAnimation = true;
this._zeroGravityEye(this._eyeL);
this._zeroGravityEye(this._eyeR);
this._setTf(this._mouth, "д");
return createjs.Tween.get(this._mouth.tf, {
override: true
}).wait(1200).set({
text: "-"
}).wait(400).call(function() {
return _this._reset();
});
};
FaceController.prototype._zeroGravityEye = function(tar) {
this._setTf(tar, "o", 0.3);
return createjs.Tween.get(tar.tf, {
override: true
}).to({
scaleX: 1,
scaleY: 1
}, 200, createjs.Ease.backOut).wait(1000).to({
scaleX: 0.3,
scaleY: 0.3
}, 200, createjs.Ease.sineOut).set({
text: "・",
scaleX: 1,
scaleY: 1
});
};
FaceController.prototype._reset = function() {
var _this = this;
this._isMouthAnimation = false;
this._isEyeAnimation = false;
this._setTf(this._mouth, "-");
this._setTf(this._eyeL, "・");
this._setTf(this._eyeR, "・");
if ((this._whistleTimer != null)) {
clearTimeout(this._whistleTimer);
}
this._whistleTimer = setTimeout(function() {
return _this._whistle();
}, Math.random() * 2000 + 1000);
if ((this._blinkTimer != null)) {
clearTimeout(this._blinkTimer);
}
return this._blinkTimer = setTimeout(function() {
return _this._blink();
}, Math.random() * 1000 + 500);
};
FaceController.prototype._setTf = function(tar, str, scale, rot) {
if (scale == null) {
scale = 1;
}
if (rot == null) {
rot = 0;
}
createjs.Tween.get(tar.tf, {
override: true
});
createjs.Tween.removeTweens(tar.tf);
tar.tf.text = str;
tar.tf.scaleX = scale;
tar.tf.scaleY = scale;
return tar.tf.rotation = rot;
};
return FaceController;
})(createjs.Container);
/* ----------------------------------------------------------------------
顔文字ステータス
*/
var EmoticonStatus;
EmoticonStatus = (function() {
function EmoticonStatus(obj) {
EventDispatcher.init(this);
this.x = this._oldX = 0;
this.y = this._oldY = 0;
this.rotation = this._oldRot = 0;
this.scaleX = 0;
this._ptObj = {};
this._radius = obj.emoRadius;
this._oldVelocity = 0;
this._oldX = 0;
this._oldY = 0;
this._isCrash = false;
this._rotationRate = 0;
this._oldRotation = 0;
this._rotCount = 0;
this._isZeroGravity = false;
this._zeroGravityCount = 0;
this._isFall = false;
}
EmoticonStatus.prototype.addPt = function(name, pt) {
return this._ptObj[name] = pt;
};
EmoticonStatus.prototype.update = function(rect) {
var degree, diff, radian, rot, velocity,
_this = this;
this.x = MyMath.getMidpoint(this._ptObj["pt3"], this._ptObj["pt7"]).x;
this.y = MyMath.getMidpoint(this._ptObj["pt1"], this._ptObj["pt5"]).y;
this.scaleX = MyMath.getDistance(this._ptObj["pt7"], this._ptObj["pt3"]) * 0.0142;
this.rotation = MyMath.getAngle(this._ptObj["pt7"], this._ptObj["pt3"]);
velocity = MyMath.getDistance({
x: this.x,
y: this.y
}, {
x: this._oldX,
y: this._oldY
});
if (!this._isCrash && (rect != null)) {
if (velocity > 15) {
radian = MyMath.getRadian({
x: this._oldX,
y: this._oldY
}, {
x: this.x,
y: this.y
});
degree = radian * 180 / 3.1415;
if (degree < 0) {
degree += 360;
}
degree = 360 - degree;
if (degree < 45 || degree > 315) {
if (this.x > rect.width - this._radius) {
this._isCrash = true;
}
} else if (degree < 135) {
if (this.y < rect.y + this._radius) {
this._isCrash = true;
}
} else if (degree < 225) {
if (this.x < rect.x + this._radius) {
this._isCrash = true;
}
} else {
if (this.y > rect.height - this._radius) {
this._isCrash = true;
}
}
}
if (this._isCrash) {
this.dispatchEvent({
type: "CRASH",
obj: {
velocity: this._oldVelocity,
radian: radian
}
});
setTimeout(function(e) {
return _this._isCrash = false;
}, 500);
}
}
this._oldVelocity = velocity;
this._oldX = this.x;
this._oldY = this.y;
rot = this.rotation;
if (rot < 0) {
rot += 360;
}
if (this._oldRotation < 0) {
this._oldRotation += 360;
}
if (rot > 270 && this._oldRotation < 90) {
rot -= 360;
} else if (this._oldRotation > 270 && rot < 90) {
this._oldRotation -= 360;
}
diff = rot - this._oldRotation;
if (diff < 0) {
diff = -diff;
}
if (diff > 15) {
this._rotCount++;
if (this._rotCount > 8) {
this._rotCount = 0;
this.dispatchEvent({
type: "STAGGER",
obj: {}
});
}
} else if (this._rotCount > 0) {
this._rotCount--;
}
this._oldRotation = this.rotation;
if (GravityStatus.isZeroGravity) {
if (!this._isZeroGravity) {
this._zeroGravityCount++;
if (this._zeroGravityCount > 5) {
this._isZeroGravity = true;
this.dispatchEvent({
type: "ZERO_GRAVITY",
obj: {}
});
}
}
} else {
this._isZeroGravity = false;
this._zeroGravityCount = 0;
}
if (velocity > 25) {
if (!this._isFall) {
this._isFall = true;
return this.dispatchEvent({
type: "FALL",
obj: {}
});
}
} else {
return this._isFall = false;
}
};
return EmoticonStatus;
})();
/* ----------------------------------------------------------------------
エフェクト制御
*/
var Effect,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Effect = (function(_super) {
__extends(Effect, _super);
function Effect() {
this.initialize();
this._stageRect = null;
this._particlePts = [];
this._particles = [];
this._particleIndex = 0;
}
Effect.prototype.init = function(stageRect) {
var i, _i, _results;
this._stageRect = stageRect;
_results = [];
for (i = _i = 0; _i < 10; i = ++_i) {
_results.push(this._createParticle());
}
return _results;
};
Effect.prototype._createParticle = function() {
var particle, particlePt, particleTf;
particlePt = new verlet.VerletPoint(100, 100, 0.8);
this._particlePts.push(particlePt);
particleTf = new createjs.Text("☆", "14px sans-serif");
particleTf.x = -7;
particleTf.y = -10;
particle = new createjs.Container();
particle.visible = false;
particle.addChild(particleTf);
particle.tf = particleTf;
this._particles.push(particle);
return this.addChild(particle);
};
Effect.prototype.crash = function(obj, emoPt) {
var cos, i, num, particle, particleObj, pt, rad, rate, sin, _i, _results;
num = ~~(obj.velocity / 10);
if (num >= 3) {
num = 3;
}
_results = [];
for (i = _i = 0; 0 <= num ? _i < num : _i > num; i = 0 <= num ? ++_i : --_i) {
particleObj = this._getNextParticle();
pt = particleObj.pt;
rad = obj.radian + 1.57 * 2 + (Math.random() * 0.78 - 0.39);
cos = Math.cos(rad);
sin = Math.sin(rad);
rate = Math.random() * 0.5 + 0.5;
pt.changeState(emoPt.x, emoPt.y, 0.8);
pt.setVelocity(cos * obj.velocity * rate, sin * obj.velocity * rate);
particle = particleObj.particle;
if (Math.random() > 0.5) {
particle.tf.text = "☆";
} else {
particle.tf.text = "★";
}
particle.scaleX = particle.scaleY = Math.random() * 0.8 + 0.5;
_results.push(createjs.Tween.get(particle, {
override: true
}).wait(1000).to({
alpha: 0
}, 500, createjs.Ease.sineOut).set({
visible: false
}));
}
return _results;
};
Effect.prototype.whistle = function(emoPt) {
var particle, particleObj, pt, tarScale;
particleObj = this._getNextParticle();
pt = particleObj.pt;
pt.changeState(emoPt.x, emoPt.y, -0.1);
pt.setVelocity(Math.random() * 10 - 5, Math.random() * 10 - 5);
particle = particleObj.particle;
if (Math.random() > 0.4) {
particle.tf.text = "♪";
} else {
particle.tf.text = "♫";
}
particle.scaleX = particle.scaleY = 0;
tarScale = Math.random() * 0.5 + 1.2;
if (GravityStatus.isCosme) {
particle.rotation = Math.random() * 360;
} else {
particle.rotation = (360 - GravityStatus.angle - 90) + Math.random() * 80 - 40;
}
return createjs.Tween.get(particle, {
override: true
}).to({
scaleX: tarScale,
scaleY: tarScale
}, 200, createjs.Ease.backOut).wait(800).to({
alpha: 0
}, 500, createjs.Ease.sineOut).set({
visible: false
});
};
Effect.prototype.sleep = function(emoPt, myScale) {
var angle, particle, particleObj, pt, rad, tarScale, vX, vY;
particleObj = this._getNextParticle();
pt = particleObj.pt;
pt.changeState(emoPt.x, emoPt.y, -0.01);
if (GravityStatus.isCosme) {
angle = Math.random() * 360;
} else {
angle = (360 - GravityStatus.angle - 180) + (Math.random() * 40 - 20);
}
rad = angle * 3.1415 / 180;
vX = Math.cos(rad) * 5 * myScale;
vY = Math.sin(rad) * 5 * myScale;
pt.setVelocity(vX, vY);
particle = particleObj.particle;
particle.tf.text = "z";
particle.scaleX = particle.scaleY = 0;
tarScale = myScale + 0.6;
particle.rotation = (360 - angle - 90) + Math.random() * 80 - 40;
return createjs.Tween.get(particle, {
override: true
}).to({
scaleX: tarScale,
scaleY: tarScale
}, 200, createjs.Ease.backOut).wait(800).to({
alpha: 0
}, 500, createjs.Ease.sineOut).set({
visible: false
});
};
Effect.prototype._getNextParticle = function() {
var particleObj;
particleObj = {};
this._particleIndex++;
if (this._particleIndex >= this._particlePts.length) {
this._particleIndex = 0;
}
particleObj.pt = this._particlePts[this._particleIndex];
particleObj.particle = this._particles[this._particleIndex];
particleObj.particle.visible = true;
particleObj.particle.alpha = 1;
return particleObj;
};
Effect.prototype.update = function() {
var i, particle, _i, _ref, _results;
_results = [];
for (i = _i = 0, _ref = this._particles.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
particle = this._particles[i];
if (particle.visible) {
this._particlePts[i].update(this._stageRect);
particle.x = this._particlePts[i].x;
_results.push(particle.y = this._particlePts[i].y);
} else {
_results.push(void 0);
}
}
return _results;
};
return Effect;
})(createjs.Container);
/* ----------------------------------------------------------------------
背景制御
*/
var Background,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Background = (function(_super) {
__extends(Background, _super);
function Background() {
this.initialize();
this._angleGround = 0;
this._angleMountain = 0;
this._groundSpr = null;
this._mountainSpr = null;
this._cosmo = null;
this._rateGround = 0;
this._rateMountain = 0;
this._tempAlpha = 1;
this._alpha = 1;
}
Background.prototype.init = function() {
var g, mountainFill, mountainSpr, mountainTexts, mountainTf, rect, saturnSpr, saturnTexts, spr, starSpr, starTexts, tfA, tfB;
this.x = SCREEN_WIDTH / 2;
this.y = SCREEN_HEIGHT / 2;
this._cosmo = new createjs.Container();
this.addChild(this._cosmo);
saturnTexts = [
" ,,,,--、 ",
" ,,/ フ丿 ",
" ,,,,r――-、,,, ./,/ / ",
" .,,ll゙”;;;;;; !レ.,,/ ",
" /゜;;;;;; / ",
" ,!;;;;;;;; /゙`;|` ",
" !;;;;;;;;;; / ;;;;;l゙ ",
" 、.',;;;;;;;;;::::; / ;;;;;;;;;,ノ ",
" .,x'゙'/ 、 ,,,,/ ;;;;;;;;;;;;;;;,,r° ",
" ,,' / r',/ -、_;;;;;_.,,,-''″ ",
" : / i_/ / ", " ..!、二‐'' "
];
saturnSpr = new createjs.Container();
this._createTfs(saturnTexts, saturnSpr, -200, -200, "#999", 19);
this._cosmo.addChild(saturnSpr);
starTexts = [
" ' + ",
" . ゚ 。 ゚",
" ",
" ゚ . 。 +",
" ゜ 。 。 ゚ ",
"。",
" ☆ ",
" +. 。 ",
" 。",
" ",
" 。 ゜",
" 。 ゚ ゚' ",
" . ☆ ",
" ",
" ",
" * . ゜ ",
" + 。 ゜",
" ゚ . + ",
" 。 ",
" +"
];
starSpr = new createjs.Container();
this._createTfs(starTexts, starSpr, -200, -200, "#AAA", 20);
this._cosmo.addChild(starSpr);
this._mountainSpr = new createjs.Container();
this.addChild(this._mountainSpr);
mountainSpr = new createjs.Container();
mountainFill = new createjs.Shape();
g = mountainFill.graphics;
g.beginLinearGradientFill(["#E6E6E6", "#EEE"], [0, 1], 0, -76.9, 0, 77).beginStroke().moveTo(114, -46).lineTo(138, -46).lineTo(234, 78).lineTo(-234, 78).lineTo(-150, -30).lineTo(-126, -30).lineTo(-72.2, 39.2).lineTo(18, -78).lineTo(42, -78).lineTo(90.2, -15.3).closePath();
mountainFill.scaleX = 1.165;
mountainFill.scaleY = 1.03;
mountainFill.x = 31;
mountainFill.y = 95;
mountainSpr.addChild(mountainFill);
mountainTexts = [
" __ ",
" / \",
" / \ __",
" __ / \ / \",
" / \ / \/ \",
" / \ / \ \",
" / \ / \ \",
"/ \ / \ \"
];
mountainTf = this._createTfs(mountainTexts, mountainSpr, -200, 0);
this._mountainSpr.addChild(mountainTf);
this._mountainSpr.spr = mountainTf;
this._groundSpr = new createjs.Container();
this.addChild(this._groundSpr);
spr = new createjs.Container();
this._groundSpr.addChild(spr);
this._groundSpr.spr = spr;
rect = new createjs.Shape();
rect.graphics.beginFill("#F3F3F3");
rect.graphics.drawRect(-300, 0, 600, 400);
spr.addChild(rect);
tfA = new createjs.Text("'\"\"'~\"'~ ''\"\"'~'~\"'~ ''\"\"'~~\"'~ ''\"\"'~\"'~ ''\"\"'~'~\"'~ ''\"\"'~~\"'~ ''\"\"''\"\"'~\"'~ ''\"\"'~'~\"'~ ''\"\"'~~\"'~ ''\"\"~ ''\"\"'~'~\"'~ ''\"\"'~~", "14px sans-serif", "#BBB");
tfA.textAlign = "center";
tfA.textBaseline = "middle";
spr.addChild(tfA);
tfB = new createjs.Text(" ::'' ::'' ;,\"' ::'' ;,\"' ", "14px sans-serif", "#BBB");
tfB.textAlign = "center";
tfB.textBaseline = "middle";
tfB.y = 20;
return spr.addChild(tfB);
};
Background.prototype._createTfs = function(texts, spr, baseX, baseY, color, lineHeight) {
var i, tf, _i, _ref;
if (baseX == null) {
baseX = 0;
}
if (baseY == null) {
baseY = 0;
}
if (color == null) {
color = "#CCC";
}
if (lineHeight == null) {
lineHeight = 16;
}
for (i = _i = 0, _ref = texts.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
if (texts[i] !== "") {
tf = new createjs.Text(texts[i], "14px sans-serif", color);
tf.x = baseX;
tf.y = lineHeight * i + baseY;
spr.addChild(tf);
}
}
return spr;
};
Background.prototype.update = function() {
var diffAngleGround, diffAngleMountain, graAngle, graRate, tarAlpha, tarAngle;
graRate = GravityStatus.gravityRate;
graAngle = GravityStatus.angle;
tarAngle = this._getAngleRange(180 - graAngle + 90);
if (GravityStatus.isCosme) {
tarAlpha = 0;
} else {
tarAlpha = 1;
}
this._tempAlpha += (tarAlpha - this._tempAlpha) * 0.2;
this._alpha += (this._tempAlpha - this._alpha) * 0.2;
this._mountainSpr.alpha = this._alpha;
this._groundSpr.alpha = this._alpha;
this._cosmo.alpha = 1 - this._alpha;
diffAngleMountain = this._correctionAngle(this._angleMountain, tarAngle);
this._angleMountain += diffAngleMountain * 0.2;
this._angleMountain = this._getAngleRange(this._angleMountain);
this._mountainSpr.rotation = this._angleMountain;
diffAngleGround = this._correctionAngle(this._angleGround, tarAngle);
if (diffAngleMountain > 40) {
if (diffAngleGround < 0) {
diffAngleGround += 360;
}
}
if (diffAngleMountain < -40) {
if (diffAngleGround > 0) {
diffAngleGround -= 360;
}
}
this._angleGround += diffAngleGround * 0.15;
this._angleGround = this._getAngleRange(this._angleGround);
this._groundSpr.rotation = this._angleGround;
this._rateMountain += (graRate - this._rateMountain) * 0.13;
this._mountainSpr.spr.y = 10 + 250 * (1 - this._rateMountain);
this._rateGround += (graRate - this._rateGround) * 0.08;
return this._groundSpr.spr.y = 110 + 220 * (1 - this._rateGround);
};
Background.prototype._getAngleRange = function(angle) {
while (angle > 360) {
angle -= 360;
}
while (angle < 0) {
angle += 360;
}
return angle;
};
Background.prototype._correctionAngle = function(current, target) {
if (target > 270 && current < 90) {
target -= 360;
} else if (current > 270 && target < 90) {
current -= 360;
}
return target - current;
};
return Background;
})(createjs.Container);
/* ----------------------------------------------------------------------
重力ステータス
*/
var GravityStatus;
GravityStatus = (function() {
function GravityStatus() {}
GravityStatus.MIN_X = "min_x";
GravityStatus.MAX_X = "max_x";
GravityStatus.MIN_Y = "min_y";
GravityStatus.MAX_Y = "max_y";
GravityStatus.MAX = 40;
GravityStatus.FREE = 5;
GravityStatus.gravityX = 0;
GravityStatus.gravityY = 0;
GravityStatus.frictionX = 0;
GravityStatus.frictionY = 0;
GravityStatus.angle = 0;
GravityStatus.gravityRate = 0.5;
GravityStatus.cosmeThreshold = 0.05;
GravityStatus.isCosme = false;
GravityStatus.isZeroGravity = false;
GravityStatus.update = function(gravityX, gravityY) {
var absGX, absGY, angle, gX, gY, max, min, rate;
gX = gravityX;
gY = -gravityY;
if (gX < 0) {
absGX = -gX;
gX += this.FREE;
if (gX > 0) {
gX = gX * 0.01;
}
} else {
absGX = gX;
gX -= this.FREE;
if (gX < 0) {
gX = gX * 0.01;
}
}
if (gY < 0) {
absGY = -gY;
gY += this.FREE;
if (gY > 0) {
gY = gY * 0.01;
}
} else {
absGY = gY;
gY -= this.FREE;
if (gY < 0) {
gY = gY * 0.01;
}
}
if (absGX < absGY) {
GravityStatus.frictionX = 1;
GravityStatus.frictionY = absGX / absGY;
} else {
GravityStatus.frictionX = absGY / absGX;
GravityStatus.frictionY = 1;
}
max = 6;
min = -6;
gX = gX / (this.MAX - this.FREE * 2) * max;
gY = gY / (this.MAX - this.FREE * 2) * min;
if (gX > max) {
gX = max;
}
if (gX < min) {
gX = min;
}
if (gY > max) {
gY = max;
}
if (gY < min) {
gY = min;
}
GravityStatus.gravityX = gX;
GravityStatus.gravityY = gY;
angle = MyMath.getAngle({
x: 0,
y: 0
}, {
x: gX,
y: -gY
});
if (angle < 0) {
angle += 360;
}
GravityStatus.angle = angle;
rate = ((absGX + absGY) - this.FREE * 2) / 20;
if (rate < 0) {
rate = 0;
}
if (rate > 1) {
rate = 1;
}
GravityStatus.gravityRate = rate;
if (this.gravityRate < this.cosmeThreshold) {
this.isCosme = true;
this.isZeroGravity = true;
} else {
this.isCosme = false;
}
if (this.gravityRate > 0.5) {
return this.isZeroGravity = false;
}
};
return GravityStatus;
})();
/* ----------------------------------------------------------------------
重力制御
*/
var GravityController,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
GravityController = (function(_super) {
__extends(GravityController, _super);
function GravityController() {
this._onMousePress = __bind(this._onMousePress, this);
this.initialize();
this._gravityX = 0;
this._gravityY = 0;
this._tarX = 0;
this._tarY = 22;
}
GravityController.prototype.init = function() {
var hitRect,
_this = this;
if (IS_IPHONE || IS_ANDROID) {
return window.addEventListener('deviceorientation', function(e) {
_this._gravityX = e.gamma;
return _this._gravityY = e.beta;
});
} else {
hitRect = new createjs.Shape();
hitRect.graphics.beginFill("#FFF");
hitRect.graphics.drawRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
hitRect.alpha = 0.01;
this.addChild(hitRect);
return hitRect.onPress = function(pressEvent) {
return _this._onMousePress(pressEvent);
};
}
};
GravityController.prototype._onMousePress = function(e) {
var hH, hW;
hW = SCREEN_WIDTH / 2;
hH = SCREEN_HEIGHT / 2;
this._tarX = (e.stageX - hW) / hW * GravityStatus.MAX;
this._tarY = (e.stageY - hH) / hH * GravityStatus.MAX;
return;
};
GravityController.prototype.update = function() {
if (!IS_IPHONE && !IS_ANDROID) {
this._gravityX += (this._tarX - this._gravityX) * 0.4;
this._gravityY += (this._tarY - this._gravityY) * 0.4;
}
return GravityStatus.update(this._gravityX, this._gravityY);
};
return GravityController;
})(createjs.Container);
//
koh5_pano
Drag mouse to navigate.
Navigation
- Left/Right Mouse drag: Changes camera heading.
- Up/Sown Mouse drag: Changes camera pitch.
- Scroll wheel: Changes camera field of view.
- I-Key: Displays Info panel with canvas size, image size and FPS.
17.Aug.2010, Martin Wengenmayer