Hint #6 -- Cheap(ish) particle systems...
Everybody loves particles, right? They really liven things up.
Canned Heat has the basics for particle handling built right in -- it uses (sys-tick), which compares the entities "age" (incremented every tick) with its "span" (if it has one). If age has exceeded the span, the entity is marked for destruction, which means, next redraw, it will be gone for good.
A super simple case for particles is to make a trail, like the one Tinkerbell (or Nyancat, if you like) sports. To do this, create a particle object every time the entity is moved. Here, I have a simple System that will emit a particle whenever any entity that has a "trail" component is set to true:
(define (sys-trail) "( --) Track trajectory of objects with trail component." (for ([e in-array (qq 'trail #t)]) (let ([x (+ e.x (/ e.w 2))] [y (+ e.y (/ e.h 2))]) (when (and (< 0 x) (< x SV.screen.width) (< 0 y) (< y SV.screen.height)) (store (object [tag 'trail] [scene #t] [x x] [y y] [age 0] [span 90]))))) )Don't be put off by that goofy math in the middle -- I'm just centreing the particle in the footprint of the trailing entity. The last bit checks to make sure the location is within the displayable area of the screen before creating it. I've had thousands of entities created with Canned Heat, but i don't want to let them get away from me... The parameters of the particle entity will snuff it out after ninety frames.
Oh, right... How would you display the particles? Try this in your render section:
(for ([e in-array (qq 'scene #t)]) (cond ...I just draw a red square for every trail particle. Easy as that.
[(= e.tag 'trail) (:= cx 'fillStyle 'red) (cx.fillRect e.x e.y 4 4)] ))
You can supply deltas and use (sys-move) to animate the particles so they don't just hang around. With some trivial extensions, there are tons of possibilities -- add a colour ramp that interpolates as the entity ages and a rising dy with some jitter? You've got fire! Collisions can be pretty fast, since you just test for the point (x, y) instead of having to take the particle size into account.
Canned Heat was partially inspired by the data structures used to manage particle systems, so it's no surprise that it handles them well!