aboutsummaryrefslogtreecommitdiff
path: root/src/macroknight/systems.hy
diff options
context:
space:
mode:
authorGene Pasquet <dev@etenil.net>2025-05-16 21:32:23 +0100
committerGene Pasquet <dev@etenil.net>2025-05-16 21:32:23 +0100
commit5af7de084933444951dfb140c084ea07cf3346a8 (patch)
tree3c1c68672f0ef632e56652694ef269257e536f9e /src/macroknight/systems.hy
parentc44bcbe373f70a5a82da1117cc5239e323f104f3 (diff)
Working macro cooldown and level goal
Diffstat (limited to 'src/macroknight/systems.hy')
-rw-r--r--src/macroknight/systems.hy22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/macroknight/systems.hy b/src/macroknight/systems.hy
index b02bc50..fccccd0 100644
--- a/src/macroknight/systems.hy
+++ b/src/macroknight/systems.hy
@@ -1,19 +1,25 @@
;; 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)]
+ (for [ent (gfor enti entities
+ :if (!= enti.id entity.id)
+ enti)]
(when (.colliderect entity.rect ent.rect)
- (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)))))
+ (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)))))