commit
35d2dd22f1
|
@ -9,25 +9,32 @@ const geometry = new THREE.BoxGeometry(
|
||||||
LASER_SIZE
|
LASER_SIZE
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const badLaserMat = new THREE.MeshStandardMaterial(0xffffff, {
|
||||||
|
flatShading: true,
|
||||||
|
color: new THREE.Color(`hsl(0,100%,70%)`),
|
||||||
|
});
|
||||||
|
|
||||||
|
const goodLaserMat = new THREE.MeshStandardMaterial(0xffffff, {
|
||||||
|
flatShading: true,
|
||||||
|
color: new THREE.Color(`hsl(180,100%,70%)`),
|
||||||
|
});
|
||||||
|
|
||||||
export class Laser {
|
export class Laser {
|
||||||
constructor(ship) {
|
constructor(ship, count) {
|
||||||
const position = new THREE.Vector3();
|
const position = new THREE.Vector3();
|
||||||
this.direction = ship.direction;
|
this.direction = ship.direction;
|
||||||
this.kill = false;
|
this.kill = false;
|
||||||
|
this.life = 10;
|
||||||
|
|
||||||
this.stepX = (Math.random() - 0.5) * BULLET_SPREAD;
|
this.stepX = (Math.random() - 0.5) * BULLET_SPREAD;
|
||||||
this.stepY = (Math.random() - 0.5) * BULLET_SPREAD;
|
this.stepY = (Math.random() - 0.5) * BULLET_SPREAD;
|
||||||
|
|
||||||
ship.mesh.getWorldPosition(position);
|
ship.mesh.getWorldPosition(position);
|
||||||
|
|
||||||
const material = new THREE.MeshStandardMaterial(0xffffff, {
|
this.mesh = new THREE.Mesh(
|
||||||
flatShading: true,
|
geometry,
|
||||||
});
|
ship.direction > 0 ? goodLaserMat : badLaserMat,
|
||||||
|
count
|
||||||
this.mesh = new THREE.Mesh(geometry, material);
|
|
||||||
|
|
||||||
this.mesh.material.color.set(
|
|
||||||
new THREE.Color(`hsl(${ship.direction > 0 ? 0 : 180},100%,70%)`)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
this.mesh.position.set(position.x, position.y, position.z);
|
this.mesh.position.set(position.x, position.y, position.z);
|
||||||
|
@ -37,9 +44,8 @@ export class Laser {
|
||||||
this.mesh.position.x += this.stepX;
|
this.mesh.position.x += this.stepX;
|
||||||
this.mesh.position.y += this.stepY;
|
this.mesh.position.y += this.stepY;
|
||||||
this.mesh.position.z += 0.5 * this.direction;
|
this.mesh.position.z += 0.5 * this.direction;
|
||||||
|
this.life -= deltaTime;
|
||||||
|
|
||||||
if (Math.abs(this.mesh.position.z > 475 / 2)) {
|
if (this.life < 0) this.kill = true;
|
||||||
this.kill = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,7 @@ export const scene = ({ ref }) => {
|
||||||
|
|
||||||
if (ship.firing) {
|
if (ship.firing) {
|
||||||
const bolt = new Laser(ship);
|
const bolt = new Laser(ship);
|
||||||
|
|
||||||
bolts.push(bolt);
|
bolts.push(bolt);
|
||||||
scene.add(bolt.mesh);
|
scene.add(bolt.mesh);
|
||||||
ship.firing = false;
|
ship.firing = false;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user