aboutsummaryrefslogtreecommitdiff
path: root/physics.scm
diff options
context:
space:
mode:
authorGene Pasquet <dev@etenil.net>2026-04-08 01:57:20 +0100
committerGene Pasquet <dev@etenil.net>2026-04-08 01:57:20 +0100
commit9e8b75f9949259ef01942cd3717b79b044efddf7 (patch)
treec6b71291ade57f0560a9bbf0db9f5b66bab65cb3 /physics.scm
parent84840ede6646ed793b61cdd889d3f57ab05e9311 (diff)
Refactor update pipelines
Diffstat (limited to 'physics.scm')
-rw-r--r--physics.scm37
1 files changed, 15 insertions, 22 deletions
diff --git a/physics.scm b/physics.scm
index 24ded09..773d922 100644
--- a/physics.scm
+++ b/physics.scm
@@ -1,5 +1,5 @@
(module downstroke-physics
- (scene-resolve-collisions resolve-entity-collisions resolve-pair
+ (resolve-entity-collisions resolve-pair
aabb-overlap? push-apart push-along-axis aabb-overlap-on-axis
entity-center-on-axis push-entity axis->velocity axis->dimension
index-pairs list-set apply-jump detect-on-solid
@@ -33,17 +33,15 @@
;; Consume #:ay into #:vy and clear it (one-shot acceleration)
(define-pipeline (apply-acceleration acceleration) (entity)
- (if (not (entity-ref entity #:gravity? #f))
- entity
- (let ((ay (entity-ref entity #:ay 0))
- (vy (entity-ref entity #:vy 0)))
- (entity-set (entity-set entity #:vy (+ vy ay)) #:ay 0))))
+ guard: (entity-ref entity #:gravity? #f)
+ (let ((ay (entity-ref entity #:ay 0))
+ (vy (entity-ref entity #:vy 0)))
+ (entity-set (entity-set entity #:vy (+ vy ay)) #:ay 0)))
;; Apply gravity to an entity if it has gravity enabled
(define-pipeline (apply-gravity gravity) (entity)
- (if (entity-ref entity #:gravity? #f)
- (entity-set entity #:vy (+ (entity-ref entity #:vy) *gravity*))
- entity))
+ guard: (entity-ref entity #:gravity? #f)
+ (entity-set entity #:vy (+ (entity-ref entity #:vy) *gravity*)))
;; Update entity's x by its vx velocity
(define-pipeline (apply-velocity-x velocity-x) (entity)
@@ -179,18 +177,16 @@
(define-pipeline (detect-on-solid on-solid)
(entity tilemap #!optional (other-entities #f))
- (if (not (entity-ref entity #:gravity? #f))
- entity
- (let* ((on-tile? (and tilemap (tile-ground-below? entity tilemap)))
- (on-entity? (and other-entities
- (entity-solid-support-below? entity other-entities))))
- (entity-set entity #:on-ground? (or on-tile? on-entity?)))))
+ guard: (entity-ref entity #:gravity? #f)
+ (let* ((on-tile? (and tilemap (tile-ground-below? entity tilemap)))
+ (on-entity? (and other-entities
+ (entity-solid-support-below? entity other-entities))))
+ (entity-set entity #:on-ground? (or on-tile? on-entity?))))
;; Set vertical acceleration for jump (consumed next frame by apply-acceleration)
(define-pipeline (apply-jump jump) (entity jump-pressed?)
- (if (and jump-pressed? (entity-ref entity #:on-ground? #f))
- (entity-set entity #:ay (- (entity-ref entity #:jump-force *jump-force*)))
- entity))
+ guard: (and jump-pressed? (entity-ref entity #:on-ground? #f))
+ (entity-set entity #:ay (- (entity-ref entity #:jump-force *jump-force*))))
;; Replace element at idx in lst with val
(define (list-set lst idx val)
@@ -318,7 +314,4 @@
entities
(index-pairs (length entities))))
- ;; Returns a new scene with entity-entity collisions resolved.
- (define (scene-resolve-collisions scene)
- (update-scene scene
- entities: (resolve-entity-collisions (scene-entities scene)))))
+)