From cbc63cd8fd8344741ae71aaa3c429373cc9a8189 Mon Sep 17 00:00:00 2001 From: Jeremy Penner Date: Wed, 2 Dec 2020 20:08:10 -0500 Subject: [PATCH] starting locations, fix level 1 --- editor/mapedit.fnl | 18 +++++++++++++++++- game/defs.fnl | 9 ++++++++- game/init.fnl | 18 ++++++++---------- game/level1.fnl | 6 ++++-- game/map1.json | 2 +- game/map2.json | 2 +- game/map3.json | 2 +- game/tiles.fnl | 9 ++++++++- 8 files changed, 48 insertions(+), 18 deletions(-) diff --git a/editor/mapedit.fnl b/editor/mapedit.fnl index 3e4311a..42777e7 100644 --- a/editor/mapedit.fnl +++ b/editor/mapedit.fnl @@ -102,6 +102,11 @@ (local tilex (+ x (* (- mx 1) tilew))) (local itile (self:itile-from-xy mx my)) (local iobject (self:iobject-from-xy mx my)) + (when (= self.itile nil) + (each [_ player (ipairs [:jaye :neut])] + (match (. self.level player) + {:x mx :y my} (renderer.draw_text style.font player tilex tiley style.text))) + (love.graphics.setColor 1 1 1)) (when (and (not= iobject nil) (= self.itile nil)) (love.graphics.setColor 1 0 (if (and (= self.itile nil) (= iobject self.iobject)) 1 0)) (love.graphics.setLineWidth 3) @@ -121,6 +126,10 @@ (not= self.iobject-linking nil) (tset (self:linking-obj) :link iobject) + (not= self.playerpos nil) + (do (tset self.level self.playerpos {:x mx :y my}) + (set self.playerpos nil)) + (= iobject nil) (let [tile (self.tilecache:tile itile)] (table.insert self.level.objects {:x mx :y my :func (or tile.word "")}) @@ -170,8 +179,15 @@ (self:draw-object-editor (+ x (* tilew mapw) 10) y)) (set y (+ y (* tileh maph) 10)) (when (checkbox self "Edit objects" (= self.itile nil) x y) - (set self.itile nil)) + (set self.itile nil) + (set self.playerpos nil)) (set y (+ y 30)) + (each [_ player (ipairs [:jaye :neut])] + (when (checkbox self (.. "Position " player) (and (= self.itile nil) (= self.playerpos player)) x y) + (set self.itile nil) + (set self.playerpos player)) + (set y (+ y 30))) + (self:draw-tile-selector x y (- self.size.x 20))) (fn MapEditView.get_name [self] (.. "Map: " self.mapfilename)) diff --git a/game/defs.fnl b/game/defs.fnl index 95561b6..87db9a2 100644 --- a/game/defs.fnl +++ b/game/defs.fnl @@ -24,6 +24,13 @@ :code vm.code }) +(local controlstate { + :jaye 0 + :neut 1 + :rexx 2 + :count 3 +}) + (fn achar [c] (bit.bor (string.byte c) 0x80)) (fn astr [s] (-> [(string.byte s 1 -1)] @@ -103,5 +110,5 @@ (let [tilelist (tiles.loadgfx tiles.fn-tiles)] (fn [label] (tiles.find-itile tilelist label)))) -{: vm : prg : mapw : maph : mon : org : achar : astr : rot8l : deflevel : say : itile} +{: vm : prg : mapw : maph : mon : org : achar : astr : rot8l : deflevel : say : itile : controlstate} diff --git a/game/init.fnl b/game/init.fnl index 3e44f81..37d8eb2 100644 --- a/game/init.fnl +++ b/game/init.fnl @@ -2,7 +2,7 @@ (local {: lo : hi : readjson} util) (local lume (require :lib.lume)) (local tile (util.reload :game.tiles)) -(local {: prg : vm : org : mapw : maph : itile} (util.reload :game.defs)) +(local {: prg : vm : org : mapw : maph : itile : controlstate} (util.reload :game.defs)) (util.reload :game.gfx) (util.reload :game.footer) @@ -32,13 +32,6 @@ (vm:var :neut-yx 0x0b08) (vm:var :rexx-yx 0xffff) -(local controlstate { - :jaye 0 - :neut 1 - :rexx 2 - :count 3 -}) - (vm:var :controlstate [:db controlstate.jaye]) (vm:word :is-jaye? :controlstate :bget controlstate.jaye :=) (vm:word :is-neut? :controlstate :bget controlstate.neut :=) @@ -132,14 +125,19 @@ ; 20x12 means full map is 240 bytes - we have an extra 16 bytes at the end to mess with? (vm:word :handle-key :read-key :player-key :hide-footer) +(vm:word :load-level + :lit :map-jaye-yx :get :jaye-yx :set + :lit :map-neut-yx :get :neut-yx :set + 0xffff :rexx-yx :set + :full-redraw) (vm.code:append :main [:jsr :reset] [:jsr :interpret] [:vm :hires - :full-redraw + :load-level (vm:forever - (vm:hotswap-sync :full-redraw) + (vm:hotswap-sync :load-level) :interactive-eval-checkpoint :handle-key ) diff --git a/game/level1.fnl b/game/level1.fnl index bc6133e..769835e 100644 --- a/game/level1.fnl +++ b/game/level1.fnl @@ -1,4 +1,4 @@ -(local {: deflevel : say : itile} (require :game.defs)) +(local {: deflevel : say : itile : controlstate} (require :game.defs)) (local {: ev} (require :game.entity)) (local level (deflevel "game/map1.json")) (local vm level.vm) @@ -12,7 +12,9 @@ (vm:if-and [[:is-jaye?] [:dup ev.touch :=]] [ :neut-hidden? (vm:if [ (say :jaye "MAYBE NEUT CAN HELP.") - :get-responder :get :dup :neut-yx :set :draw-neut-yx + controlstate.neut :controlstate :bset + :move-to-responder + controlstate.jaye :controlstate :bset (say :neut "NEUT V0.71.4RC12 ONLINE" "" "PRESS SPACE TO TAKE CONTROL") ] [ (say :jaye "NEUT IS RUNNING NOW." "I CAN HIT THE SPACE BAR" "TO CONTROL THEM.") diff --git a/game/map1.json b/game/map1.json index 544b615..74c2b6b 100644 --- a/game/map1.json +++ b/game/map1.json @@ -1 +1 @@ -{"map":"212121214121212121212121212141212121212161026161610261616102616161616102616161216143C0C0E2C0C0C0C0C0C0C081C0C0C0C0C0612161C0C0A282C0C0C0A2C0C0C061C0C0C0C0C2024161C0C0C0C0C0C0C0C0C2C0A2C1A2C0C0E082612161E2C08282C0C0C0C0A2C0C061616161616161216161616161C16181616161616143C0C0E282612161C0C0C0C0C0C0C0C0C0C0C061C0C0C0C0C0022161E08282A2C0C0C0C0E2C0C081C0C0C0C003612161E2C2C2C0C0C0C0C0C0C0C061C0C0C0C0C06141610303C063E2C0C0C0C0C0C061C0C0C023C061216161616161616161228161616161616161610221","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},{"link":6,"linkword":"","func":"exitscanner","x":9,"name":"","y":1},{"x":10,"func":"door","y":1,"linkword":"","name":""},{"x":6,"link":1,"func":"switch","linkword":"","name":"","y":6},{"x":13,"func":"firstdoor","linkword":"","name":"","y":10}]} \ No newline at end of file +{"jaye":{"y":9,"x":15},"objects":[{"x":8,"func":"door","y":6,"name":"","linkword":""},{"link":3,"x":2,"y":4,"linkword":"","name":"","func":"firstterm"},{"link":2,"x":17,"y":8,"linkword":"","name":"","func":"neutterm"},{"link":8,"x":13,"y":8,"linkword":"","name":"","func":"switch"},{"link":6,"y":1,"func":"exitscanner","name":"","linkword":"","x":9},{"x":10,"func":"door","name":"","linkword":"","y":1},{"link":1,"y":6,"func":"switch","name":"","linkword":"","x":6},{"x":13,"func":"firstdoor","y":10,"linkword":"","name":""}],"map":"212121214121212121212121212141212121212161026161610261616102616161616102616161216143C0C0E2C0C0C0C0C0C0C081C0C0C0C0C0612161C0C0A282C0C0C0A2C0C0C061C0C0C0C0C2024161C0C0C0C0C0C0C0C0C2C0A2C1A2C0C0E082612161E2C08282C0C0C0C0A2C0C061616161616161216161616161C16181616161616143C0C0E282612161C0C0C0C0C0C0C0C0C0C0C061C0C0C0C0C0022161E08282A2C0C0C0C0E2C0C081C0C0C0C003612161E2C2C2C0C0C0C0C0C0C0C061C0C0C0C0C06141610303C063E2C0C0C0C0C0C061C0C0C023C061216161616161616161228161616161616161610221"} \ No newline at end of file diff --git a/game/map2.json b/game/map2.json index 409b21b..7dc3e2f 100644 --- a/game/map2.json +++ b/game/map2.json @@ -1 +1 @@ -{"map":"616161616161626161618161616161616161612161C0C0C06361C0C0E0C0C0C0C0C06103C0C0022161E0C0C0C081C0C0C0C0C0C0C0C081C0C0E0614161C0C0C0C06143C0C0C0C0C0C04322C0C0C0222161C0C0C0C061618161616161816161C0C0C00221616181616161C0C0C06143C0C0C061618161612161C0C0C06361E0C0C061C0C0C0C0C1E0C003612122C0C0C0C061C0C0C061C0E0C0C061C0C0C0022161C0C0C0C061616161616261616161C0C0C061416101C0C0C081C0C0E061C0C0E0C081C0C0C0022162C0C0C02361E0C0C06143C0C0C061E2A2E061216161C1616261612281616122226162C1C1616121","objects":[{"x":9,"link":2,"func":"term","linkword":"","name":"","y":11},{"x":2,"link":6,"func":"term","linkword":"","name":"","y":3},{"x":6,"func":"door","linkword":"","name":"","y":10},{"x":1,"link":5,"func":"scan","linkword":"","name":"","y":5},{"x":8,"func":"door","linkword":"","name":"","y":8},{"x":7,"link":2,"func":"term","linkword":"","name":"","y":6},{"x":12,"link":8,"func":"scan","linkword":"","name":"","y":1},{"x":17,"func":"door","linkword":"","name":"","y":7},{"x":13,"link":10,"func":"scan","linkword":"","name":"","y":1},{"x":13,"func":"door","linkword":"","name":"","y":8},{"x":15,"link":12,"func":"switch","linkword":"","name":"","y":6},{"x":2,"link":13,"func":"term","linkword":"","name":"","y":10},{"x":12,"link":12,"func":"term","linkword":"","name":"","y":5},{"x":15,"link":15,"func":"scan","linkword":"","name":"","y":9},{"x":15,"func":"door","linkword":"","name":"","y":10},{"x":16,"link":17,"func":"term","linkword":"","name":"","y":6},{"x":18,"link":16,"func":"term","linkword":"","name":"","y":10},{"x":15,"func":"door","linkword":"","name":"","y":3},{"x":19,"link":18,"func":"scan","linkword":"","name":"","y":9},{"x":13,"link":21,"func":"term","linkword":"","name":"","y":3},{"x":18,"link":20,"func":"term","linkword":"","name":"","y":2},{"x":8,"link":23,"func":"scan","linkword":"","name":"","y":1},{"x":9,"func":"door","linkword":"","name":"","y":1},{"x":16,"link":3,"func":"switch","linkword":"","name":"","y":1},{"x":3,"link":26,"func":"switch","linkword":"","name":"","y":1},{"x":6,"func":"door","linkword":"","name":"","y":3},{"x":9,"link":28,"func":"term","linkword":"","name":"","y":3},{"x":7,"link":27,"func":"term","linkword":"","name":"","y":2},{"x":3,"func":"door","linkword":"","name":"","y":7},{"x":17,"link":29,"func":"switch","linkword":"","name":"","y":1}]} \ No newline at end of file +{"jaye":{"y":11,"x":11},"objects":[{"link":2,"y":11,"func":"term","name":"","linkword":"","x":9},{"link":6,"y":3,"func":"term","name":"","linkword":"","x":2},{"x":6,"func":"door","y":10,"linkword":"","name":""},{"link":5,"y":5,"func":"scan","name":"","linkword":"","x":1},{"x":8,"func":"door","y":8,"linkword":"","name":""},{"link":2,"y":6,"func":"term","name":"","linkword":"","x":7},{"link":8,"y":1,"func":"scan","name":"","linkword":"","x":12},{"x":17,"func":"door","y":7,"linkword":"","name":""},{"link":10,"y":1,"func":"scan","name":"","linkword":"","x":13},{"x":13,"func":"door","y":8,"linkword":"","name":""},{"link":12,"y":6,"func":"switch","name":"","linkword":"","x":15},{"link":13,"y":10,"func":"term","name":"","linkword":"","x":2},{"link":12,"y":5,"func":"term","name":"","linkword":"","x":12},{"link":15,"y":9,"func":"scan","name":"","linkword":"","x":15},{"x":15,"func":"door","y":10,"linkword":"","name":""},{"link":17,"y":6,"func":"term","name":"","linkword":"","x":16},{"link":16,"y":10,"func":"term","name":"","linkword":"","x":18},{"x":15,"func":"door","y":3,"linkword":"","name":""},{"link":18,"y":9,"func":"scan","name":"","linkword":"","x":19},{"link":21,"y":3,"func":"term","name":"","linkword":"","x":13},{"link":20,"y":2,"func":"term","name":"","linkword":"","x":18},{"link":23,"y":1,"func":"scan","name":"","linkword":"","x":8},{"x":9,"func":"door","y":1,"linkword":"","name":""},{"link":3,"y":1,"func":"switch","name":"","linkword":"","x":16},{"link":26,"y":1,"func":"switch","name":"","linkword":"","x":3},{"x":6,"func":"door","y":3,"linkword":"","name":""},{"link":28,"y":3,"func":"term","name":"","linkword":"","x":9},{"link":27,"y":2,"func":"term","name":"","linkword":"","x":7},{"x":3,"func":"door","y":7,"linkword":"","name":""},{"link":29,"y":1,"func":"switch","name":"","linkword":"","x":17}],"neut":{"y":12,"x":10},"map":"616161616161626161618161616161616161612161C0C0C06361C0C0E0C0C0C0C0C06103C0C0022161E0C0C0C081C0C0C0C0C0C0C0C081C0C0E0614161C0C0C0C06143C0C0C0C0C0C04322C0C0C0222161C0C0C0C061618161616161816161C0C0C00221616181616161C0C0C06143C0C0C061618161612161C0C0C06361E0C0C061C0C0C0C0C1E0C003612122C0C0C0C061C0C0C061C0E0C0C061C0C0C0022161C0C0C0C061616161616261616161C0C0C061416101C0C0C081C0C0E061C0C0E0C081C0C0C0022162C0C0C02361E0C0C06143C0C0C061E2A2E061216161C1616261612281616122226162C1C1616121"} \ No newline at end of file diff --git a/game/map3.json b/game/map3.json index dc856bf..88d1889 100644 --- a/game/map3.json +++ b/game/map3.json @@ -1 +1 @@ -{"map":"616161616161616181616161616161616161612161C063C0C0C0C0C0C0836143C0E0C2C0C043022161C0C0C0C0C0C0C0C0C022C0C0C0C0C0C0C0612161C0C0C2C0C0C0C0C0C081C0C0C0C0C0C0C0612161C08282A2C0C0C0C0436123C0C0C0C0C0030221616161616161616261616161618161616161612161C063C0C02301C0C163C0C0C0C0C0822363022122C0C0C0C0C0C0A2A1C0C0C0C0C0C0C2C0C0612181C0C0C0C0E2C0C061C0C0C0C0C0C0C0C2C061216123C0C0C0C083C061E0C2C0C0C0C0438203022161610261610261616161026161026161026161212121212121212121212121212121212121212121","objects":[{"link":2,"x":1,"y":5,"linkword":"","name":"","func":"scan"},{"x":1,"func":"door","name":"","linkword":"","y":4},{"link":4,"x":7,"y":6,"linkword":"","name":"","func":"term"},{"link":7,"x":14,"y":11,"linkword":"","name":"","func":"term"},{"link":6,"x":9,"y":6,"linkword":"","name":"","func":"switch"},{"x":11,"func":"door","name":"","linkword":"","y":9},{"link":3,"x":10,"y":3,"linkword":"","name":"","func":"term"},{"link":9,"x":11,"y":10,"linkword":"","name":"","func":"scan"},{"x":14,"func":"door","name":"","linkword":"","y":7},{"x":10,"func":"rexx","linkword":"","name":"","y":11}]} \ No newline at end of file +{"jaye":{"y":11,"x":9},"objects":[{"x":1,"func":"scan","y":5,"name":"","linkword":"","link":2},{"x":1,"func":"door","y":4,"name":"","linkword":""},{"x":7,"func":"term","y":6,"name":"","linkword":"","link":4},{"x":14,"func":"term","y":11,"name":"","linkword":"","link":7},{"x":9,"func":"switch","y":6,"name":"","linkword":"","link":6},{"x":11,"func":"door","y":9,"name":"","linkword":""},{"x":10,"func":"term","y":3,"name":"","linkword":"","link":3},{"x":11,"func":"scan","y":10,"name":"","linkword":"","link":9},{"x":14,"func":"door","y":7,"name":"","linkword":""},{"x":7,"func":"rexx","linkword":"","name":"","y":3}],"neut":{"y":12,"x":8},"map":"616161616161616181616161616161616161612161C063C0C0C0C0C0C0C06143C0E0C2C0C043022161C0C0C0C0C0C0C0C0C022C0C0C0C0C0C0C0612161C0C0C2C0C0C0C0C0C081C0C0C0C0C0C0C0612161C08282A2C0C0C0C0436123C0C0C0C0C0030221616161616161616261616161618161616161612161C063C0C02301C0C163C0C0C0C0C0822363022122C0C0C0C0C0C0A2A1C0C0C0C0C0C0C2C0C0612181C0C0C0C0E2C0C061C0C0C0C0C0C0C0C2C061216123C0C0C0C083C061E0C2C0C0C0C0438203022161610261610261616161026161026161026161212121212121212121212121212121212121212121"} \ No newline at end of file diff --git a/game/tiles.fnl b/game/tiles.fnl index c4954cc..5c03642 100644 --- a/game/tiles.fnl +++ b/game/tiles.fnl @@ -36,8 +36,15 @@ (set flags (bit.bor flags (. flag-to-bit flag)))) (org:append [:db flags]))) +(fn encode-yx [xy] + (if xy (bit.bor (bit.lshift (- xy.y 1) 8) (- xy.x 1)) 0xffff)) + (fn append-map [map org] - (org:append :map [:bytes (map.map:fromhex)] :map-entity-count [:db (length map.objects)])) + (org:append + :map [:bytes (map.map:fromhex)] + :map-entity-count [:db (length map.objects)] + :map-jaye-yx [:dw (encode-yx map.jaye)] + :map-neut-yx [:dw (encode-yx map.neut)])) (fn find-itile [tiles label ?itilenext] (local itile (or ?itilenext 1))