cutechicken commited on
Commit
b231e62
Β·
verified Β·
1 Parent(s): 18ca0cd

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +74 -63
index.html CHANGED
@@ -447,16 +447,19 @@ const defaultPlayerStats = {
447
  this.isReturning = false;
448
  this.circleAngle = 0;
449
  this.returningToCenter = false;
 
450
  }
451
 
452
- selectTarget() {
453
  if (enemies.length === 0) return null;
454
 
 
 
 
455
  let nearestEnemy = null;
456
  let minDist = Infinity;
457
 
458
  enemies.forEach(enemy => {
459
- // μŠ€ν•νŒŒμ΄μ–΄λŠ” λ¬΄μ‹œ
460
  if (enemy instanceof Spitfire) return;
461
 
462
  const dist = Math.hypot(enemy.x - this.x, enemy.y - this.y);
@@ -469,15 +472,37 @@ const defaultPlayerStats = {
469
  return nearestEnemy;
470
  }
471
 
472
-
473
  checkCollision() {
474
- if (!this.target) return false;
475
 
476
  const dist = Math.hypot(this.target.x - this.x, this.target.y - this.y);
477
  return dist < (this.width + this.target.width) / 2;
478
  }
479
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
480
  shoot() {
 
 
 
481
  if (!this.hasPlayedMGSound && !isCountingDown) {
482
  const mgSound = new Audio('ju87mg.ogg');
483
  mgSound.volume = 1.0;
@@ -504,80 +529,66 @@ const defaultPlayerStats = {
504
  });
505
  }
506
 
507
- moveToCenter() {
508
- const centerX = canvas.width / 2;
509
- const centerY = canvas.height / 2;
510
- this.angle = Math.atan2(centerY - this.y, centerX - this.x);
511
- const dist = Math.hypot(centerX - this.x, centerY - this.y);
512
-
513
- if (dist > 10) {
514
- this.x += Math.cos(this.angle) * this.speed;
515
- this.y += Math.sin(this.angle) * this.speed;
516
- return false;
517
  }
518
- return true;
519
- }
520
 
521
- update() {
522
- if (!this.hasPlayedSound) {
523
- const sirenSound = new Audio('ju87siren.ogg');
524
- sirenSound.volume = 1.0;
525
- sirenSound.play();
526
- this.hasPlayedSound = true;
527
- }
 
 
528
 
529
- const timeSinceSpawn = Date.now() - this.spawnTime;
530
-
531
- // μ‹œκ°„ μ΄ˆκ³Όμ‹œμ—λ§Œ κ·€ν™˜
532
- if (timeSinceSpawn > 5000) {
533
- if (!this.isReturning) {
534
- this.isReturning = true;
535
- this.target = null;
536
  this.returningToCenter = true;
 
 
537
  }
538
- }
539
-
540
- // 좩돌 μ‹œ μ€‘μ•™μœΌλ‘œ 이동 ν›„ 재곡격
541
- if (this.checkCollision()) {
542
- this.returningToCenter = true;
543
- this.target = null;
544
- }
545
 
546
- if (this.isReturning) {
547
- if (this.returningToCenter) {
548
- if (this.moveToCenter()) {
549
- this.returningToCenter = false;
 
 
 
 
 
550
  }
551
  } else {
552
- this.angle = Math.PI;
553
- this.x -= this.speed;
554
- return this.x > 0;
555
- }
556
- } else {
557
- if (!this.target || !enemies.includes(this.target)) {
558
- this.target = this.selectTarget();
559
- if (!this.target) {
560
- this.moveToCenter();
561
  }
562
- }
563
 
564
- if (this.target) {
565
- this.angle = Math.atan2(this.target.y - this.y, this.target.x - this.x);
566
- this.x += Math.cos(this.angle) * this.speed;
567
- this.y += Math.sin(this.angle) * this.speed;
568
 
569
- if (Date.now() - this.lastShot > 200) {
570
- this.shoot();
571
- this.lastShot = Date.now();
 
572
  }
573
  }
574
- }
575
 
576
- // ν™”λ©΄ 경계 체크
577
- this.x = Math.max(this.width/2, Math.min(canvas.width - this.width/2, this.x));
578
- this.y = Math.max(this.height/2, Math.min(canvas.height - this.height/2, this.y));
579
 
580
- return true;
581
  }
582
  }
583
  //2μŠ€ν…Œμ΄μ§€ μŠ€ν•νŒŒμ΄μ–΄
 
447
  this.isReturning = false;
448
  this.circleAngle = 0;
449
  this.returningToCenter = false;
450
+ this.ignoreCollisions = false; // 좩돌 λ¬΄μ‹œ μƒνƒœ (νƒ€κ²ŸνŒ…λ§Œ 영ν–₯)
451
  }
452
 
453
+ selectTarget() {
454
  if (enemies.length === 0) return null;
455
 
456
+ // μ€‘μ•™μœΌλ‘œ 이동 쀑일 λ•ŒλŠ” νƒ€κ²ŸνŒ… ν•˜μ§€ μ•ŠμŒ
457
+ if (this.returningToCenter || this.ignoreCollisions) return null;
458
+
459
  let nearestEnemy = null;
460
  let minDist = Infinity;
461
 
462
  enemies.forEach(enemy => {
 
463
  if (enemy instanceof Spitfire) return;
464
 
465
  const dist = Math.hypot(enemy.x - this.x, enemy.y - this.y);
 
472
  return nearestEnemy;
473
  }
474
 
 
475
  checkCollision() {
476
+ if (!this.target || this.ignoreCollisions) return false;
477
 
478
  const dist = Math.hypot(this.target.x - this.x, this.target.y - this.y);
479
  return dist < (this.width + this.target.width) / 2;
480
  }
481
 
482
+ moveToCenter() {
483
+ const centerX = canvas.width / 2;
484
+ const centerY = canvas.height / 2;
485
+ this.angle = Math.atan2(centerY - this.y, centerX - this.x);
486
+ const dist = Math.hypot(centerX - this.x, centerY - this.y);
487
+
488
+ if (dist > 10) {
489
+ // μ€‘μ•™μœΌλ‘œ μ΄λ™ν•˜λŠ” λ™μ•ˆ 더 λΉ λ₯Έ μ†λ„λ‘œ 이동
490
+ const moveSpeed = this.speed * 1.5;
491
+ this.x += Math.cos(this.angle) * moveSpeed;
492
+ this.y += Math.sin(this.angle) * moveSpeed;
493
+ return false;
494
+ }
495
+
496
+ // 쀑앙 도달 μ‹œ 좩돌 λ¬΄μ‹œ μƒνƒœ ν•΄μ œ
497
+ this.ignoreCollisions = false;
498
+ this.returningToCenter = false;
499
+ return true;
500
+ }
501
+
502
  shoot() {
503
+ // μ€‘μ•™μœΌλ‘œ 이동 쀑일 λ•ŒλŠ” λ°œμ‚¬ν•˜μ§€ μ•ŠμŒ
504
+ if (this.returningToCenter || this.ignoreCollisions) return;
505
+
506
  if (!this.hasPlayedMGSound && !isCountingDown) {
507
  const mgSound = new Audio('ju87mg.ogg');
508
  mgSound.volume = 1.0;
 
529
  });
530
  }
531
 
532
+ update() {
533
+ if (!this.hasPlayedSound) {
534
+ const sirenSound = new Audio('ju87siren.ogg');
535
+ sirenSound.volume = 1.0;
536
+ sirenSound.play();
537
+ this.hasPlayedSound = true;
 
 
 
 
538
  }
 
 
539
 
540
+ const timeSinceSpawn = Date.now() - this.spawnTime;
541
+
542
+ if (timeSinceSpawn > 5000) {
543
+ if (!this.isReturning) {
544
+ this.isReturning = true;
545
+ this.target = null;
546
+ this.returningToCenter = true;
547
+ }
548
+ }
549
 
550
+ // 좩돌 감지 및 μ€‘μ•™μœΌλ‘œ 이동 처리
551
+ if (this.checkCollision()) {
 
 
 
 
 
552
  this.returningToCenter = true;
553
+ this.ignoreCollisions = true; // 좩돌 ν›„ νƒ€κ²ŸνŒ… λ¬΄μ‹œ μƒνƒœ ν™œμ„±ν™”
554
+ this.target = null;
555
  }
 
 
 
 
 
 
 
556
 
557
+ if (this.isReturning) {
558
+ if (this.returningToCenter) {
559
+ if (this.moveToCenter()) {
560
+ this.returningToCenter = false;
561
+ }
562
+ } else {
563
+ this.angle = Math.PI;
564
+ this.x -= this.speed;
565
+ return this.x > 0;
566
  }
567
  } else {
568
+ if (!this.target || !enemies.includes(this.target)) {
569
+ this.target = this.selectTarget();
570
+ if (!this.target) {
571
+ this.moveToCenter();
572
+ }
 
 
 
 
573
  }
 
574
 
575
+ if (this.target && !this.ignoreCollisions) {
576
+ this.angle = Math.atan2(this.target.y - this.y, this.target.x - this.x);
577
+ this.x += Math.cos(this.angle) * this.speed;
578
+ this.y += Math.sin(this.angle) * this.speed;
579
 
580
+ if (Date.now() - this.lastShot > 200) {
581
+ this.shoot();
582
+ this.lastShot = Date.now();
583
+ }
584
  }
585
  }
 
586
 
587
+ // ν™”λ©΄ 경계 체크
588
+ this.x = Math.max(this.width/2, Math.min(canvas.width - this.width/2, this.x));
589
+ this.y = Math.max(this.height/2, Math.min(canvas.height - this.height/2, this.y));
590
 
591
+ return true;
592
  }
593
  }
594
  //2μŠ€ν…Œμ΄μ§€ μŠ€ν•νŒŒμ΄μ–΄