From fdaea315a1bf6657da44fc6176313299f7575b4f Mon Sep 17 00:00:00 2001 From: Elijah Lucian Date: Sun, 2 May 2021 21:20:00 -0600 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=9B=F0=9F=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webclient/src/spaceport/Laser.js | 32 ++++++++++++++++++-------------- webclient/src/spaceport/scene.js | 10 ++++++++-- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/webclient/src/spaceport/Laser.js b/webclient/src/spaceport/Laser.js index 7f82a80..c7c7382 100644 --- a/webclient/src/spaceport/Laser.js +++ b/webclient/src/spaceport/Laser.js @@ -4,31 +4,36 @@ const LASER_SIZE = 0.5; const BULLET_SPREAD = 0.1; const geometry = new THREE.BoxGeometry( - LASER_SIZE * 0.03, - LASER_SIZE * 0.03, + LASER_SIZE * 0.3, + LASER_SIZE * 0.3, 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 { - constructor(ship) { + constructor(ship, count) { const position = new THREE.Vector3(); this.direction = ship.direction; this.kill = false; + this.life = 20; this.stepX = (Math.random() - 0.5) * BULLET_SPREAD; this.stepY = (Math.random() - 0.5) * BULLET_SPREAD; ship.mesh.getWorldPosition(position); - const material = new THREE.MeshStandardMaterial(0xffffff, { - flatShading: true, - }); + this.mesh = new THREE.InstancedMesh(geometry, 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.instanceMatrix.setUsage(THREE.DynamicDrawUsage); this.mesh.position.set(position.x, position.y, position.z); } @@ -37,9 +42,8 @@ export class Laser { this.mesh.position.x += this.stepX; this.mesh.position.y += this.stepY; this.mesh.position.z += 0.5 * this.direction; + this.life -= deltaTime; - if (Math.abs(this.mesh.position.z > 475 / 2)) { - this.kill = true; - } + if (this.life < 0) this.kill = true; } } diff --git a/webclient/src/spaceport/scene.js b/webclient/src/spaceport/scene.js index 9acc117..7d9164e 100644 --- a/webclient/src/spaceport/scene.js +++ b/webclient/src/spaceport/scene.js @@ -50,10 +50,12 @@ export const scene = ({ ref }) => { ref.current.addEventListener('mousemove', (e) => { const x = e.clientX; const ratio = x / ref.current.clientWidth; - camera.position.set(5, 2, ratio*4 - 2); + camera.position.set(5, 2, ratio * 4 - 2); camera.lookAt(new THREE.Vector3(0, 0, 0)); }); + let boltCount = 0; + const animate = () => { const deltaTime = 0.075; t += deltaTime; @@ -71,7 +73,10 @@ export const scene = ({ ref }) => { ship.update({ deltaTime }); if (ship.firing) { - const bolt = new Laser(ship); + const bolt = new Laser(ship, boltCount + 1); + boltCount += 1; + + console.log('pew', boltCount); bolts.push(bolt); scene.add(bolt.mesh); ship.firing = false; @@ -86,6 +91,7 @@ export const scene = ({ ref }) => { bolt.update({ deltaTime }); if (bolt.kill) { + boltCount -= 1; scene.remove(bolt.mesh); } } From 153d629bd9db3f5f0972f5181642ca53808d8747 Mon Sep 17 00:00:00 2001 From: Elijah Lucian Date: Sun, 2 May 2021 21:21:24 -0600 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=A7=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webclient/src/spaceport/Laser.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/webclient/src/spaceport/Laser.js b/webclient/src/spaceport/Laser.js index c7c7382..286869e 100644 --- a/webclient/src/spaceport/Laser.js +++ b/webclient/src/spaceport/Laser.js @@ -4,8 +4,8 @@ const LASER_SIZE = 0.5; const BULLET_SPREAD = 0.1; const geometry = new THREE.BoxGeometry( - LASER_SIZE * 0.3, - LASER_SIZE * 0.3, + LASER_SIZE * 0.03, + LASER_SIZE * 0.03, LASER_SIZE ); @@ -24,16 +24,18 @@ export class Laser { const position = new THREE.Vector3(); this.direction = ship.direction; this.kill = false; - this.life = 20; + this.life = 10; this.stepX = (Math.random() - 0.5) * BULLET_SPREAD; this.stepY = (Math.random() - 0.5) * BULLET_SPREAD; ship.mesh.getWorldPosition(position); - this.mesh = new THREE.InstancedMesh(geometry, badLaserMat, count); - - this.mesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage); + this.mesh = new THREE.Mesh( + geometry, + ship.direction > 0 ? goodLaserMat : badLaserMat, + count + ); this.mesh.position.set(position.x, position.y, position.z); } From d1f5a0088d528c8ed5e252843572661082f09660 Mon Sep 17 00:00:00 2001 From: Elijah Lucian Date: Sun, 2 May 2021 21:23:45 -0600 Subject: [PATCH 3/3] bolt --- webclient/src/spaceport/scene.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/webclient/src/spaceport/scene.js b/webclient/src/spaceport/scene.js index 7d9164e..6c63c27 100644 --- a/webclient/src/spaceport/scene.js +++ b/webclient/src/spaceport/scene.js @@ -54,8 +54,6 @@ export const scene = ({ ref }) => { camera.lookAt(new THREE.Vector3(0, 0, 0)); }); - let boltCount = 0; - const animate = () => { const deltaTime = 0.075; t += deltaTime; @@ -73,10 +71,8 @@ export const scene = ({ ref }) => { ship.update({ deltaTime }); if (ship.firing) { - const bolt = new Laser(ship, boltCount + 1); - boltCount += 1; + const bolt = new Laser(ship); - console.log('pew', boltCount); bolts.push(bolt); scene.add(bolt.mesh); ship.firing = false; @@ -91,7 +87,6 @@ export const scene = ({ ref }) => { bolt.update({ deltaTime }); if (bolt.kill) { - boltCount -= 1; scene.remove(bolt.mesh); } }