Reimplement wireworld update; add stubs for new object types.

This commit is contained in:
David Thompson 2024-05-21 22:12:21 -04:00
parent 4c12ccc559
commit 984ea4df67
4 changed files with 125 additions and 92 deletions

View file

@ -127,18 +127,13 @@
(define (update-objects!)
(set! *objects*
;; 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.
;; z-sort the list so we render in the correct order. Then
;; convert tile positions to vec2s of pixel coordinates for
;; more efficient rendering.
(map (match-lambda
((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))
`(,type ,(vec2 (* x tile-width) (* y tile-height)) ,@properties)))
(sort ($ (level-actor *level*) 'describe)
(lambda (a b)
(match a
((_ #(_ _ az) . _)
@ -243,14 +238,9 @@
(define (draw-exit pos)
(draw-tile context tileset 27 (vec2-x pos) (vec2-y pos)))
(define (draw-wall type pos)
(define (draw-wall pos type)
(let ((x (vec2-x pos))
(y (vec2-y pos)))
(match type
('brick
(draw-tile context tileset 22 x y))
(_
(draw-tile context tileset 2 x y)))
(match type
('electron-head
(draw-tile context tileset 4 x y))
@ -258,7 +248,7 @@
(draw-tile context tileset 5 x y))
(_ #f))))
(define (draw-block type pos)
(define (draw-block pos type)
(let ((x (vec2-x pos))
(y (vec2-y pos)))
(match type
@ -287,11 +277,10 @@
(match obj
(#f #f)
(('player pos) (draw-player 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))
(('exit pos) #t) ; drawn via background
(('wall pos type) (draw-wall pos type))
(('block pos type) (draw-block pos type))
(('clock-emitter pos) #t) ; drawn via background
(('floor-switch pos on?) (draw-floor-switch pos on?))
(('gem pos) (draw-gem pos))
(('gate pos open?) (draw-gate pos open?))))