Tweak emitters so their wire state is more clear.

This has become a problem in the presence of bombs.
This commit is contained in:
David Thompson 2024-05-24 15:27:24 -04:00
parent a102a9fb06
commit 892675f2d1
3 changed files with 36 additions and 28 deletions

View file

@ -371,11 +371,17 @@
(define (draw-brick pos)
(draw-tile context tileset 22 (vec2-x pos) (vec2-y pos)))
(define (draw-clock-emitter pos)
(draw-tile context tileset 48 (vec2-x pos) (vec2-y pos)))
(define (draw-clock-emitter pos state)
(draw-tile context tileset 48 (vec2-x pos) (vec2-y pos))
(set-global-alpha! context 0.5)
(draw-wire-state pos state)
(set-global-alpha! context 1.0))
(define (draw-switched-emitter pos on?)
(draw-tile context tileset (if on? 48 47) (vec2-x pos) (vec2-y pos)))
(define (draw-switched-emitter pos state)
(draw-tile context tileset (if state 48 47) (vec2-x pos) (vec2-y pos))
(set-global-alpha! context 0.5)
(draw-wire-state pos state)
(set-global-alpha! context 1.0))
(define (draw-floor-switch pos on?)
(draw-tile context tileset (if on? 25 24) (vec2-x pos) (vec2-y pos)))
@ -420,8 +426,8 @@
(('wall pos type) (draw-wall pos type))
(('block pos type) (draw-block pos type))
(('brick pos) (draw-brick pos))
(('clock-emitter pos) (draw-clock-emitter pos))
(('switched-emitter pos on?) (draw-switched-emitter pos on?))
(('clock-emitter pos state) (draw-clock-emitter pos state))
(('switched-emitter pos state) (draw-switched-emitter pos state))
(('floor-switch pos on?) (draw-floor-switch pos on?))
(('bomb pos countdown) (draw-bomb pos countdown))
(('gem pos) (draw-gem pos))

View file

@ -165,43 +165,50 @@
(('pushed?) ($ pushed?))))
(define (^clock-emitter bcom x y interval)
(define timer (spawn ^cell -1))
(define timer (spawn ^cell 0))
(define position (vector x y 0))
(match-lambda*
(('type) 'emitter)
(('position) position)
(('tick grid-info)
(let ((t (modulo (+ ($ timer) 1) interval)))
($ timer t)
(when (= t 0)
($ grid-info 'append-event `(emit ,x ,y)))))
(('post-tick grid-info) #f)
(('enter obj grid-info) #f)
(('exit obj grid-info) #f)
(('wire-state grid-info from from-x from-y)
(define (wire-state)
(match ($ timer)
(0 'electron-head)
(1 'electron-tail)
(_ 'copper)))
(match-lambda*
(('type) 'emitter)
(('position) position)
(('tick grid-info) #f)
(('post-tick grid-info)
(let ((t (modulo (+ ($ timer) 1) interval)))
($ timer t)
(when (= t 1)
($ grid-info 'append-event `(emit ,x ,y)))))
(('enter obj grid-info) #f)
(('exit obj grid-info) #f)
(('wire-state grid-info from from-x from-y) (wire-state))
(('update-wire-state grid-info neighbor-grid) #f)
(('alive?) #t)
(('describe) `(clock-emitter ,position))
(('describe) `(clock-emitter ,position ,(wire-state)))
(('collide other offset grid-info) #f)))
(define (^switched-emitter bcom x y interval)
(define timer (spawn ^cell -1))
(define timer (spawn ^cell 0))
(define on? (spawn ^cell))
(define position (vector x y 0))
(define (wire-state)
(and ($ on?)
(match ($ timer)
(0 'electron-head)
(1 'electron-tail)
(_ 'copper))))
(match-lambda*
(('type) 'switched-emitter)
(('position) position)
(('tick grid-info)
(('tick grid-info) #f)
(('post-tick grid-info)
(when ($ on?)
(let ((t (modulo (+ ($ timer) 1) interval)))
($ timer t)
(when (= t 0)
(when (= t 1)
($ grid-info 'append-event `(emit ,x ,y))))))
(('post-tick grid-info) #f)
(('enter obj grid-info) #f)
(('exit obj grid-info) #f)
(('activate grid-info)
@ -211,16 +218,11 @@
(('deactivate grid-info)
($ on? #f)
($ grid-info 'append-event `(emitter-off ,x ,y)))
(('wire-state grid-info from from-x from-y)
(and ($ on?)
(match ($ timer)
(0 'electron-head)
(1 'electron-tail)
(_ 'copper))))
(('wire-state grid-info from from-x from-y) (wire-state))
(('update-wire-state grid-info neighbor-grid) #f)
(('alive?) #t)
(('on?) ($ on?))
(('describe) `(switched-emitter ,position ,($ on?)))
(('describe) `(switched-emitter ,position ,(wire-state)))
(('collide other offset grid-info) #f)))
(define (first-non-player-occupant grid-info x y)

View file

@ -62,7 +62,7 @@
</object>
<object id="22" type="clock-emitter" gid="49" x="32" y="144" width="16" height="16">
<properties>
<property name="interval" type="int" value="1"/>
<property name="interval" type="int" value="3"/>
</properties>
</object>
<object id="23" type="switched-emitter" gid="48" x="80" y="112" width="16" height="16">