===================================================================
--- original.js
+++ change.js
@@ -43,9 +43,9 @@
segment.rotation = lastSegmentPosition.rotation;
this.bodySegments.push(segment);
return segment;
};
- self.move = function () {
+ self._move_migrated = function () {
var targetRotation = Math.atan2(self.direction.y, self.direction.x);
var rotationDifference = targetRotation - self.rotation;
while (rotationDifference < -Math.PI) {
rotationDifference += 2 * Math.PI;
@@ -116,9 +116,9 @@
/****
* Game Code
****/
-game.on('up', function (obj) {
+game.on('up', function (x, y, obj) {
if (touchIndicator) {
touchIndicator.destroy();
touchIndicator = null;
}
@@ -168,11 +168,11 @@
var touchIndicator = null;
var fingerIndicator = null;
var isMouseDown = false;
var maxDistance = 200;
-game.on('down', function (obj) {
- var event = obj.event;
- initialTouchPosition = event.getLocalPosition(game);
+game.on('down', function (x, y, obj) {
+ var event = obj;
+ initialTouchPosition = game.toLocal(event.global);
if (touchIndicator) {
touchIndicator.destroy();
}
if (fingerIndicator) {
@@ -187,9 +187,9 @@
isMouseDown = true;
});
function handleMove(obj) {
var event = obj.event;
- var currentTouchPosition = event.getLocalPosition(game);
+ var currentTouchPosition = game.toLocal(event.global);
var dx = currentTouchPosition.x - initialTouchPosition.x;
var dy = currentTouchPosition.y - initialTouchPosition.y;
var distance = Math.sqrt(dx * dx + dy * dy) * 0.7;
if (distance > maxDistance) {
@@ -205,11 +205,14 @@
snake.direction.x = dx;
snake.direction.y = dy;
}
}
-game.on('move', handleMove);
+game.on('move', function (x, y, obj) {
+ obj.event = obj;
+ handleMove(obj);
+});
LK.on('tick', function () {
- snake.move();
+ snake._move_migrated();
for (var i = 0; i < foods.length; i++) {
var snakeHeadRadius = snake.width / 2;
var foodRadius = foods[i].width / 2;
var dx = snake.x - foods[i].x;
Single, Anaconda snake head segment. Seen from above. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
White circular touch indicator. White button like look. Game asset. No background. 2d. No shadow.
Single snake head segment. Seen from above. Cartoon.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Single snake head segment. Seen from above. Cartoon. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.