commit
5abb91d838
|
@ -3,6 +3,12 @@ import * as THREE from 'three';
|
||||||
const LASER_SIZE = 0.5;
|
const LASER_SIZE = 0.5;
|
||||||
const BULLET_SPREAD = 0.1;
|
const BULLET_SPREAD = 0.1;
|
||||||
|
|
||||||
|
const geometry = new THREE.BoxGeometry(
|
||||||
|
LASER_SIZE * 0.03,
|
||||||
|
LASER_SIZE * 0.03,
|
||||||
|
LASER_SIZE
|
||||||
|
);
|
||||||
|
|
||||||
export class Laser {
|
export class Laser {
|
||||||
constructor(ship) {
|
constructor(ship) {
|
||||||
const position = new THREE.Vector3();
|
const position = new THREE.Vector3();
|
||||||
|
@ -12,17 +18,13 @@ export class Laser {
|
||||||
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 shipGeo = new THREE.BoxGeometry(
|
const material = new THREE.MeshStandardMaterial(0xffffff, {
|
||||||
LASER_SIZE * 0.03,
|
flatShading: true,
|
||||||
LASER_SIZE * 0.03,
|
});
|
||||||
LASER_SIZE
|
|
||||||
);
|
this.mesh = new THREE.Mesh(geometry, material);
|
||||||
this.mesh = new THREE.Mesh(
|
|
||||||
shipGeo,
|
|
||||||
new THREE.MeshStandardMaterial(this.direction > 0 ? 0xff0000 : 0x0000ff, { flatShading: true })
|
|
||||||
);
|
|
||||||
|
|
||||||
this.mesh.material.color.set(
|
this.mesh.material.color.set(
|
||||||
new THREE.Color(`hsl(${ship.direction > 0 ? 0 : 180},100%,70%)`)
|
new THREE.Color(`hsl(${ship.direction > 0 ? 0 : 180},100%,70%)`)
|
||||||
|
|
|
@ -2,6 +2,14 @@ import * as THREE from 'three';
|
||||||
|
|
||||||
const SHIP_SIZE = 1;
|
const SHIP_SIZE = 1;
|
||||||
|
|
||||||
|
const geometry = new THREE.BoxGeometry(
|
||||||
|
SHIP_SIZE * 0.1,
|
||||||
|
SHIP_SIZE * 0.1,
|
||||||
|
SHIP_SIZE
|
||||||
|
);
|
||||||
|
|
||||||
|
const burstGeo = new THREE.SphereGeometry(0.1, 32, 32);
|
||||||
|
|
||||||
export class Ship {
|
export class Ship {
|
||||||
constructor(direction) {
|
constructor(direction) {
|
||||||
this.direction = direction;
|
this.direction = direction;
|
||||||
|
@ -10,18 +18,13 @@ export class Ship {
|
||||||
this.shotInterval = 3;
|
this.shotInterval = 3;
|
||||||
this.flyIn = true;
|
this.flyIn = true;
|
||||||
this.firing = false;
|
this.firing = false;
|
||||||
|
this.exploded = false;
|
||||||
|
|
||||||
const shipGeo = new THREE.BoxGeometry(
|
const material = new THREE.MeshStandardMaterial(0xffffff, {
|
||||||
SHIP_SIZE * 0.1,
|
flatShading: true,
|
||||||
SHIP_SIZE * 0.1,
|
});
|
||||||
SHIP_SIZE
|
|
||||||
);
|
|
||||||
this.mesh = new THREE.Mesh(
|
|
||||||
shipGeo,
|
|
||||||
new THREE.MeshStandardMaterial(this.direction > 0 ? 0xff0000 : 0x0000ff, { flatShading: true })
|
|
||||||
);
|
|
||||||
|
|
||||||
this.burstGeo = new THREE.SphereGeometry(0.1, 32, 32);
|
this.mesh = new THREE.Mesh(geometry, material);
|
||||||
|
|
||||||
this.y = (Math.random() - 0.5) * 4;
|
this.y = (Math.random() - 0.5) * 4;
|
||||||
this.x = (Math.random() - 0.5) * 4;
|
this.x = (Math.random() - 0.5) * 4;
|
||||||
|
@ -41,14 +44,9 @@ export class Ship {
|
||||||
this.mesh.scale.z = 10;
|
this.mesh.scale.z = 10;
|
||||||
this.mesh.position.z += 4.75 * this.direction;
|
this.mesh.position.z += 4.75 * this.direction;
|
||||||
|
|
||||||
// ship accelerating decreasing
|
|
||||||
// check if in space
|
|
||||||
if (Math.abs(this.mesh.position.z) <= 6 && this.flyIn) {
|
if (Math.abs(this.mesh.position.z) <= 6 && this.flyIn) {
|
||||||
this.flyIn = false;
|
this.flyIn = false;
|
||||||
this.mesh.scale.z = 0.5;
|
this.mesh.scale.z = 0.5;
|
||||||
//this.mesh.material.color.set(
|
|
||||||
// new THREE.Color(`hsl(${this.hue},0%,30%)`)
|
|
||||||
//);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.mesh.scale.z = 0.5;
|
this.mesh.scale.z = 0.5;
|
||||||
|
@ -62,7 +60,9 @@ export class Ship {
|
||||||
);
|
);
|
||||||
|
|
||||||
const xs = Math.sin(this.life * 0.5 + this.x);
|
const xs = Math.sin(this.life * 0.5 + this.x);
|
||||||
const yrot = Math.sin(this.life + this.x + (3.14/2 * this.direction));
|
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.1;
|
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.position.x = this.x + xs * 0.15;
|
||||||
this.mesh.rotation.x = yrot * 0.05;
|
this.mesh.rotation.x = yrot * 0.05;
|
||||||
|
@ -74,14 +74,20 @@ export class Ship {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.life < 0 && !this.flyin) {
|
if (this.life < 0 && !this.flyin && !this.exploded) {
|
||||||
this.mesh.geometry = this.burstGeo;
|
this.mesh.geometry = burstGeo;
|
||||||
|
this.mesh.material.transparent = true;
|
||||||
|
this.mesh.material.opacity *= 0.95;
|
||||||
|
this.exploded = true;
|
||||||
|
this.mesh.scale.x = 1;
|
||||||
|
this.mesh.scale.y = 1;
|
||||||
|
this.mesh.scale.z = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.exploded) {
|
||||||
this.mesh.scale.x *= 1.1;
|
this.mesh.scale.x *= 1.1;
|
||||||
this.mesh.scale.y *= 1.1;
|
this.mesh.scale.y *= 1.1;
|
||||||
this.mesh.scale.z *= 1.1;
|
this.mesh.scale.z *= 1.1;
|
||||||
|
|
||||||
this.mesh.material.transparent = true;
|
|
||||||
this.mesh.material.opacity *= 0.95;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.mesh.scale.x > 10) {
|
if (this.mesh.scale.x > 10) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user