bloatrunner/game/model/other.scm

73 lines
1.9 KiB
Scheme

;; Game state and logic for the hero entity
(define-module (game model hero)
#:use-module (ice-9 pretty-print)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-9)
#:use-module (srfi srfi-9 gnu)
#:use-module (srfi srfi-64)
#:use-module (chickadee math vector)
#:use-module (game util pipe)
#:use-module (game model level)
#:use-module (game model runner)
#:export (hero-load
hero-state
hero-bloat
hero-position
hero-x
hero-y
hero-update
))
(define-immutable-record-type <hero>
(%make-hero runner bloat)
hero?
(runner hero-runner hero-with-runner)
(bloat hero-bloat hero-with-bloat) ;; 0.0 to 2.0, how much the hero is inflated
)
(define default-state 'fall)
(define default-bloat 1.0)
(define (hero-load level)
"Create a hero at the position in the level map"
(let ((runner (runner-load (level-find-hero level))))
(%make-hero runner default-bloat)))
(define (hero-x hero)
"return the x coordinate as an integer"
(runner-x (hero-runner hero)))
(define (hero-y hero)
"return the y coordinate as an integer"
(runner-y (hero-runner hero))
)
(define (hero-state hero)
"return the current state of the hero"
(runner-state (hero-runner hero)))
(define (hero-position hero)
"return the current position of the hero"
(runner-position (hero-runner hero)))
(define (hero-update hero level inputs dt)
(hero-with-runner hero (runner-update (hero-runner hero) level inputs dt)))
;; Tests
[test-begin "hero-model"]
(let* ((level (level-parse "WWWWW\nW...W\nW.P.W\nW..HW\nWWWWW\n"))
(hero (hero-load level))
(default-position (level-find-hero level)))
(test-assert (hero? hero))
(test-equal default-bloat (hero-bloat hero))
(test-equal 1.5 (hero-bloat (hero-with-bloat hero 1.5)))
(test-equal default-bloat (hero-bloat hero))
(test-end "hero-model"))