Spaces:
Running
Running
Update index.html
Browse files- index.html +23 -16
index.html
CHANGED
|
@@ -100,7 +100,7 @@
|
|
| 100 |
const enemyShootSound = document.getElementById('enemyShootSound');
|
| 101 |
const playerHitSound = document.getElementById('playerHitSound');
|
| 102 |
const enemyHitSound = document.getElementById('enemyHitSound');
|
| 103 |
-
const attackPower = 1
|
| 104 |
|
| 105 |
|
| 106 |
canvas.width = window.innerWidth;
|
|
@@ -190,22 +190,29 @@ player.image.src = player.imageRight;
|
|
| 190 |
}
|
| 191 |
}
|
| 192 |
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
|
| 204 |
-
if (enemiesRemaining <= 0) {
|
| 205 |
-
endGame("You have successfully protected New York. Return to the time machine.");
|
| 206 |
-
}
|
| 207 |
-
}
|
| 208 |
-
});
|
| 209 |
|
| 210 |
enemyShoot(enemy);
|
| 211 |
});
|
|
|
|
| 100 |
const enemyShootSound = document.getElementById('enemyShootSound');
|
| 101 |
const playerHitSound = document.getElementById('playerHitSound');
|
| 102 |
const enemyHitSound = document.getElementById('enemyHitSound');
|
| 103 |
+
const attackPower = 1
|
| 104 |
|
| 105 |
|
| 106 |
canvas.width = window.innerWidth;
|
|
|
|
| 190 |
}
|
| 191 |
}
|
| 192 |
|
| 193 |
+
enemyBullets.forEach((bullet) => {
|
| 194 |
+
bullet.x += bullet.speed;
|
| 195 |
+
ctx.fillStyle = 'orange';
|
| 196 |
+
ctx.fillRect(bullet.x, bullet.y, bullet.width, bullet.height);
|
| 197 |
+
|
| 198 |
+
// 플레이어와 적 총알 충돌 검사
|
| 199 |
+
if (
|
| 200 |
+
bullet.x < player.x + player.width - 30 &&
|
| 201 |
+
bullet.x + bullet.width > player.x + 30 &&
|
| 202 |
+
bullet.y < player.y + player.height - 30 &&
|
| 203 |
+
bullet.y + bullet.height > player.y + 30
|
| 204 |
+
) {
|
| 205 |
+
player.health -= attackPower; // 체력을 attackPower만큼 감소
|
| 206 |
+
healthFill.style.width = (player.health / 5 * 100) + '%'; // 체력 바 업데이트
|
| 207 |
+
player.image.src = player.direction === 1 ? player.imageHitRight : player.imageHitLeft;
|
| 208 |
+
playerHitSound.play();
|
| 209 |
+
|
| 210 |
+
if (player.health <= 0) {
|
| 211 |
+
endGame("Game Over! Go back to the past and change the current result!");
|
| 212 |
+
}
|
| 213 |
+
}
|
| 214 |
+
});
|
| 215 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
|
| 217 |
enemyShoot(enemy);
|
| 218 |
});
|