Add physical gates and finish floor switches.
This commit is contained in:
parent
ba7b9ea9d8
commit
4c12ccc559
5 changed files with 157 additions and 49 deletions
62
game.scm
62
game.scm
|
@ -102,20 +102,59 @@
|
|||
(set! *snapshots* older-snapshots)
|
||||
(media-play audio:undo))))
|
||||
|
||||
(define (sort lst <=)
|
||||
(match lst
|
||||
(() '())
|
||||
((_) lst)
|
||||
((pivot . rest)
|
||||
(let lp ((left '()) (right '()) (pivot pivot) (rest rest))
|
||||
(match rest
|
||||
(() (append (sort left <=) (list pivot) (sort right <=)))
|
||||
((x . rest)
|
||||
(if (<= x pivot)
|
||||
(lp (append left (list x)) right pivot rest)
|
||||
(lp left (append right (list x)) pivot rest))))))))
|
||||
|
||||
(define (filter-map proc lst)
|
||||
(let lp ((lst lst))
|
||||
(match lst
|
||||
(() '())
|
||||
((head . tail)
|
||||
(let ((head* (proc head)))
|
||||
(if head*
|
||||
(cons head* (lp tail))
|
||||
(lp tail)))))))
|
||||
|
||||
(define (update-objects!)
|
||||
(set! *objects*
|
||||
;; TODO: Receive layer for sprite sorting
|
||||
;; Filter out the objects that are baked into the background
|
||||
;; and thus do not need to be rendered repeatedly. Then,
|
||||
;; z-sort the list so we render in the correct order.
|
||||
;; Finally, convert positions to vec2s for more efficient
|
||||
;; rendering.
|
||||
(map (match-lambda
|
||||
((type #(x y) . properties)
|
||||
`(,type ,(vec2 (* x tile-width) (* y tile-height)) ,@properties)))
|
||||
($ (level-actor *level*) 'describe))))
|
||||
((type #(x y _) . properties)
|
||||
(pk 'obj `(,type ,(vec2 (* x tile-width) (* y tile-height)) ,@properties))))
|
||||
(sort (filter-map (match-lambda
|
||||
(((or 'wall 'exit) . _) #f)
|
||||
(desc desc))
|
||||
($ (level-actor *level*) 'describe))
|
||||
(lambda (a b)
|
||||
(match a
|
||||
((_ #(_ _ az) . _)
|
||||
(match b
|
||||
((_ #(_ _ bz) . _)
|
||||
(<= az bz))))))))))
|
||||
|
||||
(define (collected-gem? idx)
|
||||
(not (memq idx *gems*)))
|
||||
|
||||
(define (load-level! idx)
|
||||
(set! *state* 'play)
|
||||
(set! *actormap* (make-whactormap))
|
||||
(clear-snapshots!)
|
||||
(with-goblins
|
||||
(set! *level* ((vector-ref levels idx) (not (memq idx *gems*))))
|
||||
(set! *level* ((vector-ref levels idx) (collected-gem? idx)))
|
||||
(update-objects!)))
|
||||
|
||||
(define (next-level!)
|
||||
|
@ -172,6 +211,8 @@
|
|||
'next-level)
|
||||
(('gem)
|
||||
(media-play audio:pickup)
|
||||
;; TODO: Maybe show a little achievement popup when all gems
|
||||
;; are collected?
|
||||
(set! *gems* (cons *level-idx* *gems*))
|
||||
#f)
|
||||
(_ #f)))
|
||||
|
@ -239,16 +280,21 @@
|
|||
(define (draw-gem pos)
|
||||
(draw-tile context tileset 28 (vec2-x pos) (vec2-y pos)))
|
||||
|
||||
(define (draw-gate pos open?)
|
||||
(draw-tile context tileset (if open? 46 45) (vec2-x pos) (vec2-y pos)))
|
||||
|
||||
(define (draw-object obj)
|
||||
(match obj
|
||||
(#f #f)
|
||||
(('player pos) (draw-player pos))
|
||||
(('exit pos) (draw-exit pos))
|
||||
(('wall pos type) (draw-wall type pos))
|
||||
;; Wall and exit tiles are baked into the background layer.
|
||||
(('exit pos) #t)
|
||||
(('wall pos type) #t)
|
||||
(('block pos type) (draw-block type pos))
|
||||
(('clock-emitter pos) (draw-clock-emitter pos))
|
||||
(('floor-switch pos on?) (draw-floor-switch pos on?))
|
||||
(('gem pos) (draw-gem pos))))
|
||||
(('gem pos) (draw-gem pos))
|
||||
(('gate pos open?) (draw-gate pos open?))))
|
||||
|
||||
(define (draw-background)
|
||||
(let* ((bv (level-background *level*))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue