diff --git a/modules/game/actors.scm b/modules/game/actors.scm index feedfdf..9798e04 100644 --- a/modules/game/actors.scm +++ b/modules/game/actors.scm @@ -44,13 +44,6 @@ ('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 @@ -372,47 +365,48 @@ (define alive? (spawn ^cell #t)) (define countdown (spawn ^cell -1)) (define pushed? (spawn ^cell)) - (define* (light-fuse #:optional (time 2)) - ($ countdown time)) + (define (light-fuse) + ($ countdown 2)) (match-lambda* (('type) 'bomb) (('position) ($ position)) (('tick grid-info) ($ pushed? #f) (when (> ($ countdown) 0) - ($ countdown (- ($ countdown) 1))) - (when (= ($ countdown) 0) - ($ alive? #f) - (match ($ position) - (#(x y z) - (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 obj - (match ($ obj 'type) - ((or 'bomb 'brick) - ($ obj 'explode)) - ('player - ($ obj 'explode) - ($ grid-info 'append-event `(player-death ,ix ,iy))) - (_ #f))))))) - ($ grid-info 'append-event `(explosion ,x ,y)))))) + (let ((cd (1- ($ countdown)))) + ($ countdown cd) + (when (= cd 0) + ($ alive? #f) + (match ($ position) + (#(x y z) + (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 obj + (match ($ obj 'type) + ((or 'bomb 'brick) + ($ obj 'explode)) + ('player + ($ obj 'explode) + ($ grid-info 'append-event `(player-death ,ix ,iy))) + (_ #f))))))) + ($ grid-info 'append-event `(explosion ,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) #f) (('update-wire-state grid-info neighbor-grid) (when (and (< ($ countdown) 0) - (grid-electrified? neighbor-grid)) + (> (electron-head-count neighbor-grid) 0)) (light-fuse))) (('alive?) ($ alive?)) (('describe) `(bomb ,($ position) ,($ countdown))) - (('explode) (light-fuse 1)) + (('explode) (light-fuse)) (('activate grid-info) #f) (('deactivate grid-info) #f) (('collide other offset grid-info) @@ -437,7 +431,7 @@ ;; A gem that has already been collected previously will still appear ;; in the level but it will be drawn differently. -(define (^gem bcom x y previously-collected?) +(define* (^gem bcom x y previously-collected? #:optional test?) (define position (vector x y 1)) (define picked-up? (spawn ^cell)) (match-lambda* diff --git a/modules/game/level.scm b/modules/game/level.scm index 5463938..08a6b95 100644 --- a/modules/game/level.scm +++ b/modules/game/level.scm @@ -67,7 +67,12 @@ (when (< x width) (let* ((i (+ (* y width) x)) (pos (vec2 (* x tile-width) (* y tile-height))) - (id (bytevector-u16-native-ref background (* i 2))) + (id (case (bytevector-u16-native-ref background (* i 2)) + ((120) 81) + ((121) 82) + ((122) 85) + ((123) 105) + (else => (lambda (v) v)))) (tile (make-level-tile pos id))) (vector-set! background* i tile)) (x-loop (1+ x))))