ProPerNounpYK commited on
Commit
1f12de5
ยท
verified ยท
1 Parent(s): 0290d1d

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +73 -57
index.html CHANGED
@@ -155,76 +155,92 @@
155
  }
156
 
157
  function updateGame() {
158
- ctx.clearRect(0, 0, canvas.width, canvas.height);
159
 
160
- player.direction = mouseX > player.x ? 1 : -1;
161
- player.image.src = player.direction === 1 ? player.imageRight : player.imageLeft;
162
- ctx.drawImage(player.image, player.x, player.y, player.width, player.height);
 
163
 
164
- bullets.forEach((bullet, index) => {
165
- bullet.x += bullet.speed;
166
- ctx.fillStyle = 'yellow';
167
- ctx.fillRect(bullet.x, bullet.y, 10, 5);
168
- });
 
169
 
170
- enemies.forEach((enemy, enemyIndex) => {
171
- enemy.x += enemy.speed;
172
- ctx.drawImage(enemy.image, enemy.x, enemy.y, enemy.width, enemy.height);
 
173
 
174
- if (checkCollision(player, enemy)) {
175
- player.health--;
176
- healthFill.style.width = (player.health / 5 * 100) + '%';
177
- player.image.src = player.direction === 1 ? player.imageHitRight : player.imageHitLeft;
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  enemies.splice(enemyIndex, 1);
179
- playerHitSound.play();
 
 
 
 
180
 
181
- if (player.health <= 0) {
182
- endGame("Game Over! Go back to the past and change the current result!");
183
- }
184
  }
 
 
185
 
186
- bullets.forEach((bullet, bulletIndex) => {
187
- if (checkCollision(bullet, enemy)) {
188
- enemy.image.src = enemy.speed > 0 ? enemy.imageHitRight : enemy.imageHitLeft;
189
- setTimeout(() => {
190
- enemies.splice(enemyIndex, 1);
191
- bullets.splice(bulletIndex, 1);
192
- enemiesRemaining--;
193
- enemyCount.textContent = enemiesRemaining;
194
- }, 100);
195
- enemyHitSound.play();
196
 
197
- if (enemiesRemaining <= 0) {
198
- endGame("You have successfully protected New York. Return to the time machine.");
199
- }
200
- }
201
- });
202
 
203
- enemyShoot(enemy);
204
- });
 
 
 
 
 
 
 
 
205
 
206
- enemyBullets.forEach((bullet, index) => {
207
- bullet.x += bullet.speed;
208
- ctx.fillStyle = 'orange';
209
- ctx.fillRect(bullet.x, bullet.y, bullet.width, bullet.height);
 
210
 
211
- if (
212
- bullet.x < player.x + player.width - 30 &&
213
- bullet.x + bullet.width > player.x + 30 &&
214
- bullet.y < player.y + player.height - 30 &&
215
- bullet.y + bullet.height > player.y + 30
216
- ) {
217
- player.health--;
218
- healthFill.style.width = (player.health / 5 * 100) + '%';
219
- player.image.src = player.direction === 1 ? player.imageHitRight : player.imageHitLeft;
220
- enemyBullets.splice(index, 1);
221
- playerHitSound.play();
222
 
223
- if (player.health <= 0) {
224
- endGame("Game Over! Go back to the past and change the current result!");
225
- }
226
- }
227
- });
228
 
229
  // ํ™”๋ฉด ๋ฐ–์˜ ์ด์•Œ ์ œ๊ฑฐ
230
  bullets = bullets.filter(bullet =>
 
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, bullet.width, bullet.height);
170
+ });
171
 
172
+ // ์  ์—…๋ฐ์ดํŠธ ๋ฐ ์ถฉ๋Œ ์ฒดํฌ
173
+ enemies.forEach((enemy, enemyIndex) => {
174
+ enemy.x += enemy.speed;
175
+ ctx.drawImage(enemy.image, enemy.x, enemy.y, enemy.width, enemy.height);
176
 
177
+ // ํ”Œ๋ ˆ์ด์–ด์™€ ์  ์ถฉ๋Œ ์ฒดํฌ
178
+ if (checkCollision(player, enemy)) {
179
+ player.health--;
180
+ healthFill.style.width = (player.health / 10 * 100) + '%';
181
+ enemies.splice(enemyIndex, 1);
182
+ playerHitSound.play();
183
+
184
+ if (player.health <= 0) {
185
+ endGame("Game Over! Go back to the past and change the current result!");
186
+ }
187
+ }
188
+
189
+ // ํ”Œ๋ ˆ์ด์–ด์˜ ์ด์•Œ๊ณผ ์  ์ถฉ๋Œ ์ฒดํฌ
190
+ bullets.forEach((bullet, bulletIndex) => {
191
+ if (checkCollision(bullet, enemy)) {
192
+ enemy.image.src = enemy.speed > 0 ? enemy.imageHitRight : enemy.imageHitLeft;
193
+ setTimeout(() => {
194
  enemies.splice(enemyIndex, 1);
195
+ bullets.splice(bulletIndex, 1);
196
+ enemiesRemaining--;
197
+ enemyCount.textContent = enemiesRemaining;
198
+ }, 100);
199
+ enemyHitSound.play();
200
 
201
+ if (enemiesRemaining <= 0) {
202
+ endGame("You have successfully protected New York. Return to the time machine.");
 
203
  }
204
+ }
205
+ });
206
 
207
+ // ์ ์˜ ์ด์•Œ ๋ฐœ์‚ฌ
208
+ enemyShoot(enemy);
209
+ });
 
 
 
 
 
 
 
210
 
211
+ // ์ ์˜ ์ด์•Œ ์—…๋ฐ์ดํŠธ ๋ฐ ์ถฉ๋Œ ์ฒดํฌ
212
+ enemyBullets.forEach((bullet, index) => {
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 / 10 * 100) + '%';
225
+ enemyBullets.splice(index, 1);
226
+ playerHitSound.play();
227
 
228
+ if (player.health <= 0) {
229
+ endGame("Game Over! Go back to the past and change the current result!");
230
+ }
231
+ }
232
+ });
233
 
234
+ // ํ™”๋ฉด ๋ฐ–์œผ๋กœ ๋‚˜๊ฐ„ ์ด์•Œ ์ œ๊ฑฐ
235
+ bullets = bullets.filter(bullet => bullet.x >= 0 && bullet.x <= canvas.width);
236
+ enemyBullets = enemyBullets.filter(bullet => bullet.x >= 0 && bullet.x <= canvas.width);
237
+
238
+ // ๊ฒŒ์ž„ ์˜ค๋ฒ„๊ฐ€ ์•„๋‹ˆ๋ฉด ๊ณ„์† ์—…๋ฐ์ดํŠธ
239
+ if (!gameOver) {
240
+ requestAnimationFrame(updateGame);
241
+ }
242
+ }
 
 
243
 
 
 
 
 
 
244
 
245
  // ํ™”๋ฉด ๋ฐ–์˜ ์ด์•Œ ์ œ๊ฑฐ
246
  bullets = bullets.filter(bullet =>