Spaces:
Running
Running
in the beginig there is no ball to eat to start the game
Browse files- script.js +12 -3
- wormate.js +8 -3
script.js
CHANGED
|
@@ -15,15 +15,24 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 15 |
// Worm
|
| 16 |
let worm = [];
|
| 17 |
worm[0] = {x: Math.floor(tileCount/2) * gridSize, y: Math.floor(tileCount/2) * gridSize};
|
| 18 |
-
|
| 19 |
-
// Food
|
| 20 |
let food = {
|
| 21 |
x: Math.floor(Math.random() * tileCount) * gridSize,
|
| 22 |
y: Math.floor(Math.random() * tileCount) * gridSize,
|
| 23 |
color: getRandomColor()
|
| 24 |
};
|
| 25 |
|
| 26 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
let xVelocity = 0;
|
| 28 |
let yVelocity = 0;
|
| 29 |
|
|
|
|
| 15 |
// Worm
|
| 16 |
let worm = [];
|
| 17 |
worm[0] = {x: Math.floor(tileCount/2) * gridSize, y: Math.floor(tileCount/2) * gridSize};
|
| 18 |
+
// Initial food
|
|
|
|
| 19 |
let food = {
|
| 20 |
x: Math.floor(Math.random() * tileCount) * gridSize,
|
| 21 |
y: Math.floor(Math.random() * tileCount) * gridSize,
|
| 22 |
color: getRandomColor()
|
| 23 |
};
|
| 24 |
|
| 25 |
+
// Add 5 more foods at start
|
| 26 |
+
for (let i = 0; i < 5; i++) {
|
| 27 |
+
setTimeout(() => {
|
| 28 |
+
food = {
|
| 29 |
+
x: Math.floor(Math.random() * tileCount) * gridSize,
|
| 30 |
+
y: Math.floor(Math.random() * tileCount) * gridSize,
|
| 31 |
+
color: getRandomColor()
|
| 32 |
+
};
|
| 33 |
+
}, i * 1000);
|
| 34 |
+
}
|
| 35 |
+
// Direction
|
| 36 |
let xVelocity = 0;
|
| 37 |
let yVelocity = 0;
|
| 38 |
|
wormate.js
CHANGED
|
@@ -14,15 +14,20 @@ function resizeCanvas() {
|
|
| 14 |
}
|
| 15 |
window.addEventListener('resize', resizeCanvas);
|
| 16 |
resizeCanvas();
|
| 17 |
-
|
| 18 |
// Game state
|
| 19 |
let gameStarted = false;
|
| 20 |
let playerId = null;
|
| 21 |
let players = {};
|
| 22 |
-
let foods = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
let powerUps = [];
|
| 24 |
let score = 0;
|
| 25 |
-
|
| 26 |
// Player controls
|
| 27 |
const keys = {
|
| 28 |
ArrowUp: false,
|
|
|
|
| 14 |
}
|
| 15 |
window.addEventListener('resize', resizeCanvas);
|
| 16 |
resizeCanvas();
|
|
|
|
| 17 |
// Game state
|
| 18 |
let gameStarted = false;
|
| 19 |
let playerId = null;
|
| 20 |
let players = {};
|
| 21 |
+
let foods = [
|
| 22 |
+
{
|
| 23 |
+
x: Math.random() * canvas.width,
|
| 24 |
+
y: Math.random() * canvas.height,
|
| 25 |
+
radius: 10,
|
| 26 |
+
color: getRandomColor()
|
| 27 |
+
}
|
| 28 |
+
];
|
| 29 |
let powerUps = [];
|
| 30 |
let score = 0;
|
|
|
|
| 31 |
// Player controls
|
| 32 |
const keys = {
|
| 33 |
ArrowUp: false,
|