particles.jamo (built in)

particles: sparks, explosions, smoke and trails in a line or two. use "particles.jamo"

Keep one Particles for a game, add bursts and sprays to it when things happen, and each frame call update with the frame's time and draw with the screen. Each particle moves, falls with gravity, slows with drag, and fades and shrinks as it gets old.

var sparks = new_particles()
sparks.gravity = 600.0
...when a coin is caught:
sparks.burst(x, y, 20, rgb(255, 210, 60), 200.0, 0.6)
...each frame:
sparks.update(window.frame_time())
sparks.draw(screen)

structParticle

struct Particle
    x: float
    y: float
    vx: float
    vy: float
    age: float
    life: float
    size: float
    color: Color
end

structParticles

struct Particles
    items: [Particle]
    gravity: float        # how fast they fall, in pixels a second each second. Below 0 floats them up, like smoke
    drag: float           # how much speed they lose each second, from 0.0 (none) to 1.0 (stop at once)
    size: float           # how big a new particle is, in pixels
    most: int             # the oldest ones go when there are more than this
end

funcnew_particles

func new_particles(): Particles

funcParticles.add

func Particles.add(x: float, y: float, vx: float, vy: float, color: Color, life: float)

One particle at x, y moving at vx, vy pixels a second, lasting life seconds

funcParticles.burst

func Particles.burst(x: float, y: float, count: int, color: Color, speed: float, life: float)

count particles flying out every way from x, y, at up to speed pixels a second, for about life seconds

funcParticles.spray

func Particles.spray(x: float, y: float, angle: float, spread: float, count: int, color: Color, speed: float, life: float)

count particles going toward angle (in radians: 0 is right, pi() / 2.0 is down), spread that many radians either side

funcParticles.update

func Particles.update(seconds: float)

Moves every particle on by seconds and drops the ones that are too old

funcParticles.draw

func Particles.draw(screen: Gfx)

Draws them, each fading and shrinking as it gets old

funcParticles.count

func Particles.count(): int

How many are flying now

funcParticles.clear

func Particles.clear()