Spaces:
Running
Running
Update index.html
Browse files- index.html +35 -32
index.html
CHANGED
|
@@ -105,23 +105,23 @@
|
|
| 105 |
canvas.height = window.innerHeight;
|
| 106 |
|
| 107 |
const player = {
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
|
| 126 |
let enemies = [];
|
| 127 |
let bullets = [];
|
|
@@ -209,27 +209,30 @@
|
|
| 209 |
});
|
| 210 |
|
| 211 |
// ์ ์ด์ ์
๋ฐ์ดํธ
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
healthFill.style.width = (player.health / 5 * 100) + '%'; // ์ฒด๋ ฅ ๋ฐ ์
๋ฐ์ดํธ
|
| 225 |
player.image.src = player.direction === 1 ? player.imageHitRight : player.imageHitLeft;
|
| 226 |
playerHitSound.play();
|
| 227 |
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
}
|
| 231 |
}
|
| 232 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
// ํ๋ฉด ๋ฐ ์ ์ด์ ์ ๊ฑฐ
|
| 234 |
enemyBullets = enemyBullets.filter(bullet => bullet.x >= 0 && bullet.x <= canvas.width);
|
| 235 |
|
|
|
|
| 105 |
canvas.height = window.innerHeight;
|
| 106 |
|
| 107 |
const player = {
|
| 108 |
+
x: canvas.width / 2.3,
|
| 109 |
+
y: canvas.height - 260,
|
| 110 |
+
width: 250,
|
| 111 |
+
height: 250,
|
| 112 |
+
speed: 10,
|
| 113 |
+
health: 5, // ํ๋ ์ด์ด ์ฒด๋ ฅ์ 5๋ก ์ค์
|
| 114 |
+
bullets: 35,
|
| 115 |
+
direction: 1,
|
| 116 |
+
image: new Image(),
|
| 117 |
+
imageLeft: 'Maincharacterdefaultleft.png',
|
| 118 |
+
imageRight: 'Maincharacterdefaultright.png',
|
| 119 |
+
imageShootLeft: 'Maincharactergunshotleft.png',
|
| 120 |
+
imageShootRight: 'Maincharactergunshotright.png',
|
| 121 |
+
imageHitLeft: 'MainCharacterExplosionLeft.png',
|
| 122 |
+
imageHitRight: 'MainCharacterExplosionRight.png'
|
| 123 |
+
};
|
| 124 |
+
player.image.src = player.imageRight;
|
| 125 |
|
| 126 |
let enemies = [];
|
| 127 |
let bullets = [];
|
|
|
|
| 209 |
});
|
| 210 |
|
| 211 |
// ์ ์ด์ ์
๋ฐ์ดํธ
|
| 212 |
+
enemyBullets.forEach((bullet) => {
|
| 213 |
+
bullet.x += bullet.speed;
|
| 214 |
+
ctx.fillStyle = 'orange';
|
| 215 |
+
ctx.fillRect(bullet.x, bullet.y, bullet.width, bullet.height);
|
| 216 |
|
| 217 |
+
if (
|
| 218 |
+
bullet.x < player.x + player.width - 30 &&
|
| 219 |
+
bullet.x + bullet.width > player.x + 30 &&
|
| 220 |
+
bullet.y < player.y + player.height - 30 &&
|
| 221 |
+
bullet.y + bullet.height > player.y + 30
|
| 222 |
+
) {
|
| 223 |
+
player.health--; // ํ๋ ์ด์ด ์ฒด๋ ฅ ๊ฐ์
|
| 224 |
healthFill.style.width = (player.health / 5 * 100) + '%'; // ์ฒด๋ ฅ ๋ฐ ์
๋ฐ์ดํธ
|
| 225 |
player.image.src = player.direction === 1 ? player.imageHitRight : player.imageHitLeft;
|
| 226 |
playerHitSound.play();
|
| 227 |
|
| 228 |
+
if (player.health <= 0) {
|
| 229 |
+
endGame("Game Over! Go back to the past and change the current result!"); // ์ฒด๋ ฅ์ด 0์ด ๋๋ฉด ๊ฒ์ ์ค๋ฒ
|
|
|
|
| 230 |
}
|
| 231 |
+
}
|
| 232 |
+
});
|
| 233 |
+
|
| 234 |
+
// ์ฒด๋ ฅ ๋ฐ๋ฅผ ์ด๊ธฐํํ ๋
|
| 235 |
+
healthFill.style.width = (player.health / 5 * 100) + '%';
|
| 236 |
// ํ๋ฉด ๋ฐ ์ ์ด์ ์ ๊ฑฐ
|
| 237 |
enemyBullets = enemyBullets.filter(bullet => bullet.x >= 0 && bullet.x <= canvas.width);
|
| 238 |
|