Spaces:
Running
Running
Update index-backup1.html
Browse files- index-backup1.html +14 -2
index-backup1.html
CHANGED
@@ -158,6 +158,7 @@
|
|
158 |
</head>
|
159 |
<body>
|
160 |
<audio id="bgMusic" src="soundz.wav" loop></audio>
|
|
|
161 |
|
162 |
<div id="startScreen">
|
163 |
<h1 id="gameTitle">ZOMBIE SURVIVAL</h1>
|
@@ -179,6 +180,7 @@
|
|
179 |
const healthElement = document.getElementById('health');
|
180 |
const gameOverElement = document.getElementById('gameOver');
|
181 |
const bgMusic = document.getElementById('bgMusic');
|
|
|
182 |
|
183 |
let score = 0;
|
184 |
let health = 100;
|
@@ -190,6 +192,17 @@
|
|
190 |
let playerX = window.innerWidth / 2;
|
191 |
let playerY = window.innerHeight / 2;
|
192 |
let zombieSpawnInterval;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
|
194 |
function startGame() {
|
195 |
startScreen.style.display = 'none';
|
@@ -200,7 +213,6 @@
|
|
200 |
healthElement.textContent = `Health: ${health}`;
|
201 |
gameOverElement.style.display = 'none';
|
202 |
|
203 |
-
// Start background music
|
204 |
bgMusic.play();
|
205 |
|
206 |
zombies.forEach(zombie => zombie.element.remove());
|
@@ -277,6 +289,7 @@
|
|
277 |
};
|
278 |
|
279 |
createMuzzleFlash();
|
|
|
280 |
|
281 |
document.body.appendChild(bullet);
|
282 |
bullets.push({
|
@@ -364,7 +377,6 @@
|
|
364 |
document.addEventListener('mousedown', shoot);
|
365 |
startButton.addEventListener('click', startGame);
|
366 |
|
367 |
-
// Initial setup
|
368 |
updatePlayer();
|
369 |
</script>
|
370 |
</body>
|
|
|
158 |
</head>
|
159 |
<body>
|
160 |
<audio id="bgMusic" src="soundz.wav" loop></audio>
|
161 |
+
<audio id="gunSound" src="soundgun.wav"></audio>
|
162 |
|
163 |
<div id="startScreen">
|
164 |
<h1 id="gameTitle">ZOMBIE SURVIVAL</h1>
|
|
|
180 |
const healthElement = document.getElementById('health');
|
181 |
const gameOverElement = document.getElementById('gameOver');
|
182 |
const bgMusic = document.getElementById('bgMusic');
|
183 |
+
const gunSound = document.getElementById('gunSound');
|
184 |
|
185 |
let score = 0;
|
186 |
let health = 100;
|
|
|
192 |
let playerX = window.innerWidth / 2;
|
193 |
let playerY = window.innerHeight / 2;
|
194 |
let zombieSpawnInterval;
|
195 |
+
let lastShotTime = 0;
|
196 |
+
const shotCooldown = 100;
|
197 |
+
|
198 |
+
function playGunSound() {
|
199 |
+
const currentTime = Date.now();
|
200 |
+
if (currentTime - lastShotTime >= shotCooldown) {
|
201 |
+
gunSound.currentTime = 0;
|
202 |
+
gunSound.play();
|
203 |
+
lastShotTime = currentTime;
|
204 |
+
}
|
205 |
+
}
|
206 |
|
207 |
function startGame() {
|
208 |
startScreen.style.display = 'none';
|
|
|
213 |
healthElement.textContent = `Health: ${health}`;
|
214 |
gameOverElement.style.display = 'none';
|
215 |
|
|
|
216 |
bgMusic.play();
|
217 |
|
218 |
zombies.forEach(zombie => zombie.element.remove());
|
|
|
289 |
};
|
290 |
|
291 |
createMuzzleFlash();
|
292 |
+
playGunSound();
|
293 |
|
294 |
document.body.appendChild(bullet);
|
295 |
bullets.push({
|
|
|
377 |
document.addEventListener('mousedown', shoot);
|
378 |
startButton.addEventListener('click', startGame);
|
379 |
|
|
|
380 |
updatePlayer();
|
381 |
</script>
|
382 |
</body>
|