;; Define systems here (setv GRAVITY 5) (defclass GoalHit [Exception]) (defn apply-gravity [entity entities] (when (not entity.fixed) (.move entity #(0 GRAVITY)))) (defn apply-collisions [entity entities] (when (not entity.fixed) (for [ent (gfor enti entities :if (!= enti.id entity.id) enti)] (when (.colliderect entity.rect ent.rect) (if (= ent.type "goal") (raise (GoalHit)) (let [collision-rect (.clip entity.rect ent.rect) move-x (get entity.total-move 0) move-y (get entity.total-move 1)] (when (!= move-x 0) (.move entity #((* (if (> move-x 0) -1 1) collision-rect.width) 0))) (when (!= move-y 0) (.move entity #(0 (* (if (> move-y 0) -1 1) collision-rect.height)))))) (.ground entity)))))