dannyboy84 commited on
Commit
dc42002
·
verified ·
1 Parent(s): b7bb800

ok for some reason your not working can you fix this, please test the game when you finish

Browse files
Files changed (3) hide show
  1. index.html +6 -6
  2. script.js +305 -1
  3. style.css +72 -0
index.html CHANGED
@@ -16,13 +16,13 @@
16
  <body>
17
  <wormate-nav></wormate-nav>
18
  <div id="game-container">
19
- <ring-game></ring-game>
 
 
 
 
 
20
  </div>
21
- <section id="about-preview" class="info-section">
22
- <h2>About the Game</h2>
23
- <p>Grow your worm, compete with others, and dominate the leaderboard!</p>
24
- <a href="about.html" class="info-link">Learn More →</a>
25
- </section>
26
  <game-footer></game-footer>
27
  <script src="script.js"></script>
28
  </body>
 
16
  <body>
17
  <wormate-nav></wormate-nav>
18
  <div id="game-container">
19
+ <canvas id="gameCanvas"></canvas>
20
+ <div id="game-ui">
21
+ <div id="score-display">Score: 0</div>
22
+ <div id="leaderboard"></div>
23
+ <button id="play-btn" class="wormate-btn">PLAY</button>
24
+ </div>
25
  </div>
 
 
 
 
 
26
  <game-footer></game-footer>
27
  <script src="script.js"></script>
28
  </body>
script.js CHANGED
@@ -1,5 +1,309 @@
1
 
 
2
  document.addEventListener('DOMContentLoaded', () => {
 
 
 
 
3
  // Initialize Feather Icons
4
- feather.replace();
 
 
5
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
 
2
+ // Game initialization
3
  document.addEventListener('DOMContentLoaded', () => {
4
+ // Initialize game
5
+ const game = new WormateGame();
6
+ game.init();
7
+
8
  // Initialize Feather Icons
9
+ if (typeof feather !== 'undefined') {
10
+ feather.replace();
11
+ }
12
  });
13
+
14
+ class WormateGame {
15
+ constructor() {
16
+ this.canvas = document.getElementById('gameCanvas');
17
+ this.ctx = this.canvas.getContext('2d');
18
+ this.scoreDisplay = document.getElementById('score-display');
19
+ this.leaderboard = document.getElementById('leaderboard');
20
+ this.playBtn = document.getElementById('play-btn');
21
+
22
+ this.gameStarted = false;
23
+ this.playerId = null;
24
+ this.players = {};
25
+ this.foods = [];
26
+ this.powerUps = [];
27
+ this.score = 0;
28
+ this.keys = {
29
+ ArrowUp: false,
30
+ ArrowDown: false,
31
+ ArrowLeft: false,
32
+ ArrowRight: false
33
+ };
34
+ }
35
+
36
+ init() {
37
+ this.resizeCanvas();
38
+ window.addEventListener('resize', () => this.resizeCanvas());
39
+
40
+ // Keyboard controls
41
+ window.addEventListener('keydown', (e) => {
42
+ if (this.keys.hasOwnProperty(e.key)) {
43
+ this.keys[e.key] = true;
44
+ e.preventDefault();
45
+ }
46
+ });
47
+
48
+ window.addEventListener('keyup', (e) => {
49
+ if (this.keys.hasOwnProperty(e.key)) {
50
+ this.keys[e.key] = false;
51
+ e.preventDefault();
52
+ }
53
+ });
54
+
55
+ // Start game button
56
+ this.playBtn.addEventListener('click', () => this.startGame());
57
+
58
+ // Start game loop
59
+ this.gameLoop();
60
+ }
61
+
62
+ resizeCanvas() {
63
+ this.canvas.width = window.innerWidth;
64
+ this.canvas.height = window.innerHeight;
65
+ }
66
+
67
+ startGame() {
68
+ const playerName = prompt('Enter your name:', 'Player' + Math.floor(Math.random() * 1000));
69
+ if (playerName) {
70
+ this.playerId = 'local-' + Date.now();
71
+ this.players[this.playerId] = {
72
+ id: this.playerId,
73
+ name: playerName,
74
+ color: this.getRandomColor(),
75
+ score: 0,
76
+ segments: [
77
+ { x: this.canvas.width/2, y: this.canvas.height/2, radius: 15 },
78
+ { x: this.canvas.width/2 - 20, y: this.canvas.height/2, radius: 14 },
79
+ { x: this.canvas.width/2 - 40, y: this.canvas.height/2, radius: 13 }
80
+ ]
81
+ };
82
+
83
+ // Generate initial food
84
+ for (let i = 0; i < 50; i++) {
85
+ this.foods.push({
86
+ x: Math.random() * this.canvas.width,
87
+ y: Math.random() * this.canvas.height,
88
+ radius: 8 + Math.random() * 4,
89
+ color: this.getRandomColor()
90
+ });
91
+ }
92
+
93
+ this.gameStarted = true;
94
+ this.playBtn.style.display = 'none';
95
+ }
96
+ }
97
+
98
+ gameLoop() {
99
+ if (this.gameStarted) {
100
+ this.update();
101
+ this.render();
102
+ }
103
+ requestAnimationFrame(() => this.gameLoop());
104
+ }
105
+
106
+ update() {
107
+ // Move player worm
108
+ const player = this.players[this.playerId];
109
+ if (!player) return;
110
+
111
+ const head = player.segments[0];
112
+ let newX = head.x;
113
+ let newY = head.y;
114
+
115
+ if (this.keys.ArrowUp) newY -= 5;
116
+ if (this.keys.ArrowDown) newY += 5;
117
+ if (this.keys.ArrowLeft) newX -= 5;
118
+ if (this.keys.ArrowRight) newX += 5;
119
+
120
+ // Add new head position
121
+ player.segments.unshift({
122
+ x: newX,
123
+ y: newY,
124
+ radius: head.radius
125
+ });
126
+
127
+ // Remove tail segment
128
+ player.segments.pop();
129
+
130
+ // Check food collision
131
+ this.foods = this.foods.filter(food => {
132
+ const distance = Math.sqrt(
133
+ Math.pow(head.x - food.x, 2) +
134
+ Math.pow(head.y - food.y, 2)
135
+ );
136
+
137
+ if (distance < head.radius + food.radius) {
138
+ // Eat food - grow worm
139
+ const tail = player.segments[player.segments.length - 1];
140
+ for (let i = 0; i < 5; i++) {
141
+ player.segments.push({
142
+ x: tail.x,
143
+ y: tail.y,
144
+ radius: tail.radius * 0.95
145
+ });
146
+ }
147
+ player.score += Math.floor(food.radius);
148
+ this.score = player.score;
149
+ this.scoreDisplay.textContent = `Score: ${this.score}`;
150
+ return false; // Remove food
151
+ }
152
+ return true; // Keep food
153
+ });
154
+
155
+ // Add new food if needed
156
+ if (this.foods.length < 30 && Math.random() < 0.1) {
157
+ this.foods.push({
158
+ x: Math.random() * this.canvas.width,
159
+ y: Math.random() * this.canvas.height,
160
+ radius: 8 + Math.random() * 4,
161
+ color: this.getRandomColor()
162
+ });
163
+ }
164
+
165
+ // Check wall collision
166
+ if (
167
+ head.x < -head.radius ||
168
+ head.x > this.canvas.width + head.radius ||
169
+ head.y < -head.radius ||
170
+ head.y > this.canvas.height + head.radius
171
+ ) {
172
+ this.gameOver();
173
+ }
174
+
175
+ // Update leaderboard
176
+ this.updateLeaderboard();
177
+ }
178
+
179
+ render() {
180
+ // Clear canvas
181
+ this.ctx.fillStyle = '#1a1a2e';
182
+ this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
183
+
184
+ // Draw foods
185
+ this.foods.forEach(food => {
186
+ this.ctx.fillStyle = food.color;
187
+ this.ctx.beginPath();
188
+ this.ctx.arc(food.x, food.y, food.radius, 0, Math.PI * 2);
189
+ this.ctx.fill();
190
+ });
191
+
192
+ // Draw players
193
+ Object.values(this.players).forEach(player => {
194
+ // Draw worm segments
195
+ player.segments.forEach((segment, i) => {
196
+ const gradient = this.ctx.createRadialGradient(
197
+ segment.x, segment.y, 0,
198
+ segment.x, segment.y, segment.radius
199
+ );
200
+ gradient.addColorStop(0, player.color);
201
+ gradient.addColorStop(1, this.darkenColor(player.color, 0.3));
202
+
203
+ this.ctx.fillStyle = gradient;
204
+ this.ctx.beginPath();
205
+ this.ctx.arc(segment.x, segment.y, segment.radius, 0, Math.PI * 2);
206
+ this.ctx.fill();
207
+
208
+ // Draw eyes on head
209
+ if (i === 0 && player.segments.length > 1) {
210
+ const angle = Math.atan2(
211
+ player.segments[1].y - segment.y,
212
+ player.segments[1].x - segment.x
213
+ );
214
+
215
+ const eyeRadius = segment.radius * 0.3;
216
+ const eyeOffset = segment.radius * 0.6;
217
+
218
+ // Eyes
219
+ this.ctx.fillStyle = 'white';
220
+ this.ctx.beginPath();
221
+ this.ctx.arc(
222
+ segment.x + Math.cos(angle + Math.PI/2) * eyeOffset,
223
+ segment.y + Math.sin(angle + Math.PI/2) * eyeOffset,
224
+ eyeRadius, 0, Math.PI * 2
225
+ );
226
+ this.ctx.fill();
227
+
228
+ this.ctx.beginPath();
229
+ this.ctx.arc(
230
+ segment.x + Math.cos(angle - Math.PI/2) * eyeOffset,
231
+ segment.y + Math.sin(angle - Math.PI/2) * eyeOffset,
232
+ eyeRadius, 0, Math.PI * 2
233
+ );
234
+ this.ctx.fill();
235
+
236
+ // Pupils
237
+ this.ctx.fillStyle = 'black';
238
+ this.ctx.beginPath();
239
+ this.ctx.arc(
240
+ segment.x + Math.cos(angle + Math.PI/2) * eyeOffset + Math.cos(angle) * eyeRadius/2,
241
+ segment.y + Math.sin(angle + Math.PI/2) * eyeOffset + Math.sin(angle) * eyeRadius/2,
242
+ eyeRadius/2, 0, Math.PI * 2
243
+ );
244
+ this.ctx.fill();
245
+
246
+ this.ctx.beginPath();
247
+ this.ctx.arc(
248
+ segment.x + Math.cos(angle - Math.PI/2) * eyeOffset + Math.cos(angle) * eyeRadius/2,
249
+ segment.y + Math.sin(angle - Math.PI/2) * eyeOffset + Math.sin(angle) * eyeRadius/2,
250
+ eyeRadius/2, 0, Math.PI * 2
251
+ );
252
+ this.ctx.fill();
253
+ }
254
+ });
255
+
256
+ // Draw player name
257
+ if (player.segments.length > 0) {
258
+ const head = player.segments[0];
259
+ this.ctx.fillStyle = 'white';
260
+ this.ctx.font = '12px "Press Start 2P", cursive';
261
+ this.ctx.textAlign = 'center';
262
+ this.ctx.fillText(player.name, head.x, head.y - head.radius - 10);
263
+ }
264
+ });
265
+ }
266
+
267
+ updateLeaderboard() {
268
+ const sortedPlayers = Object.values(this.players).sort((a, b) => b.score - a.score);
269
+ this.leaderboard.innerHTML = '<h3>Leaderboard</h3>' +
270
+ sortedPlayers.map(p =>
271
+ `<div class="player-row ${p.id === this.playerId ? 'you' : ''}">
272
+ <span class="player-name">${p.name}</span>
273
+ <span class="player-score">${p.score}</span>
274
+ </div>`
275
+ ).join('');
276
+ }
277
+
278
+ gameOver() {
279
+ alert(`Game Over! Your score: ${this.score}`);
280
+ this.gameStarted = false;
281
+ this.playBtn.style.display = 'block';
282
+ this.players = {};
283
+ this.foods = [];
284
+ this.score = 0;
285
+ this.scoreDisplay.textContent = `Score: 0`;
286
+ }
287
+
288
+ getRandomColor() {
289
+ const colors = [
290
+ '#FF5252', '#FF4081', '#E040FB', '#7C4DFF',
291
+ '#536DFE', '#448AFF', '#40C4FF', '#18FFFF',
292
+ '#64FFDA', '#69F0AE', '#B2FF59', '#EEFF41',
293
+ '#FFFF00', '#FFD740', '#FFAB40', '#FF6E40'
294
+ ];
295
+ return colors[Math.floor(Math.random() * colors.length)];
296
+ }
297
+
298
+ darkenColor(color, amount) {
299
+ let r = parseInt(color.substr(1, 2), 16);
300
+ let g = parseInt(color.substr(3, 2), 16);
301
+ let b = parseInt(color.substr(5, 2), 16);
302
+
303
+ r = Math.max(0, Math.floor(r * (1 - amount)));
304
+ g = Math.max(0, Math.floor(g * (1 - amount)));
305
+ b = Math.max(0, Math.floor(b * (1 - amount)));
306
+
307
+ return `#${((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)}`;
308
+ }
309
+ }
style.css CHANGED
@@ -69,6 +69,78 @@ body {
69
  width: 100%;
70
  height: 100vh;
71
  overflow: hidden;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  }
73
  =======
74
  #gameCanvas {
 
69
  width: 100%;
70
  height: 100vh;
71
  overflow: hidden;
72
+ background: #1a1a2e;
73
+ }
74
+
75
+ #gameCanvas {
76
+ display: block;
77
+ width: 100%;
78
+ height: 100%;
79
+ }
80
+
81
+ #game-ui {
82
+ position: absolute;
83
+ top: 0;
84
+ left: 0;
85
+ padding: 1rem;
86
+ pointer-events: none;
87
+ z-index: 10;
88
+ }
89
+
90
+ #score-display {
91
+ font-size: 1.2rem;
92
+ margin-bottom: 1rem;
93
+ color: #ff6b6b;
94
+ text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
95
+ }
96
+
97
+ #leaderboard {
98
+ background: rgba(26, 26, 46, 0.8);
99
+ padding: 1rem;
100
+ border-radius: 5px;
101
+ max-width: 200px;
102
+ font-size: 0.8rem;
103
+ }
104
+
105
+ #leaderboard h3 {
106
+ margin: 0 0 0.5rem 0;
107
+ color: #ff6b6b;
108
+ font-size: 0.9rem;
109
+ }
110
+
111
+ .player-row {
112
+ display: flex;
113
+ justify-content: space-between;
114
+ margin-bottom: 0.3rem;
115
+ }
116
+
117
+ .player-row.you {
118
+ color: #69f0ae;
119
+ font-weight: bold;
120
+ }
121
+
122
+ .wormate-btn {
123
+ position: absolute;
124
+ top: 50%;
125
+ left: 50%;
126
+ transform: translate(-50%, -50%);
127
+ padding: 1rem 2rem;
128
+ font-family: 'Press Start 2P', cursive;
129
+ font-size: 1rem;
130
+ background: #ff6b6b;
131
+ color: white;
132
+ border: none;
133
+ border-radius: 5px;
134
+ cursor: pointer;
135
+ pointer-events: auto;
136
+ transition: all 0.3s;
137
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
138
+ z-index: 20;
139
+ }
140
+
141
+ .wormate-btn:hover {
142
+ background: #ff5252;
143
+ transform: translate(-50%, -50%) scale(1.05);
144
  }
145
  =======
146
  #gameCanvas {