cutechicken commited on
Commit
5153a18
ยท
verified ยท
1 Parent(s): df98913

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +40 -22
game.js CHANGED
@@ -42,6 +42,12 @@ class TankPlayer {
42
  this.scene = new THREE.Scene();
43
  this.camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
44
  this.renderer = new THREE.WebGLRenderer({ antialias: true });
 
 
 
 
 
 
45
  }
46
  // ๋ณ„๋„์˜ ๋ฉ”์„œ๋“œ๋กœ ๋ถ„๋ฆฌ
47
  createExplosionEffect(scene, position) {
@@ -308,28 +314,36 @@ class TankPlayer {
308
  return bullet;
309
  }
310
  applyCameraShake() {
311
- if (!window.gameInstance || !window.gameInstance.camera) return;
312
-
313
  const camera = window.gameInstance.camera;
314
- const originalPosition = camera.position.clone();
315
- let shakeTime = 0;
316
- const shakeIntensity = 0.2; // ๋ฐœ์‚ฌ ์‹œ ํ”๋“ค๋ฆผ ๊ฐ•๋„
317
- const shakeDuration = 300; // ํ”๋“ค๋ฆผ ์ง€์† ์‹œ๊ฐ„ (ms)
318
-
319
- const shakeCamera = () => {
320
- if (shakeTime < shakeDuration) {
321
- camera.position.x = originalPosition.x + (Math.random() - 0.5) * shakeIntensity;
322
- camera.position.y = originalPosition.y + (Math.random() - 0.5) * shakeIntensity;
323
- camera.position.z = originalPosition.z + (Math.random() - 0.5) * shakeIntensity;
324
-
325
- shakeTime += 16; // ์•ฝ 60fps ๊ธฐ์ค€
326
- requestAnimationFrame(shakeCamera);
327
- } else {
328
- camera.position.copy(originalPosition);
329
- }
330
- };
331
-
332
- shakeCamera();
 
 
 
 
 
 
 
 
333
  }
334
 
335
  startReload() {
@@ -2647,7 +2661,11 @@ updateCrosshair() {
2647
  if (!this.isLoading) {
2648
  this.handleMovement();
2649
  this.tank.update(this.mouse.x, this.mouse.y, this.scene);
2650
-
 
 
 
 
2651
  const tankPosition = this.tank.getPosition();
2652
  this.enemies.forEach(enemy => {
2653
  enemy.update(tankPosition);
 
42
  this.scene = new THREE.Scene();
43
  this.camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
44
  this.renderer = new THREE.WebGLRenderer({ antialias: true });
45
+ this.cameraShake = {
46
+ active: false,
47
+ intensity: 0,
48
+ duration: 0,
49
+ time: 0,
50
+ originalPosition: null
51
  }
52
  // ๋ณ„๋„์˜ ๋ฉ”์„œ๋“œ๋กœ ๋ถ„๋ฆฌ
53
  createExplosionEffect(scene, position) {
 
314
  return bullet;
315
  }
316
  applyCameraShake() {
317
+ if (!this.cameraShake || !this.cameraShake.active) return;
318
+
319
  const camera = window.gameInstance.camera;
320
+ if (!camera) return;
321
+
322
+ // ์›๋ณธ ์œ„์น˜ ์ €์žฅ
323
+ if (!this.cameraShake.originalPosition) {
324
+ this.cameraShake.originalPosition = camera.position.clone();
325
+ }
326
+
327
+ // ์‹œ๊ฐ„ ์—…๋ฐ์ดํŠธ
328
+ this.cameraShake.time += 16; // ์•ฝ 60fps ๊ธฐ์ค€
329
+
330
+ // ๊ฐ์‡  ๊ณ„์ˆ˜ ๊ณ„์‚ฐ (์‹œ๊ฐ„์ด ์ง€๋‚ ์ˆ˜๋ก ํ”๋“ค๋ฆผ์ด ์ค„์–ด๋“ฆ)
331
+ const damping = 1 - (this.cameraShake.time / this.cameraShake.duration);
332
+
333
+ if (this.cameraShake.time < this.cameraShake.duration) {
334
+ // ๋žœ๋คํ•œ ์˜คํ”„์…‹ ์ ์šฉ
335
+ camera.position.x = this.cameraShake.originalPosition.x +
336
+ (Math.random() - 0.5) * this.cameraShake.intensity * damping;
337
+ camera.position.y = this.cameraShake.originalPosition.y +
338
+ (Math.random() - 0.5) * this.cameraShake.intensity * damping;
339
+ camera.position.z = this.cameraShake.originalPosition.z +
340
+ (Math.random() - 0.5) * this.cameraShake.intensity * damping;
341
+ } else {
342
+ // ํšจ๊ณผ ์ข…๋ฃŒ
343
+ camera.position.copy(this.cameraShake.originalPosition);
344
+ this.cameraShake.active = false;
345
+ this.cameraShake.originalPosition = null;
346
+ }
347
  }
348
 
349
  startReload() {
 
2661
  if (!this.isLoading) {
2662
  this.handleMovement();
2663
  this.tank.update(this.mouse.x, this.mouse.y, this.scene);
2664
+
2665
+ // ์นด๋ฉ”๋ผ ํ”๋“ค๋ฆผ ํšจ๊ณผ ์—…๋ฐ์ดํŠธ
2666
+ if (this.tank.cameraShake && this.tank.cameraShake.active) {
2667
+ this.tank.applyCameraShake();
2668
+ }
2669
  const tankPosition = this.tank.getPosition();
2670
  this.enemies.forEach(enemy => {
2671
  enemy.update(tankPosition);