cutechicken commited on
Commit
c6641c1
ยท
verified ยท
1 Parent(s): e88205f

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +311 -7
game.js CHANGED
@@ -641,7 +641,7 @@ class Fighter {
641
  }
642
  }
643
 
644
- updateBullets(scene, deltaTime) {
645
  for (let i = this.bullets.length - 1; i >= 0; i--) {
646
  const bullet = this.bullets[i];
647
  bullet.position.add(bullet.velocity.clone().multiplyScalar(deltaTime));
@@ -651,9 +651,17 @@ class Fighter {
651
  const angle = Math.atan2(direction.x, direction.z);
652
  bullet.rotation.y = angle;
653
 
654
- // 6000m ์ด์ƒ ๋‚ ์•„๊ฐ€๋ฉด ์ œ๊ฑฐ
 
 
 
 
 
 
 
 
 
655
  if (bullet.position.distanceTo(bullet.startPosition) > 6000 ||
656
- bullet.position.y < 0 ||
657
  bullet.position.y > GAME_CONSTANTS.MAX_ALTITUDE + 500) {
658
  scene.remove(bullet);
659
  this.bullets.splice(i, 1);
@@ -695,7 +703,7 @@ class EnemyFighter {
695
  this.velocity = new THREE.Vector3(0, 0, 120);
696
  this.rotation = new THREE.Euler(0, 0, 0);
697
  this.health = GAME_CONSTANTS.MAX_HEALTH; // ์ฒด๋ ฅ 1000
698
- this.speed = 514; // 1000kt in m/s (1000 * 0.514444)
699
  this.bullets = [];
700
  this.lastShootTime = 0;
701
 
@@ -1034,8 +1042,18 @@ class EnemyFighter {
1034
  const bullet = this.bullets[i];
1035
  bullet.position.add(bullet.velocity.clone().multiplyScalar(deltaTime));
1036
 
1037
- if (bullet.position.distanceTo(this.position) > 5000 ||
1038
- bullet.position.y < 0) {
 
 
 
 
 
 
 
 
 
 
1039
  this.scene.remove(bullet);
1040
  this.bullets.splice(i, 1);
1041
  }
@@ -1866,6 +1884,292 @@ class Game {
1866
  });
1867
  }
1868
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1869
  checkCollisions() {
1870
  // ํ”Œ๋ ˆ์ด์–ด ํƒ„ํ™˜ vs ์ ๊ธฐ ์ถฉ๋Œ
1871
  for (let i = this.fighter.bullets.length - 1; i >= 0; i--) {
@@ -2073,7 +2377,7 @@ class Game {
2073
 
2074
  this.fighter.updateControls(this.keys, deltaTime);
2075
  this.fighter.updatePhysics(deltaTime);
2076
- this.fighter.updateBullets(this.scene, deltaTime);
2077
 
2078
  // ๋งˆ์šฐ์Šค ๋ˆ„๋ฆ„ ์ƒํƒœ์ผ ๋•Œ ์—ฐ์† ๋ฐœ์‚ฌ
2079
  if (this.fighter.isMouseDown && this.isStarted) {
 
641
  }
642
  }
643
 
644
+ updateBullets(scene, deltaTime, gameInstance) {
645
  for (let i = this.bullets.length - 1; i >= 0; i--) {
646
  const bullet = this.bullets[i];
647
  bullet.position.add(bullet.velocity.clone().multiplyScalar(deltaTime));
 
651
  const angle = Math.atan2(direction.x, direction.z);
652
  bullet.rotation.y = angle;
653
 
654
+ // ์ง€๋ฉด ์ถฉ๋Œ ์ฒดํฌ ์ถ”๊ฐ€
655
+ if (bullet.position.y <= 0) {
656
+ // ํฌ๊ณ  ํ™”๋ คํ•œ ์ง€๋ฉด ์ถฉ๋Œ ํšจ๊ณผ
657
+ gameInstance.createGroundImpactEffect(bullet.position);
658
+ scene.remove(bullet);
659
+ this.bullets.splice(i, 1);
660
+ continue;
661
+ }
662
+
663
+ // 6000m ์ด์ƒ ๋‚ ์•„๊ฐ€๊ฑฐ๋‚˜ ๋†’์ด ์ œํ•œ ์ดˆ๊ณผ ์‹œ ์ œ๊ฑฐ
664
  if (bullet.position.distanceTo(bullet.startPosition) > 6000 ||
 
665
  bullet.position.y > GAME_CONSTANTS.MAX_ALTITUDE + 500) {
666
  scene.remove(bullet);
667
  this.bullets.splice(i, 1);
 
703
  this.velocity = new THREE.Vector3(0, 0, 120);
704
  this.rotation = new THREE.Euler(0, 0, 0);
705
  this.health = GAME_CONSTANTS.MAX_HEALTH; // ์ฒด๋ ฅ 1000
706
+ this.speed = 386; // 750kt in m/s (750 * 0.514444) - 1000kt์—์„œ 750kt๋กœ ๊ฐ์†Œ
707
  this.bullets = [];
708
  this.lastShootTime = 0;
709
 
 
1042
  const bullet = this.bullets[i];
1043
  bullet.position.add(bullet.velocity.clone().multiplyScalar(deltaTime));
1044
 
1045
+ // ์ง€๋ฉด ์ถฉ๋Œ ์ฒดํฌ ์ถ”๊ฐ€
1046
+ if (bullet.position.y <= 0) {
1047
+ // ํฌ๊ณ  ํ™”๋ คํ•œ ์ง€๋ฉด ์ถฉ๋Œ ํšจ๊ณผ - Game ์ธ์Šคํ„ด์Šค๋ฅผ ํ†ตํ•ด ํ˜ธ์ถœ
1048
+ if (window.gameInstance) {
1049
+ window.gameInstance.createGroundImpactEffect(bullet.position);
1050
+ }
1051
+ this.scene.remove(bullet);
1052
+ this.bullets.splice(i, 1);
1053
+ continue;
1054
+ }
1055
+
1056
+ if (bullet.position.distanceTo(this.position) > 5000) {
1057
  this.scene.remove(bullet);
1058
  this.bullets.splice(i, 1);
1059
  }
 
1884
  });
1885
  }
1886
 
1887
+ // ์ƒˆ๋กœ์šด ๋ฉ”์„œ๋“œ: ํฌ๊ณ  ํ™”๋ คํ•œ ์ง€๋ฉด ์ถฉ๋Œ ํšจ๊ณผ
1888
+ createGroundImpactEffect(position) {
1889
+ // ๋ฉ”์ธ ํญ๋ฐœ ํ”Œ๋ž˜์‹œ
1890
+ const flashGeometry = new THREE.SphereGeometry(15, 16, 16);
1891
+ const flashMaterial = new THREE.MeshBasicMaterial({
1892
+ color: 0xffaa00,
1893
+ emissive: 0xffaa00,
1894
+ emissiveIntensity: 3.0,
1895
+ transparent: true,
1896
+ opacity: 1.0
1897
+ });
1898
+
1899
+ const flash = new THREE.Mesh(flashGeometry, flashMaterial);
1900
+ flash.position.copy(position);
1901
+ flash.position.y = 2; // ์ง€๋ฉด์—์„œ ์•ฝ๊ฐ„ ์œ„
1902
+ this.scene.add(flash);
1903
+
1904
+ // ์ถฉ๊ฒฉํŒŒ ๋ง
1905
+ const ringGeometry = new THREE.RingGeometry(1, 15, 32);
1906
+ const ringMaterial = new THREE.MeshBasicMaterial({
1907
+ color: 0xff6600,
1908
+ side: THREE.DoubleSide,
1909
+ transparent: true,
1910
+ opacity: 0.8
1911
+ });
1912
+
1913
+ const shockwaveRing = new THREE.Mesh(ringGeometry, ringMaterial);
1914
+ shockwaveRing.position.copy(position);
1915
+ shockwaveRing.position.y = 1;
1916
+ shockwaveRing.rotation.x = -Math.PI / 2;
1917
+ this.scene.add(shockwaveRing);
1918
+
1919
+ // ํŒŒํŽธ ํŒŒํ‹ฐํด (๋” ๋งŽ์ด, ๋” ํฌ๊ฒŒ)
1920
+ const particleCount = 30;
1921
+ const particles = [];
1922
+ const debris = [];
1923
+
1924
+ for (let i = 0; i < particleCount; i++) {
1925
+ // ๋ถˆ๊ฝƒ ํŒŒํ‹ฐํด
1926
+ const particleGeometry = new THREE.SphereGeometry(1 + Math.random(), 6, 6);
1927
+ const particleMaterial = new THREE.MeshBasicMaterial({
1928
+ color: Math.random() > 0.3 ? 0xffaa00 : 0xff0000,
1929
+ emissive: 0xffaa00,
1930
+ emissiveIntensity: 2.0,
1931
+ transparent: true,
1932
+ opacity: 1.0
1933
+ });
1934
+
1935
+ const particle = new THREE.Mesh(particleGeometry, particleMaterial);
1936
+ particle.position.copy(position);
1937
+ particle.position.y = 1;
1938
+
1939
+ // ๋” ๊ฐ•๋ ฅํ•œ ํญ๋ฐœ ์†๋„
1940
+ const angle = Math.random() * Math.PI * 2;
1941
+ const speed = 50 + Math.random() * 150;
1942
+ const upSpeed = 30 + Math.random() * 100;
1943
+
1944
+ particle.velocity = new THREE.Vector3(
1945
+ Math.cos(angle) * speed,
1946
+ upSpeed,
1947
+ Math.sin(angle) * speed
1948
+ );
1949
+
1950
+ particle.life = 1.5; // ๋” ์˜ค๋ž˜ ์ง€์†
1951
+
1952
+ this.scene.add(particle);
1953
+ particles.push(particle);
1954
+
1955
+ // ํ™ ํŒŒํŽธ
1956
+ if (i % 3 === 0) {
1957
+ const debrisGeometry = new THREE.BoxGeometry(
1958
+ 2 + Math.random() * 3,
1959
+ 2 + Math.random() * 3,
1960
+ 2 + Math.random() * 3
1961
+ );
1962
+ const debrisMaterial = new THREE.MeshLambertMaterial({
1963
+ color: 0x4a3c28, // ํ™์ƒ‰
1964
+ transparent: true,
1965
+ opacity: 1.0
1966
+ });
1967
+
1968
+ const debrisPiece = new THREE.Mesh(debrisGeometry, debrisMaterial);
1969
+ debrisPiece.position.copy(position);
1970
+ debrisPiece.position.y = 1;
1971
+
1972
+ // ํšŒ์ „ ์ถ”๊ฐ€
1973
+ debrisPiece.rotation.set(
1974
+ Math.random() * Math.PI,
1975
+ Math.random() * Math.PI,
1976
+ Math.random() * Math.PI
1977
+ );
1978
+
1979
+ // ํŒŒํŽธ ์†๋„
1980
+ const debrisAngle = Math.random() * Math.PI * 2;
1981
+ const debrisSpeed = 30 + Math.random() * 70;
1982
+
1983
+ debrisPiece.velocity = new THREE.Vector3(
1984
+ Math.cos(debrisAngle) * debrisSpeed,
1985
+ 20 + Math.random() * 50,
1986
+ Math.sin(debrisAngle) * debrisSpeed
1987
+ );
1988
+
1989
+ debrisPiece.angularVelocity = new THREE.Vector3(
1990
+ (Math.random() - 0.5) * 10,
1991
+ (Math.random() - 0.5) * 10,
1992
+ (Math.random() - 0.5) * 10
1993
+ );
1994
+
1995
+ debrisPiece.life = 2.0;
1996
+
1997
+ this.scene.add(debrisPiece);
1998
+ debris.push(debrisPiece);
1999
+ }
2000
+ }
2001
+
2002
+ // ์—ฐ๊ธฐ ํšจ๊ณผ
2003
+ const smokeCount = 8;
2004
+ const smokes = [];
2005
+
2006
+ for (let i = 0; i < smokeCount; i++) {
2007
+ const smokeGeometry = new THREE.SphereGeometry(5 + Math.random() * 5, 8, 8);
2008
+ const smokeMaterial = new THREE.MeshBasicMaterial({
2009
+ color: 0x222222,
2010
+ transparent: true,
2011
+ opacity: 0.6
2012
+ });
2013
+
2014
+ const smoke = new THREE.Mesh(smokeGeometry, smokeMaterial);
2015
+ smoke.position.copy(position);
2016
+ smoke.position.y = 2 + Math.random() * 5;
2017
+ smoke.position.x += (Math.random() - 0.5) * 10;
2018
+ smoke.position.z += (Math.random() - 0.5) * 10;
2019
+
2020
+ smoke.velocity = new THREE.Vector3(
2021
+ (Math.random() - 0.5) * 10,
2022
+ 5 + Math.random() * 15,
2023
+ (Math.random() - 0.5) * 10
2024
+ );
2025
+
2026
+ smoke.life = 3.0;
2027
+
2028
+ this.scene.add(smoke);
2029
+ smokes.push(smoke);
2030
+ }
2031
+
2032
+ // ์ง€๋ฉด ํฌ๋ ˆ์ดํ„ฐ (์ž„์‹œ ํšจ๊ณผ)
2033
+ const craterGeometry = new THREE.RingGeometry(5, 20, 16);
2034
+ const craterMaterial = new THREE.MeshBasicMaterial({
2035
+ color: 0x2a2a2a,
2036
+ side: THREE.DoubleSide,
2037
+ transparent: true,
2038
+ opacity: 0.7
2039
+ });
2040
+
2041
+ const crater = new THREE.Mesh(craterGeometry, craterMaterial);
2042
+ crater.position.copy(position);
2043
+ crater.position.y = 0.1;
2044
+ crater.rotation.x = -Math.PI / 2;
2045
+ this.scene.add(crater);
2046
+
2047
+ // ์• ๋‹ˆ๋ฉ”์ด์…˜
2048
+ const animateExplosion = () => {
2049
+ let allDead = true;
2050
+
2051
+ // ๋ฉ”์ธ ํ”Œ๋ž˜์‹œ
2052
+ if (flash.material.opacity > 0) {
2053
+ flash.material.opacity -= 0.03;
2054
+ flash.scale.multiplyScalar(1.15);
2055
+ allDead = false;
2056
+ } else if (flash.parent) {
2057
+ this.scene.remove(flash);
2058
+ }
2059
+
2060
+ // ์ถฉ๊ฒฉํŒŒ ๋ง
2061
+ if (shockwaveRing.material.opacity > 0) {
2062
+ shockwaveRing.material.opacity -= 0.02;
2063
+ shockwaveRing.scale.x += 0.5;
2064
+ shockwaveRing.scale.y += 0.5;
2065
+ allDead = false;
2066
+ } else if (shockwaveRing.parent) {
2067
+ this.scene.remove(shockwaveRing);
2068
+ }
2069
+
2070
+ // ํŒŒํ‹ฐํด ์—…๋ฐ์ดํŠธ
2071
+ particles.forEach((particle, index) => {
2072
+ if (particle.life > 0) {
2073
+ allDead = false;
2074
+ particle.life -= 0.02;
2075
+
2076
+ // ์œ„์น˜ ์—…๋ฐ์ดํŠธ
2077
+ particle.position.add(particle.velocity.clone().multiplyScalar(0.02));
2078
+
2079
+ // ์ค‘๋ ฅ
2080
+ particle.velocity.y -= 3;
2081
+
2082
+ // ๊ณต๊ธฐ ์ €ํ•ญ
2083
+ particle.velocity.multiplyScalar(0.98);
2084
+
2085
+ // ํŽ˜์ด๋“œ ์•„์›ƒ
2086
+ particle.material.opacity = particle.life;
2087
+
2088
+ // ํฌ๊ธฐ ๊ฐ์†Œ
2089
+ const scale = particle.life * 0.8 + 0.2;
2090
+ particle.scale.set(scale, scale, scale);
2091
+ } else if (particle.parent) {
2092
+ this.scene.remove(particle);
2093
+ }
2094
+ });
2095
+
2096
+ // ํŒŒํŽธ ์—…๋ฐ์ดํŠธ
2097
+ debris.forEach(piece => {
2098
+ if (piece.life > 0) {
2099
+ allDead = false;
2100
+ piece.life -= 0.02;
2101
+
2102
+ // ์œ„์น˜ ์—…๋ฐ์ดํŠธ
2103
+ piece.position.add(piece.velocity.clone().multiplyScalar(0.02));
2104
+
2105
+ // ํšŒ์ „
2106
+ piece.rotation.x += piece.angularVelocity.x * 0.02;
2107
+ piece.rotation.y += piece.angularVelocity.y * 0.02;
2108
+ piece.rotation.z += piece.angularVelocity.z * 0.02;
2109
+
2110
+ // ์ค‘๋ ฅ
2111
+ piece.velocity.y -= 5;
2112
+
2113
+ // ์ง€๋ฉด ์ถฉ๋Œ
2114
+ if (piece.position.y <= 0) {
2115
+ piece.position.y = 0;
2116
+ piece.velocity.y *= -0.3;
2117
+ piece.velocity.x *= 0.7;
2118
+ piece.velocity.z *= 0.7;
2119
+ }
2120
+
2121
+ // ํŽ˜์ด๋“œ ์•„์›ƒ
2122
+ piece.material.opacity = piece.life / 2;
2123
+ } else if (piece.parent) {
2124
+ this.scene.remove(piece);
2125
+ }
2126
+ });
2127
+
2128
+ // ์—ฐ๊ธฐ ์—…๋ฐ์ดํŠธ
2129
+ smokes.forEach(smoke => {
2130
+ if (smoke.life > 0) {
2131
+ allDead = false;
2132
+ smoke.life -= 0.015;
2133
+
2134
+ // ์œ„์น˜ ์—…๋ฐ์ดํŠธ
2135
+ smoke.position.add(smoke.velocity.clone().multiplyScalar(0.02));
2136
+
2137
+ // ์ƒ์Šน
2138
+ smoke.velocity.y *= 0.98;
2139
+
2140
+ // ํ™•์‚ฐ
2141
+ smoke.scale.multiplyScalar(1.02);
2142
+
2143
+ // ํŽ˜์ด๋“œ ์•„์›ƒ
2144
+ smoke.material.opacity = smoke.life / 5;
2145
+ } else if (smoke.parent) {
2146
+ this.scene.remove(smoke);
2147
+ }
2148
+ });
2149
+
2150
+ // ํฌ๋ ˆ์ดํ„ฐ ํŽ˜์ด๋“œ
2151
+ if (crater.material.opacity > 0) {
2152
+ crater.material.opacity -= 0.005;
2153
+ allDead = false;
2154
+ } else if (crater.parent) {
2155
+ this.scene.remove(crater);
2156
+ }
2157
+
2158
+ if (!allDead) {
2159
+ requestAnimationFrame(animateExplosion);
2160
+ }
2161
+ };
2162
+
2163
+ animateExplosion();
2164
+
2165
+ // ์ถฉ๋Œ ์‚ฌ์šด๋“œ ์žฌ์ƒ
2166
+ try {
2167
+ const impactSound = new Audio('sounds/explode.ogg');
2168
+ impactSound.volume = 0.4;
2169
+ impactSound.play().catch(e => {});
2170
+ } catch (e) {}
2171
+ }
2172
+
2173
  checkCollisions() {
2174
  // ํ”Œ๋ ˆ์ด์–ด ํƒ„ํ™˜ vs ์ ๊ธฐ ์ถฉ๋Œ
2175
  for (let i = this.fighter.bullets.length - 1; i >= 0; i--) {
 
2377
 
2378
  this.fighter.updateControls(this.keys, deltaTime);
2379
  this.fighter.updatePhysics(deltaTime);
2380
+ this.fighter.updateBullets(this.scene, deltaTime, this); // this ์ถ”๊ฐ€
2381
 
2382
  // ๋งˆ์šฐ์Šค ๋ˆ„๋ฆ„ ์ƒํƒœ์ผ ๋•Œ ์—ฐ์† ๋ฐœ์‚ฌ
2383
  if (this.fighter.isMouseDown && this.isStarted) {