cutechicken commited on
Commit
43f1890
ยท
verified ยท
1 Parent(s): bdab9d2

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +179 -24
game.js CHANGED
@@ -1506,44 +1506,44 @@ class EnemyFighter {
1506
  if (this.mesh) {
1507
  console.log('Removing enemy mesh from scene');
1508
 
1509
- // ๋ฉ”์‹œ๊ฐ€ ๊ทธ๋ฃน์ธ ๊ฒฝ์šฐ ๋ชจ๋“  ์ž์‹ ์š”์†Œ๋„ ์ œ๊ฑฐ
1510
- if (this.mesh.children && this.mesh.children.length > 0) {
1511
- while (this.mesh.children.length > 0) {
1512
- const child = this.mesh.children[0];
1513
- this.mesh.remove(child);
1514
 
1515
- // ์ž์‹ ์š”์†Œ์˜ geometry์™€ material๋„ ์ •๋ฆฌ
1516
- if (child.geometry) child.geometry.dispose();
 
 
 
 
1517
  if (child.material) {
1518
  if (Array.isArray(child.material)) {
1519
- child.material.forEach(mat => mat.dispose());
 
 
1520
  } else {
1521
- child.material.dispose();
1522
  }
1523
  }
1524
  }
1525
- }
1526
 
1527
- // ๋ฉ”์‹œ ์ž์ฒด์˜ geometry์™€ material ์ •๋ฆฌ
1528
- if (this.mesh.geometry) this.mesh.geometry.dispose();
1529
- if (this.mesh.material) {
1530
- if (Array.isArray(this.mesh.material)) {
1531
- this.mesh.material.forEach(mat => mat.dispose());
1532
- } else {
1533
- this.mesh.material.dispose();
1534
- }
1535
  }
1536
 
1537
- // ์”ฌ์—์„œ ๋ฉ”์‹œ ์ œ๊ฑฐ
1538
- this.scene.remove(this.mesh);
1539
-
1540
- // ๋ฉ”์‹œ๊ฐ€ ์‹ค์ œ๋กœ ์ œ๊ฑฐ๋˜์—ˆ๋Š”์ง€ ํ™•์ธ
1541
  if (this.mesh.parent) {
1542
- console.log('Mesh still has parent, forcing removal');
1543
  this.mesh.parent.remove(this.mesh);
1544
  }
1545
 
1546
- // ๋ฉ”์‹œ ์ฐธ์กฐ ์ œ๊ฑฐ
 
 
 
1547
  this.mesh = null;
1548
  }
1549
 
@@ -1567,6 +1567,161 @@ class EnemyFighter {
1567
  console.log('EnemyFighter destroyed successfully');
1568
  }
1569
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1570
  // Game ํด๋ž˜์Šค์˜ checkCollisions ๋ฉ”์„œ๋“œ๋„ ์•ฝ๊ฐ„ ์ˆ˜์ •
1571
  checkCollisions() {
1572
  // ํ”Œ๋ ˆ์ด์–ด ํƒ„ํ™˜ vs ์ ๊ธฐ ์ถฉ๋Œ
 
1506
  if (this.mesh) {
1507
  console.log('Removing enemy mesh from scene');
1508
 
1509
+ // GLB ๋ชจ๋ธ์€ ๋ณต์žกํ•œ ๊ตฌ์กฐ๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ์ „์ฒด ๊ณ„์ธต๊ตฌ์กฐ๋ฅผ ์ˆœํšŒํ•˜๋ฉฐ ์ œ๊ฑฐ
1510
+ this.mesh.traverse((child) => {
1511
+ if (child.isMesh) {
1512
+ console.log('Disposing mesh:', child.name || 'unnamed');
 
1513
 
1514
+ // geometry ์ œ๊ฑฐ
1515
+ if (child.geometry) {
1516
+ child.geometry.dispose();
1517
+ }
1518
+
1519
+ // material ์ œ๊ฑฐ
1520
  if (child.material) {
1521
  if (Array.isArray(child.material)) {
1522
+ child.material.forEach(mat => {
1523
+ if (mat.dispose) mat.dispose();
1524
+ });
1525
  } else {
1526
+ if (child.material.dispose) child.material.dispose();
1527
  }
1528
  }
1529
  }
1530
+ });
1531
 
1532
+ // ์”ฌ์—์„œ ๋ฉ”์‹œ ์ œ๊ฑฐ - ์—ฌ๋Ÿฌ ๋ฐฉ๋ฒ• ์‹œ๋„
1533
+ if (this.scene) {
1534
+ this.scene.remove(this.mesh);
 
 
 
 
 
1535
  }
1536
 
1537
+ // parent๊ฐ€ ์žˆ๋‹ค๋ฉด parent์—์„œ๋„ ์ œ๊ฑฐ
 
 
 
1538
  if (this.mesh.parent) {
1539
+ console.log('Mesh still has parent, forcing removal from parent');
1540
  this.mesh.parent.remove(this.mesh);
1541
  }
1542
 
1543
+ // ๋ฉ”์‹œ๋ฅผ ๋น„ํ™œ์„ฑํ™”
1544
+ this.mesh.visible = false;
1545
+
1546
+ // ๋ฉ”์‹œ ์ฐธ์กฐ ์™„์ „ํžˆ ์ œ๊ฑฐ
1547
  this.mesh = null;
1548
  }
1549
 
 
1567
  console.log('EnemyFighter destroyed successfully');
1568
  }
1569
 
1570
+ // Game ํด๋ž˜์Šค์˜ checkCollisions ๋ฉ”์„œ๋“œ ์ˆ˜์ •
1571
+ checkCollisions() {
1572
+ // ํ”Œ๋ ˆ์ด์–ด ํƒ„ํ™˜ vs ์ ๊ธฐ ์ถฉ๋Œ
1573
+ for (let i = this.fighter.bullets.length - 1; i >= 0; i--) {
1574
+ const bullet = this.fighter.bullets[i];
1575
+
1576
+ for (let j = this.enemies.length - 1; j >= 0; j--) {
1577
+ const enemy = this.enemies[j];
1578
+
1579
+ // ์ด๋ฏธ ํŒŒ๊ดด๋œ ์ ์€ ๊ฑด๋„ˆ๋›ฐ๊ธฐ
1580
+ if (!enemy.mesh || !enemy.isLoaded || enemy.isDestroyed) continue;
1581
+
1582
+ const distance = bullet.position.distanceTo(enemy.position);
1583
+ if (distance < 90) {
1584
+ console.log(`Hit detected! Distance: ${distance}, Enemy health: ${enemy.health}`);
1585
+
1586
+ // ํžˆํŠธ ํ‘œ์‹œ ์ถ”๊ฐ€
1587
+ this.showHitMarker(enemy.position);
1588
+ // ํ”ผ๊ฒฉ ์ดํŽ™ํŠธ ์ถ”๊ฐ€
1589
+ this.createHitEffect(enemy.position);
1590
+
1591
+ // ํƒ„ํ™˜ ์ œ๊ฑฐ
1592
+ this.scene.remove(bullet);
1593
+ this.fighter.bullets.splice(i, 1);
1594
+
1595
+ // ์ ๊ธฐ์— ๋ฐ๋ฏธ์ง€ ์ž…ํžˆ๊ธฐ
1596
+ const isDestroyed = enemy.takeDamage(GAME_CONSTANTS.BULLET_DAMAGE);
1597
+ console.log(`Enemy damaged. New health: ${enemy.health}, Destroyed: ${isDestroyed}`);
1598
+
1599
+ if (isDestroyed) {
1600
+ console.log('Enemy destroyed! Creating explosion effect...');
1601
+
1602
+ // ํญ๋ฐœ ํšจ๊ณผ ์ƒ์„ฑ - ์œ„์น˜๋ฅผ ๋ณต์‚ฌํ•ด์„œ ์ „๋‹ฌ
1603
+ const explosionPosition = enemy.position.clone();
1604
+ console.log('Explosion position:', explosionPosition);
1605
+
1606
+ // ํญ๋ฐœ ํšจ๊ณผ ์ฆ‰์‹œ ์ƒ์„ฑ
1607
+ this.createExplosionEffect(explosionPosition);
1608
+
1609
+ // ์ ๊ธฐ ๋ฉ”์‹œ๋ฅผ ๋จผ์ € ์ˆจ๊ธฐ๊ธฐ
1610
+ if (enemy.mesh) {
1611
+ enemy.mesh.visible = false;
1612
+ }
1613
+
1614
+ // ์ ๊ธฐ ์ œ๊ฑฐ
1615
+ enemy.destroy();
1616
+
1617
+ // ๋ฐฐ์—ด์—์„œ ์ œ๊ฑฐ
1618
+ this.enemies.splice(j, 1);
1619
+ this.score += 100;
1620
+
1621
+ console.log(`Enemy removed. Remaining enemies: ${this.enemies.length}`);
1622
+ }
1623
+ break;
1624
+ }
1625
+ }
1626
+ }
1627
+
1628
+ // ์  ํƒ„ํ™˜ vs ํ”Œ๋ ˆ์ด์–ด ์ถฉ๋Œ
1629
+ this.enemies.forEach(enemy => {
1630
+ // ํŒŒ๊ดด๋œ ์ ์€ ์ฒ˜๋ฆฌํ•˜์ง€ ์•Š์Œ
1631
+ if (enemy.isDestroyed) return;
1632
+
1633
+ for (let index = enemy.bullets.length - 1; index >= 0; index--) {
1634
+ const bullet = enemy.bullets[index];
1635
+ const distance = bullet.position.distanceTo(this.fighter.position);
1636
+ if (distance < 100) {
1637
+ // ํ”Œ๋ ˆ์ด์–ด ํ”ผ๊ฒฉ ์ดํŽ™ํŠธ
1638
+ this.createHitEffect(this.fighter.position);
1639
+
1640
+ // ํƒ„ํ™˜ ์ œ๊ฑฐ
1641
+ this.scene.remove(bullet);
1642
+ enemy.bullets.splice(index, 1);
1643
+
1644
+ if (this.fighter.takeDamage(GAME_CONSTANTS.BULLET_DAMAGE)) {
1645
+ // ํ”Œ๋ ˆ์ด์–ด ํŒŒ๊ดด ์‹œ ํญ๋ฐœ ํšจ๊ณผ ์ถ”๊ฐ€
1646
+ this.createExplosionEffect(this.fighter.position);
1647
+
1648
+ this.endGame(false);
1649
+ }
1650
+ }
1651
+ }
1652
+ });
1653
+ }
1654
+
1655
+ // EnemyFighter์˜ update ๋ฉ”์„œ๋“œ์—๋„ ์ถ”๊ฐ€ ๋ณดํ˜ธ ์žฅ์น˜
1656
+ update(playerPosition, deltaTime) {
1657
+ // ํŒŒ๊ดด๋˜์—ˆ๊ฑฐ๋‚˜ ๋ฉ”์‹œ๊ฐ€ ์—†์œผ๋ฉด ์•„๋ฌด๊ฒƒ๋„ ํ•˜์ง€ ์•Š์Œ
1658
+ if (!this.mesh || !this.isLoaded || this.isDestroyed || !this.mesh.visible) return;
1659
+
1660
+ // ... ๋‚˜๋จธ์ง€ update ๋กœ์ง
1661
+
1662
+ // ํšŒํ”ผ ํƒ€์ด๋จธ ์—…๋ฐ์ดํŠธ
1663
+ if (this.temporaryEvadeMode && this.evadeTimer > 0) {
1664
+ this.evadeTimer -= deltaTime;
1665
+ if (this.evadeTimer <= 0) {
1666
+ this.temporaryEvadeMode = false;
1667
+ }
1668
+ }
1669
+
1670
+ const distanceToPlayer = this.position.distanceTo(playerPosition);
1671
+
1672
+ // 100m ์ด๋‚ด๋ฉด ์ฆ‰์‹œ ํ›„ํ‡ด ๋ชจ๋“œ ํ™œ์„ฑํ™”
1673
+ if (distanceToPlayer < 100) {
1674
+ this.isRetreating = true;
1675
+ this.aiState = 'retreat';
1676
+ console.log(`Enemy retreating! Distance: ${distanceToPlayer.toFixed(1)}m`);
1677
+ }
1678
+
1679
+ // 250m ์ด์ƒ ๋–จ์–ด์ง€๋ฉด ํ›„ํ‡ด ๋ชจ๋“œ ํ•ด์ œ
1680
+ if (this.isRetreating && distanceToPlayer >= this.retreatTargetDistance) {
1681
+ this.isRetreating = false;
1682
+ console.log(`Enemy retreat complete. Distance: ${distanceToPlayer.toFixed(1)}m`);
1683
+ }
1684
+
1685
+ // ์ƒํƒœ ๊ฒฐ์ • - ํ›„ํ‡ด๊ฐ€ ์ตœ์šฐ์„ 
1686
+ if (this.isRetreating) {
1687
+ this.aiState = 'retreat';
1688
+ } else if (this.temporaryEvadeMode) {
1689
+ this.aiState = 'evade';
1690
+ } else if (distanceToPlayer <= 3000) {
1691
+ this.aiState = 'combat';
1692
+ } else {
1693
+ this.aiState = 'patrol';
1694
+ }
1695
+
1696
+ // ์ถฉ๋Œ ํšŒํ”ผ ๊ณ„์‚ฐ (ํ›„ํ‡ด ์ค‘์ด ์•„๋‹ ๋•Œ๋งŒ)
1697
+ if (!this.isRetreating) {
1698
+ this.calculateAvoidance();
1699
+ this.checkCollisionPrediction(deltaTime);
1700
+ }
1701
+
1702
+ // AI ํ–‰๋™ ์‹คํ–‰
1703
+ switch (this.aiState) {
1704
+ case 'patrol':
1705
+ this.executePatrol(deltaTime);
1706
+ break;
1707
+ case 'combat':
1708
+ this.executeCombat(playerPosition, deltaTime);
1709
+ break;
1710
+ case 'evade':
1711
+ this.executeEmergencyEvade(deltaTime);
1712
+ break;
1713
+ case 'retreat':
1714
+ this.executeRetreat(playerPosition, deltaTime);
1715
+ break;
1716
+ }
1717
+
1718
+ // ๋ฌผ๋ฆฌ ์—…๋ฐ์ดํŠธ
1719
+ this.updatePhysics(deltaTime);
1720
+
1721
+ // ํƒ„ํ™˜ ์—…๋ฐ์ดํŠธ
1722
+ this.updateBullets(deltaTime);
1723
+ }
1724
+
1725
  // Game ํด๋ž˜์Šค์˜ checkCollisions ๋ฉ”์„œ๋“œ๋„ ์•ฝ๊ฐ„ ์ˆ˜์ •
1726
  checkCollisions() {
1727
  // ํ”Œ๋ ˆ์ด์–ด ํƒ„ํ™˜ vs ์ ๊ธฐ ์ถฉ๋Œ