Code edit (2 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Allow spawning multiple food at once, configure a global variable which stores the default number to spawn
User prompt
Migrate to the latest version of LK
User prompt
Make the snake five times as fast.
User prompt
Make it ten times slower.
User prompt
Make the snake four times as fast.
User prompt
Make the snake 2x as fast
User prompt
Make the snake 5x slower
User prompt
Do number 3
User prompt
Ensure food never spawns on the margin
===================================================================
--- original.js
+++ change.js
@@ -1,7 +1,7 @@
/****
* Classes
-****/
+****/
var Dot = Container.expand(function () {
var self = Container.call(this);
var dotGraphics = self.attachAsset('dot', {
anchorX: 0.5,
@@ -27,9 +27,9 @@
});
self.length = 1;
self.direction = 'right';
self.body = [];
- self.move = function () {
+ self._move_migrated = function () {
var gridSize = 100;
var oldHeadPosition = {
x: snakeGraphics.x,
y: snakeGraphics.y
@@ -100,16 +100,16 @@
});
/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
-****/
+****/
var gridSize = 100;
var marginX = 2048 % gridSize / 2;
var marginY = 2732 % gridSize / 2;
var background = game.attachAsset('background', {});
@@ -136,9 +136,9 @@
var moveFrequency = 8;
LK.on('tick', function () {
tickCounter++;
if (tickCounter % moveFrequency == 0) {
- snake.move();
+ snake._move_migrated();
snake.checkCollision();
}
if (isGameOver) {
LK.showGameOver();
@@ -162,16 +162,16 @@
}
}
});
var startSwipePos = null;
-game.on('down', function (obj) {
- startSwipePos = obj.event.getLocalPosition(game);
+game.on('down', function (x, y, obj) {
+ startSwipePos = game.toLocal(obj.global);
});
-game.on('up', function (obj) {
+game.on('up', function (x, y, obj) {
if (!startSwipePos) {
return;
}
- var endSwipePos = obj.event.getLocalPosition(game);
+ var endSwipePos = game.toLocal(obj.global);
var dx = endSwipePos.x - startSwipePos.x;
var dy = endSwipePos.y - startSwipePos.y;
if (Math.abs(dx) > Math.abs(dy)) {
if (snake.direction !== 'up' && snake.direction !== 'down') {