Implement level 1 introduction

This commit is contained in:
Jeremy Penner 2021-02-10 23:26:08 -05:00
parent a30f8a2d8f
commit 51c5b9c6b7
5 changed files with 45 additions and 12 deletions

Binary file not shown.

View file

@ -4,7 +4,7 @@
(local lume (require :lib.lume)) (local lume (require :lib.lume))
(local {: mouse-inside : activate : active? : checkbox : textfield : textbutton} (util.require :editor.imstate)) (local {: mouse-inside : activate : active? : checkbox : textfield : textbutton} (util.require :editor.imstate))
(local {: tilestrip-to-sprite} (util.require :editor.tiledraw)) (local {: tilestrip-to-sprite} (util.require :editor.tiledraw))
(local {: encode-yx} (util.require :game.tiles)) (local {: encode-yx : encode-itile : decode-itile} (util.require :game.tiles))
(local MapEditView (GraphicsEditView:extend)) (local MapEditView (GraphicsEditView:extend))
(local sprite-scale 3) (local sprite-scale 3)
@ -26,10 +26,7 @@
(fn update-map [map mx my itile] (fn update-map [map mx my itile]
(local imap (imap-from-xy mx my)) (local imap (imap-from-xy mx my))
(local enctile (local enctile (encode-itile itile))
(bit.bor
(bit.lshift (bit.band (- itile 1) 0x07) 5)
(bit.rshift (bit.band (- itile 1) 0xf8) 3)))
(.. (..
(map:sub 1 imap) (map:sub 1 imap)
(string.char enctile) (string.char enctile)
@ -38,9 +35,7 @@
(fn MapEditView.itile-from-xy [self mx my] (fn MapEditView.itile-from-xy [self mx my]
(local imap (+ (imap-from-xy mx my) 1)) (local imap (+ (imap-from-xy mx my) 1))
(local enctile (string.byte (self.level.map:sub imap imap))) (local enctile (string.byte (self.level.map:sub imap imap)))
(+ 1 (bit.bor (decode-itile enctile))
(bit.lshift (bit.band enctile 0x1f) 3)
(bit.rshift (bit.band enctile 0xe0) 5))))
(fn MapEditView.set-tile [self mx my itile] (fn MapEditView.set-tile [self mx my itile]
(set self.level.map (update-map self.level.map mx my itile))) (set self.level.map (update-map self.level.map mx my itile)))

View file

@ -1,8 +1,39 @@
(local {: deflevel : say : itile : controlstate} (require :game.defs)) (local {: readjson} (require :lib.util))
(local {: deflevel : say : itile : controlstate : tilelist} (require :game.defs))
(local {: ev} (require :game.entity)) (local {: ev} (require :game.entity))
(local {: decode-itile : encode-yx} (require :game.tiles))
(local level (deflevel "game/map1.json" :level1)) (local level (deflevel "game/map1.json" :level1))
(local vm level.vm) (local vm level.vm)
(let [map (readjson "game/map1.json")
maptiles (map.map:fromhex)
furniture-yx []]
(for [ibyte 1 (length maptiles)]
(let [btile (maptiles:sub ibyte ibyte)
enctile (string.byte btile)
itile (+ (decode-itile enctile) 1)
mx (+ (% (- ibyte 1) 20) 1)
my (- 12 (math.floor (/ (- ibyte 1) 20)))]
(when (. tilelist itile :flags :debris)
(print mx my itile)
(table.insert furniture-yx (encode-yx {:x mx :y my})))))
(vm.code:append :furniture-yx)
(for [_ 1 10]
(let [ifurniture (math.random 1 (length furniture-yx))]
(vm.code:append [:dw (. furniture-yx ifurniture)])
(table.remove furniture-yx ifurniture))))
(vm:word :earthquake ; --
:full-redraw
:lit :furniture-yx
10 (vm:for :rnd :shl4 0x7ff :& :snooze
:dup :get :dup :itile-at 0x20 :+ :update-itile
:snd-explode
(vm:i) 9 := (vm:when (say :jaye "WOAH!") :hide-footer)
2 :+) :drop
0x1000 :snooze
(say :jaye "THAT WAS AN EARTHQUAKE!"))
(vm:word :firstdoor (vm:word :firstdoor
(vm:if-and [[:is-jaye?] [:dup ev.touch :=] [:responder-itile (itile :doorclosed) :=]] [ (vm:if-and [[:is-jaye?] [:dup ev.touch :=] [:responder-itile (itile :doorclosed) :=]] [
(say :jaye "IT WON'T OPEN!") (say :jaye "IT WON'T OPEN!")

View file

@ -1 +1 @@
{"loadword":"","map":"212121214121212121212121212141212121212161026161610261616102616161616102616161216143C0C0E2C0C0C0C0C0C0C081C0C0C0C0C0612161C0C0A282C0C0C0A2C0C0C061C0C0C0C0C2024161C0C0C0C0C0C0C0C0C2C0A2C1A2C0C0E082612161E2C08282C0C0C0C0A2C0C061616161616161216161616161C16181616161616143C0C0E282612161C0C0C0C0C0C0C0C0C0C0C061C0C0C0C0C0022161E08282A2C0C0C0C0E2C0C081C0C0C0C003612161E2C2C2C0C0C0C0C0C0C0C061C0C0C0C0C06141610303C063E2C0C0C0C0C0C061C0C0C023C061216161616161616161228161616161616161610221","jaye":{"y":9,"x":15},"tickword":"","moveword":"","objects":[{"x":8,"func":"door","name":"","linkword":"","y":6},{"link":3,"y":4,"func":"firstterm","name":"","linkword":"","x":2},{"link":2,"y":8,"func":"neutterm","name":"","linkword":"","x":17},{"link":8,"y":8,"func":"switch","name":"","linkword":"","x":13},{"x":9,"link":6,"func":"exitscanner","linkword":"","name":"","y":1},{"x":10,"linkentity":"level2","func":"exitdoor","y":1,"linkword":"exitlevel","name":""},{"x":6,"link":1,"func":"switch","linkword":"","name":"","y":6},{"x":13,"func":"firstdoor","linkword":"","name":"","y":10}]} {"loadword":"earthquake","map":"212121214121212121212121212141212121212161026161610261616102616161616102616161216143C0C0C2C0C0C0C0C0C0C081C0C0C0C0C0612161C0C08282C0C0C082C0C0C061C0C0C0C0C2024161C0C0C0C0C0C0C0C0C2C082C182C0C0E082612161C2C08282C0C0C0C082C0C061616161616161216161616161C16181616161616143C0C0C282612161C0C0C0C0C0C0C0C0C0C0C061C0C0C0C0C0022161E0828282C0C0C0C0C2C0C081C0C0C0C003612161C2C2C2C0C0C0C0C0C0C0C061C0C0C0C0C06141610303C043C2C0C0C0C0C0C061C0C0C003C061216161616161616161228161616161616161610221","jaye":{"y":9,"x":15},"tickword":"","moveword":"","objects":[{"x":8,"func":"door","linkword":"","name":"","y":6},{"x":2,"func":"firstterm","y":4,"name":"","linkword":"","link":3},{"x":17,"func":"neutterm","y":8,"name":"","linkword":"","link":2},{"x":13,"func":"switch","y":8,"name":"","linkword":"","link":8},{"link":6,"x":9,"y":1,"linkword":"","name":"","func":"exitscanner"},{"x":10,"linkentity":"level2","func":"exitdoor","y":1,"name":"","linkword":"exitlevel"},{"link":1,"x":6,"y":6,"linkword":"","name":"","func":"switch"},{"x":13,"func":"firstdoor","name":"","linkword":"","y":10}]}

View file

@ -54,7 +54,14 @@
(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] (fn encode-itile [itile]
(bit.bor (bit.lshift (bit.band (- itile 1) 0x07) 5) (bit.rshift (bit.band (- itile 1) 0xf8) 3))) (bit.bor
(bit.lshift (bit.band (- itile 1) 0x07) 5)
(bit.rshift (bit.band (- itile 1) 0xf8) 3)))
(fn decode-itile [enctile]
(+ 1 (bit.bor
(bit.lshift (bit.band enctile 0x1f) 3)
(bit.rshift (bit.band enctile 0xe0) 5))))
(fn find-itile [tiles label ?itilenext] (fn find-itile [tiles label ?itilenext]
(local itile (or ?itilenext 1)) (local itile (or ?itilenext 1))
@ -64,5 +71,5 @@
(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 : encode-itile} : fn-tiles : fn-portraits : fn-font : encode-yx : encode-itile : decode-itile}