User prompt
No red screen
User prompt
No red screen
User prompt
If the snake touch the wall don't end game
User prompt
When the snake touch dot it size increase
User prompt
Snake can move Left Right as user wants
User prompt
Snake can move Left Right as user wants
User prompt
Snake move where the user wants
User prompt
No game over
Initial prompt
Snake
===================================================================
--- original.js
+++ change.js
@@ -99,28 +99,34 @@
LK.gui.top.addChild(scoreTxt);
// Handle touch events to change snake direction
game.down = function (x, y, obj) {
var head = snake.body[0];
- if (x < head.x) {
- snake.direction = {
- x: -1,
- y: 0
- }; // Move left
- } else if (x > head.x) {
- snake.direction = {
- x: 1,
- y: 0
- }; // Move right
- } else if (y < head.y) {
- snake.direction = {
- x: 0,
- y: -1
- }; // Move up
- } else if (y > head.y) {
- snake.direction = {
- x: 0,
- y: 1
- }; // Move down
+ var dx = x - head.x;
+ var dy = y - head.y;
+ if (Math.abs(dx) > Math.abs(dy)) {
+ if (dx > 0) {
+ snake.direction = {
+ x: 1,
+ y: 0
+ }; // Move right
+ } else {
+ snake.direction = {
+ x: -1,
+ y: 0
+ }; // Move left
+ }
+ } else {
+ if (dy > 0) {
+ snake.direction = {
+ x: 0,
+ y: 1
+ }; // Move down
+ } else {
+ snake.direction = {
+ x: 0,
+ y: -1
+ }; // Move up
+ }
}
};
// Update game logic
game.update = function () {