~starkingdoms/starkingdoms

29b0c98b9b5371e09d7066875ee124eab9ec62b7 — c0repwn3r 2 years ago 4289761
particle system++
2 files changed, 40 insertions(+), 158 deletions(-)

M client/src/index.ts
M client/src/particle.ts
M client/src/index.ts => client/src/index.ts +33 -157
@@ 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);
                }
            }


M client/src/particle.ts => client/src/particle.ts +7 -1
@@ 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 {