ProPerNounpYK commited on
Commit
264388d
Β·
verified Β·
1 Parent(s): b1e64b7

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +357 -0
index.html CHANGED
@@ -188,4 +188,361 @@ playAudioForDuration('reflected-light-147979.mp3', 31000);
188
 
189
  </script>
190
  </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  </html>
 
188
 
189
  </script>
190
  </body>
191
+ </html>
192
+
193
+ after 1 sec
194
+
195
+ <!DOCTYPE html>
196
+ <html>
197
+ <head>
198
+ <style>
199
+ body {
200
+ margin: 0;
201
+ overflow: hidden;
202
+ background: black;
203
+ }
204
+ #gameCanvas {
205
+ background-image: url('stage 1.jpg');
206
+ background-size: cover;
207
+ }
208
+ #message {
209
+ position: fixed;
210
+ bottom: 550px;
211
+ left: 0;
212
+ width: 100%;
213
+ color: white;
214
+ text-align: center;
215
+ font-size: 30px;
216
+ font-family: Arial;
217
+ }
218
+ #stats {
219
+ position: fixed;
220
+ top: 20px;
221
+ left: 20px;
222
+ color: white;
223
+ font-family: Arial;
224
+ font-size: 28px;
225
+ }
226
+ #villainCount {
227
+ position: fixed;
228
+ top: 20px;
229
+ right: 20px;
230
+ color: white;
231
+ font-family: Arial;
232
+ font-size: 28px;
233
+ }
234
+ #healthBar {
235
+ width: 300px;
236
+ height: 30px;
237
+ background: #333;
238
+ margin-top: 5px;
239
+ }
240
+ #healthFill {
241
+ width: 100%;
242
+ height: 100%;
243
+ background: red;
244
+ transition: width 0.3s;
245
+ }
246
+ #bulletCount, #enemyCount {
247
+ font-size: 28px;
248
+ }
249
+ #replayButton {
250
+ position: fixed;
251
+ top: 50%;
252
+ left: 50%;
253
+ transform: translate(-50%, -50%);
254
+ padding: 15px 30px;
255
+ font-size: 20px;
256
+ font-family: Arial;
257
+ background-color: white;
258
+ color: black;
259
+ border: none;
260
+ border-radius: 5px;
261
+ display: none;
262
+ cursor: pointer;
263
+ }
264
+ #replayButton:hover {
265
+ background-color: lightgray;
266
+ }
267
+ </style>
268
+ </head>
269
+ <body>
270
+ <canvas id="gameCanvas"></canvas>
271
+ <div id="message"></div>
272
+ <div id="stats">
273
+ Health:<div id="healthBar"><div id="healthFill"></div></div>
274
+ Bullets: <span id="bulletCount">35</span>
275
+ </div>
276
+ <div id="villainCount">Villains: <span id="enemyCount">30</span></div>
277
+ <button id="replayButton">Replay</button>
278
+ <audio id="bgMusic" src="cinematic-time-lapse-115672.mp3" loop></audio>
279
+ <audio id="playerShootSound" src="Maincharactergunsound.mp3"></audio>
280
+ <audio id="enemyShootSound" src="Renovatorsgunshot.mp3"></audio>
281
+ <audio id="playerHitSound" src="Maincharactershot.mp3"></audio>
282
+ <audio id="enemyHitSound" src="Renovatorsgetshot.mp3"></audio>
283
+
284
+ <script>
285
+ const canvas = document.getElementById('gameCanvas');
286
+ const ctx = canvas.getContext('2d');
287
+ const message = document.getElementById('message');
288
+ const healthFill = document.getElementById('healthFill');
289
+ const bulletCount = document.getElementById('bulletCount');
290
+ const enemyCount = document.getElementById('enemyCount');
291
+ const bgMusic = document.getElementById('bgMusic');
292
+ const replayButton = document.getElementById('replayButton');
293
+ const playerShootSound = document.getElementById('playerShootSound');
294
+ const enemyShootSound = document.getElementById('enemyShootSound');
295
+ const playerHitSound = document.getElementById('playerHitSound');
296
+ const enemyHitSound = document.getElementById('enemyHitSound');
297
+
298
+ canvas.width = window.innerWidth;
299
+ canvas.height = window.innerHeight;
300
+
301
+ const player = {
302
+ x: canvas.width / 2.3,
303
+ y: canvas.height - 260,
304
+ width: 250,
305
+ height: 250,
306
+ speed: 10,
307
+ health: 10,
308
+ bullets: 35,
309
+ direction: 1,
310
+ image: new Image(),
311
+ imageLeft: 'Maincharacterdefaultleft.png',
312
+ imageRight: 'Maincharacterdefaultright.png',
313
+ imageShootLeft: 'gunshotleft.png',
314
+ imageShootRight: 'gunshotright.png',
315
+ imageHitLeft: 'ExplosionLeft.png',
316
+ imageHitRight: 'ExplosionRight.png'
317
+ };
318
+ player.image.src = player.imageRight;
319
+
320
+ let enemies = [];
321
+ let bullets = [];
322
+ let enemyBullets = [];
323
+ let enemiesRemaining = 30;
324
+ let mouseX = 0;
325
+ let gameStarted = false;
326
+ let gameOver = false;
327
+
328
+ function spawnEnemy() {
329
+ if (!gameStarted || gameOver) {
330
+ return;
331
+ }
332
+
333
+ if (enemies.length >= 10) { // λ™μ‹œμ— μ‘΄μž¬ν•  수 μžˆλŠ” 적의 수 μ œν•œ
334
+ return;
335
+ }
336
+
337
+ const side = Math.random() < 0.5 ? 0 : canvas.width;
338
+ const enemy = {
339
+ x: side,
340
+ y: Math.random() * (canvas.height - 150),
341
+ width: 250,
342
+ height: 250,
343
+ speed: side === 0 ? 1 : -1,
344
+ image: new Image(),
345
+ imageLeft: 'Renovators Default Right.png',
346
+ imageRight: 'RenovatorsDefaultLeft.png',
347
+ imageShootLeft: 'RenovatorsgunLeft.png',
348
+ imageShootRight: 'RenovatorsGunRight.png',
349
+ imageHitLeft: 'RenovatorsExplodeLeft.png',
350
+ imageHitRight: 'RenovatorsExplodeRight.png',
351
+ lastShootTime: Date.now()
352
+ };
353
+ enemy.image.src = side === 0 ? enemy.imageLeft : enemy.imageRight;
354
+ enemies.push(enemy);
355
+ }
356
+ function updateGame() {
357
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
358
+
359
+ player.direction = mouseX > player.x ? 1 : -1;
360
+ player.image.src = player.direction === 1 ? player.imageRight : player.imageLeft;
361
+ ctx.drawImage(player.image, player.x, player.y, player.width, player.height);
362
+
363
+ // ν”Œλ ˆμ΄μ–΄κ°€ λ°œμ‚¬ν•œ μ΄μ•Œ 처리
364
+ bullets.forEach((bullet, index) => {
365
+ bullet.x += bullet.speed;
366
+ ctx.fillStyle = 'yellow';
367
+ ctx.fillRect(bullet.x, bullet.y, 10, 5);
368
+ });
369
+
370
+ // 적 처리
371
+ enemies.forEach((enemy, enemyIndex) => {
372
+ enemy.x += enemy.speed;
373
+ ctx.drawImage(enemy.image, enemy.x, enemy.y, enemy.width, enemy.height);
374
+
375
+ // ν”Œλ ˆμ΄μ–΄μ™€ 적이 μΆ©λŒν–ˆμ„ 경우 처리
376
+ if (checkCollision(player, enemy)) {
377
+ player.health--;
378
+ healthFill.style.width = (player.health / 5 * 100) + '%';
379
+ player.image.src = player.direction === 1 ? player.imageHitRight : player.imageHitLeft;
380
+ enemies.splice(enemyIndex, 1); // 적 제거
381
+ playerHitSound.play();
382
+
383
+ if (player.health <= 0) {
384
+ endGame("Game Over! Go back to the past and change the current result!");
385
+ }
386
+ }
387
+
388
+ // ν”Œλ ˆμ΄μ–΄μ˜ μ΄μ•Œμ΄ 적을 λ§žμ·„μ„ 경우 처리
389
+ bullets.forEach((bullet, bulletIndex) => {
390
+ if (checkCollision(bullet, enemy)) {
391
+ // μ΄μ•Œμ΄ 적을 λ§žμ·„μ„ λ•Œ 처리
392
+ enemy.image.src = enemy.speed > 0 ? enemy.imageHitRight : enemy.imageHitLeft;
393
+ setTimeout(() => {
394
+ enemies.splice(enemyIndex, 1); // 적 제거
395
+ bullets.splice(bulletIndex, 1); // μ΄μ•Œ 제거
396
+ enemiesRemaining--;
397
+ enemyCount.textContent = enemiesRemaining;
398
+ }, 100);
399
+ enemyHitSound.play();
400
+
401
+ if (enemiesRemaining <= 0) {
402
+ endGame("You have successfully protected New York. Return to the time machine.");
403
+ }
404
+ }
405
+ });
406
+
407
+ // 적의 μ΄μ•Œ λ°œμ‚¬
408
+ enemyShoot(enemy);
409
+ });
410
+ if (enemiesRemaining <= 0 && enemies.length === 0) {
411
+ endGame("You have successfully protected New York. Return to the time machine.");
412
+ return; // κ²Œμž„ μ’…λ£Œ ν›„ 더 이상 μ—…λ°μ΄νŠΈν•˜μ§€ μ•ŠμŒ
413
+ }
414
+ // 적의 μ΄μ•Œ 처리
415
+ enemyBullets.forEach((bullet, index) => {
416
+ bullet.x += bullet.speed;
417
+ ctx.fillStyle = 'orange';
418
+ ctx.fillRect(bullet.x, bullet.y, bullet.width, bullet.height);
419
+
420
+ // μ΄μ•Œμ΄ ν”Œλ ˆμ΄μ–΄μ™€ μΆ©λŒν–ˆμ„ 경우 처리
421
+ if (
422
+ bullet.x < player.x + player.width - 30 &&
423
+ bullet.x + bullet.width > player.x + 30 &&
424
+ bullet.y < player.y + player.height - 30 &&
425
+ bullet.y + bullet.height > player.y + 30
426
+ ) {
427
+ player.health--;
428
+ healthFill.style.width = (player.health / 5 * 100) + '%';
429
+ player.image.src = player.direction === 1 ? player.imageHitRight : player.imageHitLeft;
430
+ enemyBullets.splice(index, 1); // μ΄μ•Œ 제거
431
+ playerHitSound.play();
432
+
433
+ if (player.health <= 0) {
434
+ endGame("Game Over! Go back to the past and change the current result!");
435
+ }
436
+ }
437
+ });
438
+
439
+ // ν™”λ©΄ λ°–μœΌλ‘œ λ‚˜κ°„ μ΄μ•Œ 제거
440
+ bullets = bullets.filter(bullet =>
441
+ bullet.x >= 0 && bullet.x <= canvas.width
442
+ );
443
+ enemyBullets = enemyBullets.filter(bullet =>
444
+ bullet.x >= 0 && bullet.x <= canvas.width
445
+ );
446
+
447
+ // κ²Œμž„μ΄ μ’…λ£Œλ˜μ§€ μ•ŠμœΌλ©΄ 계속 μ—…λ°μ΄νŠΈ
448
+ if (!gameOver) {
449
+ requestAnimationFrame(updateGame);
450
+ }
451
+ }
452
+ setTimeout(() => {
453
+ message.textContent = "Click on the character";
454
+ setTimeout(() => {
455
+ message.textContent = "You can move your character using the arrow keys.";
456
+ setTimeout(() => {
457
+ message.textContent = "The character's direction follows the mouse cursor.";
458
+ setTimeout(() => {
459
+ message.textContent = "Press the space bar to shoot a bullet.";
460
+ setTimeout(() => {
461
+ message.textContent = "Your mission is to defeat the Renovators who have attacked New York. Defeat them all and save New York in 2030!";
462
+ setTimeout(() => {
463
+ message.textContent = "";
464
+ gameStarted = true;
465
+ }, 5000);
466
+ }, 3000);
467
+ }, 4000);
468
+ }, 4000);
469
+ }, 4000);
470
+ }, 0);
471
+
472
+ function endGame(messageText) {
473
+ gameOver = true;
474
+ message.textContent = messageText;
475
+ replayButton.style.display = 'block';
476
+ }
477
+ function checkCollision(rect1, rect2) {
478
+ return (
479
+ rect1.x + rect1.width * 0.2 < rect2.x + rect2.width * 0.8 &&
480
+ rect1.x + rect1.width * 0.8 > rect2.x + rect2.width * 0.2 &&
481
+ rect1.y + rect1.height * 0.2 < rect2.y + rect2.height * 0.8 &&
482
+ rect1.y + rect1.height * 0.8 > rect2.y + rect2.height * 0.2
483
+ );
484
+ }
485
+ function enemyShoot(enemy) {
486
+ const now = Date.now();
487
+ if (now - enemy.lastShootTime >= 3000 && !gameOver) {
488
+ enemy.image.src = enemy.speed > 0 ? enemy.imageShootRight : enemy.imageShootLeft;
489
+ enemyBullets.push({
490
+ x: enemy.x + enemy.width / 2,
491
+ y: enemy.y + enemy.height / 2.5,
492
+ width: 10,
493
+ height: 5,
494
+ speed: enemy.speed > 0 ? 5 : -5
495
+ });
496
+ enemy.lastShootTime = now; // Update the last shoot time
497
+ enemyShootSound.play();
498
+ }
499
+ }
500
+
501
+ window.addEventListener('keydown', (e) => {
502
+ if (!gameOver) {
503
+ switch (e.key) {
504
+ case 'ArrowUp':
505
+ if (player.y > 0) player.y -= player.speed;
506
+ break;
507
+ case 'ArrowDown':
508
+ if (player.y < canvas.height - player.height) player.y += player.speed;
509
+ break;
510
+ case 'ArrowLeft':
511
+ if (player.x > 0) player.x -= player.speed;
512
+ break;
513
+ case 'ArrowRight':
514
+ if (player.x < canvas.width - player.width) player.x += player.speed;
515
+ break;
516
+ case ' ':
517
+ if (player.bullets > 0) {
518
+ player.image.src = player.direction === 1 ? player.imageShootRight : player.imageShootLeft;
519
+ bullets.push({
520
+ x: player.x + player.width / 2,
521
+ y: player.y + player.height / 2.5,
522
+ width: 10,
523
+ height: 5,
524
+ speed: player.direction * 10
525
+ });
526
+ player.bullets--;
527
+ bulletCount.textContent = player.bullets;
528
+ playerShootSound.play();
529
+ }
530
+ break;
531
+ }
532
+ }
533
+ });
534
+
535
+ window.addEventListener('mousemove', (e) => {
536
+ mouseX = e.clientX;
537
+ });
538
+
539
+ replayButton.addEventListener('click', () => {
540
+ location.reload();
541
+ });
542
+
543
+ setInterval(spawnEnemy, 2000);
544
+ bgMusic.play();
545
+ updateGame();
546
+ </script>
547
+ </body>
548
  </html>