From e5755016d513662e87c6d52746424f39e20cbe1c Mon Sep 17 00:00:00 2001 From: loading <49134864+load1n9@users.noreply.github.com> Date: Sat, 18 Dec 2021 23:29:03 -0500 Subject: [PATCH] feat: particles are now circles --- examples/particle.ts | 3 ++- src/Renderer.ts | 7 +------ src/entities/particle/Particle.ts | 7 ++++++- src/entities/particle/ParticleSystem.ts | 3 +++ 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/examples/particle.ts b/examples/particle.ts index d9a9018..56625e7 100644 --- a/examples/particle.ts +++ b/examples/particle.ts @@ -4,11 +4,12 @@ import { World, Scene, ParticleSystem } from '../mod.ts'; class Game extends Scene { public test = new ParticleSystem(this, { density: 80, - particleSize: 10, + particleSize: 2, startingX: 100, startingY: 30, gravity: 0.25, maxLife: 50, + fill: "#00ff00" }); public setup() { diff --git a/src/Renderer.ts b/src/Renderer.ts index f998719..5325df0 100644 --- a/src/Renderer.ts +++ b/src/Renderer.ts @@ -158,12 +158,7 @@ export class Renderer { entity.update(); for (const particle of entity.particles) { this.world.setDrawColor(255, 255, 255, 255); - this.world.fillRect( - Math.round(particle.x), - Math.round(particle.y), - particle.settings.particleSize, - particle.settings.particleSize, - ); + this.render(new Circle(Math.round(particle.x), Math.round(particle.y), particle.settings.particleSize, particle.settings.fill)) } } } diff --git a/src/entities/particle/Particle.ts b/src/entities/particle/Particle.ts index fbd5be7..d65decf 100644 --- a/src/entities/particle/Particle.ts +++ b/src/entities/particle/Particle.ts @@ -1,10 +1,14 @@ +import type { RGBA } from "../../types.ts"; +import { hexToRGBA } from '../../utils/mod.ts'; + interface Settings { density: number, particleSize: number, startingX: number, startingY: number, gravity: number, - maxLife: number + maxLife: number, + fill: RGBA | string, } export class Particle { @@ -23,6 +27,7 @@ export class Particle { this.vy = Math.random() * 20 - 5; this.life = 0; this.settings = settings; + this.settings.fill = typeof this.settings.fill === 'string' ? hexToRGBA(this.settings.fill) : this.settings.fill; } diff --git a/src/entities/particle/ParticleSystem.ts b/src/entities/particle/ParticleSystem.ts index eae4cee..b8e5a45 100644 --- a/src/entities/particle/ParticleSystem.ts +++ b/src/entities/particle/ParticleSystem.ts @@ -1,5 +1,7 @@ import { Entity, Scene } from "../../../mod.ts"; import { BasicParticle, Particle } from "./mod.ts"; +import type { RGBA } from "../../types.ts"; + interface Settings { density: number; @@ -8,6 +10,7 @@ interface Settings { startingY: number; gravity: number; maxLife: number; + fill: RGBA | string; } export class ParticleSystem extends Entity { public particles: Array = [];