File size: 14,762 Bytes
62cabf1
ec0a41c
62cabf1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
<!DOCTYPE html>
<html>
<head>
    <style>
        body {
            margin: 0;
            overflow: hidden;
            background: #1a1a1a;
            font-family: Arial;
        }
        #hud {
            position: fixed;
            top: 20px;
            left: 20px;
            color: white;
        }
        #healthBar {
            width: 200px;
            height: 20px;
            background: #333;
            border-radius: 10px;
            overflow: hidden;
        }
        #health {
            width: 100%;
            height: 100%;
            background: #2ecc71;
            transition: width 0.2s;
        }
        #controls {
            position: fixed;
            top: 20px;
            right: 20px;
            color: white;
            background: rgba(0,0,0,0.7);
            padding: 15px;
            border-radius: 5px;
        }
        #round {
            position: fixed;
            top: 20px;
            left: 50%;
            transform: translateX(-50%);
            color: white;
            font-size: 24px;
        }
        #gameOver {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background: rgba(0,0,0,0.8);
            color: white;
            padding: 20px;
            border-radius: 10px;
            text-align: center;
            display: none;
        }
        #restart {
            background: #2ecc71;
            border: none;
            color: white;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            margin-top: 10px;
        }
    </style>
</head>
<body>
    <canvas id="game"></canvas>
    <div id="hud">
        <div id="healthBar">
            <div id="health"></div>
        </div>
    </div>
    <div id="round">Round 1</div>
    <div id="controls">
        WASD - Move<br>
        Mouse - Aim<br>
        Space - Shoot
    </div>
    <div id="gameOver">
        Game Over!<br>
        <button id="restart" onclick="restartGame()">Restart Game</button>
    </div>

    <script>
        const canvas = document.getElementById('game');
        const ctx = canvas.getContext('2d');

        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;

        const PLAYER_SIZE = 30;
        const BULLET_SPEED = 10;
        const ENEMY_SPEED = 2;
        const SHOOTING_INTERVAL = 333; // 3 shots per second

        let game = {
            player: {
                x: canvas.width/2,
                y: canvas.height/2,
                speed: 5,
                health: 1000,
                maxHealth: 1000,
                bullets: [],
                bulletsPerShot: 1
            },
            enemies: [],
            items: [],
            round: 1,
            keys: {},
            mouse: {x: 0, y: 0},
            lastShot: 0,
            shooting: false
        };

        const gunSound = new Audio('data:audio/wav;base64,UklGRnoGAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YWoGAACBhYqFbF1pbphwX4WqY0J0zGYhdPV3I2vyd5qCvHKTlZJ0j6p+cJGYhIaHmH1li6R9YH6hooCEjaB0f4SOo3yLkZSCeq+bXY/FdWt9tnhcl69yZ5mfdGSSoYKEkZuBdYqgeIKEm4Joe6GJfX+VmnuBjZaFhqmQYY7Hc36QiXd6kpWLgpSieIeQnICEkZeEhJOcfH6Om4GBjZWEgpOYfICLl4OBjZSEgZKYfICKloKBjJODgZGXe3+JlYGAi5KCgJCWen+IlICAfoh+gY2ScICBjX+ChImFhYuJhYeHhoeHh4iIiIiIiIiIiIiIiIiIiIiIiIiHh4aGhYSCgYB/fn18fHx9fn+AgYKEhYeIiYuMjo+RkpSVl5iZmptcW15hZGhrbW5vcHFydHZ4enx+gIKEh4mMj5GSk5OTkpGQjo2LiomIiImKi4yOj5GSlJ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3d7f4OHi4+Tl5ufo6err7O3u7/Dx8vP09fb3+Pn6+/z9/v8=');

        function spawnEnemies() {
            const enemyCount = game.round * 5;
            for(let i = 0; i < enemyCount; i++) {
                game.enemies.push({
                    x: Math.random() * canvas.width,
                    y: Math.random() * canvas.height,
                    health: 1000,
                    maxHealth: 1000,
                    bullets: [],
                    lastShot: 0,
                    direction: {
                        x: Math.random() * 2 - 1,
                        y: Math.random() * 2 - 1
                    }
                });
            }
        }

        function update() {
            // Player movement
            if(game.keys['w'] && game.player.y > PLAYER_SIZE) 
                game.player.y -= game.player.speed;
            if(game.keys['s'] && game.player.y < canvas.height - PLAYER_SIZE) 
                game.player.y += game.player.speed;
            if(game.keys['a'] && game.player.x > PLAYER_SIZE) 
                game.player.x -= game.player.speed;
            if(game.keys['d'] && game.player.x < canvas.width - PLAYER_SIZE) 
                game.player.x += game.player.speed;

            // Player shooting
            if(game.shooting && Date.now() - game.lastShot > SHOOTING_INTERVAL) {
                const angle = Math.atan2(
                    game.mouse.y - game.player.y,
                    game.mouse.x - game.player.x
                );
                
                for(let i = 0; i < game.player.bulletsPerShot; i++) {
                    game.player.bullets.push({
                        x: game.player.x,
                        y: game.player.y,
                        angle: angle + (Math.random() - 0.5) * 0.2
                    });
                }
                gunSound.cloneNode().play();
                game.lastShot = Date.now();
            }

            // Update bullets and check collisions
            for(let i = game.player.bullets.length - 1; i >= 0; i--) {
                const bullet = game.player.bullets[i];
                bullet.x += Math.cos(bullet.angle) * BULLET_SPEED;
                bullet.y += Math.sin(bullet.angle) * BULLET_SPEED;

                // Remove out of bounds bullets
                if(bullet.x < 0 || bullet.x > canvas.width || 
                   bullet.y < 0 || bullet.y > canvas.height) {
                    game.player.bullets.splice(i, 1);
                }

                // Check enemy hits
                for(let j = game.enemies.length - 1; j >= 0; j--) {
                    const enemy = game.enemies[j];
                    const dx = bullet.x - enemy.x;
                    const dy = bullet.y - enemy.y;
                    if(Math.sqrt(dx*dx + dy*dy) < PLAYER_SIZE/2) {
                        enemy.health -= 100;
                        game.player.bullets.splice(i, 1);
                        if(enemy.health <= 0) {
                            game.enemies.splice(j, 1);
                            game.player.bulletsPerShot++;
                            // Drop health item
                            game.items.push({
                                x: enemy.x,
                                y: enemy.y,
                                type: 'health'
                            });
                        }
                        break;
                    }
                }
            }

            // Update enemies
            game.enemies.forEach(enemy => {
                // Movement
                enemy.x += enemy.direction.x * ENEMY_SPEED;
                enemy.y += enemy.direction.y * ENEMY_SPEED;

                // Bounce off walls
                if(enemy.x < 0 || enemy.x > canvas.width) enemy.direction.x *= -1;
                if(enemy.y < 0 || enemy.y > canvas.height) enemy.direction.y *= -1;

                // Shooting
                if(Date.now() - enemy.lastShot > 1000) {
                    const angle = Math.atan2(
                        game.player.y - enemy.y,
                        game.player.x - enemy.x
                    );
                    enemy.bullets.push({
                        x: enemy.x,
                        y: enemy.y,
                        angle: angle
                    });
                    enemy.lastShot = Date.now();
                }

                // Update enemy bullets
                for(let i = enemy.bullets.length - 1; i >= 0; i--) {
                    const bullet = enemy.bullets[i];
                    bullet.x += Math.cos(bullet.angle) * BULLET_SPEED/2;
                    bullet.y += Math.sin(bullet.angle) * BULLET_SPEED/2;

                    // Check player hit
                    const dx = bullet.x - game.player.x;
                    const dy = bullet.y - game.player.y;
                    if(Math.sqrt(dx*dx + dy*dy) < PLAYER_SIZE/2) {
                        game.player.health -= 50;
                        enemy.bullets.splice(i, 1);
                        document.getElementById('health').style.width = 
                            (game.player.health/game.player.maxHealth * 100) + '%';
                        
                        if(game.player.health <= 0) {
                            document.getElementById('gameOver').style.display = 'block';
                        }
                    }

                    // Remove out of bounds bullets
                    if(bullet.x < 0 || bullet.x > canvas.width || 
                       bullet.y < 0 || bullet.y > canvas.height) {
                        enemy.bullets.splice(i, 1);
                    }
                }
            });

            // Update items
            for(let i = game.items.length - 1; i >= 0; i--) {
                const item = game.items[i];
                const dx = item.x - game.player.x;
                const dy = item.y - game.player.y;
                if(Math.sqrt(dx*dx + dy*dy) < PLAYER_SIZE) {
                    game.player.health = Math.min(
                        game.player.maxHealth, 
                        game.player.health + 200
                    );
                    document.getElementById('health').style.width = 
                        (game.player.health/game.player.maxHealth * 100) + '%';
                    game.items.splice(i, 1);
                }
            }

            // Check round completion
            if(game.enemies.length === 0) {
                if(game.round < 10) {
                    game.round++;
                    document.getElementById('round').textContent = `Round ${game.round}`;
                    game.player.health = game.player.maxHealth;
                    document.getElementById('health').style.width = '100%';
                    game.player.bulletsPerShot = 1; // Reset bullets per shot
                    spawnEnemies();
                }
            }
        }

        function draw() {
            ctx.clearRect(0, 0, canvas.width, canvas.height);

            // Draw player
            ctx.fillStyle = 'white';
            ctx.font = '30px Arial';
            ctx.fillText('🐭', game.player.x - 15, game.player.y + 15);

            // Draw player bullets
            ctx.fillStyle = 'yellow';
            game.player.bullets.forEach(bullet => {
                ctx.beginPath();
                ctx.arc(bullet.x, bullet.y, 3, 0, Math.PI * 2);
                ctx.fill();
            });

            // Draw enemies
            game.enemies.forEach(enemy => {
                // Enemy
                ctx.fillStyle = 'white';
                ctx.fillText('🐱', enemy.x - 15, enemy.y + 15);

                // Health bar
                ctx.fillStyle = '#600';
                ctx.fillRect(enemy.x - 25, enemy.y - 30, 50, 5);
                ctx.fillStyle = '#f00';
                ctx.fillRect(enemy.x - 25, enemy.y - 30, 
                           (enemy.health/enemy.maxHealth) * 50, 5);

                // Enemy bullets
                ctx.fillStyle = 'red';
                enemy.bullets.forEach(bullet => {
                    ctx.beginPath();
                    ctx.arc(bullet.x, bullet.y, 3, 0, Math.PI * 2);
                    ctx.fill();
                });
            });

            // Draw items
            ctx.fillStyle = 'green';
            game.items.forEach(item => {
                ctx.fillText('✚', item.x - 10, item.y + 10);
            });
        }

        function gameLoop() {
            if(game.player.health > 0) {
                update();
                draw();
            }
            requestAnimationFrame(gameLoop);
        }

        function restartGame() {
            game = {
                player: {
                    x: canvas.width/2,
                    y: canvas.height/2,
                    speed: 5,
                    health: 1000,
                    maxHealth: 1000,
                    bullets: [],
                    bulletsPerShot: 1
                },
                enemies: [],
                items: [],
                round: 1,
                keys: game.keys,
                mouse: game.mouse,
                lastShot: 0,
                shooting: false
            };
            document.getElementById('health').style.width = '100%';
            document.getElementById('round').textContent = 'Round 1';
            document.getElementById('gameOver').style.display = 'none';
            spawnEnemies();
        }

        // Event listeners
        window.addEventListener('keydown', e => game.keys[e.key] = true);
        window.addEventListener('keyup', e => game.keys[e.key] = false);
        window.addEventListener('mousemove', e => {
            game.mouse.x = e.clientX;
            game.mouse.y = e.clientY;
        });
        window.addEventListener('keydown', e => {
            if(e.code === 'Space') game.shooting = true;
        });
        window.addEventListener('keyup', e => {
            if(e.code === 'Space') game.shooting = false;
        });

        // Start game
        spawnEnemies();
        gameLoop();
    </script>
</body>
</html><script async data-explicit-opt-in="true" data-cookie-opt-in="true" src="https://vercel.live/_next-live/feedback/feedback.js"></script>