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

@ -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))
(define (wire-state)
(match ($ timer)
(0 'electron-head)
(1 'electron-tail)
(_ 'copper)))
(match-lambda*
(('type) 'emitter)
(('position) position)
(('tick grid-info)
(('tick grid-info) #f)
(('post-tick grid-info)
(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)
(('wire-state grid-info from from-x from-y)
(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)
(('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">