cutechicken commited on
Commit
36d3f59
Β·
verified Β·
1 Parent(s): 022d403

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +54 -62
game.js CHANGED
@@ -208,6 +208,13 @@ class TankPlayer {
208
  // μƒˆλ‘œμš΄ μœ„μΉ˜ 계산
209
  const newPosition = this.body.position.clone().add(moveVector);
210
 
 
 
 
 
 
 
 
211
  // μƒˆλ‘œμš΄ μœ„μΉ˜μ˜ μ§€ν˜• 높이 κ°€μ Έμ˜€κΈ°
212
  const heightAtNewPos = window.gameInstance.getHeightAtPosition(newPosition.x, newPosition.z);
213
 
@@ -217,7 +224,7 @@ class TankPlayer {
217
  // 경사가 λ„ˆλ¬΄ κ°€νŒŒλ₯Έμ§€ 체크
218
  const currentHeight = this.body.position.y;
219
  const heightDifference = Math.abs(newPosition.y - currentHeight);
220
- const maxClimbAngle = 0.5; // μ΅œλŒ€ λ“±λ°˜ 각도
221
 
222
  if (heightDifference / this.moveSpeed < maxClimbAngle) {
223
  this.body.position.copy(newPosition);
@@ -371,6 +378,12 @@ class Enemy {
371
  const moveVector = direction.multiplyScalar(this.moveSpeed);
372
  const newPosition = this.mesh.position.clone().add(moveVector);
373
 
 
 
 
 
 
 
374
  // μƒˆλ‘œμš΄ μœ„μΉ˜μ˜ μ§€ν˜• 높이 κ°€μ Έμ˜€κΈ°
375
  const heightAtNewPos = window.gameInstance.getHeightAtPosition(newPosition.x, newPosition.z);
376
  newPosition.y = heightAtNewPos + TANK_HEIGHT;
@@ -411,14 +424,15 @@ class Enemy {
411
  }
412
  }
413
 
414
-
415
  // μ΄μ•Œ μ—…λ°μ΄νŠΈ λΆ€λΆ„
416
  for (let i = this.bullets.length - 1; i >= 0; i--) {
417
  const bullet = this.bullets[i];
418
  bullet.position.add(bullet.velocity);
419
 
420
- if (Math.abs(bullet.position.x) > MAP_SIZE ||
421
- Math.abs(bullet.position.z) > MAP_SIZE) {
 
 
422
  this.scene.remove(bullet);
423
  this.bullets.splice(i, 1);
424
  }
@@ -566,64 +580,42 @@ class Game {
566
  this.scene.add(directionalLight);
567
 
568
  // μ§€ν˜• 생성 μˆ˜μ •
569
- const groundGeometry = new THREE.PlaneGeometry(MAP_SIZE, MAP_SIZE, 100, 100);
570
- const groundMaterial = new THREE.MeshStandardMaterial({
571
- color: 0xD2B48C,
572
- roughness: 0.8,
573
- metalness: 0.2,
574
- wireframe: false
575
- });
576
-
577
- const ground = new THREE.Mesh(groundGeometry, groundMaterial);
578
- ground.rotation.x = -Math.PI / 2;
579
- ground.receiveShadow = true;
580
-
581
- // μ§€ν˜• 높이 μ„€μ •
582
- const vertices = ground.geometry.attributes.position.array;
583
- const heightScale = 15;
584
- const baseFrequency = 0.008;
585
-
586
- // 평지 μ˜μ—­ μ •μ˜
587
- const flatlandRadius = MAP_SIZE * 0.3; // 평지 μ˜μ—­μ˜ 반경
588
- const transitionZone = MAP_SIZE * 0.1; // 평지와 언덕 μ‚¬μ΄μ˜ μ „ν™˜ ꡬ역
589
-
590
- for (let i = 0; i < vertices.length; i += 3) {
591
- const x = vertices[i];
592
- const y = vertices[i + 1];
593
-
594
- // μ€‘μ‹¬μ μœΌλ‘œλΆ€ν„°μ˜ 거리 계산
595
- const distanceFromCenter = Math.sqrt(x * x + y * y);
596
-
597
- // 평지 μ˜μ—­μ΄λ©΄ 높이λ₯Ό 0으둜 μ„€μ •
598
- if (distanceFromCenter < flatlandRadius) {
599
- vertices[i + 2] = 0;
600
- }
601
- // μ „ν™˜ ꡬ역이면 λΆ€λ“œλŸ½κ²Œ 높이 증가
602
- else if (distanceFromCenter < flatlandRadius + transitionZone) {
603
- const transitionFactor = (distanceFromCenter - flatlandRadius) / transitionZone;
604
- let height = 0;
605
-
606
- // 언덕 높이 계산
607
- height += Math.sin(x * baseFrequency) * Math.cos(y * baseFrequency) * heightScale;
608
- height += Math.sin(x * baseFrequency * 2) * Math.cos(y * baseFrequency * 2) * (heightScale * 0.5);
609
- height += Math.sin(x * baseFrequency * 4) * Math.cos(y * baseFrequency * 4) * (heightScale * 0.25);
610
-
611
- vertices[i + 2] = height * transitionFactor;
612
- }
613
- // 언덕 μ˜μ—­
614
- else {
615
- let height = 0;
616
- height += Math.sin(x * baseFrequency) * Math.cos(y * baseFrequency) * heightScale;
617
- height += Math.sin(x * baseFrequency * 2) * Math.cos(y * baseFrequency * 2) * (heightScale * 0.5);
618
- height += Math.sin(x * baseFrequency * 4) * Math.cos(y * baseFrequency * 4) * (heightScale * 0.25);
619
- vertices[i + 2] = height;
620
- }
621
- }
622
-
623
- ground.geometry.attributes.position.needsUpdate = true;
624
- ground.geometry.computeVertexNormals();
625
- this.ground = ground;
626
- this.scene.add(ground);
627
 
628
  // λ“±κ³ μ„  효과 (언덕 μ˜μ—­μ—λ§Œ 적용)
629
  const contourMaterial = new THREE.LineBasicMaterial({
 
208
  // μƒˆλ‘œμš΄ μœ„μΉ˜ 계산
209
  const newPosition = this.body.position.clone().add(moveVector);
210
 
211
+ // 맡 경계 체크
212
+ const halfMap = MAP_SIZE / 2;
213
+ const margin = 10; // 맡 κ²½κ³„μ—μ„œμ˜ μ—¬μœ  곡간
214
+
215
+ newPosition.x = Math.max(-halfMap + margin, Math.min(halfMap - margin, newPosition.x));
216
+ newPosition.z = Math.max(-halfMap + margin, Math.min(halfMap - margin, newPosition.z));
217
+
218
  // μƒˆλ‘œμš΄ μœ„μΉ˜μ˜ μ§€ν˜• 높이 κ°€μ Έμ˜€κΈ°
219
  const heightAtNewPos = window.gameInstance.getHeightAtPosition(newPosition.x, newPosition.z);
220
 
 
224
  // 경사가 λ„ˆλ¬΄ κ°€νŒŒλ₯Έμ§€ 체크
225
  const currentHeight = this.body.position.y;
226
  const heightDifference = Math.abs(newPosition.y - currentHeight);
227
+ const maxClimbAngle = 0.5;
228
 
229
  if (heightDifference / this.moveSpeed < maxClimbAngle) {
230
  this.body.position.copy(newPosition);
 
378
  const moveVector = direction.multiplyScalar(this.moveSpeed);
379
  const newPosition = this.mesh.position.clone().add(moveVector);
380
 
381
+ // 맡 경계 체크
382
+ const halfMap = MAP_SIZE / 2;
383
+ const margin = 10;
384
+ newPosition.x = Math.max(-halfMap + margin, Math.min(halfMap - margin, newPosition.x));
385
+ newPosition.z = Math.max(-halfMap + margin, Math.min(halfMap - margin, newPosition.z));
386
+
387
  // μƒˆλ‘œμš΄ μœ„μΉ˜μ˜ μ§€ν˜• 높이 κ°€μ Έμ˜€κΈ°
388
  const heightAtNewPos = window.gameInstance.getHeightAtPosition(newPosition.x, newPosition.z);
389
  newPosition.y = heightAtNewPos + TANK_HEIGHT;
 
424
  }
425
  }
426
 
 
427
  // μ΄μ•Œ μ—…λ°μ΄νŠΈ λΆ€λΆ„
428
  for (let i = this.bullets.length - 1; i >= 0; i--) {
429
  const bullet = this.bullets[i];
430
  bullet.position.add(bullet.velocity);
431
 
432
+ // μ΄μ•Œμ΄ 맡 경계λ₯Ό λ²—μ–΄λ‚˜λ©΄ 제거
433
+ const halfMap = MAP_SIZE / 2;
434
+ if (Math.abs(bullet.position.x) > halfMap ||
435
+ Math.abs(bullet.position.z) > halfMap) {
436
  this.scene.remove(bullet);
437
  this.bullets.splice(i, 1);
438
  }
 
580
  this.scene.add(directionalLight);
581
 
582
  // μ§€ν˜• 생성 μˆ˜μ •
583
+ const groundGeometry = new THREE.PlaneGeometry(MAP_SIZE, MAP_SIZE, 100, 100);
584
+ const groundMaterial = new THREE.MeshStandardMaterial({
585
+ color: 0xD2B48C, // 사막색
586
+ roughness: 0.8,
587
+ metalness: 0.2,
588
+ wireframe: false
589
+ });
590
+
591
+ const ground = new THREE.Mesh(groundGeometry, groundMaterial);
592
+ ground.rotation.x = -Math.PI / 2;
593
+ ground.receiveShadow = true;
594
+
595
+ // μ§€ν˜• 높이 μ„€μ • - 평지와 λͺ¨λž˜μ–Έλ•λ§Œ μ‘΄μž¬ν•˜λ„λ‘ μˆ˜μ •
596
+ const vertices = ground.geometry.attributes.position.array;
597
+ const heightScale = 15;
598
+
599
+ for (let i = 0; i < vertices.length; i += 3) {
600
+ const x = vertices[i];
601
+ const z = vertices[i + 1];
602
+
603
+ // 맡을 4λΆ„ν• ν•˜μ—¬ μ™Όμͺ½ μœ„λŠ” 평지, λ‚˜λ¨Έμ§€λŠ” λͺ¨λž˜μ–Έλ•μœΌλ‘œ μ„€μ •
604
+ if (x < 0 && z > 0) {
605
+ // 평지 μ˜μ—­
606
+ vertices[i + 2] = 0;
607
+ } else {
608
+ // λͺ¨λž˜μ–Έλ• μ˜μ—­
609
+ const distance = Math.sqrt(x * x + z * z);
610
+ const height = Math.sin(distance * 0.02) * heightScale;
611
+ vertices[i + 2] = Math.max(0, height); // 음수 높이 방지
612
+ }
613
+ }
614
+
615
+ ground.geometry.attributes.position.needsUpdate = true;
616
+ ground.geometry.computeVertexNormals();
617
+ this.ground = ground;
618
+ this.scene.add(ground);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
619
 
620
  // λ“±κ³ μ„  효과 (언덕 μ˜μ—­μ—λ§Œ 적용)
621
  const contourMaterial = new THREE.LineBasicMaterial({