ProPerNounpYK commited on
Commit
9623bb6
Β·
verified Β·
1 Parent(s): 2531a15

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +78 -71
index.html CHANGED
@@ -159,92 +159,99 @@
159
  enemy.image.src = side === 0 ? enemy.imageLeft : enemy.imageRight;
160
  enemies.push(enemy);
161
  }
162
-
163
  function updateGame() {
164
- ctx.clearRect(0, 0, canvas.width, canvas.height);
165
-
166
- player.direction = mouseX > player.x ? 1 : -1;
167
- player.image.src = player.direction === 1 ? player.imageRight : player.imageLeft;
168
- ctx.drawImage(player.image, player.x, player.y, player.width, player.height);
169
 
170
- bullets.forEach((bullet, index) => {
171
- bullet.x += bullet.speed;
172
- ctx.fillStyle = 'yellow';
173
- ctx.fillRect(bullet.x, bullet.y, 10, 5);
174
- });
175
 
176
- enemies.forEach((enemy, enemyIndex) => {
177
- enemy.x += enemy.speed;
178
- ctx.drawImage(enemy.image, enemy.x, enemy.y, enemy.width, enemy.height);
 
 
 
179
 
180
- if (checkCollision(player, enemy)) {
181
- player.health--;
182
- healthFill.style.width = (player.health / 5 * 100) + '%';
183
- player.image.src = player.direction === 1 ? player.imageHitRight : player.imageHitLeft;
184
- enemies.splice(enemyIndex, 1);
185
- playerHitSound.play();
186
 
187
- if (player.health <= 0) {
188
- endGame("Game Over! Go back to the past and change the current result!");
189
- }
190
- }
191
-
192
- bullets.forEach((bullet, bulletIndex) => {
193
- if (checkCollision(bullet, enemy)) {
194
- enemy.image.src = enemy.speed > 0 ? enemy.imageHitRight : enemy.imageHitLeft;
195
- setTimeout(() => {
196
- enemies.splice(enemyIndex, 1);
197
- bullets.splice(bulletIndex, 1);
198
- enemiesRemaining--;
199
- enemyCount.textContent = enemiesRemaining;
200
- }, 100);
201
- enemyHitSound.play();
202
 
203
- if (enemiesRemaining <= 0) {
204
- endGame("You have successfully protected New York. Return to the time machine.");
205
- }
206
- }
207
- });
208
 
209
- enemyShoot(enemy);
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 / 5 * 100) + '%';
225
- player.image.src = player.direction === 1 ? player.imageHitRight : player.imageHitLeft;
226
- enemyBullets.splice(index, 1);
227
- playerHitSound.play();
228
 
229
- if (player.health <= 0) {
230
- endGame("Game Over! Go back to the past and change the current result!");
231
- }
232
- }
233
- });
234
 
235
- // ν™”λ©΄ λ°–μ˜ μ΄μ•Œ 제거
236
- bullets = bullets.filter(bullet =>
237
- bullet.x >= 0 && bullet.x <= canvas.width
238
- );
239
- enemyBullets = enemyBullets.filter(bullet =>
240
- bullet.x >= 0 && bullet.x <= canvas.width
241
- );
 
 
 
 
 
242
 
243
- if (!gameOver) {
244
- requestAnimationFrame(updateGame);
245
  }
246
  }
 
 
 
 
 
 
 
 
 
247
 
 
 
 
 
 
248
  setTimeout(() => {
249
  message.textContent = "Click on the character";
250
  setTimeout(() => {
 
159
  enemy.image.src = side === 0 ? enemy.imageLeft : enemy.imageRight;
160
  enemies.push(enemy);
161
  }
 
162
  function updateGame() {
163
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
 
 
 
 
164
 
165
+ player.direction = mouseX > player.x ? 1 : -1;
166
+ player.image.src = player.direction === 1 ? player.imageRight : player.imageLeft;
167
+ ctx.drawImage(player.image, player.x, player.y, player.width, player.height);
 
 
168
 
169
+ // ν”Œλ ˆμ΄μ–΄κ°€ λ°œμ‚¬ν•œ μ΄μ•Œ 처리
170
+ bullets.forEach((bullet, index) => {
171
+ bullet.x += bullet.speed;
172
+ ctx.fillStyle = 'yellow';
173
+ ctx.fillRect(bullet.x, bullet.y, 10, 5);
174
+ });
175
 
176
+ // 적 처리
177
+ enemies.forEach((enemy, enemyIndex) => {
178
+ enemy.x += enemy.speed;
179
+ ctx.drawImage(enemy.image, enemy.x, enemy.y, enemy.width, enemy.height);
 
 
180
 
181
+ // ν”Œλ ˆμ΄μ–΄μ™€ 적이 μΆ©λŒν–ˆμ„ 경우 처리
182
+ if (checkCollision(player, enemy)) {
183
+ player.health--;
184
+ healthFill.style.width = (player.health / 5 * 100) + '%';
185
+ player.image.src = player.direction === 1 ? player.imageHitRight : player.imageHitLeft;
186
+ enemies.splice(enemyIndex, 1); // 적 제거
187
+ playerHitSound.play();
 
 
 
 
 
 
 
 
188
 
189
+ if (player.health <= 0) {
190
+ endGame("Game Over! Go back to the past and change the current result!");
191
+ }
192
+ }
 
193
 
194
+ // ν”Œλ ˆμ΄μ–΄μ˜ μ΄μ•Œμ΄ 적을 λ§žμ·„μ„ 경우 처리
195
+ bullets.forEach((bullet, bulletIndex) => {
196
+ if (checkCollision(bullet, enemy)) {
197
+ // μ΄μ•Œμ΄ 적을 λ§žμ·„μ„ λ•Œ 처리
198
+ enemy.image.src = enemy.speed > 0 ? enemy.imageHitRight : enemy.imageHitLeft;
199
+ setTimeout(() => {
200
+ enemies.splice(enemyIndex, 1); // 적 제거
201
+ bullets.splice(bulletIndex, 1); // μ΄μ•Œ 제거
202
+ enemiesRemaining--;
203
+ enemyCount.textContent = enemiesRemaining;
204
+ }, 100);
205
+ enemyHitSound.play();
206
 
207
+ if (enemiesRemaining <= 0) {
208
+ endGame("You have successfully protected New York. Return to the time machine.");
209
+ }
210
+ }
211
+ });
212
 
213
+ // 적의 μ΄μ•Œ λ°œμ‚¬
214
+ enemyShoot(enemy);
215
+ });
 
 
 
 
 
 
 
 
216
 
217
+ // 적의 μ΄μ•Œ 처리
218
+ enemyBullets.forEach((bullet, index) => {
219
+ bullet.x += bullet.speed;
220
+ ctx.fillStyle = 'orange';
221
+ ctx.fillRect(bullet.x, bullet.y, bullet.width, bullet.height);
222
 
223
+ // μ΄μ•Œμ΄ ν”Œλ ˆμ΄μ–΄μ™€ μΆ©λŒν–ˆμ„ 경우 처리
224
+ if (
225
+ bullet.x < player.x + player.width - 30 &&
226
+ bullet.x + bullet.width > player.x + 30 &&
227
+ bullet.y < player.y + player.height - 30 &&
228
+ bullet.y + bullet.height > player.y + 30
229
+ ) {
230
+ player.health--;
231
+ healthFill.style.width = (player.health / 5 * 100) + '%';
232
+ player.image.src = player.direction === 1 ? player.imageHitRight : player.imageHitLeft;
233
+ enemyBullets.splice(index, 1); // μ΄μ•Œ 제거
234
+ playerHitSound.play();
235
 
236
+ if (player.health <= 0) {
237
+ endGame("Game Over! Go back to the past and change the current result!");
238
  }
239
  }
240
+ });
241
+
242
+ // ν™”λ©΄ λ°–μœΌλ‘œ λ‚˜κ°„ μ΄μ•Œ 제거
243
+ bullets = bullets.filter(bullet =>
244
+ bullet.x >= 0 && bullet.x <= canvas.width
245
+ );
246
+ enemyBullets = enemyBullets.filter(bullet =>
247
+ bullet.x >= 0 && bullet.x <= canvas.width
248
+ );
249
 
250
+ // κ²Œμž„μ΄ μ’…λ£Œλ˜μ§€ μ•ŠμœΌλ©΄ 계속 μ—…λ°μ΄νŠΈ
251
+ if (!gameOver) {
252
+ requestAnimationFrame(updateGame);
253
+ }
254
+ }
255
  setTimeout(() => {
256
  message.textContent = "Click on the character";
257
  setTimeout(() => {