fixed other model to deal with ladders

This commit is contained in:
Peter Tillemans 2024-05-23 17:28:55 +02:00
parent aa12c340e9
commit 182d9d5693
6 changed files with 89 additions and 12 deletions

View file

@ -60,6 +60,32 @@ So now, go out, collect the keys and maintain a healthy diet!
* Installation and Development
** Download from itch.io
Download the latest version from [[https://snamellit.itch.io/bloatrunner][Bloatrunner page on Itch.io]].
Untar the filename, enter the newly created folder and launch `bloatrunner/bloatrunner`.
#+BEGIN_SRC
tar -xzvf <download tar ball>
cd <terrible name>
bloatrunner/bloatrunner
#+END_SRC
*** TODO make an upload script which cleans up the filename
The current filename contains the GUIX UUID which is ugly and not very
userfriendly.
There should be some CI script to build/create the tarball, rename it
and upload it with a friendly name + version number.
No idea how to get the name of the tarball from guix pack without
parsing the output.
** Using Guix
We *highly recommend* using [Guix](https://guix.gnu.org/) to manage your

View file

@ -37,7 +37,7 @@
(define (update dt)
(poll-coop-repl-server repl)
(set! hero (hero-update hero level inputs dt))
(set! others (map (lambda (other) (other-update other level dt)) others))
(set! others (map (lambda (other) (other-update other level hero others dt)) others))
)
(define (draw _alpha)

View file

@ -7,6 +7,7 @@
#:use-module (srfi srfi-64)
#:use-module (chickadee math vector)
#:use-module (game util pipe)
#:use-module (game model hero)
#:use-module (game model level)
#:use-module (game model runner)
#:export (other-load-others
@ -19,6 +20,9 @@
))
;; The enemies in this game are called "others" because they are not you
;; They are represented by a runner and try to reach the player to give
;; unwelcome advice unwittingly killing the player with cringe.
(define-immutable-record-type <other>
(%make-other runner)
other?
@ -51,9 +55,40 @@
"return the current position of the other"
(runner-position (other-runner other)))
(define (safe-ladder-position? position level)
"return true if the other can move left or right without falling of the ladder"
(let ((this-block (level-tile-at level position))
(block-left (level-tile-at level (vec2+ position (vec2 -1 0))))
(block-down-left (level-tile-at level (vec2+ position (vec2 -1 -1))))
(block-right (level-tile-at level (vec2+ position (vec2 1 0))))
(block-down-right (level-tile-at level (vec2+ position (vec2 1 -1)))))
(if (equal? this-block 'ladder)
(and
(not (equal? block-left 'brick))
(not (equal? block-right 'brick))
(member block-down-left '(brick ladder))
(member block-down-right '(brick ladder)))
#t ;; if not on ladder, it's safe
)))
(define (other-update other level dt)
(other-with-runner other (runner-update (other-runner other) level '() dt)))
;; Generate inputs for the other based on the level and
;; the hero and other others.
(define (determine-actions other level hero others)
(let ((actions '()))
(when (safe-ladder-position? (other-position other) level)
(when (< (hero-x hero) (other-x other))
(set! actions (cons 'left actions)))
(when (> (hero-x hero) (other-x other))
(set! actions (cons 'right actions))))
(when (< (hero-y hero) (other-y other))
(set! actions (cons 'down actions)))
(when (> (hero-y hero) (other-y other))
(set! actions (cons 'up actions)))
actions))
(define (other-update other level hero others dt)
(let ((inputs (determine-actions other level hero others)))
(other-with-runner other (runner-update (other-runner other) level inputs dt))))
@ -66,6 +101,22 @@
(test-equal 2 (length others))
)
(let* ((level (level-parse "WWWWWWW\nW...H...W\nW.BBHBB.W\nW...H...W\nW..H..W\nWBBBBBW\nWWWWWWW\n"))
(others (other-load-others level)))
(test-assert (safe-ladder-position? (vec2 32 32) level)) ;; not on ladder is safe
(test-assert (safe-ladder-position? (vec2 56 40) level)) ;; middle of ladder is safe
(test-assert (not (safe-ladder-position? (vec2 64 48) level))) ;; left edge of ladder is unsafe
(test-assert (not (safe-ladder-position? (vec2 79 48) level))) ;; right edge of ladder is unsafe
(test-assert (not (safe-ladder-position? (vec2 64 48) level))) ;; edge inside platform is unsafe
(test-assert (not (safe-ladder-position? (vec2 79 48) level))) ;; edge inside platform is unsafe
(test-assert (not (safe-ladder-position? (vec2 64 63) level))) ;; edge inside platform is unsafe
(test-assert (not (safe-ladder-position? (vec2 79 63) level))) ;; edge inside platform is unsafe
(test-assert (safe-ladder-position? (vec2 64 80) level)) ;; edge at platform is safe
(test-assert (safe-ladder-position? (vec2 79 80) level)) ;; edge at platform is safe
)
(test-end "other-model")

View file

@ -77,7 +77,7 @@
(define (safe-move level pos move)
(let ((new-pos (vec2+ pos move)))
(if (level-tile-blocked? level new-pos)
(round-position pos) ;; snap to grid on collision with hard scenery
(pk "snap position " pos "to" (round-position pos)) ;; snap to grid on collision with hard scenery
new-pos
)))

View file

@ -39,20 +39,20 @@
(case (other-state other)
((stationary) (draw-sprite
(other-sprite-stationary other)
(vec2+ (other-position other) (vec2 -0.0 1.0))))
(vec2+ (other-position other) (vec2 -8.0 1.0))))
((fall) (draw-sprite
(other-sprite-falling other)
(vec2+ (other-position other) (vec2 -0.0 1.0))))
(vec2+ (other-position other) (vec2 -8.0 1.0))))
((climb) (draw-sprite
(other-sprite-climbing other)
(vec2+ (other-position other) (vec2 -0.0 1.0))))
(vec2+ (other-position other) (vec2 -8.0 1.0))))
((go-left) (draw-sprite
(other-sprite-walking other)
(vec2+ (other-position other) (vec2 0.0 1.0))
(vec2+ (other-position other) (vec2 8.0 1.0))
#:scale (vec2 -1.0 1.0)
))
((go-right) (draw-sprite
(other-sprite-walking other)
(vec2+ (other-position other) (vec2 -0.0 1.0))))
(vec2+ (other-position other) (vec2 -8.0 1.0))))
)
)