bloatrunner/game/render/hero.scm

59 lines
1.9 KiB
Scheme
Raw Normal View History

(define-module (game render hero)
#:use-module (game model hero)
2024-05-22 23:29:52 +02:00
#:use-module (game util assets)
#:use-module (chickadee)
#:use-module (chickadee math vector)
#:use-module (chickadee graphics sprite)
#:use-module (chickadee graphics texture)
#:export (render-hero
render-hero-load))
;; start index of the walk animation
(define hero-walking-offset 56)
(define hero-falling-offset 32)
2024-05-21 20:59:48 +02:00
(define hero-climbing-offset 48)
(define (hero-sprite-walking hero)
(let* ((x (hero-x hero))
(animation-frame (remainder x 8))
(hero-index (+ hero-walking-offset animation-frame)))
(texture-atlas-ref hero-atlas hero-index)))
(define (hero-sprite-stationary _hero)
(texture-atlas-ref hero-atlas 56))
(define (hero-sprite-falling hero)
(let* ((y (hero-y hero))
(animation-frame (remainder y 8))
(hero-index (+ hero-falling-offset animation-frame)))
(texture-atlas-ref hero-atlas hero-index)))
(define (hero-sprite-climbing hero)
(let* ((y (hero-y hero))
(animation-frame (remainder y 8))
(hero-index (+ hero-climbing-offset animation-frame)))
(texture-atlas-ref hero-atlas hero-index)))
(define (render-hero hero)
(case (hero-state hero)
((stationary) (draw-sprite
(hero-sprite-stationary hero)
2024-05-21 20:59:48 +02:00
(vec2+ (hero-position hero) (vec2 -16.0 1.0))))
((fall) (draw-sprite
(hero-sprite-falling hero)
(vec2+ (hero-position hero) (vec2 -16.0 1.0))))
((climb) (draw-sprite
(hero-sprite-climbing hero)
(vec2+ (hero-position hero) (vec2 -16.0 1.0))))
((go-left) (draw-sprite
(hero-sprite-walking hero)
2024-05-21 20:59:48 +02:00
(vec2+ (hero-position hero) (vec2 16.0 1.0))
#:scale (vec2 -1.0 1.0)
))
((go-right) (draw-sprite
(hero-sprite-walking hero)
2024-05-21 20:59:48 +02:00
(vec2+ (hero-position hero) (vec2 -16.0 1.0))))
)
)