Add ^switched-emitter, test in level 4

This commit is contained in:
Juliana Sims 2024-05-22 15:28:42 -04:00
parent aa8a302fcb
commit 50b6c67db8
6 changed files with 50 additions and 2 deletions

View file

@ -6,6 +6,7 @@
^wall
^block
^clock-emitter
^switched-emitter
^floor-switch
^gate
^gem
@ -145,6 +146,39 @@
(('describe) `(clock-emitter ,position))
(('collide other offset grid-info) #f)))
(define (^switched-emitter bcom x y interval)
(define timer (spawn ^cell -1))
(define on? (spawn ^cell))
(define position (vector x y 0))
(match-lambda*
(('type) 'switched-emitter)
(('position) position)
(('tick grid-info)
(when ($ on?)
($ timer (+ ($ timer) 1))))
(('post-tick grid-info) #f)
(('enter obj grid-info) #f)
(('exit obj grid-info) #f)
(('activate grid-info)
($ on? #t)
($ timer 0))
(('deactivate grid-info) ($ on? #f))
(('wire-state grid-info)
(when ($ on?)
(let ((t ($ timer)))
(cond
((= (modulo t interval) 0)
'electron-head)
((= (modulo t interval) 1)
'electron-tail)
(else
'copper)))))
(('update-wire-state grid-info) #f)
(('alive?) #t)
(('on?) ($ on?))
(('describe) `(switched-emitter ,position ,($ on?)))
(('collide other offset grid-info) #f)))
(define (first-non-player-occupant grid-info x y)
(let lp ((objs ($ grid-info 'occupants x y)))
(match objs