Code edit (1 edits merged)
Please save this source code
User prompt
Wrap the snake when it touches the margins rather than just going beyond them
User prompt
Wrap the snake when it goes beyond greater than or equal to the margin
User prompt
Wrap the snake when it's less than or equal to the margin
User prompt
Calculate marginX/Y before setting the background position
User prompt
Declare grid size at the start of the game method so it's defined before setting background width/height
User prompt
Background starting position should be adjusted too
User prompt
The background size should match the grid given to the snake
User prompt
Ensure the margin is added to the snake coordinates too
User prompt
Fix Bug: 'ReferenceError: marginX is not defined' in this line: 'if (snakeGraphics.x < marginX) snakeGraphics.x = maxX - gridSize + marginX;' Line Number: 56
User prompt
Move the game's x/y so that it has margin , so that the grid available to the snake which is divisible by 100 is centred
User prompt
Ensure maxX/y used by the snake is divisible by 100.
User prompt
Make grid size 100 instead of 128*5
User prompt
Fix Bug: 'Uncaught ReferenceError: gridSize is not defined' in this line: 'dot.x = Math.floor(Math.random() * (2048 / gridSize)) * gridSize;' Line Number: 131
User prompt
Change snake grid Size to 100 and only declare it once
User prompt
Only allow turning, i.e. from down direction you can only go to left/right, etc.
User prompt
Prevent going in the reverse direction to where you are facing
User prompt
Do self collision by checking the head against each body piece
User prompt
Do LK gameover inside snake, as the game doesn't know about that variable
User prompt
Call the LK gameover when it's gameover
User prompt
You lose if you collide with yourself
User prompt
Make it every 10 score that the ticks reduce
User prompt
Every 5 score decrease the ticks per move by 1, to a minimum of q
User prompt
Make snake move faster every 5 food you get, where by faster it's decreasing the number of ticks needed by 1 (keep minimum of 1 move per tick). Also slow the initial speed to 1 move per 7 ticks.
User prompt
Make score text a monospace font
===================================================================
--- original.js
+++ change.js
@@ -56,11 +56,11 @@
var maxX = 2000;
var maxY = 2700;
var marginX = 2048 % gridSize / 2;
var marginY = 2732 % gridSize / 2;
- if (snakeGraphics.x < marginX) snakeGraphics.x = maxX - gridSize + marginX;
+ if (snakeGraphics.x < marginX - gridSize) snakeGraphics.x = maxX - gridSize + marginX;
if (snakeGraphics.x >= maxX + marginX) snakeGraphics.x = marginX;
- if (snakeGraphics.y < marginY) snakeGraphics.y = maxY - gridSize + marginY;
+ if (snakeGraphics.y < marginY - gridSize) snakeGraphics.y = maxY - gridSize + marginY;
if (snakeGraphics.y >= maxY + marginY) snakeGraphics.y = marginY;
for (var i = 0; i < self.body.length; i++) {
if (snakeGraphics.x === self.body[i].x && snakeGraphics.y === self.body[i].y) {
LK.showGameOver();