ProPerNounpYK commited on
Commit
60ac1f3
ยท
verified ยท
1 Parent(s): 67b7031

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +81 -68
index.html CHANGED
@@ -155,89 +155,102 @@
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
- if (bullet.x < 0 || bullet.x > canvas.width) {
170
- bullets.splice(index, 1);
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
- if (checkCollision(player, enemy)) {
179
- player.health--;
180
- healthFill.style.width = (player.health / 5 * 100) + '%';
181
- player.image.src = player.direction === 1 ? player.imageHitRight : player.imageHitLeft;
182
- enemies.splice(enemyIndex, 1);
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
- 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
- enemyShoot(enemy);
208
- });
 
 
 
 
 
209
 
210
- enemyBullets.forEach((bullet, index) => {
211
- bullet.x += bullet.speed;
212
- ctx.fillStyle = 'orange';
213
- ctx.fillRect(bullet.x, bullet.y, bullet.width, bullet.height);
214
 
215
- if (
216
- bullet.x < player.x + player.width - 30 &&
217
- bullet.x + bullet.width > player.x + 30 &&
218
- bullet.y < player.y + player.height - 30 &&
219
- bullet.y + bullet.height > player.y + 30
220
- ) {
221
- player.health--;
222
- healthFill.style.width = (player.health / 5 * 100) + '%';
223
- player.image.src = player.direction === 1 ? player.imageHitRight : player.imageHitLeft;
224
- enemyBullets.splice(index, 1);
225
- playerHitSound.play();
226
 
227
- if (player.health <= 0) {
228
- endGame("Game Over! Go back to the past and change the current result!");
229
- }
230
  }
 
 
231
 
232
- if (bullet.x < 0 || bullet.x > canvas.width) {
233
- enemyBullets.splice(index, 1);
234
- }
235
- });
236
 
237
- if (!gameOver) {
238
- requestAnimationFrame(updateGame);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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";