Spaces:
Running
Running
Update game.js
Browse files
game.js
CHANGED
|
@@ -19,85 +19,7 @@ const ENEMY_CONFIG = {
|
|
| 19 |
BULLET_SPEED: 2
|
| 20 |
};
|
| 21 |
|
| 22 |
-
// TankPlayer ํด๋์ค ์ ์
|
| 23 |
-
class TankPlayer {
|
| 24 |
-
constructor() {
|
| 25 |
-
this.body = null;
|
| 26 |
-
this.turret = null;
|
| 27 |
-
this.position = new THREE.Vector3(0, 0, 0);
|
| 28 |
-
this.rotation = new THREE.Euler(0, 0, 0);
|
| 29 |
-
this.turretRotation = 0;
|
| 30 |
-
this.moveSpeed = 0.5;
|
| 31 |
-
this.turnSpeed = 0.03;
|
| 32 |
-
this.turretGroup = new THREE.Group(); // ํฌํ ๊ทธ๋ฃน ์ถ๊ฐ
|
| 33 |
-
}
|
| 34 |
-
|
| 35 |
-
async initialize(scene, loader) {
|
| 36 |
-
try {
|
| 37 |
-
// ๋ชธ์ฒด ๋ก๋
|
| 38 |
-
const bodyResult = await loader.loadAsync('/models/abramslow.glb');
|
| 39 |
-
this.body = bodyResult.scene;
|
| 40 |
-
this.body.position.copy(this.position);
|
| 41 |
-
|
| 42 |
-
// ํฌํ ๋ก๋
|
| 43 |
-
const turretResult = await loader.loadAsync('/models/abramsTlow.glb');
|
| 44 |
-
this.turret = turretResult.scene;
|
| 45 |
-
|
| 46 |
-
// ํฌํ ๊ทธ๋ฃน ์ค์
|
| 47 |
-
this.turretGroup.position.y = TANK_HEIGHT;
|
| 48 |
-
this.turretGroup.add(this.turret);
|
| 49 |
-
this.body.add(this.turretGroup);
|
| 50 |
-
|
| 51 |
-
// ๊ทธ๋ฆผ์ ์ค์
|
| 52 |
-
this.body.traverse((child) => {
|
| 53 |
-
if (child.isMesh) {
|
| 54 |
-
child.castShadow = true;
|
| 55 |
-
child.receiveShadow = true;
|
| 56 |
-
}
|
| 57 |
-
});
|
| 58 |
-
|
| 59 |
-
this.turret.traverse((child) => {
|
| 60 |
-
if (child.isMesh) {
|
| 61 |
-
child.castShadow = true;
|
| 62 |
-
child.receiveShadow = true;
|
| 63 |
-
}
|
| 64 |
-
});
|
| 65 |
-
|
| 66 |
-
scene.add(this.body);
|
| 67 |
-
|
| 68 |
-
} catch (error) {
|
| 69 |
-
console.error('Error loading tank models:', error);
|
| 70 |
-
}
|
| 71 |
-
}
|
| 72 |
-
|
| 73 |
-
update(mouseX, mouseY) {
|
| 74 |
-
if (!this.body || !this.turretGroup) return;
|
| 75 |
-
|
| 76 |
-
// ๋ง์ฐ์ค ์์น๋ฅผ ์ด์ฉํ ํฌํ ํ์ ๊ณ์ฐ
|
| 77 |
-
const targetAngle = Math.atan2(mouseX, mouseY);
|
| 78 |
-
|
| 79 |
-
// ํฌํ ๋ถ๋๋ฌ์ด ํ์
|
| 80 |
-
const currentRotation = this.turretGroup.rotation.y;
|
| 81 |
-
const rotationDiff = targetAngle - currentRotation;
|
| 82 |
-
this.turretGroup.rotation.y += rotationDiff * 0.1;
|
| 83 |
-
}
|
| 84 |
|
| 85 |
-
move(direction) {
|
| 86 |
-
if (!this.body) return;
|
| 87 |
-
|
| 88 |
-
const moveVector = new THREE.Vector3();
|
| 89 |
-
moveVector.x = direction.x * this.moveSpeed;
|
| 90 |
-
moveVector.z = direction.z * this.moveSpeed;
|
| 91 |
-
|
| 92 |
-
moveVector.applyEuler(this.body.rotation);
|
| 93 |
-
this.body.position.add(moveVector);
|
| 94 |
-
}
|
| 95 |
-
|
| 96 |
-
rotate(angle) {
|
| 97 |
-
if (!this.body) return;
|
| 98 |
-
this.body.rotation.y += angle * this.turnSpeed;
|
| 99 |
-
}
|
| 100 |
-
}
|
| 101 |
// TankPlayer ํด๋์ค ์์
|
| 102 |
class TankPlayer {
|
| 103 |
constructor() {
|
|
|
|
| 19 |
BULLET_SPEED: 2
|
| 20 |
};
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
// TankPlayer ํด๋์ค ์์
|
| 24 |
class TankPlayer {
|
| 25 |
constructor() {
|