Random debris generation

This commit is contained in:
Jeremy Penner 2021-01-24 11:32:49 -05:00
parent d4bd5302f7
commit e941fae745
7 changed files with 31 additions and 15 deletions

Binary file not shown.

View file

@ -18,8 +18,5 @@
[:bne :sample]] [:bne :sample]]
(vm:drop) (vm:drop)) (vm:drop) (vm:drop))
(var noisebytes "") (vm:word :snd-explode 0x40 :lit :randombytes :blipmem)
(for [i 0 0x40] (set noisebytes (.. noisebytes (string.char (math.random 0 255)))))
(vm.code:append :noise [:bytes noisebytes])
(vm:word :snd-explode 0x40 :lit :noise :blipmem)

View file

@ -116,6 +116,19 @@
[:sta vm.TOPH :x] [:sta vm.TOPH :x]
[:sta :0xc010]]) [:sta :0xc010]])
; "random" numbers
; this is used only for cosmetic purposes and short noise generation, so we can get away
; with just including a short table of random digits rather than implementing our own
; pseudorandom number generator
(var randombytes "")
(for [i 0 0x40] (set randombytes (.. randombytes (string.char (math.random 0 255)))))
(vm.code:append :randombytes [:bytes randombytes])
(vm:var :irandom [:db 0])
(vm:word :rnd
:irandom :bget
:dup 1 :+ 0x3f :& :irandom :bset
:lit :randombytes :+ :bget)
; 20x12 means full map is 240 bytes - we have an extra 16 bytes at the end for metadata ; 20x12 means full map is 240 bytes - we have an extra 16 bytes at the end for metadata
(fn append-map [map org label] (fn append-map [map org label]
(org:append (org:append
@ -162,11 +175,10 @@
(table.insert result :dismiss-dialog) (table.insert result :dismiss-dialog)
result) result)
(local itile (local tilelist (tiles.loadgfx tiles.fn-tiles))
(let [tilelist (tiles.loadgfx tiles.fn-tiles)] (fn itile [label] (tiles.find-itile tilelist label))
(fn [label] (tiles.find-itile tilelist label))))
(set vm.code org.code) (set vm.code org.code)
{: vm : prg : mapw : maph : mon : org : achar : astr : style : rot8l : deflevel : say : say-runon : itile : controlstate} {: vm : prg : mapw : maph : mon : org : achar : astr : style : rot8l : deflevel : say : say-runon : itile : tilelist : controlstate}

View file

@ -27,7 +27,7 @@
(vm:var :tick-count) (vm:var :tick-count)
(vm:word :handle-key :tick :read-key :player-key :hide-footer) (vm:word :handle-key :tick :read-key :player-key :hide-footer)
(vm:word :tick :map-specific-tick :tick-count :get 1 :+ :tick-count :set :player-redraw) (vm:word :tick :map-specific-tick :tick-count :get 1 :+ :tick-count :set :player-redraw :rnd :drop)
(vm:var :next-level 0) (vm:var :next-level 0)
(vm:word :load-next-level :next-level :get :dup (vm:if [:load-level 0 :next-level :set] [:drop])) (vm:word :load-next-level :next-level :get :dup (vm:if [:load-level 0 :next-level :set] [:drop]))

View file

@ -1,11 +1,16 @@
(local {: deflevel : say : itile : controlstate} (require :game.defs)) (local {: deflevel : say : itile : controlstate : tilelist} (require :game.defs))
(local {: ev} (require :game.entity)) (local {: ev} (require :game.entity))
(local tile (require :game.tiles)) (local tile (require :game.tiles))
(local {: walkable : neutable : debris : sittable} tile.flag-to-bit) (local {: walkable : neutable : debris : sittable} tile.flag-to-bit)
(local level (deflevel "game/map5.json" :level5)) (local level (deflevel "game/map5.json" :level5))
(local vm level.vm) (local vm level.vm)
(vm:word :randomgarbage (itile :broken-table)) (vm.code:append :debristiles)
(each [itile tiledef (ipairs tilelist)]
(when tiledef.flags.debris
(vm.code:append [:db (tile.encode-itile itile)])))
(vm:word :randomgarbage :rnd 0x03 :& :lit :debristiles :+ :bget)
(vm:var :doortimer 0) (vm:var :doortimer 0)
(vm:word :start-doortimer 0x10 :doortimer :set) (vm:word :start-doortimer 0x10 :doortimer :set)
(vm:word :doortimer-tick (vm:word :doortimer-tick

View file

@ -1 +1 @@
{"neut":{"y":1,"x":5},"map":"210261616161616161616161812261616161E1614161C2C081C0C0C0C0C0C0C0C0C001C081C0C0622161E04384C0C0C043C0C0C043C0C0C0848201612102616161C0C061610281026161C0C0616161612161C2C0C0C0C061E2C0C0C0A261C0C0C0C0E2612161E003C0C0C061C0C0C0C08261C0C0C003E06121026161C0C0C061E08282E2E061C0C0C06161612161C2C0C0C0C06103C0C0C02361C0C0C0C0C2614161E003C0C0C0616102C1026161C0C0C003E06121026184C0C0C0C043C043C063C0C0C0846161612161E081C0C0C0C0C0C0C0C0C0C0C0C081C083612161612261816161616161616161616161616161","loadword":"","tickword":"","jaye":{"y":2,"x":6},"gord-following":true,"moveword":"","objects":[{"x":3,"link":6,"func":"c4","linkword":"linkloop","name":"","y":10},{"x":5,"link":3,"func":"keypad2","linkword":"","name":"","y":10},{"x":5,"func":"door","linkword":"","name":"","y":11},{"x":11,"func":"door","linkword":"","name":"","y":9},{"x":13,"link":17,"func":"c9","linkword":"linkloop","name":"","y":6},{"x":9,"link":5,"func":"c8","linkword":"linkloop","name":"","y":6},{"link":23,"x":11,"y":4,"name":"","linkword":"","func":"switch"},{"x":3,"link":1,"func":"c3","linkword":"linkloop","name":"","y":7},{"x":3,"link":8,"func":"c2","linkword":"linkloop","name":"","y":4},{"x":3,"link":23,"func":"c1","linkword":"linkloop","name":"","y":2},{"x":4,"func":"door","linkword":"","name":"","y":2},{"x":4,"link":11,"func":"keypad1","linkword":"","name":"","y":3},{"x":4,"link":4,"func":"scan","linkword":"","name":"","y":1},{"x":17,"func":"door","linkword":"","name":"","y":2},{"x":17,"link":14,"func":"keypad3","linkword":"","name":"","y":3},{"x":19,"func":"rexx","linkword":"","name":"","y":2},{"x":19,"link":18,"func":"c5","linkword":"linkloop","name":"","y":4},{"x":19,"link":19,"func":"c6","linkword":"linkloop","name":"","y":7},{"x":19,"link":10,"func":"c7","linkword":"linkloop","name":"firewall","y":10},{"x":19,"link":19,"func":"switch","linkword":"","name":"","y":12},{"x":17,"link":22,"func":"keypad4","linkword":"","name":"","y":10},{"x":17,"func":"door","linkword":"","name":"","y":11},{"x":15,"link":9,"func":"cx","linkword":"linkloop","name":"","y":11},{"x":14,"link":25,"func":"scan","linkword":"","name":"","y":12},{"x":13,"linkentity":"","func":"exitdoor","linkword":"endgame","name":"","y":12}]} {"neut":{"y":1,"x":5},"map":"210261616161616161616161812261616161E1614161C2C081C0C0C0C0C0C0C0C0C0E0C081C0C0622161E04384C0C0C043C0C0C043C0C0C0848201612102616161C0C061610281026161C0C0616161612161C2C0C0C0C061E2C0C0C0A261C0C0C0C0E2612161E003C0C0C061C0C0C0C08261C0C0C003E06121026161C0C0C061E08282E2E061C0C0C06161612161C2C0C0C0C06103C0C0C02361C0C0C0C0C2614161E003C0C0C0616102C1026161C0C0C003E06121026184C0C0C0C043C043C063C0C0C0846161612161E081C0C0C0C0C0C0C0C0C0C0C0C081C083612161612261816161616161616161616161616161","loadword":"","tickword":"","jaye":{"y":2,"x":6},"gord-following":true,"moveword":"","objects":[{"link":6,"y":10,"func":"c4","name":"","linkword":"linkloop","x":3},{"link":3,"y":10,"func":"keypad2","name":"","linkword":"","x":5},{"x":5,"func":"door","y":11,"linkword":"","name":""},{"x":11,"func":"door","y":9,"linkword":"","name":""},{"link":17,"y":6,"func":"c9","name":"","linkword":"linkloop","x":13},{"link":5,"y":6,"func":"c8","name":"","linkword":"linkloop","x":9},{"x":11,"func":"switch","y":4,"linkword":"","name":"","link":23},{"link":1,"y":7,"func":"c3","name":"","linkword":"linkloop","x":3},{"link":8,"y":4,"func":"c2","name":"","linkword":"linkloop","x":3},{"link":23,"y":2,"func":"c1","name":"","linkword":"linkloop","x":3},{"x":4,"func":"door","y":2,"linkword":"","name":""},{"link":11,"y":3,"func":"keypad1","name":"","linkword":"","x":4},{"link":4,"y":1,"func":"scan","name":"","linkword":"","x":4},{"x":17,"func":"door","y":2,"linkword":"","name":""},{"link":14,"y":3,"func":"keypad3","name":"","linkword":"","x":17},{"x":19,"func":"rexx","y":2,"linkword":"","name":""},{"link":18,"y":4,"func":"c5","name":"","linkword":"linkloop","x":19},{"link":19,"y":7,"func":"c6","name":"","linkword":"linkloop","x":19},{"link":10,"y":10,"func":"c7","name":"firewall","linkword":"linkloop","x":19},{"link":19,"y":12,"func":"switch","name":"","linkword":"","x":19},{"link":22,"y":10,"func":"keypad4","name":"","linkword":"","x":17},{"x":17,"func":"door","y":11,"linkword":"","name":""},{"link":9,"y":11,"func":"cx","name":"","linkword":"linkloop","x":15},{"link":25,"y":12,"func":"scan","name":"","linkword":"","x":14},{"x":13,"linkentity":"","func":"exitdoor","y":12,"linkword":"endgame","name":""}]}

View file

@ -53,14 +53,16 @@
(fn encode-yx [xy] (fn encode-yx [xy]
(if xy (bit.bor (bit.lshift (- xy.y 1) 8) (- xy.x 1)) 0xffff)) (if xy (bit.bor (bit.lshift (- xy.y 1) 8) (- xy.x 1)) 0xffff))
(fn encode-itile [itile]
(bit.bor (bit.lshift (bit.band (- itile 1) 0x07) 5) (bit.rshift (bit.band (- itile 1) 0xf8) 3)))
(fn find-itile [tiles label ?itilenext] (fn find-itile [tiles label ?itilenext]
(local itile (or ?itilenext 1)) (local itile (or ?itilenext 1))
(local tile (. tiles itile)) (local tile (. tiles itile))
(assert (not= tile nil) (.. "No such tile " label)) (assert (not= tile nil) (.. "No such tile " label))
(if (= tile.label label) (if (= tile.label label) (encode-itile itile)
(bit.bor (bit.lshift (bit.band (- itile 1) 0x07) 5) (bit.rshift (bit.band (- itile 1) 0xf8) 3))
(find-itile tiles label (+ itile 1)))) (find-itile tiles label (+ itile 1))))
{: loadgfx : savegfx : appendtiles : appendgfx : flags : flag-to-bit : find-itile {: loadgfx : savegfx : appendtiles : appendgfx : flags : flag-to-bit : find-itile
: fn-tiles : fn-portraits : fn-font : encode-yx} : fn-tiles : fn-portraits : fn-font : encode-yx : encode-itile}