Spaces:
Running
Running
cutechicken
commited on
Commit
β’
7111402
1
Parent(s):
897f660
Update game.js
Browse files
game.js
CHANGED
@@ -42,35 +42,6 @@ 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 |
-
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,12 +254,6 @@ class TankPlayer {
|
|
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,17 +421,6 @@ startReload() {
|
|
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--) {
|
@@ -972,42 +926,21 @@ class Game {
|
|
972 |
|
973 |
async initialize() {
|
974 |
try {
|
975 |
-
// BGM
|
976 |
-
if (!this.bgm) {
|
977 |
this.bgm = new Audio('sounds/BGM.ogg');
|
978 |
this.bgm.volume = 0.5;
|
979 |
this.bgm.loop = true;
|
|
|
|
|
980 |
}
|
981 |
-
|
982 |
-
// μ¬μ©μ μνΈμμ© ν BGM μ¬μ
|
983 |
-
const playBGM = () => {
|
984 |
-
if (this.bgm && !this.bgmPlaying) {
|
985 |
-
this.bgm.play()
|
986 |
-
.then(() => {
|
987 |
-
this.bgmPlaying = true;
|
988 |
-
})
|
989 |
-
.catch(error => {
|
990 |
-
console.error('BGM playback failed:', error);
|
991 |
-
});
|
992 |
-
}
|
993 |
-
};
|
994 |
-
|
995 |
// μμ μ¬μ΄λ μ¬μ
|
996 |
const startSounds = ['sounds/start1.ogg', 'sounds/start2.ogg', 'sounds/start3.ogg'];
|
997 |
const randomStartSound = startSounds[Math.floor(Math.random() * startSounds.length)];
|
998 |
const startAudio = new Audio(randomStartSound);
|
999 |
startAudio.volume = 0.5;
|
1000 |
-
|
1001 |
-
// μμ μ¬μ΄λ μ¬μ ν BGM μμ
|
1002 |
-
startAudio.play()
|
1003 |
-
.then(() => {
|
1004 |
-
playBGM();
|
1005 |
-
})
|
1006 |
-
.catch(error => {
|
1007 |
-
console.error('Start sound playback failed:', error);
|
1008 |
-
playBGM(); // μμ μ¬μ΄λ μ€ν¨ν΄λ BGM μμ
|
1009 |
-
});
|
1010 |
-
|
1011 |
|
1012 |
// λ λλ¬ μ€μ
|
1013 |
this.renderer.shadowMap.enabled = true;
|
@@ -1905,11 +1838,7 @@ class Game {
|
|
1905 |
|
1906 |
// Start game
|
1907 |
window.startGame = function() {
|
1908 |
-
|
1909 |
-
if (startScreen) {
|
1910 |
-
startScreen.style.display = 'none';
|
1911 |
-
}
|
1912 |
-
|
1913 |
document.body.requestPointerLock();
|
1914 |
|
1915 |
if (!window.gameInstance) {
|
@@ -1918,25 +1847,18 @@ window.startGame = function() {
|
|
1918 |
|
1919 |
// κ²μ μμ μ€μ
|
1920 |
window.gameInstance.isStarted = true;
|
1921 |
-
window.gameInstance.initialize()
|
1922 |
-
console.error('Failed to initialize game:', error);
|
1923 |
-
});
|
1924 |
};
|
1925 |
|
1926 |
// Initialize game
|
1927 |
document.addEventListener('DOMContentLoaded', () => {
|
1928 |
-
// κ²μ
|
1929 |
window.gameInstance = new Game();
|
1930 |
|
1931 |
-
// κΈ°λ³Έμ μΈ μ¬
|
1932 |
window.gameInstance.setupScene();
|
1933 |
-
window.gameInstance.animate();
|
1934 |
|
1935 |
// μμ νλ©΄ νμ
|
1936 |
-
|
1937 |
-
if (startScreen) {
|
1938 |
-
startScreen.style.display = 'flex';
|
1939 |
-
startScreen.style.justifyContent = 'center';
|
1940 |
-
startScreen.style.alignItems = 'center';
|
1941 |
-
}
|
1942 |
});
|
|
|
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 |
scene.add(this.body);
|
255 |
this.isLoaded = true;
|
256 |
this.updateAmmoDisplay();
|
|
|
|
|
|
|
|
|
|
|
|
|
257 |
|
258 |
} catch (error) {
|
259 |
console.error('Error loading tank models:', error);
|
|
|
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--) {
|
|
|
926 |
|
927 |
async initialize() {
|
928 |
try {
|
929 |
+
// BGMμ΄ μμ§ μ¬μλμ§ μμ κ²½μ°μλ§ μ¬μ
|
930 |
+
if (!this.bgmPlaying && !this.bgm) {
|
931 |
this.bgm = new Audio('sounds/BGM.ogg');
|
932 |
this.bgm.volume = 0.5;
|
933 |
this.bgm.loop = true;
|
934 |
+
this.bgm.play();
|
935 |
+
this.bgmPlaying = true;
|
936 |
}
|
937 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
938 |
// μμ μ¬μ΄λ μ¬μ
|
939 |
const startSounds = ['sounds/start1.ogg', 'sounds/start2.ogg', 'sounds/start3.ogg'];
|
940 |
const randomStartSound = startSounds[Math.floor(Math.random() * startSounds.length)];
|
941 |
const startAudio = new Audio(randomStartSound);
|
942 |
startAudio.volume = 0.5;
|
943 |
+
startAudio.play();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
944 |
|
945 |
// λ λλ¬ μ€μ
|
946 |
this.renderer.shadowMap.enabled = true;
|
|
|
1838 |
|
1839 |
// Start game
|
1840 |
window.startGame = function() {
|
1841 |
+
document.getElementById('startScreen').style.display = 'none';
|
|
|
|
|
|
|
|
|
1842 |
document.body.requestPointerLock();
|
1843 |
|
1844 |
if (!window.gameInstance) {
|
|
|
1847 |
|
1848 |
// κ²μ μμ μ€μ
|
1849 |
window.gameInstance.isStarted = true;
|
1850 |
+
window.gameInstance.initialize();
|
|
|
|
|
1851 |
};
|
1852 |
|
1853 |
// Initialize game
|
1854 |
document.addEventListener('DOMContentLoaded', () => {
|
1855 |
+
// κ²μ μΈμ€ν΄μ€λ§ μμ±νκ³ μ΄κΈ°νλ νμ§ μμ
|
1856 |
window.gameInstance = new Game();
|
1857 |
|
1858 |
+
// κΈ°λ³Έμ μΈ μ¬ μ€μ λ§ μν
|
1859 |
window.gameInstance.setupScene();
|
1860 |
+
window.gameInstance.animate(); // λ λλ§ μμ
|
1861 |
|
1862 |
// μμ νλ©΄ νμ
|
1863 |
+
document.getElementById('startScreen').style.display = 'block';
|
|
|
|
|
|
|
|
|
|
|
1864 |
});
|