Spaces:
Running
Running
Update game.js
Browse files
game.js
CHANGED
|
@@ -43,21 +43,21 @@ class TankPlayer {
|
|
| 43 |
const bodyResult = await loader.loadAsync('/models/abramsBody.glb');
|
| 44 |
this.body = bodyResult.scene;
|
| 45 |
this.body.position.copy(this.position);
|
| 46 |
-
|
| 47 |
const turretResult = await loader.loadAsync('/models/abramsTurret.glb');
|
| 48 |
this.turret = turretResult.scene;
|
| 49 |
-
|
| 50 |
this.turretGroup.position.y = 0.2;
|
| 51 |
this.turretGroup.add(this.turret);
|
| 52 |
this.body.add(this.turretGroup);
|
| 53 |
-
|
| 54 |
this.body.traverse((child) => {
|
| 55 |
if (child.isMesh) {
|
| 56 |
child.castShadow = true;
|
| 57 |
child.receiveShadow = true;
|
| 58 |
}
|
| 59 |
});
|
| 60 |
-
|
| 61 |
this.turret.traverse((child) => {
|
| 62 |
if (child.isMesh) {
|
| 63 |
child.castShadow = true;
|
|
@@ -67,29 +67,13 @@ class TankPlayer {
|
|
| 67 |
|
| 68 |
scene.add(this.body);
|
| 69 |
this.isLoaded = true;
|
|
|
|
| 70 |
} catch (error) {
|
| 71 |
console.error('Error loading tank models:', error);
|
| 72 |
this.isLoaded = false;
|
| 73 |
}
|
| 74 |
}
|
| 75 |
|
| 76 |
-
reload() {
|
| 77 |
-
if (this.ammo < 10) {
|
| 78 |
-
const reloadTime = 2000; // 2์ด ๋์ ์ฌ์ฅ์
|
| 79 |
-
document.getElementById('reloadButton').disabled = true; // ๋ฒํผ ๋นํ์ฑํ
|
| 80 |
-
document.getElementById('reloadButton').textContent = 'Reloading...';
|
| 81 |
-
|
| 82 |
-
setTimeout(() => {
|
| 83 |
-
this.ammo = 10; // ํ์ฝ ์ถฉ์
|
| 84 |
-
document.getElementById('ammo').textContent = `${this.ammo}/10`; // UI ์
๋ฐ์ดํธ
|
| 85 |
-
document.getElementById('reloadButton').disabled = false; // ๋ฒํผ ํ์ฑํ
|
| 86 |
-
document.getElementById('reloadButton').textContent = 'Reload'; // ๋ฒํผ ํ
์คํธ ๋ณต๊ตฌ
|
| 87 |
-
}, reloadTime);
|
| 88 |
-
}
|
| 89 |
-
}
|
| 90 |
-
}
|
| 91 |
-
|
| 92 |
-
|
| 93 |
shoot(scene) {
|
| 94 |
const currentTime = Date.now();
|
| 95 |
if (currentTime - this.lastShootTime < this.shootInterval || this.ammo <= 0) return null;
|
|
|
|
| 43 |
const bodyResult = await loader.loadAsync('/models/abramsBody.glb');
|
| 44 |
this.body = bodyResult.scene;
|
| 45 |
this.body.position.copy(this.position);
|
| 46 |
+
|
| 47 |
const turretResult = await loader.loadAsync('/models/abramsTurret.glb');
|
| 48 |
this.turret = turretResult.scene;
|
| 49 |
+
|
| 50 |
this.turretGroup.position.y = 0.2;
|
| 51 |
this.turretGroup.add(this.turret);
|
| 52 |
this.body.add(this.turretGroup);
|
| 53 |
+
|
| 54 |
this.body.traverse((child) => {
|
| 55 |
if (child.isMesh) {
|
| 56 |
child.castShadow = true;
|
| 57 |
child.receiveShadow = true;
|
| 58 |
}
|
| 59 |
});
|
| 60 |
+
|
| 61 |
this.turret.traverse((child) => {
|
| 62 |
if (child.isMesh) {
|
| 63 |
child.castShadow = true;
|
|
|
|
| 67 |
|
| 68 |
scene.add(this.body);
|
| 69 |
this.isLoaded = true;
|
| 70 |
+
|
| 71 |
} catch (error) {
|
| 72 |
console.error('Error loading tank models:', error);
|
| 73 |
this.isLoaded = false;
|
| 74 |
}
|
| 75 |
}
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
shoot(scene) {
|
| 78 |
const currentTime = Date.now();
|
| 79 |
if (currentTime - this.lastShootTime < this.shootInterval || this.ammo <= 0) return null;
|