Refine bomb logic

This commit is the first of a series introducing hidden logic through
non-obvious commits. I'm mentioning it in the commit messages in the hopes no
one reads these so I can sneak it in without leaving no record at all ;)
This commit is contained in:
Juliana Sims 2024-05-26 00:33:38 -04:00
parent d725310239
commit f87e7f3f76
No known key found for this signature in database
GPG key ID: 2A00BD4B0090029E
2 changed files with 34 additions and 35 deletions

View file

@ -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,16 +365,17 @@
(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)
(let ((cd (1- ($ countdown))))
($ countdown cd)
(when (= cd 0)
($ alive? #f)
(match ($ position)
(#(x y z)
@ -401,18 +395,18 @@
($ obj 'explode)
($ grid-info 'append-event `(player-death ,ix ,iy)))
(_ #f)))))))
($ grid-info 'append-event `(explosion ,x ,y))))))
($ 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*

View file

@ -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))))