aboutsummaryrefslogtreecommitdiff
path: root/src/macroknight/systems.hy
blob: 27622477b8aeb7c94a99fcbc4add6276fd5b7bbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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))))