Nymbo commited on
Commit
be3b168
1 Parent(s): c15f632

slowing the enemies down by 60%

Browse files
Files changed (1) hide show
  1. index.html +17 -8
index.html CHANGED
@@ -1,9 +1,12 @@
1
  <!DOCTYPE html>
 
 
 
2
  <html lang="en">
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Snake Game (WASD Controls, Larger Area, Obstacles, Enemies)</title>
7
  <style>
8
  body {
9
  display: flex;
@@ -36,6 +39,7 @@
36
  let score = 0;
37
  let obstacles = [];
38
  let enemies = [];
 
39
 
40
  function generateObstacles() {
41
  obstacles = [];
@@ -90,13 +94,17 @@
90
  }
91
 
92
  function moveEnemies() {
93
- enemies.forEach(enemy => {
94
- const head = snake[0];
95
- if (enemy.x < head.x) enemy.x++;
96
- else if (enemy.x > head.x) enemy.x--;
97
- if (enemy.y < head.y) enemy.y++;
98
- else if (enemy.y > head.y) enemy.y--;
99
- });
 
 
 
 
100
  }
101
 
102
  function drawSnake() {
@@ -170,6 +178,7 @@
170
  dx = 0;
171
  dy = 0;
172
  score = 0;
 
173
  generateObstacles();
174
  generateEnemies();
175
  generateFood();
 
1
  <!DOCTYPE html>
2
+
3
+ <!-- this was mostly written by Claude-3.5-Sonnet btw -->
4
+
5
  <html lang="en">
6
  <head>
7
  <meta charset="UTF-8">
8
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
9
+ <title>Snake Game (WASD Controls, Larger Area, Obstacles, Slower Enemies)</title>
10
  <style>
11
  body {
12
  display: flex;
 
39
  let score = 0;
40
  let obstacles = [];
41
  let enemies = [];
42
+ let enemyMoveCounter = 0;
43
 
44
  function generateObstacles() {
45
  obstacles = [];
 
94
  }
95
 
96
  function moveEnemies() {
97
+ enemyMoveCounter++;
98
+ if (enemyMoveCounter >= 2.5) { // Move enemies every 2.5 game loops (60% slower)
99
+ enemyMoveCounter = 0;
100
+ enemies.forEach(enemy => {
101
+ const head = snake[0];
102
+ if (enemy.x < head.x) enemy.x++;
103
+ else if (enemy.x > head.x) enemy.x--;
104
+ if (enemy.y < head.y) enemy.y++;
105
+ else if (enemy.y > head.y) enemy.y--;
106
+ });
107
+ }
108
  }
109
 
110
  function drawSnake() {
 
178
  dx = 0;
179
  dy = 0;
180
  score = 0;
181
+ enemyMoveCounter = 0;
182
  generateObstacles();
183
  generateEnemies();
184
  generateFood();