71 lines
1.7 KiB
Scheme
71 lines
1.7 KiB
Scheme
;; Game state and logic for the other entity
|
|
(define-module (game model other)
|
|
#: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 (other-load-others
|
|
other-state
|
|
other-bloat
|
|
other-position
|
|
other-x
|
|
other-y
|
|
other-update
|
|
))
|
|
|
|
|
|
(define-immutable-record-type <other>
|
|
(%make-other runner)
|
|
other?
|
|
(runner other-runner other-with-runner)
|
|
)
|
|
|
|
(define default-state 'fall)
|
|
(define default-bloat 1.0)
|
|
|
|
(define (other-load-others level)
|
|
"Create a other at the position in the level map"
|
|
(map
|
|
(compose %make-other runner-load)
|
|
(level-find-others level)))
|
|
|
|
(define (other-x other)
|
|
"return the x coordinate as an integer"
|
|
(runner-x (other-runner other)))
|
|
|
|
(define (other-y other)
|
|
"return the y coordinate as an integer"
|
|
(runner-y (other-runner other))
|
|
)
|
|
|
|
(define (other-state other)
|
|
"return the current state of the other"
|
|
(runner-state (other-runner other)))
|
|
|
|
(define (other-position other)
|
|
"return the current position of the other"
|
|
(runner-position (other-runner other)))
|
|
|
|
|
|
(define (other-update other level dt)
|
|
(other-with-runner other (runner-update (other-runner other) level '() dt)))
|
|
|
|
|
|
|
|
;; Tests
|
|
(test-begin "other-model")
|
|
|
|
(let* ((level (level-parse "WWWWW\nW...W\nWO.OW\nW..HW\nWWWWW\n"))
|
|
(others (other-load-others level)))
|
|
(test-assert (other? (car others)))
|
|
(test-equal 2 (length others))
|
|
)
|
|
|
|
|
|
(test-end "other-model")
|
|
|