From 29b0c98b9b5371e09d7066875ee124eab9ec62b7 Mon Sep 17 00:00:00 2001 From: c0repwn3r Date: Fri, 30 Jun 2023 14:02:58 -0400 Subject: [PATCH] particle system++ --- client/src/index.ts | 190 +++++++---------------------------------- client/src/particle.ts | 8 +- 2 files changed, 40 insertions(+), 158 deletions(-) diff --git a/client/src/index.ts b/client/src/index.ts index 86cfc62441092c71975da8c19b7946aa64428315..caee2cedeea01d744aba1fd5ddd35d5ceb25e6c6 100644 --- a/client/src/index.ts +++ b/client/src/index.ts @@ -517,11 +517,35 @@ async function client_main(server: string, username: string, texture_quality: st const thruster_end_a = 0; const thruster_start_size = 4; const thruster_end_size = 50; - + const thruster_final_rotation = 90; + + function createThrusterParticle(x: number, y: number, vel_x: number, vel_y: number) { + createParticle({ + x: global.me!.x + calculateRotated(x, y, global.me!.rotation)[0], + y: global.me!.y + calculateRotated(x, y, global.me!.rotation)[1], + lifetime: 500, + timer: 0, + startSize: thruster_start_size, + finalSize: thruster_end_size, + startRotation: 0, + finalRotation: thruster_final_rotation, + startOpacity: thruster_start_a, + endOpacity: thruster_end_a, + startR: thruster_r, + startG: thruster_g, + startB: thruster_b, + endR: thruster_r, + endG: thruster_g, + endB: thruster_b, + velocity_x: calculateRotated(vel_x, vel_y, global.me!.rotation)[0], + velocity_y: calculateRotated(vel_x, vel_y, global.me!.rotation)[1] + }); + } if (global.me !== null) { console.log(thruster_counter); thruster_counter += 1; + //thruster_counter = 1; // uncomment this line to disable particle limits if (thruster_counter > 5) { console.log("resetting counter"); thruster_counter = 0; @@ -530,177 +554,29 @@ async function client_main(server: string, username: string, texture_quality: st if (global.keys.up) { // two backward thrusters // this one is blue - createParticle({ - x: global.me.x + calculateRotated(-25, 25, global.me.rotation)[0], - y: global.me.y + calculateRotated(-25, 25, global.me.rotation)[1], - lifetime: 500, - timer: 0, - startSize: thruster_start_size, - finalSize: thruster_end_size, - startRotation: 0, - finalRotation: 180, - startOpacity: thruster_start_a, - endOpacity: thruster_end_a, - startR: thruster_r, - startG: thruster_g, - startB: thruster_b, - endR: thruster_r, - endG: thruster_g, - endB: thruster_b - }); - - // two backward thrusters - // this one is pink - createParticle({ - x: global.me.x + calculateRotated(25, -25, global.me.rotation + Math.PI/2)[0], - y: global.me.y + calculateRotated(25, -25, global.me.rotation + Math.PI/2)[1], - lifetime: 500, - timer: 0, - startSize: thruster_start_size, - finalSize: thruster_end_size, - startRotation: 0, - finalRotation: 180, - startOpacity: thruster_start_a, - endOpacity: thruster_end_a, - startR: thruster_r, - startG: thruster_g, - startB: thruster_b, - endR: thruster_r, - endG: thruster_g, - endB: thruster_b - }); + createThrusterParticle(-25, 25, 0, 0.5); + createThrusterParticle(25, 25, 0, 0.5); } if (global.keys.down) { // two backward thrusters // this one is blue - createParticle({ - x: global.me.x + calculateRotated(25, -25, global.me.rotation)[0], - y: global.me.y + calculateRotated(25, -25, global.me.rotation)[1], - lifetime: 500, - timer: 0, - startSize: thruster_start_size, - finalSize: thruster_end_size, - startRotation: 0, - finalRotation: 180, - startOpacity: thruster_start_a, - endOpacity: thruster_end_a, - startR: thruster_r, - startG: thruster_g, - startB: thruster_b, - endR: thruster_r, - endG: thruster_g, - endB: thruster_b - }); - - // two backward thrusters - // this one is pink - createParticle({ - x: global.me.x + calculateRotated(-25, 25, global.me.rotation + Math.PI/2)[0], - y: global.me.y + calculateRotated(-25, 25, global.me.rotation + Math.PI/2)[1], - lifetime: 500, - timer: 0, - startSize: thruster_start_size, - finalSize: thruster_end_size, - startRotation: 0, - finalRotation: 180, - startOpacity: thruster_start_a, - endOpacity: thruster_end_a, - startR: thruster_r, - startG: thruster_g, - startB: thruster_b, - endR: thruster_r, - endG: thruster_g, - endB: thruster_b - }); + createThrusterParticle(25, -25, 0, -0.5); + createThrusterParticle(-25, -25, 0, -0.5); } if (global.keys.left) { // two backward thrusters // this one is blue - createParticle({ - x: global.me.x + calculateRotated(25, 25, global.me.rotation)[0], - y: global.me.y + calculateRotated(25, 25, global.me.rotation)[1], - lifetime: 500, - timer: 0, - startSize: thruster_start_size, - finalSize: thruster_end_size, - startRotation: 0, - finalRotation: 180, - startOpacity: thruster_start_a, - endOpacity: thruster_end_a, - startR: thruster_r, - startG: thruster_g, - startB: thruster_b, - endR: thruster_r, - endG: thruster_g, - endB: thruster_b - }); - - // two backward thrusters - // this one is pink - createParticle({ - x: global.me.x + calculateRotated(-25, 25, global.me.rotation + Math.PI/2)[0], - y: global.me.y + calculateRotated(-25, 25, global.me.rotation + Math.PI/2)[1], - lifetime: 500, - timer: 0, - startSize: thruster_start_size, - finalSize: thruster_end_size, - startRotation: 0, - finalRotation: 180, - startOpacity: thruster_start_a, - endOpacity: thruster_end_a, - startR: thruster_r, - startG: thruster_g, - startB: thruster_b, - endR: thruster_r, - endG: thruster_g, - endB: thruster_b - }); + createThrusterParticle(25, 25, 0, 0.5); + createThrusterParticle(-25, -25, 0, -0.5); } if (global.keys.right) { // two backward thrusters // this one is blue - createParticle({ - x: global.me.x + calculateRotated(-25, 25, global.me.rotation)[0], - y: global.me.y + calculateRotated(-25, 25, global.me.rotation)[1], - lifetime: 500, - timer: 0, - startSize: thruster_start_size, - finalSize: thruster_end_size, - startRotation: 0, - finalRotation: 180, - startOpacity: thruster_start_a, - endOpacity: thruster_end_a, - startR: thruster_r, - startG: thruster_g, - startB: thruster_b, - endR: thruster_r, - endG: thruster_g, - endB: thruster_b - }); - - // two backward thrusters - // this one is pink - createParticle({ - x: global.me.x + calculateRotated(-25, -25, global.me.rotation + Math.PI/2)[0], - y: global.me.y + calculateRotated(-25, -25, global.me.rotation + Math.PI/2)[1], - lifetime: 500, - timer: 0, - startSize: thruster_start_size, - finalSize: thruster_end_size, - startRotation: 0, - finalRotation: 180, - startOpacity: thruster_start_a, - endOpacity: thruster_end_a, - startR: thruster_r, - startG: thruster_g, - startB: thruster_b, - endR: thruster_r, - endG: thruster_g, - endB: thruster_b - }); + createThrusterParticle(-25, 25, 0,0.5); + createThrusterParticle(25, -25, 0, -0.5); } } diff --git a/client/src/particle.ts b/client/src/particle.ts index ee35c5fb0c469485a930589def4abc48024a68eb..63cb6b8063156b3bd20e361f6d9dd9c832471451 100644 --- a/client/src/particle.ts +++ b/client/src/particle.ts @@ -16,7 +16,9 @@ export interface Particle { startG: number, endG: number, startB: number, - endB: number + endB: number, + velocity_x: number, + velocity_y: number } let particles: Particle[] = []; @@ -61,6 +63,10 @@ export function tickParticles(delta: number) { let keptParticles = [] for (let i = 0; i < particles.length; i++) { particles[i].timer += delta; + + particles[i].x += particles[i].velocity_x * delta; + particles[i].y += particles[i].velocity_y * delta; + if (!(particles[i].timer > particles[i].lifetime)) { keptParticles.push(particles[i]); } else {