Hint #3 -- Powerful queries and collision detection...
So, if you've looked at my presentation or read through some of the examples, you know that the "grab/s" functions can query the Store for entities with a particular tag or key value setting. However, you can also feed grab and friends a query function, which can be arbitrarily powerful...
Here is a system that implements 2D collision detection. Yes, there's an example of this in %invade.rkt, but this one is better.
(define (sys-hit) "( --) Collision detection." (let* ([hero (q1 'hero)] [items (grabs (λ (e) (and e.hit (< hero.x (+ e.x e.w)) (> (+ hero.x hero.w) e.x) (< hero.y (+ e.y e.h)) (> (+ hero.y hero.h) e.y))))] ) (when (not (empty? items)) (for ([item in-array items]) (item.hit item hero))) ))It gets the "hero" entity and runs a function query to check it's position against everything that has a collision handler ("hit"). When it finds them, it runs the handler with the item and the hero as arguments (this is a Canned Heat convention).
Notice that I check to see if the entity has a collision handler before I attempt the geometry testing -- this make things faster because it only does the expensive comparisons on things that warrant it.