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! 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] start project organization
- [X] select some assets to start with - [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 - [ ] automate upload to itch.io
- [X] create other's AI - [X] create other's AI
- [X] add keys and portal - [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 - [ ] add foods and bloat indicator
- [ ] scale hero waist related to bloat level - [ ] scale hero waist related to bloat level
- [ ] create more levels - [ ] create more levels
@ -75,8 +77,6 @@ Untar the filename, enter the newly created folder and launch `bloatrunner/bloat
#+END_SRC #+END_SRC
*** TODO make an upload script which cleans up the filename *** TODO make an upload script which cleans up the filename
The current filename contains the GUIX UUID which is ugly and not very 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) (define (blocked-by-door? level keys position)
"return true if the hero is blocked by a door" "return true if the hero is blocked by a door"
(let ((door-position (level-find-goal level))) (let ((door-position (level-find-goal level)))
(pk 'blocked-by-door? keys (null? keys) position (and (collides? position door-position)
(and (collides? position door-position) (not (null? keys)))))
(not (null? keys))))))
(define (hero-update hero level inputs keys dt) (define (hero-update hero level inputs keys dt)
(let ((new-runner (runner-update (hero-runner hero) level inputs dt))) (let ((new-runner (runner-update (hero-runner hero) level inputs dt)))

View file

@ -21,7 +21,7 @@
) )
(define (key-collides? key position) (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) (define (keys-load level)

View file

@ -73,10 +73,31 @@
#t ;; if not on ladder, it's safe #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 ;; Generate inputs for the other based on the level and
;; the hero and other others. ;; the hero and other others.
(define (determine-actions other level hero 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 (safe-ladder-position? (other-position other) level)
(when (< (hero-x hero) (other-x other)) (when (< (hero-x hero) (other-x other))
(set! actions (cons 'left actions))) (set! actions (cons 'left actions)))
@ -86,11 +107,14 @@
(set! actions (cons 'down actions))) (set! actions (cons 'down actions)))
(when (> (hero-y hero) (other-y other)) (when (> (hero-y hero) (other-y other))
(set! actions (cons 'up actions))) (set! actions (cons 'up actions)))
actions)) actions))
(define (other-update other level hero others dt) (define (other-update other level hero others dt)
(let ((inputs (determine-actions other level hero others))) (let ((inputs (determine-actions other level hero others)))
(other-with-runner other (runner-update (other-runner other) level inputs dt)))) (other-with-runner other (runner-update (other-runner other) level inputs dt))))

View file

@ -72,7 +72,7 @@
(define (safe-move level pos move) (define (safe-move level pos move)
(let ((new-pos (vec2+ pos move))) (let ((new-pos (vec2+ pos move)))
(if (level-tile-blocked? level new-pos) (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 new-pos
))) )))

View file

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