diff options
Diffstat (limited to 'physics.scm')
| -rw-r--r-- | physics.scm | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/physics.scm b/physics.scm index 06cb12c..627dbea 100644 --- a/physics.scm +++ b/physics.scm @@ -90,6 +90,8 @@ ;; Resolve collisions with tiles along a single axis. ;; push-fn: (v col row) -> new-pos + ;; For v>0 (moving right/down): snap to the FIRST solid cell (shallowest penetration). + ;; For v<0 (moving left/up): snap to the LAST solid cell (deepest penetration from above/left). (define (resolve-tile-collisions-axis entity tilemap vel-key pos-key push-fn) (let ((v (entity-ref entity vel-key 0))) (if (zero? v) @@ -101,7 +103,9 @@ (tile-id (tilemap-tile-at tilemap col row))) (if (zero? tile-id) acc - (entity-set (entity-set acc pos-key (push-fn v col row)) vel-key 0)))) + (if (and (> v 0) (zero? (entity-ref acc vel-key v))) + acc ; v>0: first collision already resolved, don't overwrite + (entity-set (entity-set acc pos-key (push-fn v col row)) vel-key 0))))) entity (entity-tile-cells entity tilemap))))) |
