2024-05-20 19:49:32 +02:00
|
|
|
(define-module (game render hero)
|
|
|
|
#:use-module (game model hero)
|
2024-05-22 23:29:52 +02:00
|
|
|
#:use-module (game util assets)
|
2024-05-20 19:49:32 +02:00
|
|
|
#:use-module (chickadee)
|
|
|
|
#:use-module (chickadee math vector)
|
|
|
|
#:use-module (chickadee graphics sprite)
|
|
|
|
#:use-module (chickadee graphics texture)
|
|
|
|
#:export (render-hero
|
2024-05-23 21:46:50 +02:00
|
|
|
render-hero-load))
|
2024-05-20 19:49:32 +02:00
|
|
|
|
|
|
|
;; start index of the walk animation
|
2024-05-21 17:52:30 +02:00
|
|
|
(define hero-walking-offset 56)
|
|
|
|
(define hero-falling-offset 32)
|
2024-05-21 20:59:48 +02:00
|
|
|
(define hero-climbing-offset 48)
|
2024-05-20 19:49:32 +02:00
|
|
|
|
2024-05-21 17:52:30 +02:00
|
|
|
(define (hero-sprite-walking hero)
|
|
|
|
(let* ((x (hero-x hero))
|
2024-05-21 13:56:18 +02:00
|
|
|
(animation-frame (remainder x 8))
|
2024-05-21 17:52:30 +02:00
|
|
|
(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)))
|
2024-05-20 19:49:32 +02:00
|
|
|
(texture-atlas-ref hero-atlas hero-index)))
|
|
|
|
|
|
|
|
(define (render-hero hero)
|
2024-05-21 17:52:30 +02:00
|
|
|
(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))))
|
2024-05-21 17:52:30 +02:00
|
|
|
((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))
|
2024-05-21 17:52:30 +02:00
|
|
|
#: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))))
|
2024-05-21 17:52:30 +02:00
|
|
|
)
|
|
|
|
)
|