Spaces:
Running
Running
Update index.html
Browse files- index.html +81 -68
index.html
CHANGED
|
@@ -155,89 +155,102 @@
|
|
| 155 |
}
|
| 156 |
|
| 157 |
function updateGame() {
|
| 158 |
-
|
| 159 |
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
|
|
|
| 163 |
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
|
|
|
|
|
|
| 168 |
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
enemies.forEach((enemy, enemyIndex) => {
|
| 175 |
-
enemy.x += enemy.speed;
|
| 176 |
-
ctx.drawImage(enemy.image, enemy.x, enemy.y, enemy.width, enemy.height);
|
| 177 |
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
playerHitSound.play();
|
| 184 |
-
|
| 185 |
-
if (player.health <= 0) {
|
| 186 |
-
endGame("Game Over! Go back to the past and change the current result!");
|
| 187 |
-
}
|
| 188 |
-
}
|
| 189 |
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
enemies.splice(enemyIndex, 1);
|
| 195 |
-
bullets.splice(bulletIndex, 1);
|
| 196 |
-
enemiesRemaining--;
|
| 197 |
-
enemyCount.textContent = enemiesRemaining;
|
| 198 |
-
}, 100);
|
| 199 |
-
enemyHitSound.play();
|
| 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 |
setTimeout(() => {
|
| 243 |
message.textContent = "Click on the character";
|
|
|
|
| 155 |
}
|
| 156 |
|
| 157 |
function updateGame() {
|
| 158 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
| 159 |
|
| 160 |
+
// ํ๋ ์ด์ด ๋ฐฉํฅ ์
๋ฐ์ดํธ
|
| 161 |
+
player.direction = mouseX > player.x ? 1 : -1;
|
| 162 |
+
player.image.src = player.direction === 1 ? player.imageRight : player.imageLeft;
|
| 163 |
+
ctx.drawImage(player.image, player.x, player.y, player.width, player.height);
|
| 164 |
|
| 165 |
+
// ์ด์ ์
๋ฐ์ดํธ ๋ฐ ๋ ๋๋ง
|
| 166 |
+
bullets.forEach((bullet, index) => {
|
| 167 |
+
bullet.x += bullet.speed;
|
| 168 |
+
ctx.fillStyle = 'yellow';
|
| 169 |
+
ctx.fillRect(bullet.x, bullet.y, 10, 5);
|
| 170 |
+
});
|
| 171 |
|
| 172 |
+
// ๊ธฐ์กด ์ด์ ์ ๊ฑฐ ๋ก์ง ์ถ๊ฐ (ํ๋ฉด ๋ฐ ์ด์ ์ ๊ฑฐ)
|
| 173 |
+
bullets = bullets.filter(bullet =>
|
| 174 |
+
bullet.x >= 0 && bullet.x <= canvas.width
|
| 175 |
+
);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
|
| 177 |
+
enemyBullets.forEach((bullet, index) => {
|
| 178 |
+
bullet.x += bullet.speed;
|
| 179 |
+
ctx.fillStyle = 'orange';
|
| 180 |
+
ctx.fillRect(bullet.x, bullet.y, bullet.width, bullet.height);
|
| 181 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
+
// ๊ธฐ์กด ์ ์ด์ ์ ๊ฑฐ ๋ก์ง ์ถ๊ฐ
|
| 184 |
+
enemyBullets = enemyBullets.filter(bullet =>
|
| 185 |
+
bullet.x >= 0 && bullet.x <= canvas.width
|
| 186 |
+
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
|
| 188 |
+
// ์ ์
๋ฐ์ดํธ ๋ฐ ๋ ๋๋ง
|
| 189 |
+
enemies.forEach((enemy, enemyIndex) => {
|
| 190 |
+
enemy.x += enemy.speed;
|
| 191 |
+
ctx.drawImage(enemy.image, enemy.x, enemy.y, enemy.width, enemy.height);
|
|
|
|
| 192 |
|
| 193 |
+
// ์ ๊ณผ ํ๋ ์ด์ด ์ถฉ๋ ์ฒ๋ฆฌ
|
| 194 |
+
if (checkCollision(player, enemy)) {
|
| 195 |
+
player.health--;
|
| 196 |
+
healthFill.style.width = (player.health / 5 * 100) + '%';
|
| 197 |
+
player.image.src = player.direction === 1 ? player.imageHitRight : player.imageHitLeft;
|
| 198 |
+
enemies.splice(enemyIndex, 1);
|
| 199 |
+
playerHitSound.play();
|
| 200 |
|
| 201 |
+
if (player.health <= 0) {
|
| 202 |
+
endGame("Game Over! Go back to the past and change the current result!");
|
| 203 |
+
}
|
| 204 |
+
}
|
| 205 |
|
| 206 |
+
// ํ๋ ์ด์ด ์ด์๊ณผ ์ ์ถฉ๋ ์ฒ๋ฆฌ
|
| 207 |
+
bullets.forEach((bullet, bulletIndex) => {
|
| 208 |
+
if (checkCollision(bullet, enemy)) {
|
| 209 |
+
enemy.image.src = enemy.speed > 0 ? enemy.imageHitRight : enemy.imageHitLeft;
|
| 210 |
+
setTimeout(() => {
|
| 211 |
+
enemies.splice(enemyIndex, 1);
|
| 212 |
+
bullets.splice(bulletIndex, 1);
|
| 213 |
+
enemiesRemaining--;
|
| 214 |
+
enemyCount.textContent = enemiesRemaining;
|
| 215 |
+
}, 100);
|
| 216 |
+
enemyHitSound.play();
|
| 217 |
|
| 218 |
+
if (enemiesRemaining <= 0) {
|
| 219 |
+
endGame("You have successfully protected New York. Return to the time machine.");
|
|
|
|
| 220 |
}
|
| 221 |
+
}
|
| 222 |
+
});
|
| 223 |
|
| 224 |
+
// ์ ์ด์ ๋ฐ์ฌ
|
| 225 |
+
enemyShoot(enemy);
|
| 226 |
+
});
|
|
|
|
| 227 |
|
| 228 |
+
// ์ ์ด์๊ณผ ํ๋ ์ด์ด ์ถฉ๋ ์ฒ๋ฆฌ
|
| 229 |
+
enemyBullets.forEach((bullet, index) => {
|
| 230 |
+
bullet.x += bullet.speed;
|
| 231 |
+
if (
|
| 232 |
+
bullet.x < player.x + player.width - 30 &&
|
| 233 |
+
bullet.x + bullet.width > player.x + 30 &&
|
| 234 |
+
bullet.y < player.y + player.height - 30 &&
|
| 235 |
+
bullet.y + bullet.height > player.y + 30
|
| 236 |
+
) {
|
| 237 |
+
player.health--;
|
| 238 |
+
healthFill.style.width = (player.health / 5 * 100) + '%';
|
| 239 |
+
player.image.src = player.direction === 1 ? player.imageHitRight : player.imageHitLeft;
|
| 240 |
+
enemyBullets.splice(index, 1);
|
| 241 |
+
playerHitSound.play();
|
| 242 |
+
|
| 243 |
+
if (player.health <= 0) {
|
| 244 |
+
endGame("Game Over! Go back to the past and change the current result!");
|
| 245 |
}
|
| 246 |
}
|
| 247 |
+
});
|
| 248 |
+
|
| 249 |
+
if (!gameOver) {
|
| 250 |
+
requestAnimationFrame(updateGame);
|
| 251 |
+
}
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
|
| 255 |
setTimeout(() => {
|
| 256 |
message.textContent = "Click on the character";
|