Implement interval logic for emitters

This commit is contained in:
Juliana Sims 2024-05-23 16:28:53 -04:00
parent 65076c40f3
commit 13aa8606a9
6 changed files with 65 additions and 30 deletions

View file

@ -379,7 +379,7 @@
(('exit pos) #t) ; drawn via background (('exit pos) #t) ; drawn via background
(('wall pos type) (draw-wall pos type)) (('wall pos type) (draw-wall pos type))
(('block pos type) (draw-block pos type)) (('block pos type) (draw-block pos type))
(('clock-emitter pos) #t) ; drawn via background (('clock-emitter pos) (draw-clock-emitter pos))
(('switched-emitter pos on?) (draw-switched-emitter pos on?)) (('switched-emitter pos on?) (draw-switched-emitter pos on?))
(('floor-switch pos on?) (draw-floor-switch pos on?)) (('floor-switch pos on?) (draw-floor-switch pos on?))
(('gem pos) (draw-gem pos)) (('gem pos) (draw-gem pos))

View file

@ -66,7 +66,8 @@
(4 (spawn ^exit x y)) (4 (spawn ^exit x y))
(5 (spawn ^block x y 'copper)) (5 (spawn ^block x y 'copper))
(6 (spawn ^block x y 'crate)) (6 (spawn ^block x y 'crate))
(7 (spawn ^clock-emitter x y 4)) (7 (spawn ^clock-emitter x y
(bytevector-u8-ref objects (+ i 3))))
(8 (let ((target-x (bytevector-u8-ref objects (+ i 3))) (8 (let ((target-x (bytevector-u8-ref objects (+ i 3)))
(target-y (bytevector-u8-ref objects (+ i 4)))) (target-y (bytevector-u8-ref objects (+ i 4))))
(spawn ^floor-switch x y target-x target-y))) (spawn ^floor-switch x y target-x target-y)))
@ -86,15 +87,18 @@
(spawn ^electron-warp x y target-x target-y))) (spawn ^electron-warp x y target-x target-y)))
(15 (spawn ^or-gate x y (15 (spawn ^or-gate x y
(bytevector-u8-ref objects (+ i 3)))) (bytevector-u8-ref objects (+ i 3))))
(16 (spawn ^switched-emitter x y 4)) (16 (spawn ^switched-emitter x y
(bytevector-u8-ref objects (+ i 3))))
(id (error "invalid level object" id)))) (id (error "invalid level object" id))))
(i* (+ i (match id (i* (+ i (match id
;; floor-switch ;; floor-switch
;; electric-switch ;; electric-switch
;; electron-warp ;; electron-warp
((or 8 12 14) 5) ((or 8 12 14) 5)
;; clock-emitter
;; logic gates ;; logic gates
((or 11 13 15) 4) ;; switched-emitter
((or 7 11 13 15 16) 4)
(_ 3))))) (_ 3)))))
(when obj (when obj
($ level* 'add-object obj)) ($ level* 'add-object obj))

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<map version="1.8" tiledversion="1.8.6" orientation="orthogonal" renderorder="right-down" width="20" height="15" tilewidth="16" tileheight="16" infinite="0" nextlayerid="3" nextobjectid="23"> <map version="1.8" tiledversion="1.8.6" orientation="orthogonal" renderorder="right-down" width="20" height="15" tilewidth="16" tileheight="16" infinite="0" nextlayerid="3" nextobjectid="26">
<tileset firstgid="1" source="tiles.tsx"/> <tileset firstgid="1" source="tiles.tsx"/>
<layer id="1" name="background" width="20" height="15"> <layer id="1" name="background" width="20" height="15">
<data encoding="csv"> <data encoding="csv">
@ -7,13 +7,13 @@
81,83,83,82,83,83,83,82,83,83,83,83,82,83,83,84,23,23,23,23, 81,83,83,82,83,83,83,82,83,83,83,83,82,83,83,84,23,23,23,23,
85,24,24,24,24,24,24,24,24,24,24,24,24,24,24,106,81,82,82,84, 85,24,24,24,24,24,24,24,24,24,24,24,24,24,24,106,81,82,82,84,
105,24,24,24,24,24,24,24,24,24,24,24,24,24,24,106,105,24,24,86, 105,24,24,24,24,24,24,24,24,24,24,24,24,24,24,106,105,24,24,86,
105,24,49,3,3,24,3,3,3,3,3,3,24,24,24,106,105,24,24,106, 105,24,24,3,3,24,3,3,3,3,3,3,24,24,24,106,105,24,24,106,
85,24,24,24,24,24,24,24,24,24,24,24,24,3,24,106,105,24,24,106, 85,24,24,24,24,24,24,24,24,24,24,24,24,3,24,106,105,24,24,106,
85,24,24,24,24,24,49,3,3,3,3,3,24,24,24,24,24,24,24,106, 85,24,24,24,24,24,24,3,3,3,3,3,24,24,24,24,24,24,24,106,
85,24,24,24,24,24,24,24,24,24,24,24,24,24,24,106,105,24,24,106, 85,24,24,24,24,24,24,24,24,24,24,24,24,24,24,106,105,24,24,106,
85,24,24,24,24,24,24,24,24,24,24,24,24,24,24,106,105,28,24,86, 85,24,24,24,24,24,24,24,24,24,24,24,24,24,24,106,105,28,24,86,
105,24,24,24,24,24,24,24,24,24,24,24,24,24,81,104,105,24,24,86, 105,24,24,24,24,24,24,24,24,24,24,24,24,24,81,104,105,24,24,86,
105,49,3,3,24,61,61,66,24,24,24,24,24,24,106,23,105,24,24,86, 105,24,3,3,24,61,61,66,24,24,24,24,24,24,106,23,105,24,24,86,
85,24,24,24,24,24,24,64,61,61,24,3,3,24,86,23,101,102,102,104, 85,24,24,24,24,24,24,64,61,61,24,3,3,24,86,23,101,102,102,104,
101,103,103,102,102,102,103,102,103,103,102,102,102,102,104,23,23,23,23,23, 101,103,103,102,102,102,103,102,103,103,102,102,102,102,104,23,23,23,23,23,
23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23, 23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,
@ -57,5 +57,20 @@
<property name="target-y" type="int" value="10"/> <property name="target-y" type="int" value="10"/>
</properties> </properties>
</object> </object>
<object id="23" type="clock-emitter" gid="49" x="96" y="96" width="16" height="16">
<properties>
<property name="interval" type="int" value="4"/>
</properties>
</object>
<object id="24" type="clock-emitter" gid="49" x="32" y="64" width="16" height="16">
<properties>
<property name="interval" type="int" value="4"/>
</properties>
</object>
<object id="25" type="clock-emitter" gid="49" x="16" y="160" width="16" height="16">
<properties>
<property name="interval" type="int" value="4"/>
</properties>
</object>
</objectgroup> </objectgroup>
</map> </map>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<map version="1.8" tiledversion="1.8.6" orientation="orthogonal" renderorder="right-down" width="20" height="15" tilewidth="16" tileheight="16" infinite="0" nextlayerid="3" nextobjectid="21"> <map version="1.8" tiledversion="1.8.6" orientation="orthogonal" renderorder="right-down" width="20" height="15" tilewidth="16" tileheight="16" infinite="0" nextlayerid="3" nextobjectid="24">
<tileset firstgid="1" source="tiles.tsx"/> <tileset firstgid="1" source="tiles.tsx"/>
<layer id="1" name="background" width="20" height="15"> <layer id="1" name="background" width="20" height="15">
<data encoding="csv"> <data encoding="csv">
@ -8,11 +8,11 @@
23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23, 23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,
23,23,24,24,24,24,24,24,24,24,24,24,24,24,23,23,23,23,23,23, 23,23,24,24,24,24,24,24,24,24,24,24,24,24,23,23,23,23,23,23,
23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,23,24,24,24,23, 23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,23,24,24,24,23,
23,24,24,24,24,49,3,24,3,24,24,24,24,24,24,23,24,28,24,23, 23,24,24,24,24,24,3,24,3,24,24,24,24,24,24,23,24,28,24,23,
23,24,24,24,24,24,24,24,24,24,3,24,24,24,24,23,24,24,24,23, 23,24,24,24,24,24,24,24,24,24,3,24,24,24,24,23,24,24,24,23,
23,24,24,24,24,48,3,3,3,24,24,24,3,24,24,24,24,24,24,23, 23,24,24,24,24,24,3,3,3,24,24,24,3,24,24,24,24,24,24,23,
23,24,24,24,24,24,24,24,24,24,3,24,24,24,24,23,24,24,24,23, 23,24,24,24,24,24,24,24,24,24,3,24,24,24,24,23,24,24,24,23,
23,24,49,3,3,24,3,3,3,24,24,24,24,24,24,23,24,24,24,23, 23,24,24,3,3,24,3,3,3,24,24,24,24,24,24,23,24,24,24,23,
23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,23,24,24,24,23, 23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,23,24,24,24,23,
23,23,24,24,24,24,24,24,24,24,24,24,24,24,23,23,23,23,23,23, 23,23,24,24,24,24,24,24,24,24,24,24,24,24,23,23,23,23,23,23,
23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23, 23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,
@ -55,5 +55,20 @@
<property name="target-y" type="int" value="7"/> <property name="target-y" type="int" value="7"/>
</properties> </properties>
</object> </object>
<object id="21" type="clock-emitter" gid="49" x="80" y="80" width="16" height="16">
<properties>
<property name="interval" type="int" value="4"/>
</properties>
</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"/>
</properties>
</object>
<object id="23" type="switched-emitter" gid="48" x="80" y="112" width="16" height="16">
<properties>
<property name="interval" type="int" value="4"/>
</properties>
</object>
</objectgroup> </objectgroup>
</map> </map>

View file

@ -12,8 +12,6 @@
</properties> </properties>
</tile> </tile>
<tile id="27" type="exit"/> <tile id="27" type="exit"/>
<tile id="47" type="switched-emitter"/>
<tile id="48" type="clock-emitter"/>
<tile id="80" type="wall"> <tile id="80" type="wall">
<properties> <properties>
<property name="kind" value="brick"/> <property name="kind" value="brick"/>

View file

@ -575,7 +575,8 @@ the default ORIENTATION value of 'orthogonal' is supported."
(layer (tile-map-layer-ref tile-map layer-name))) (layer (tile-map-layer-ref tile-map layer-name)))
(append-map (lambda (y) (append-map (lambda (y)
(concatenate (concatenate
(filter-map (lambda (x) (filter-map
(lambda (x)
(match (tile-layer-ref layer x y) (match (tile-layer-ref layer x y)
(#f #f) (#f #f)
((= map-tile-ref tile) ((= map-tile-ref tile)
@ -587,8 +588,6 @@ the default ORIENTATION value of 'orthogonal' is supported."
("copper" (list x y obj:wall:copper)) ("copper" (list x y obj:wall:copper))
(kind (error "unsupported wall kind" kind)))) (kind (error "unsupported wall kind" kind))))
("exit" (list x y obj:exit)) ("exit" (list x y obj:exit))
("clock-emitter" (list x y obj:clock-emitter))
("switched-emitter" (list x y obj:switched-emitter))
(type (error "unsupported background object" type)))))) (type (error "unsupported background object" type))))))
(iota (tile-layer-width layer))))) (iota (tile-layer-width layer)))))
(iota (tile-layer-height layer))))) (iota (tile-layer-height layer)))))
@ -621,6 +620,10 @@ the default ORIENTATION value of 'orthogonal' is supported."
(assq-ref properties 'target-y))) (assq-ref properties 'target-y)))
('gem (list x y obj:gem)) ('gem (list x y obj:gem))
('gate (list x y obj:gate)) ('gate (list x y obj:gate))
('clock-emitter (list x y obj:clock-emitter
(assq-ref properties 'interval)))
('switched-emitter (list x y obj:switched-emitter
(assq-ref properties 'interval)))
('and-gate (list x y obj:and-gate ('and-gate (list x y obj:and-gate
(parse-direction (parse-direction
(assq-ref properties 'direction)))) (assq-ref properties 'direction))))