- #1
shivajikobardan
- 674
- 54
- TL;DR Summary
- snake game javascript
Relevant code:
where snake is an array of objects. Each object is x and y coordinates of snake position and food is an object with x and y coordinates randomly placed.
Here's the full code:
JavaScript:
if (food.x === snake[0].x && food.y === snake[0].y) {
// increase the size of the snake
snake.push({
x: snake[snake.length - 1].x,
y: snake[snake.length - 1].y });
where snake is an array of objects. Each object is x and y coordinates of snake position and food is an object with x and y coordinates randomly placed.
Here's the full code: