forked from Job-madi/Blast-From-The-past
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnake.js
More file actions
38 lines (30 loc) · 952 Bytes
/
snake.js
File metadata and controls
38 lines (30 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const snakeboard = document.getElementById("gameCanvas");
const snakeboard_ctx = gameCanvas.getContext("2d");
let snake = [{ x: 200, y: 200 }, { x: 190, y: 200 }, { x: 180, y: 200 },
{ x: 170, y: 200 }, { x: 160, y: 200 },];
function drawSnakePart(snakePart) {
snakeboard_ctx.fillStyle = 'lightblue';
snakeboard_ctx.strokestyle = 'darkblue';
snakeboard_ctx.fillRect(snakePart.x, snakePart.y, 10, 10);
snakeboard_ctx.strokeRect(snakePart.x, snakePart.y, 10, 10);
}
/*Function that prints the parts*/
function drawSnake() {
snake.forEach(drawSnakePart);
}
function move_snake() {
const head = { x: snake[0].x + dx, y: snake[0].y };
const head = { x: snake[0].x + dx, y: snake[0].y + dy };
snake.unshift(head);
snake.pop();
}
function main() {
setTimeout(function onTick() {
clearCanvas();
advanceSnake();
drawSnake();
// Call main again
main();
}, 100)
}
Putting