File size: 12,707 Bytes
8adb4d9
097e83a
8adb4d9
 
 
 
 
 
 
027d025
 
8adb4d9
 
027d025
 
 
 
 
 
 
 
 
 
 
 
 
8adb4d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
027d025
 
8adb4d9
027d025
8adb4d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
027d025
 
 
8adb4d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
027d025
 
8adb4d9
 
 
 
 
 
 
 
 
 
 
027d025
 
 
 
 
 
 
 
 
 
8adb4d9
 
 
 
 
 
 
 
 
 
027d025
 
8adb4d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
027d025
8adb4d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
027d025
8adb4d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
027d025
 
8adb4d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
027d025
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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Zombie Survival</title>
    <style>
        body {
            margin: 0;
            overflow: hidden;
            background: url('back1.webp') repeat;
            background-size: auto;
            font-family: Arial, sans-serif;
            cursor: crosshair;
            image-rendering: pixelated;
        }
        
        body::before {
            content: '';
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.3);
            pointer-events: none;
            z-index: 1;
        }
        
        #score {
            position: fixed;
            top: 20px;
            left: 20px;
            color: #fff;
            font-size: 24px;
            z-index: 100;
        }
        
        #health {
            position: fixed;
            top: 20px;
            right: 20px;
            color: #f00;
            font-size: 24px;
            z-index: 100;
        }
        
        #startScreen {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.8);
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            z-index: 1000;
        }
        
        #startButton {
            padding: 15px 40px;
            font-size: 24px;
            background: #4CAF50;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: transform 0.2s;
        }
        
        #startButton:hover {
            transform: scale(1.1);
        }
        
        #gameTitle {
            color: #fff;
            font-size: 48px;
            margin-bottom: 30px;
            text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
        }
        
        #gameOver {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            color: #f00;
            font-size: 48px;
            display: none;
            text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
            z-index: 100;
        }
        
        .bullet {
            position: absolute;
            width: 8px;
            height: 8px;
            background: #ffd700;
            border-radius: 50%;
            z-index: 50;
            box-shadow: 0 0 10px #ffd700;
        }
        
        #player {
            position: absolute;
            width: 40px;
            height: 40px;
            background: #0f0;
            border-radius: 50%;
            transform-origin: center;
            z-index: 90;
            box-shadow: 0 0 20px rgba(0, 255, 0, 0.5);
        }
        
        #playerGun {
            position: absolute;
            width: 20px;
            height: 8px;
            background: #666;
            top: 50%;
            right: -15px;
            transform: translateY(-50%);
        }
        
        .zombie {
            position: absolute;
            width: 40px;
            height: 40px;
            background: url('zom1.webp') no-repeat center center;
            background-size: cover;
            z-index: 80;
            transform-origin: center;
        }
        
        .explosion {
            position: absolute;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            animation: explode 0.5s ease-out forwards;
            z-index: 85;
        }
        
        @keyframes explode {
            0% {
                transform: scale(1);
                background: #ff4500;
                opacity: 1;
            }
            100% {
                transform: scale(2);
                background: #ff0000;
                opacity: 0;
            }
        }
        
        .muzzleFlash {
            position: absolute;
            width: 20px;
            height: 20px;
            background: #ffd700;
            border-radius: 50%;
            opacity: 0;
            animation: flash 0.1s ease-out;
        }
        
        @keyframes flash {
            0% { opacity: 1; transform: scale(1); }
            100% { opacity: 0; transform: scale(2); }
        }
    </style>
</head>
<body>
    <audio id="bgMusic" src="soundz.wav" loop></audio>
    <audio id="gunSound" src="soundgun.wav"></audio>
    
    <div id="startScreen">
        <h1 id="gameTitle">ZOMBIE SURVIVAL</h1>
        <button id="startButton">START GAME</button>
    </div>
    
    <div id="score">Score: 0</div>
    <div id="health">Health: 100</div>
    <div id="gameOver">GAME OVER</div>
    <div id="player">
        <div id="playerGun"></div>
    </div>
    
    <script>
        const startScreen = document.getElementById('startScreen');
        const startButton = document.getElementById('startButton');
        const player = document.getElementById('player');
        const scoreElement = document.getElementById('score');
        const healthElement = document.getElementById('health');
        const gameOverElement = document.getElementById('gameOver');
        const bgMusic = document.getElementById('bgMusic');
        const gunSound = document.getElementById('gunSound');
        
        let score = 0;
        let health = 100;
        let zombies = [];
        let bullets = [];
        let gameRunning = false;
        let mouseX = 0;
        let mouseY = 0;
        let playerX = window.innerWidth / 2;
        let playerY = window.innerHeight / 2;
        let zombieSpawnInterval;
        let lastShotTime = 0;
        const shotCooldown = 100;
        function playGunSound() {
            const currentTime = Date.now();
            if (currentTime - lastShotTime >= shotCooldown) {
                gunSound.currentTime = 0;
                gunSound.play();
                lastShotTime = currentTime;
            }
        }
        
        function startGame() {
            startScreen.style.display = 'none';
            gameRunning = true;
            score = 0;
            health = 100;
            scoreElement.textContent = `Score: ${score}`;
            healthElement.textContent = `Health: ${health}`;
            gameOverElement.style.display = 'none';
            
            bgMusic.play();
            
            zombies.forEach(zombie => zombie.element.remove());
            zombies = [];
            bullets.forEach(bullet => bullet.element.remove());
            bullets = [];
            
            playerX = window.innerWidth / 2;
            playerY = window.innerHeight / 2;
            updatePlayer();
            
            zombieSpawnInterval = setInterval(createZombie, 1000);
            requestAnimationFrame(gameLoop);
        }
        
        function updatePlayer() {
            player.style.left = `${playerX - 20}px`;
            player.style.top = `${playerY - 20}px`;
            
            const angle = Math.atan2(mouseY - playerY, mouseX - playerX);
            player.style.transform = `rotate(${angle}rad)`;
        }
        
        function createZombie() {
            if (!gameRunning) return;
            
            const zombie = document.createElement('div');
            zombie.className = 'zombie';
            
            const side = Math.floor(Math.random() * 4);
            let x, y;
            
            switch(side) {
                case 0: x = Math.random() * window.innerWidth; y = -40; break;
                case 1: x = window.innerWidth + 40; y = Math.random() * window.innerHeight; break;
                case 2: x = Math.random() * window.innerWidth; y = window.innerHeight + 40; break;
                case 3: x = -40; y = Math.random() * window.innerHeight; break;
            }
            
            document.body.appendChild(zombie);
            zombies.push({
                element: zombie,
                x: x,
                y: y,
                speed: 2 + Math.random()
            });
        }
        
        function createMuzzleFlash() {
            const flash = document.createElement('div');
            flash.className = 'muzzleFlash';
            const angle = Math.atan2(mouseY - playerY, mouseX - playerX);
            const distance = 30;
            const flashX = playerX + Math.cos(angle) * distance;
            const flashY = playerY + Math.sin(angle) * distance;
            
            flash.style.left = `${flashX - 10}px`;
            flash.style.top = `${flashY - 10}px`;
            document.body.appendChild(flash);
            
            setTimeout(() => flash.remove(), 100);
        }
        
        function shoot(e) {
            if (!gameRunning || e.button !== 0) return;
            
            const bullet = document.createElement('div');
            bullet.className = 'bullet';
            
            const angle = Math.atan2(mouseY - playerY, mouseX - playerX);
            const velocity = {
                x: Math.cos(angle) * 15,
                y: Math.sin(angle) * 15
            };
            
            createMuzzleFlash();
            playGunSound();
            
            document.body.appendChild(bullet);
            bullets.push({
                element: bullet,
                x: playerX,
                y: playerY,
                velocity: velocity
            });
        }
        
        function createExplosion(x, y) {
            const explosion = document.createElement('div');
            explosion.className = 'explosion';
            explosion.style.left = `${x - 20}px`;
            explosion.style.top = `${y - 20}px`;
            document.body.appendChild(explosion);
            
            setTimeout(() => explosion.remove(), 500);
        }
        
        function gameLoop() {
            if (!gameRunning) return;
            
            bullets.forEach((bullet, bulletIndex) => {
                bullet.x += bullet.velocity.x;
                bullet.y += bullet.velocity.y;
                bullet.element.style.left = `${bullet.x - 4}px`;
                bullet.element.style.top = `${bullet.y - 4}px`;
                
                if (bullet.x < 0 || bullet.x > window.innerWidth || 
                    bullet.y < 0 || bullet.y > window.innerHeight) {
                    bullet.element.remove();
                    bullets.splice(bulletIndex, 1);
                }
            });
            
            zombies.forEach((zombie, zombieIndex) => {
                const angle = Math.atan2(playerY - zombie.y, playerX - zombie.x);
                zombie.x += Math.cos(angle) * zombie.speed;
                zombie.y += Math.sin(angle) * zombie.speed;
                zombie.element.style.left = `${zombie.x - 20}px`;
                zombie.element.style.top = `${zombie.y - 20}px`;
                zombie.element.style.transform = `rotate(${angle}rad)`;  // μ’€λΉ„ νšŒμ „
                
                const distToPlayer = Math.hypot(playerX - zombie.x, playerY - zombie.y);
                if (distToPlayer < 40) {
                    health -= 1;
                    healthElement.textContent = `Health: ${health}`;
                    if (health <= 0) gameOver();
                }
                
                bullets.forEach((bullet, bulletIndex) => {
                    const distToBullet = Math.hypot(bullet.x - zombie.x, bullet.y - zombie.y);
                    if (distToBullet < 30) {
                        createExplosion(zombie.x, zombie.y);
                        zombie.element.remove();
                        bullet.element.remove();
                        zombies.splice(zombieIndex, 1);
                        bullets.splice(bulletIndex, 1);
                        score += 10;
                        scoreElement.textContent = `Score: ${score}`;
                    }
                });
            });
            
            requestAnimationFrame(gameLoop);
        }
        
        function gameOver() {
            gameRunning = false;
            gameOverElement.style.display = 'block';
            clearInterval(zombieSpawnInterval);
            bgMusic.pause();
            bgMusic.currentTime = 0;
            setTimeout(() => {
                startScreen.style.display = 'flex';
            }, 2000);
        }
        
        document.addEventListener('mousemove', (e) => {
            mouseX = e.clientX;
            mouseY = e.clientY;
            if (gameRunning) updatePlayer();
        });
        
        document.addEventListener('mousedown', shoot);
        startButton.addEventListener('click', startGame);
        
        updatePlayer();
    </script>
</body>
</html>