This commit is contained in:
Elijah Lucian 2021-04-03 17:57:54 -06:00
parent 7a95d734de
commit 6867eb5d8b
2 changed files with 37 additions and 32 deletions

View File

@ -9,8 +9,6 @@ const geometry = new THREE.BoxGeometry(
LASER_SIZE LASER_SIZE
); );
const material = new THREE.MeshStandardMaterial(this.direction > 0 ? 0xff0000 : 0x0000ff, { flatShading: true })
export class Laser { export class Laser {
constructor(ship) { constructor(ship) {
const position = new THREE.Vector3(); const position = new THREE.Vector3();
@ -20,12 +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);
this.mesh = new THREE.Mesh( const material = new THREE.MeshStandardMaterial(0xffffff, {
geometery, flatShading: true,
material });
);
this.mesh = new THREE.Mesh(geometry, material);
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%)`)

View File

@ -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) {