Spaces:
Running
Running
cutechicken
commited on
Update index.html
Browse files- 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 |
-
|
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 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
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 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
|
|
|
|
528 |
|
529 |
-
|
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 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
|
|
|
|
|
|
|
|
|
|
550 |
}
|
551 |
} else {
|
552 |
-
this.
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
if (!this.target || !enemies.includes(this.target)) {
|
558 |
-
this.target = this.selectTarget();
|
559 |
-
if (!this.target) {
|
560 |
-
this.moveToCenter();
|
561 |
}
|
562 |
-
}
|
563 |
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
|
569 |
-
|
570 |
-
|
571 |
-
|
|
|
572 |
}
|
573 |
}
|
574 |
-
}
|
575 |
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
|
580 |
-
|
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μ€ν
μ΄μ§ μ€ννμ΄μ΄
|