Skip to content

Commit

Permalink
feat: particles are now circles
Browse files Browse the repository at this point in the history
  • Loading branch information
load1n9 committed Dec 19, 2021
1 parent abf7631 commit e575501
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
3 changes: 2 additions & 1 deletion examples/particle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
7 changes: 1 addition & 6 deletions src/Renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/entities/particle/Particle.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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;

}

Expand Down
3 changes: 3 additions & 0 deletions src/entities/particle/ParticleSystem.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -8,6 +10,7 @@ interface Settings {
startingY: number;
gravity: number;
maxLife: number;
fill: RGBA | string;
}
export class ParticleSystem extends Entity {
public particles: Array<Particle> = [];
Expand Down

0 comments on commit e575501

Please sign in to comment.