Spaces:
Running
Running
Update game.js
Browse files
game.js
CHANGED
|
@@ -587,33 +587,38 @@ class Fighter {
|
|
| 587 |
|
| 588 |
this.ammo--;
|
| 589 |
|
| 590 |
-
|
|
|
|
| 591 |
const bulletMaterial = new THREE.MeshBasicMaterial({
|
| 592 |
color: 0xffff00,
|
| 593 |
emissive: 0xffff00,
|
| 594 |
-
emissiveIntensity: 0
|
| 595 |
});
|
| 596 |
const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
|
| 597 |
|
| 598 |
-
// 기수 끝에서 발사
|
| 599 |
-
const muzzleOffset = new THREE.Vector3(0, 0,
|
| 600 |
muzzleOffset.applyEuler(this.rotation);
|
| 601 |
bullet.position.copy(this.position).add(muzzleOffset);
|
| 602 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 603 |
// 탄환 초기 위치 저장
|
| 604 |
bullet.startPosition = bullet.position.clone();
|
| 605 |
|
| 606 |
const bulletSpeed = 1000;
|
| 607 |
const direction = new THREE.Vector3(0, 0, 1);
|
| 608 |
direction.applyEuler(this.rotation);
|
| 609 |
-
bullet.velocity = direction.multiplyScalar(bulletSpeed)
|
| 610 |
|
| 611 |
scene.add(bullet);
|
| 612 |
this.bullets.push(bullet);
|
| 613 |
|
| 614 |
-
//
|
| 615 |
try {
|
| 616 |
-
const audio = new Audio('sounds/
|
| 617 |
if (audio) {
|
| 618 |
audio.volume = 0.3;
|
| 619 |
audio.play().catch(e => console.log('Gunfire sound failed to play'));
|
|
@@ -626,6 +631,11 @@ class Fighter {
|
|
| 626 |
const bullet = this.bullets[i];
|
| 627 |
bullet.position.add(bullet.velocity.clone().multiplyScalar(deltaTime));
|
| 628 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 629 |
// 1000m 이상 날아가면 제거
|
| 630 |
if (bullet.position.distanceTo(bullet.startPosition) > 1000 ||
|
| 631 |
bullet.position.y < 0 ||
|
|
@@ -792,18 +802,23 @@ class EnemyFighter {
|
|
| 792 |
shoot() {
|
| 793 |
this.lastShootTime = Date.now();
|
| 794 |
|
| 795 |
-
|
|
|
|
| 796 |
const bulletMaterial = new THREE.MeshBasicMaterial({
|
| 797 |
color: 0xff0000,
|
| 798 |
emissive: 0xff0000,
|
| 799 |
-
emissiveIntensity: 0
|
| 800 |
});
|
| 801 |
const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
|
| 802 |
|
| 803 |
-
const muzzleOffset = new THREE.Vector3(0, 0,
|
| 804 |
muzzleOffset.applyEuler(this.rotation);
|
| 805 |
bullet.position.copy(this.position).add(muzzleOffset);
|
| 806 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 807 |
const direction = new THREE.Vector3(0, 0, 1);
|
| 808 |
direction.applyEuler(this.rotation);
|
| 809 |
bullet.velocity = direction.multiplyScalar(800);
|
|
@@ -1650,7 +1665,7 @@ class Game {
|
|
| 1650 |
// 마우스 누름 상태일 때 연속 발사
|
| 1651 |
if (this.fighter.isMouseDown && this.isStarted) {
|
| 1652 |
const currentShootTime = Date.now();
|
| 1653 |
-
if (!this.lastShootTime || currentShootTime - this.lastShootTime >=
|
| 1654 |
this.fighter.shoot(this.scene);
|
| 1655 |
this.lastShootTime = currentShootTime;
|
| 1656 |
}
|
|
|
|
| 587 |
|
| 588 |
this.ammo--;
|
| 589 |
|
| 590 |
+
// 직선 모양의 탄환 (더 두껍게)
|
| 591 |
+
const bulletGeometry = new THREE.CylinderGeometry(0.5, 0.5, 8, 8); // 반지름 0.5, 길이 8
|
| 592 |
const bulletMaterial = new THREE.MeshBasicMaterial({
|
| 593 |
color: 0xffff00,
|
| 594 |
emissive: 0xffff00,
|
| 595 |
+
emissiveIntensity: 1.0
|
| 596 |
});
|
| 597 |
const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
|
| 598 |
|
| 599 |
+
// 기수 끝에서 발사 (더 앞쪽에서)
|
| 600 |
+
const muzzleOffset = new THREE.Vector3(0, 0, 10);
|
| 601 |
muzzleOffset.applyEuler(this.rotation);
|
| 602 |
bullet.position.copy(this.position).add(muzzleOffset);
|
| 603 |
|
| 604 |
+
// 탄환을 발사 방향으로 회전
|
| 605 |
+
bullet.rotation.copy(this.rotation);
|
| 606 |
+
bullet.rotateX(Math.PI / 2); // 실린더가 Z축 방향을 향하도록
|
| 607 |
+
|
| 608 |
// 탄환 초기 위치 저장
|
| 609 |
bullet.startPosition = bullet.position.clone();
|
| 610 |
|
| 611 |
const bulletSpeed = 1000;
|
| 612 |
const direction = new THREE.Vector3(0, 0, 1);
|
| 613 |
direction.applyEuler(this.rotation);
|
| 614 |
+
bullet.velocity = direction.multiplyScalar(bulletSpeed);
|
| 615 |
|
| 616 |
scene.add(bullet);
|
| 617 |
this.bullets.push(bullet);
|
| 618 |
|
| 619 |
+
// m134.ogg 소리 재생
|
| 620 |
try {
|
| 621 |
+
const audio = new Audio('sounds/m134.ogg');
|
| 622 |
if (audio) {
|
| 623 |
audio.volume = 0.3;
|
| 624 |
audio.play().catch(e => console.log('Gunfire sound failed to play'));
|
|
|
|
| 631 |
const bullet = this.bullets[i];
|
| 632 |
bullet.position.add(bullet.velocity.clone().multiplyScalar(deltaTime));
|
| 633 |
|
| 634 |
+
// 탄환도 같은 방향을 유지하도록 회전 업데이트
|
| 635 |
+
const direction = bullet.velocity.clone().normalize();
|
| 636 |
+
const angle = Math.atan2(direction.x, direction.z);
|
| 637 |
+
bullet.rotation.y = angle;
|
| 638 |
+
|
| 639 |
// 1000m 이상 날아가면 제거
|
| 640 |
if (bullet.position.distanceTo(bullet.startPosition) > 1000 ||
|
| 641 |
bullet.position.y < 0 ||
|
|
|
|
| 802 |
shoot() {
|
| 803 |
this.lastShootTime = Date.now();
|
| 804 |
|
| 805 |
+
// 직선 모양의 탄환 (적기도 동일하게 적용)
|
| 806 |
+
const bulletGeometry = new THREE.CylinderGeometry(0.4, 0.4, 6, 8);
|
| 807 |
const bulletMaterial = new THREE.MeshBasicMaterial({
|
| 808 |
color: 0xff0000,
|
| 809 |
emissive: 0xff0000,
|
| 810 |
+
emissiveIntensity: 1.0
|
| 811 |
});
|
| 812 |
const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
|
| 813 |
|
| 814 |
+
const muzzleOffset = new THREE.Vector3(0, 0, 8);
|
| 815 |
muzzleOffset.applyEuler(this.rotation);
|
| 816 |
bullet.position.copy(this.position).add(muzzleOffset);
|
| 817 |
|
| 818 |
+
// 탄환을 발사 방향으로 회전
|
| 819 |
+
bullet.rotation.copy(this.rotation);
|
| 820 |
+
bullet.rotateX(Math.PI / 2);
|
| 821 |
+
|
| 822 |
const direction = new THREE.Vector3(0, 0, 1);
|
| 823 |
direction.applyEuler(this.rotation);
|
| 824 |
bullet.velocity = direction.multiplyScalar(800);
|
|
|
|
| 1665 |
// 마우스 누름 상태일 때 연속 발사
|
| 1666 |
if (this.fighter.isMouseDown && this.isStarted) {
|
| 1667 |
const currentShootTime = Date.now();
|
| 1668 |
+
if (!this.lastShootTime || currentShootTime - this.lastShootTime >= 200) { // 0.2초마다
|
| 1669 |
this.fighter.shoot(this.scene);
|
| 1670 |
this.lastShootTime = currentShootTime;
|
| 1671 |
}
|