ProPerNounpYK commited on
Commit
312ba0e
·
verified ·
1 Parent(s): 4bf2319

Update index.html

Browse files
Files changed (1) hide show
  1. 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; // 한 번 맞을 때마다 체력을 1 감소시킴
104
 
105
 
106
  canvas.width = window.innerWidth;
@@ -190,22 +190,29 @@ player.image.src = player.imageRight;
190
  }
191
  }
192
 
193
- bullets.forEach((bullet, bulletIndex) => {
194
- if (checkCollision(bullet, enemy)) {
195
- enemy.image.src = enemy.speed > 0 ? enemy.imageHitRight : enemy.imageHitLeft;
196
- setTimeout(() => {
197
- enemies.splice(enemyIndex, 1);
198
- bullets.splice(bulletIndex, 1);
199
- enemiesRemaining--;
200
- enemyCount.textContent = enemiesRemaining;
201
- }, 100);
202
- enemyHitSound.play();
 
 
 
 
 
 
 
 
 
 
 
 
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
  });