cutechicken commited on
Commit
20b339e
β€’
1 Parent(s): 8495bf4

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +101 -108
game.js CHANGED
@@ -41,125 +41,118 @@ class TankPlayer {
41
  }
42
  // λ³„λ„μ˜ λ©”μ„œλ“œλ‘œ 뢄리
43
  createExplosionEffect(scene, position) {
44
- // 폭발 쀑심 ν”Œλž˜μ‹œ
45
- const flashGeometry = new THREE.SphereGeometry(3);
46
- const flashMaterial = new THREE.MeshBasicMaterial({
47
- color: 0xffff00,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  transparent: true,
49
  opacity: 1
50
  });
51
- const flash = new THREE.Mesh(flashGeometry, flashMaterial);
52
- flash.position.copy(position);
53
- scene.add(flash);
54
-
55
- // 폭발 νŒŒν‹°ν΄
56
- for (let i = 0; i < 30; i++) {
57
- const size = Math.random() * 0.5 + 0.3;
58
- const geometry = new THREE.SphereGeometry(size);
59
-
60
- const colors = [0xff4500, 0xff8c00, 0xff0000, 0xffd700];
61
- const material = new THREE.MeshBasicMaterial({
62
- color: colors[Math.floor(Math.random() * colors.length)],
63
- transparent: true,
64
- opacity: 1
65
- });
66
-
67
- const particle = new THREE.Mesh(geometry, material);
68
- particle.position.copy(position);
69
-
70
- const speed = Math.random() * 0.5 + 0.3;
71
- const angle = Math.random() * Math.PI * 2;
72
- const elevation = Math.random() * Math.PI - Math.PI / 2;
73
-
74
- particle.velocity = new THREE.Vector3(
75
- Math.cos(angle) * Math.cos(elevation) * speed,
76
- Math.sin(elevation) * speed,
77
- Math.sin(angle) * Math.cos(elevation) * speed
78
- );
79
-
80
- particle.gravity = -0.015;
81
- particle.life = Math.random() * 30 + 30;
82
- particle.fadeRate = 0.97;
83
-
84
- scene.add(particle);
85
- window.gameInstance.particles.push({
86
- mesh: particle,
87
- velocity: particle.velocity,
88
- gravity: particle.gravity,
89
- life: particle.life,
90
- fadeRate: particle.fadeRate
91
- });
92
- }
93
-
94
- // 폭발 링 μ΄νŽ™νŠΈ
95
- this.createExplosionRing(scene, position);
96
-
97
- // μ‚¬μš΄λ“œ 효과
98
- this.playExplosionSound();
99
 
100
- // 카메라 흔듀림 효과
101
- this.createCameraShake(scene);
 
 
 
 
 
 
 
 
 
 
102
  }
103
 
104
- // 보쑰 λ©”μ„œλ“œλ“€λ‘œ 뢄리
105
- createExplosionRing(scene, position) {
106
- const ringGeometry = new THREE.RingGeometry(0.1, 2, 32);
107
- const ringMaterial = new THREE.MeshBasicMaterial({
108
- color: 0xff8c00,
109
- transparent: true,
110
- opacity: 1,
111
- side: THREE.DoubleSide
112
- });
113
- const ring = new THREE.Mesh(ringGeometry, ringMaterial);
114
- ring.position.copy(position);
115
- ring.lookAt(new THREE.Vector3(0, 1, 0));
116
- scene.add(ring);
117
-
118
- const expandRing = () => {
119
- ring.scale.x += 0.2;
120
- ring.scale.y += 0.2;
121
- ring.material.opacity *= 0.95;
122
-
123
- if (ring.material.opacity > 0.01) {
124
- requestAnimationFrame(expandRing);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  } else {
126
- scene.remove(ring);
127
  }
128
  };
129
- expandRing();
130
  }
131
 
132
- playExplosionSound() {
133
- const explosionSounds = ['sounds/explosion.ogg'];
134
- const randomSound = explosionSounds[Math.floor(Math.random() * explosionSounds.length)];
135
- const audio = new Audio(randomSound);
136
- audio.volume = 0.4;
137
- audio.play();
138
- }
139
-
140
- createCameraShake(scene) {
141
- if (window.gameInstance && window.gameInstance.camera) {
142
- const camera = window.gameInstance.camera;
143
- const originalPosition = camera.position.clone();
144
- let shakeTime = 0;
145
- const shakeIntensity = 0.3;
146
- const shakeDuration = 500;
147
-
148
- const shakeCamera = () => {
149
- if (shakeTime < shakeDuration) {
150
- camera.position.x = originalPosition.x + (Math.random() - 0.5) * shakeIntensity;
151
- camera.position.y = originalPosition.y + (Math.random() - 0.5) * shakeIntensity;
152
- camera.position.z = originalPosition.z + (Math.random() - 0.5) * shakeIntensity;
153
-
154
- shakeTime += 16;
155
- requestAnimationFrame(shakeCamera);
156
- } else {
157
- camera.position.copy(originalPosition);
158
- }
159
- };
160
- shakeCamera();
161
- }
162
- }
163
 
164
  async initialize(scene, loader) {
165
  try {
 
41
  }
42
  // λ³„λ„μ˜ λ©”μ„œλ“œλ‘œ 뢄리
43
  createExplosionEffect(scene, position) {
44
+ // 폭발 쀑심 ν”Œλž˜μ‹œ
45
+ const flashGeometry = new THREE.SphereGeometry(3);
46
+ const flashMaterial = new THREE.MeshBasicMaterial({
47
+ color: 0xffff00,
48
+ transparent: true,
49
+ opacity: 1
50
+ });
51
+ const flash = new THREE.Mesh(flashGeometry, flashMaterial);
52
+ flash.position.copy(position);
53
+ scene.add(flash);
54
+
55
+ // 폭발 νŒŒν‹°ν΄
56
+ for (let i = 0; i < 30; i++) {
57
+ const size = Math.random() * 0.5 + 0.3;
58
+ const geometry = new THREE.SphereGeometry(size);
59
+
60
+ // λ‹€μ–‘ν•œ μƒ‰μƒμ˜ νŒŒν‹°ν΄
61
+ const colors = [0xff4500, 0xff8c00, 0xff0000, 0xffd700];
62
+ const material = new THREE.MeshBasicMaterial({
63
+ color: colors[Math.floor(Math.random() * colors.length)],
64
  transparent: true,
65
  opacity: 1
66
  });
67
+
68
+ const particle = new THREE.Mesh(geometry, material);
69
+ particle.position.copy(position);
70
+
71
+ // νŒŒν‹°ν΄ 속도와 λ°©ν–₯ μ„€μ •
72
+ const speed = Math.random() * 0.5 + 0.3;
73
+ const angle = Math.random() * Math.PI * 2;
74
+ const elevation = Math.random() * Math.PI - Math.PI / 2;
75
+
76
+ particle.velocity = new THREE.Vector3(
77
+ Math.cos(angle) * Math.cos(elevation) * speed,
78
+ Math.sin(elevation) * speed,
79
+ Math.sin(angle) * Math.cos(elevation) * speed
80
+ );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
+ particle.gravity = -0.015;
83
+ particle.life = Math.random() * 30 + 30;
84
+ particle.fadeRate = 0.97;
85
+
86
+ scene.add(particle);
87
+ window.gameInstance.particles.push({
88
+ mesh: particle,
89
+ velocity: particle.velocity,
90
+ gravity: particle.gravity,
91
+ life: particle.life,
92
+ fadeRate: particle.fadeRate
93
+ });
94
  }
95
 
96
+ // 폭발 링 μ΄νŽ™νŠΈ
97
+ const ringGeometry = new THREE.RingGeometry(0.1, 2, 32);
98
+ const ringMaterial = new THREE.MeshBasicMaterial({
99
+ color: 0xff8c00,
100
+ transparent: true,
101
+ opacity: 1,
102
+ side: THREE.DoubleSide
103
+ });
104
+ const ring = new THREE.Mesh(ringGeometry, ringMaterial);
105
+ ring.position.copy(position);
106
+ ring.lookAt(new THREE.Vector3(0, 1, 0));
107
+ scene.add(ring);
108
+
109
+ // 링 ν™•μž₯ μ• λ‹ˆλ©”μ΄μ…˜
110
+ const expandRing = () => {
111
+ ring.scale.x += 0.2;
112
+ ring.scale.y += 0.2;
113
+ ring.material.opacity *= 0.95;
114
+
115
+ if (ring.material.opacity > 0.01) {
116
+ requestAnimationFrame(expandRing);
117
+ } else {
118
+ scene.remove(ring);
119
+ }
120
+ };
121
+ expandRing();
122
+
123
+ // 폭발음 효과
124
+ const explosionSound = new Audio('sounds/explosion.ogg');
125
+ explosionSound.volume = 0.4;
126
+ explosionSound.play();
127
+
128
+ // 카메라 흔듀림 효과
129
+ if (window.gameInstance && window.gameInstance.camera) {
130
+ const camera = window.gameInstance.camera;
131
+ const originalPosition = camera.position.clone();
132
+ let shakeTime = 0;
133
+ const shakeIntensity = 0.3;
134
+ const shakeDuration = 500;
135
+
136
+ const shakeCamera = () => {
137
+ if (shakeTime < shakeDuration) {
138
+ camera.position.x = originalPosition.x + (Math.random() - 0.5) * shakeIntensity;
139
+ camera.position.y = originalPosition.y + (Math.random() - 0.5) * shakeIntensity;
140
+ camera.position.z = originalPosition.z + (Math.random() - 0.5) * shakeIntensity;
141
+
142
+ shakeTime += 16;
143
+ requestAnimationFrame(shakeCamera);
144
  } else {
145
+ camera.position.copy(originalPosition);
146
  }
147
  };
148
+ shakeCamera();
149
  }
150
 
151
+ // 쀑심 ν”Œλž˜μ‹œ 제거
152
+ setTimeout(() => {
153
+ scene.remove(flash);
154
+ }, 100);
155
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
 
157
  async initialize(scene, loader) {
158
  try {