From 52691e8f0bb2b6c73e7bfee6bbeff6a3549405e0 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Mon, 22 Mar 2021 00:20:39 +0000 Subject: [PATCH] Make the ships explode --- webclient/src/light.css | 2 +- webclient/src/spaceport/Ship.js | 33 ++++++++++++++++++++------------ webclient/src/spaceport/scene.js | 17 ++++++++++------ 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/webclient/src/light.css b/webclient/src/light.css index 62b430e..de21c9b 100644 --- a/webclient/src/light.css +++ b/webclient/src/light.css @@ -127,7 +127,7 @@ body { @media (min-width: 650px) { .footer-content { transition: all 0.2s ease-in; - opacity: 0.25; + opacity: 0.5; } .footer-content:hover { diff --git a/webclient/src/spaceport/Ship.js b/webclient/src/spaceport/Ship.js index 95aaa7e..e2a5eea 100644 --- a/webclient/src/spaceport/Ship.js +++ b/webclient/src/spaceport/Ship.js @@ -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; } } diff --git a/webclient/src/spaceport/scene.js b/webclient/src/spaceport/scene.js index 0cfcffc..bc19f89 100644 --- a/webclient/src/spaceport/scene.js +++ b/webclient/src/spaceport/scene.js @@ -22,17 +22,22 @@ export const scene = ({ ref }) => { const camera = new THREE.PerspectiveCamera(65, width / height, 0.01, 1000); - camera.position.set(5, 0.5, 1); - camera.lookAt(new THREE.Vector3(-9, 0, 3)); + camera.position.set(5, 2, 1); camera.lookAt(new THREE.Vector3(0, 0, 0)); scene.add(camera); ref.current.appendChild(renderer.domElement); - const light = new THREE.DirectionalLight('#fff', 1); - light.position.x = 3; - light.position.z = 1; - scene.add(light); + const light1 = new THREE.DirectionalLight('#fff', 1); + light1.position.x = 3; + light1.position.z = 1; + scene.add(light1); + + const light2 = new THREE.PointLight('#fff', 2); + light2.position.x = 5; + light2.position.y = 5; + light2.position.z = 1; + scene.add(light2); let ships = []; let bolts = [];