diff options
| author | Gene Pasquet <dev@etenil.net> | 2026-04-08 01:05:50 +0100 |
|---|---|---|
| committer | Gene Pasquet <dev@etenil.net> | 2026-04-08 01:05:50 +0100 |
| commit | 995342fb74fdd1ba5aeaa172a428538e7dd0dcdc (patch) | |
| tree | 82a60034eaa097191d360fe07e4ef3a52dae9c2a /animation.scm | |
| parent | 0c3a700aa94a0256c5e5b1a14819f10b3d3e869b (diff) | |
Code cleanup
Diffstat (limited to 'animation.scm')
| -rw-r--r-- | animation.scm | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/animation.scm b/animation.scm index a152753..4caf1fe 100644 --- a/animation.scm +++ b/animation.scm @@ -32,24 +32,25 @@ ;; Pass the animation table for this entity's type. ;; Entities without #:anim-name are returned unchanged. + (define (advance-animation entity anim) + (let* ((tick (+ 1 (entity-ref entity #:anim-tick 0))) + (duration (animation-duration anim)) + (frames (animation-frames anim)) + (frame (entity-ref entity #:anim-frame 0))) + (if (>= tick duration) + (let ((new-frame (modulo (+ frame 1) (length frames)))) + (entity-set (entity-set (entity-set entity + #:anim-tick 0) + #:anim-frame new-frame) + #:tile-id (frame->tile-id frames new-frame))) + (entity-set (entity-set entity #:anim-tick tick) + #:tile-id (frame->tile-id frames frame))))) + (define (animate-entity entity animations) - (let ((anim-name (entity-ref entity #:anim-name #f))) - (if (not anim-name) - entity - (let* ((entry (assq anim-name animations)) - (anim (and entry (cdr entry)))) - (if (not anim) - entity - (let* ((tick (+ 1 (entity-ref entity #:anim-tick 0))) - (duration (animation-duration anim)) - (frames (animation-frames anim)) - (frame (entity-ref entity #:anim-frame 0))) - (if (>= tick duration) - (let ((new-frame (modulo (+ frame 1) (length frames)))) - (entity-set (entity-set (entity-set entity - #:anim-tick 0) - #:anim-frame new-frame) - #:tile-id (frame->tile-id frames new-frame))) - (entity-set (entity-set entity #:anim-tick tick) - #:tile-id (frame->tile-id frames frame))))))))) + (let* ((anim-name (entity-ref entity #:anim-name #f)) + (entry (and anim-name (assq anim-name animations))) + (anim (and entry (cdr entry)))) + (if anim + (advance-animation entity anim) + entity))) ) ;; End of animation module |
