Spaces:
Running
Running
Update game.js
Browse files
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--) {
|