cutechicken commited on
Commit
7111402
β€’
1 Parent(s): 897f660

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +12 -90
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
- const startScreen = document.getElementById('startScreen');
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().catch(error => {
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
- const startScreen = document.getElementById('startScreen');
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
  });