cutechicken commited on
Commit
9b5680b
ยท
verified ยท
1 Parent(s): ea69448

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +46 -0
game.js CHANGED
@@ -42,6 +42,35 @@ 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) {
@@ -254,6 +283,12 @@ class TankPlayer {
254
  scene.add(this.body);
255
  this.isLoaded = true;
256
  this.updateAmmoDisplay();
 
 
 
 
 
 
257
 
258
  } catch (error) {
259
  console.error('Error loading tank models:', error);
@@ -421,6 +456,17 @@ startReload() {
421
  const absoluteTurretRotation = mouseX;
422
  this.turretGroup.rotation.y = absoluteTurretRotation - this.body.rotation.y;
423
  this.turretRotation = absoluteTurretRotation;
 
 
 
 
 
 
 
 
 
 
 
424
 
425
  // ์ด์•Œ ์—…๋ฐ์ดํŠธ ๋ฐ ์ถฉ๋Œ ์ฒดํฌ
426
  for (let i = this.bullets.length - 1; i >= 0; i--) {
 
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
+ this.aimLine = null;
47
+ this.aimLineLength = 100; // ์กฐ์ค€์„  ๊ธธ์ด
48
+ this.createAimLine();
49
+ }
50
+ // ์กฐ์ค€์„  ์ƒ์„ฑ ๋ฉ”์„œ๋“œ
51
+ createAimLine() {
52
+ const geometry = new THREE.BufferGeometry();
53
+ const material = new THREE.LineBasicMaterial({
54
+ color: 0xff0000,
55
+ linewidth: 1,
56
+ transparent: true,
57
+ opacity: 0.5
58
+ });
59
+
60
+ // ์‹œ์ž‘์ ๊ณผ ๋์ ์œผ๋กœ ์„  ์ƒ์„ฑ
61
+ const points = [
62
+ new THREE.Vector3(0, 0, 0),
63
+ new THREE.Vector3(0, 0, this.aimLineLength)
64
+ ];
65
+ geometry.setFromPoints(points);
66
+
67
+ this.aimLine = new THREE.Line(geometry, material);
68
+ this.aimLine.position.y = 0.5; // ํฌํƒ‘ ๋†’์ด์— ๋งž์ถค
69
+
70
+ // ํฌํƒ‘ ๊ทธ๋ฃน์— ์กฐ์ค€์„  ์ถ”๊ฐ€
71
+ if (this.turretGroup) {
72
+ this.turretGroup.add(this.aimLine);
73
+ }
74
  }
75
  // ๋ณ„๋„์˜ ๋ฉ”์„œ๋“œ๋กœ ๋ถ„๋ฆฌ
76
  createExplosionEffect(scene, position) {
 
283
  scene.add(this.body);
284
  this.isLoaded = true;
285
  this.updateAmmoDisplay();
286
+ // ์กฐ์ค€์„  ์ถ”๊ฐ€
287
+ this.createAimLine();
288
+
289
+ scene.add(this.body);
290
+ this.isLoaded = true;
291
+ this.updateAmmoDisplay();
292
 
293
  } catch (error) {
294
  console.error('Error loading tank models:', error);
 
456
  const absoluteTurretRotation = mouseX;
457
  this.turretGroup.rotation.y = absoluteTurretRotation - this.body.rotation.y;
458
  this.turretRotation = absoluteTurretRotation;
459
+ // ์กฐ์ค€์„  ์—…๋ฐ์ดํŠธ
460
+ if (this.aimLine) {
461
+ // ์กฐ์ค€์„ ์˜ ํˆฌ๋ช…๋„๋ฅผ ๊ฑฐ๋ฆฌ์— ๋”ฐ๋ผ ์กฐ์ ˆ
462
+ const points = this.aimLine.geometry.attributes.position.array;
463
+ for (let i = 0; i < points.length; i += 3) {
464
+ const distance = Math.sqrt(points[i] * points[i] + points[i + 2] * points[i + 2]);
465
+ const opacity = 1 - (distance / this.aimLineLength);
466
+ this.aimLine.material.opacity = Math.max(0.2, opacity);
467
+ }
468
+ }
469
+
470
 
471
  // ์ด์•Œ ์—…๋ฐ์ดํŠธ ๋ฐ ์ถฉ๋Œ ์ฒดํฌ
472
  for (let i = this.bullets.length - 1; i >= 0; i--) {