Page 442 - 완) I MDP 프로젝트 작품 보고서(전체과 1학년)1.6
P. 442
var thisCupsPosition = this.kineticImage.position();
var otherCupsPosition = otherCup.KineticImage.position();
var xDistance = Math.abs(otherCupsPosition.x - thisCupsPosition.x);
var yDistance = Math.abs(otherCupsPosition.y - thisCupsPosition.y);
if (otherCupsPosition.x < thisCupsPosition.x) {
xDistance = xDistance * (-1);
}
if (otherCupsPosition.y < thisCupsPosition.y) {
yDistance = yDistance * (-1);
}
this.move(speed, 0, xDistance, yDistance, this, function () {
_this.isSwapInProgress = false;
if (!otherCup.IsSwapInProgress) {
onSwapDone();
}
});
otherCup.move(speed, 0, (-1) * xDistance, (-1) * yDistance, otherCup, function
() {
otherCup.IsSwapInProgress = false;
if (!_this.isSwapInProgress) {
onSwapDone();
}
});
}
};
Cup.prototype.move = function (speed, progress, xDistance, yDistance, self, callBack) {
if (progress < speed) {
var xStep = xDistance / speed;
var yStep = yDistance / speed;
self.KineticImage.move({
x: xStep,
y: yStep
});
if (self.hasBall) {
self.ball.KineticImage.move({
x: xStep,
y: yStep
});
}
self.game.layer.draw();
- 435 -