make other avoid each other, update readme and remove pk's

This commit is contained in:
Peter Tillemans 2024-05-23 23:05:09 +02:00
parent 45dec36dfe
commit 84c617b7ba
6 changed files with 35 additions and 13 deletions

View file

@ -36,7 +36,7 @@ let the _others_ fall in so you can pass over their head.
So now, go out, collect the keys and maintain a healthy diet!
* Game Plan [11/18]
* Game Plan [12/20]
- [X] start project organization
- [X] select some assets to start with
@ -53,6 +53,8 @@ So now, go out, collect the keys and maintain a healthy diet!
- [ ] automate upload to itch.io
- [X] create other's AI
- [X] add keys and portal
- [X] make other avoid each other
- [ ] Detect success reaching the goal and progress to next level
- [ ] add foods and bloat indicator
- [ ] scale hero waist related to bloat level
- [ ] create more levels
@ -75,8 +77,6 @@ Untar the filename, enter the newly created folder and launch `bloatrunner/bloat
#+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

View file

@ -58,9 +58,8 @@
(define (blocked-by-door? level keys position)
"return true if the hero is blocked by a door"
(let ((door-position (level-find-goal level)))
(pk 'blocked-by-door? keys (null? keys) position
(and (collides? position door-position)
(not (null? keys))))))
(not (null? keys)))))
(define (hero-update hero level inputs keys dt)
(let ((new-runner (runner-update (hero-runner hero) level inputs dt)))

View file

@ -21,7 +21,7 @@
)
(define (key-collides? key position)
(< (pk "key distance" (vec2-magnitude (vec2- (key-position key) position))) 4))
(< (vec2-magnitude (vec2- (key-position key) position)) 4))
(define (keys-load level)

View file

@ -73,10 +73,31 @@
#t ;; if not on ladder, it's safe
)))
(define (other-distance a b)
(vec2-magnitude (vec2- (other-position a) (other-position b))))
;; find closest other to given other
(define (find-closest-other other others)
(let ((other-others (remove (lambda (o) (equal? o other)) others)))
(fold (lambda (a b)
(if (< (other-distance a other) (other-distance b other)) a b))
(car other-others)
(cdr other-others))))
;; Generate inputs for the other based on the level and
;; the hero and other others.
(define (determine-actions other level hero others)
(let ((actions '()))
(let ((actions '())
(closest (find-closest-other other others)))
;; keep distance from each other
(if (< (other-distance closest other) (* 2 level-cell-size))
(let ((diff (vec2- (other-position closest) (other-position other))))
(when (< (vec2-x diff) 0) (set! actions (cons 'right actions)))
(when (> (vec2-x diff) 0) (set! actions (cons 'left actions)))
(when (< (vec2-y diff) 0) (set! actions (cons 'up actions)))
(when (> (vec2-y diff) 0) (set! actions (cons 'down actions)))))
;; move towards hero without falling off ladders
(when (safe-ladder-position? (other-position other) level)
(when (< (hero-x hero) (other-x other))
(set! actions (cons 'left actions)))
@ -86,8 +107,11 @@
(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))))

View file

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

View file

@ -15,7 +15,6 @@
(texture-atlas-ref tile-atlas key-index)
(vec2+ (key-position key) (vec2 -8 0))))
(define (render-goal keys goal-position)
(let ((goal-index (if (null? keys) open-goal-index closed-goal-index)))
(draw-sprite