|
|
|
@ -20,12 +20,17 @@ export class Ship { |
|
|
|
|
shipGeo, |
|
|
|
|
new THREE.MeshStandardMaterial(this.direction > 0 ? 0xff0000 : 0x0000ff, { flatShading: true }) |
|
|
|
|
); |
|
|
|
|
this.y = (Math.random() - 0.5) * 2; |
|
|
|
|
this.x = (Math.random() - 0.5) * 2; |
|
|
|
|
|
|
|
|
|
this.burstGeo = new THREE.SphereGeometry(0.1, 32, 32); |
|
|
|
|
|
|
|
|
|
this.y = (Math.random() - 0.5) * 4; |
|
|
|
|
this.x = (Math.random() - 0.5) * 4; |
|
|
|
|
|
|
|
|
|
this.mesh.material.color.set( |
|
|
|
|
new THREE.Color(`hsl(${direction > 0 ? 0 : 180},30%,40%)`) |
|
|
|
|
); |
|
|
|
|
this.mesh.material.opacity = 1; |
|
|
|
|
|
|
|
|
|
this.mesh.position.y = this.y; |
|
|
|
|
this.mesh.position.x = this.x; |
|
|
|
|
this.mesh.position.z = (-475/4 - 6) * this.direction; //+ Math.random()
|
|
|
|
@ -52,11 +57,15 @@ export class Ship { |
|
|
|
|
this.life -= deltaTime; |
|
|
|
|
|
|
|
|
|
if (!this.flyIn) { |
|
|
|
|
this.mesh.material.color.set( |
|
|
|
|
new THREE.Color(`hsl(${this.direction > 0 ? 0 : 180},30%,20%)`) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
const xs = Math.sin(this.life * 0.5 + this.x); |
|
|
|
|
const yrot = Math.sin(this.life + this.x + (3.14/2 * this.direction)); |
|
|
|
|
this.mesh.position.y = this.y + Math.sin(this.life + this.y) * 0.2; |
|
|
|
|
this.mesh.position.y = this.y + Math.sin(this.life + this.y) * 0.1; |
|
|
|
|
this.mesh.position.x = this.x + xs * 0.15; |
|
|
|
|
this.mesh.rotation.x = yrot * 0.15; |
|
|
|
|
this.mesh.rotation.x = yrot * 0.05; |
|
|
|
|
this.mesh.position.z += 0.01 * this.direction; |
|
|
|
|
this.nextShot -= deltaTime; |
|
|
|
|
if (this.nextShot <= 0) { |
|
|
|
@ -65,17 +74,17 @@ export class Ship { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (this.life < 0) { |
|
|
|
|
const a = Math.abs(this.life); |
|
|
|
|
this.mesh.position.z += a * 2 * this.direction; |
|
|
|
|
this.mesh.scale.z = a * 4; |
|
|
|
|
this.firing = false; |
|
|
|
|
if (this.life < 0 && !this.flyin) { |
|
|
|
|
this.mesh.geometry = this.burstGeo; |
|
|
|
|
this.mesh.scale.x *= 1.1; |
|
|
|
|
this.mesh.scale.y *= 1.1; |
|
|
|
|
this.mesh.scale.z *= 1.1; |
|
|
|
|
|
|
|
|
|
this.mesh.rotation.y = 0; |
|
|
|
|
this.mesh.rotation.x = 0; |
|
|
|
|
this.mesh.material.transparent = true; |
|
|
|
|
this.mesh.material.opacity *= 0.95; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (Math.abs(this.mesh.position.z > 475/2)) { |
|
|
|
|
if (this.mesh.scale.x > 10) { |
|
|
|
|
this.kill = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|