Add bombs and explodable bricks
This commit is contained in:
parent
23f034a868
commit
feb5b8f3d6
6 changed files with 86 additions and 2 deletions
|
@ -9,6 +9,8 @@
|
|||
^switched-emitter
|
||||
^floor-switch
|
||||
^gate
|
||||
^bomb
|
||||
^brick
|
||||
^gem
|
||||
^ghost-gem
|
||||
^and-gate
|
||||
|
@ -28,6 +30,13 @@
|
|||
('electron-head 'electron-tail)
|
||||
('electron-tail 'copper)))
|
||||
|
||||
(define (grid-electrified? neighbor-grid)
|
||||
(let lp ((i 0))
|
||||
(cond
|
||||
((= i (vector-length neighbor-grid)) #f)
|
||||
((eq? (vector-ref neighbor-grid i) 'electron-head) #t)
|
||||
(else (lp (+ i 1))))))
|
||||
|
||||
(define (electron-head-count neighbor-grid)
|
||||
(define (check state)
|
||||
(match state
|
||||
|
@ -92,6 +101,27 @@
|
|||
(('describe) `(wall ,position ,type))
|
||||
(('collide other offset grid-info) #f)))
|
||||
|
||||
(define (^brick bcom x y)
|
||||
(define position (vector x y 1))
|
||||
(define alive? (spawn ^cell #t))
|
||||
(define exploding? (spawn ^cell))
|
||||
(match-lambda*
|
||||
(('type) 'brick)
|
||||
(('position) position)
|
||||
(('tick grid-info) #f)
|
||||
(('post-tick grid-info)
|
||||
(when ($ exploding?)
|
||||
($ alive? #f)))
|
||||
(('enter obj grid-info) #f)
|
||||
(('exit obj grid-info) #f)
|
||||
(('wire-state grid-info from from-x from-y) #f)
|
||||
(('update-wire-state grid-info neighbor-grid) #f)
|
||||
(('alive?) ($ alive?))
|
||||
(('explode)
|
||||
($ exploding? #t))
|
||||
(('describe) `(brick ,position ,($ exploding?)))
|
||||
(('collide other offset grid-info) #f)))
|
||||
|
||||
;; TODO: Maybe make separate actors for conductive vs. inert blocks.
|
||||
(define (^block bcom x y type)
|
||||
(define position (spawn ^cell (vector x y 1)))
|
||||
|
@ -315,6 +345,43 @@
|
|||
(('describe) `(electron-warp ,position ,($ state)))
|
||||
(('collide other offset grid-info) #f)))
|
||||
|
||||
(define (^bomb bcom x y)
|
||||
(define position (vector x y 2))
|
||||
(define alive? (spawn ^cell #t))
|
||||
(define lit? (spawn ^cell))
|
||||
(define exploding? (spawn ^cell))
|
||||
(match-lambda*
|
||||
(('type) 'bomb)
|
||||
(('position) position)
|
||||
(('tick grid-info)
|
||||
(cond
|
||||
(($ exploding?)
|
||||
($ alive? #f)
|
||||
(do ((ix (- x 1) (+ ix 1)))
|
||||
((> ix (+ x 1)))
|
||||
(do ((iy (- y 1) (+ iy 1)))
|
||||
((> iy (+ y 1)))
|
||||
(unless (and (= ix x) (= iy y))
|
||||
(let ((obj (match ($ grid-info 'occupants ix iy)
|
||||
(() #f)
|
||||
((obj . rest) obj))))
|
||||
(when (and obj (eq? ($ obj 'type) 'brick))
|
||||
($ obj 'explode)))))))
|
||||
(($ lit?)
|
||||
($ exploding? #t))
|
||||
(else #f)))
|
||||
(('post-tick grid-info) #f)
|
||||
(('enter obj grid-info) #f)
|
||||
(('exit obj grid-info) #f)
|
||||
(('wire-state grid-info from from-x from-y) #f)
|
||||
(('update-wire-state grid-info neighbor-grid)
|
||||
(when (and (not ($ lit?))
|
||||
(grid-electrified? neighbor-grid))
|
||||
($ lit? #t)))
|
||||
(('alive?) ($ alive?))
|
||||
(('describe) `(bomb ,position ,($ exploding?)))
|
||||
(('collide other offset grid-info) #f)))
|
||||
|
||||
(define (^gem bcom x y)
|
||||
(define position (vector x y 1))
|
||||
(define picked-up? (spawn ^cell))
|
||||
|
|
|
@ -98,6 +98,8 @@
|
|||
(bytevector-u8-ref objects (+ i 3)))))
|
||||
(16 (spawn ^switched-emitter x y
|
||||
(bytevector-u8-ref objects (+ i 3))))
|
||||
(17 (spawn ^bomb x y))
|
||||
(18 (spawn ^brick x y))
|
||||
(id (error "invalid level object" id))))
|
||||
(i* (+ i (match id
|
||||
;; floor-switch
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
130,209,89,129,211,105,24,24,24,24,24,24,24,24,106,209,211,90,211,149,
|
||||
111,89,191,151,151,105,24,24,24,24,24,24,24,24,106,131,150,151,91,149,
|
||||
109,191,169,209,89,85,24,24,24,24,24,24,24,24,86,211,130,150,129,190,
|
||||
91,171,151,131,211,101,102,102,81,82,24,83,84,102,104,189,211,189,169,109,
|
||||
91,171,151,131,211,101,102,102,88,31,24,31,87,102,104,189,211,189,169,109,
|
||||
89,170,150,209,131,171,81,83,108,24,24,24,107,84,169,151,131,111,191,191,
|
||||
130,129,190,209,91,81,108,24,24,24,24,24,24,107,84,131,111,109,189,211,
|
||||
171,190,149,189,211,105,24,24,24,24,24,24,24,24,106,131,129,89,90,170,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?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="30">
|
||||
<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="33">
|
||||
<tileset firstgid="1" source="tiles.tsx"/>
|
||||
<layer id="1" name="background" width="20" height="15">
|
||||
<data encoding="csv">
|
||||
|
@ -70,5 +70,7 @@
|
|||
<property name="interval" type="int" value="4"/>
|
||||
</properties>
|
||||
</object>
|
||||
<object id="30" type="bomb" gid="51" x="64" y="112" width="16" height="16"/>
|
||||
<object id="31" type="brick" gid="23" x="48" y="112" width="16" height="16"/>
|
||||
</objectgroup>
|
||||
</map>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue