User prompt
delete the tailSegmentDelay where it's initialized to 16
User prompt
set the tailSegmentDelay to 25
User prompt
when creating a new snake segment, also set the rotation of the new segment to the rotation of the previous segment
User prompt
Rotate the snake body segment graphics by 90 degrees clockwise
User prompt
Rotate the snake graphics by 90 degrees counter clockwise
User prompt
Add score to the game, use impact for the score. Increment score by one for each food you eat
User prompt
when releasing the mouse set the direction x and y to the current direction of the snake
User prompt
when I release the mouse, the snake should keep moving in the direction it was currently moving in
User prompt
As soon as you release the mouse, the snake should stop changing rotation
User prompt
Increase the allowed rotation speed by 25%
User prompt
Use circle to circle intersection to test if the snake is self intersecting, use a variable for the threshold distance
User prompt
If the head intersects with any body segment, except for the first body segment. call gameover
User prompt
Update spawn positions of food such that it has a 30px margin to the edge of the screen
User prompt
Don't allow the snake to wrap around the screen, instead call gameover if you hit an edge
User prompt
when adding segments to snakeContainer attach to z-index zero
User prompt
Create a snake container in the Game object and attach all snake elements to that
User prompt
Add a simple container to game.
User prompt
add a container that all snake elements are attached to
User prompt
when calling self.addBodySegment don't attach element to stage, instead return the new segment to game, which will add it to itself
User prompt
Decrease the tail segment delay by half
User prompt
Increase turn speed by 30%
User prompt
make tail segment delay a variable rather than hardcoding 32
User prompt
make snake 50% faster
User prompt
make snake rotation 3x as slow
Code edit (1 edits merged)
Please save this source code
var SnakeBodySegment = Container.expand(function () { var self = Container.call(this); var bodySegmentGraphics = self.createAsset('snakeBodySegment', 'Snake Body Segment Graphics', .5, .5); }); var FingerIndicator = Container.expand(function () { var self = Container.call(this); var fingerIndicatorGraphics = self.createAsset('fingerIndicator', 'Finger Indicator Graphics', 0.5, 0.5); fingerIndicatorGraphics.alpha = .5; }); var TouchIndicator = Container.expand(function () { var self = Container.call(this); var touchIndicatorGraphics = self.createAsset('touchIndicator', 'Touch Indicator Graphics', 0.5, 0.5); touchIndicatorGraphics.alpha = .3; }); var Snake = Container.expand(function () { var self = Container.call(this); var snakeGraphics = self.createAsset('snake', 'Snake Graphics', .5, .5); self.direction = { x: 0, y: 0 }; self.speed = 7.5; self.angle = 0; self.headPositions = []; self.bodySegments = []; self.addBodySegment = function () { var segment = new SnakeBodySegment(); var lastSegmentPosition = this.bodySegments.length > 0 ? this.bodySegments[this.bodySegments.length - 1] : this; segment.x = lastSegmentPosition.x; segment.y = lastSegmentPosition.y; this.bodySegments.push(segment); return segment; }; self.move = function () { var targetRotation = Math.atan2(self.direction.y, self.direction.x); var rotationDifference = targetRotation - self.rotation; while (rotationDifference < -Math.PI) rotationDifference += 2 * Math.PI; while (rotationDifference > Math.PI) rotationDifference -= 2 * Math.PI; var turnRate = Math.PI / 96 * 1.625; self.rotation += Math.sign(rotationDifference) * Math.min(Math.abs(rotationDifference), turnRate); self.x = self.x + Math.cos(self.rotation) * self.speed; self.y = self.y + Math.sin(self.rotation) * self.speed; if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) { LK.showGameOver(); } var thresholdDistance = 50; for (var i = 1; i < self.bodySegments.length; i++) { var dx = self.x - self.bodySegments[i].x; var dy = self.y - self.bodySegments[i].y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < thresholdDistance) { LK.showGameOver(); } } self.headPositions.push({ x: self.x, y: self.y, rotation: self.rotation }); var tailSegmentDelay = 16; while (self.headPositions.length > self.bodySegments.length * tailSegmentDelay + 1) { self.headPositions.shift(); } for (var i = 0; i < self.bodySegments.length; i++) { var tailSegmentDelay = 16; var segmentIndex = (i + 1) * tailSegmentDelay; if (self.headPositions.length > segmentIndex) { var pos = self.headPositions[self.headPositions.length - 1 - segmentIndex]; self.bodySegments[i].x = pos.x; self.bodySegments[i].y = pos.y; self.bodySegments[i].rotation = pos.rotation; } } }; }); var Food = Container.expand(function () { var self = Container.call(this); var foodGraphics = self.createAsset('food', 'Food Graphics', .5, .5); self.spawn = function () { this.x = Math.random() * (2048 - 60) + 30; this.y = Math.random() * (2732 - 60) + 30; }; }); var Game = Container.expand(function () { stage.on('up', function (obj) { if (touchIndicator) { touchIndicator.destroy(); touchIndicator = null; } isMouseDown = false; if (fingerIndicator) { fingerIndicator.destroy(); fingerIndicator = null; } snake.direction.x = Math.cos(snake.rotation) * snake.speed; snake.direction.y = Math.sin(snake.rotation) * snake.speed; }); var self = Container.call(this); var snakeContainer = self.addChild(new Container()); var snake = snakeContainer.addChild(new Snake()); var foods = []; snake.x = 2048 / 2; snake.y = 2732 / 2; var food = new Food(); food.spawn(); foods.push(food); self.addChild(food); var dragNode = null; var initialTouchPosition = { x: 0, y: 0 }; var touchIndicator = null; var fingerIndicator = null; var isMouseDown = false; var maxDistance = 200; stage.on('down', function (obj) { var event = obj.event; initialTouchPosition = event.getLocalPosition(self); if (touchIndicator) { touchIndicator.destroy(); } if (fingerIndicator) { fingerIndicator.destroy(); } touchIndicator = self.addChild(new TouchIndicator()); touchIndicator.x = initialTouchPosition.x; touchIndicator.y = initialTouchPosition.y; fingerIndicator = self.addChild(new FingerIndicator()); fingerIndicator.x = initialTouchPosition.x; fingerIndicator.y = initialTouchPosition.y; isMouseDown = true; }); function handleMove(obj) { var event = obj.event; var currentTouchPosition = event.getLocalPosition(self); var dx = currentTouchPosition.x - initialTouchPosition.x; var dy = currentTouchPosition.y - initialTouchPosition.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > maxDistance) { var angle = Math.atan2(dy, dx); dx = maxDistance * Math.cos(angle); dy = maxDistance * Math.sin(angle); } if (fingerIndicator) { fingerIndicator.x = initialTouchPosition.x + dx; fingerIndicator.y = initialTouchPosition.y + dy; } if (isMouseDown) { snake.direction.x = dx; snake.direction.y = dy; } } stage.on('move', handleMove); LK.on('tick', function () { snake.move(); for (var i = 0; i < foods.length; i++) { if (snake.intersects(foods[i])) { foods[i].destroy(); foods.splice(i, 1); var newSegment = snake.addBodySegment(); snakeContainer.addChildAt(newSegment, 0); var newFood = new Food(); newFood.spawn(); foods.push(newFood); self.addChild(newFood); } } }); });
===================================================================
--- original.js
+++ change.js
@@ -91,8 +91,10 @@
if (fingerIndicator) {
fingerIndicator.destroy();
fingerIndicator = null;
}
+ snake.direction.x = Math.cos(snake.rotation) * snake.speed;
+ snake.direction.y = Math.sin(snake.rotation) * snake.speed;
});
var self = Container.call(this);
var snakeContainer = self.addChild(new Container());
var snake = snakeContainer.addChild(new Snake());
Single, Anaconda snake head segment. Seen from above. 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.
Golden Apple Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Bright Amazing games background for modern snake game. It should be epic!
White circular touch indicator. White button like look. Game asset. No background. 2d. No shadow.