diff options
author | Gene Pasquet <gene@pacerevenue.com> | 2025-05-15 13:46:26 +0200 |
---|---|---|
committer | Gene Pasquet <gene@pacerevenue.com> | 2025-05-15 13:46:26 +0200 |
commit | cee75e57560b77e8ec0a394c1d3c98b9839be80e (patch) | |
tree | 8bd29322dc951ad827435e0c4ab162ed13ff911e /src/macroknight/systems.hy | |
parent | b8580d616831213934eb424d9284621aadc4c544 (diff) |
Refactor!!
Diffstat (limited to 'src/macroknight/systems.hy')
-rw-r--r-- | src/macroknight/systems.hy | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/macroknight/systems.hy b/src/macroknight/systems.hy new file mode 100644 index 0000000..2762247 --- /dev/null +++ b/src/macroknight/systems.hy @@ -0,0 +1,20 @@ +;; Define systems here +(setv GRAVITY 5) + +(defn apply-gravity [entity entities] + (when (not entity.fixed) + (.move entity #(0 GRAVITY)))) + +(defn apply-collisions [entity entities] + (for [ent entities] + (when (and (!= ent.id entity.id) + (.colliderect entity.rect ent.rect) + (not entity.fixed)) + (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)))) |