From 264ce5d269fc6515180f0eddf43bc06857fffb59 Mon Sep 17 00:00:00 2001 From: Jeremy Penner Date: Thu, 31 Dec 2020 11:49:52 -0500 Subject: [PATCH] Boss key --- game/bosskey.fnl | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ game/defs.fnl | 16 ++++++++---- game/gfx.fnl | 3 +++ game/init.fnl | 1 + game/player.fnl | 1 + 5 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 game/bosskey.fnl diff --git a/game/bosskey.fnl b/game/bosskey.fnl new file mode 100644 index 0000000..7888076 --- /dev/null +++ b/game/bosskey.fnl @@ -0,0 +1,64 @@ +(local util (require :lib.util)) +(local {: vm : prg : astr : style} (util.require :game.defs)) +(vm:word :boss-key :textmode :page2 (vm:until :read-key) :hires :page1) + +; if we upload to page 2 we don't have to worry about clobbering screen holes +(local textorg (prg:org 0x0800)) + +(fn padding [s w style] + (string.rep (astr " " style) (- w (length s)))) +(fn pad [s w style] + (.. s (padding s w style))) +(fn rpad [s w style] + (.. (padding s w style) s)) +(fn cellpad [s ?style] + (local textstyle (or ?style style.normal)) + (match (type s) + :nil (pad "" 9 textstyle) + :string (pad (astr s textstyle) 9 textstyle) + :number (rpad (astr (.. s " ") textstyle) 9 textstyle) + :table (cellpad (. s 1) (. s 2)))) +(fn cells [r a b c d] + (.. (rpad (.. r "") 3 style.inverse) + (cellpad a) (cellpad b) (cellpad c) (cellpad d))) + +(fn generate-boss-screen-lines [] + [(-> (astr "A16 (L) TOTAL" style.inverse) + (pad 38 style.inverse) + (.. (astr "C!" style.inverse))) + (.. (pad "" 38 style.inverse) (astr "24")) + "" + (cells "" [" A" style.inverse] [" B" style.inverse] [" C" style.inverse] [" D" style.inverse]) + (cells 1 "DEFINITEL" "Y REAL WO" "RK" "") + (cells 2 "(NOT PLAY" "ING COMPU" "TER GAMES" ")") + (cells 3) + (cells 4 "" "HAMMERS" "BILLS" "SANDWICH") + (cells 5 "JANUARY" 23 "$1" "CLUB") + (cells 6 "FEBRUARY" 121 "$2" "REUBEN") + (cells 7 "MARCH" 38 "$5" "BLT") + (cells 8 "SMARCH" 97 "$10" "HOT DOG") + (cells 9 "APRIL" 555 "$20" "I SAID IT") + (cells 10 "WEDNESDAY" 246 "$50" "EGG SALAD") + (cells 11 "KEYCODE" 1337 2757 9876) + (cells 12 "NUMBERS" 12345 "$100" "IF I HAD") + (cells 13 "LETTERS" "MARMOTS" "BENJAMIN" "100 I'D") + (cells 14 "SYMBOLS" "^!@#%&?" "$$$$$" "EAT THEM") + (cells 15) + (cells 16 ["TOTAL" style.inverse] "TOO MANY" ["* MAGIC *" style.flashing] "ALL@ONCE") + (cells 17) (cells 18) (cells 19) (cells 20)]) + +(fn splice [bytes offset str] + (.. (bytes:sub 1 offset) + str + (bytes:sub (+ (length str) offset 1)))) + +(fn bytes-from-lines [lines] + (var bytes (string.rep (astr " ") 0x400)) + (each [y line (ipairs lines)] + (local offset (+ (* (math.floor (/ (- y 1) 8)) 0x28) + (* (% (- y 1) 8) 0x80))) + (set bytes (splice bytes offset line))) + bytes) + +(textorg:append [:bytes (bytes-from-lines (generate-boss-screen-lines))]) + diff --git a/game/defs.fnl b/game/defs.fnl index 0caac57..5e862a6 100644 --- a/game/defs.fnl +++ b/game/defs.fnl @@ -34,11 +34,17 @@ :count 5 }) -(fn achar [c] (bit.bor (string.byte c) 0x80)) -(fn astr [s] +(local style { + :normal 0x80 + :inverse 0x00 + :flashing 0x40 +}) +(fn str-with-style [s stylebits] (-> [(string.byte s 1 -1)] - (lume.map #(bit.bor $1 0x80)) - (-> (table.unpack) (string.char)))) + (lume.map #(bit.bor (bit.band $1 0x3f) stylebits)) + (-> (table.unpack) (string.char)))) +(fn achar [c] (bit.bor (string.byte c) style.normal)) +(fn astr [s ?style] (str-with-style s (or ?style style.normal))) (fn rot8l [n] ; clears carry (local block [:block [:clc]]) @@ -118,5 +124,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 : say-runon : itile : controlstate} +{: vm : prg : mapw : maph : mon : org : achar : astr : style : rot8l : deflevel : say : say-runon : itile : controlstate} diff --git a/game/gfx.fnl b/game/gfx.fnl index f2f8116..3af7556 100644 --- a/game/gfx.fnl +++ b/game/gfx.fnl @@ -8,6 +8,9 @@ [:sta :0xc052]) (vm:def :mixed [:sta :0xc053]) +(vm:def :textmode [:sta :0xc051]) +(vm:def :page1 [:sta :0xc054]) +(vm:def :page2 [:sta :0xc055]) ; starting address: ; 0x2000 + (x*2) + (y%4 * 0x100) + ((y/4) * 0x28) diff --git a/game/init.fnl b/game/init.fnl index 22aabf6..eb0c0a8 100644 --- a/game/init.fnl +++ b/game/init.fnl @@ -8,6 +8,7 @@ (util.reload :game.map) (util.reload :game.entity) (util.reload :game.player) +(util.reload :game.bosskey) (tile.appendtiles org.tiles) (tile.appendgfx org.font (tile.loadgfx tile.fn-font)) diff --git a/game/player.fnl b/game/player.fnl index 928356a..3c1d120 100644 --- a/game/player.fnl +++ b/game/player.fnl @@ -157,6 +157,7 @@ (vm:ifchain [:dup (string.byte " ") :=] [:drop :toggle-player] [:dup (string.byte "Z") :=] [:drop :trigger-sidekick] + [:dup 2 :=] [:drop :boss-key] [:movement-dir :dup] [:player-yx :get :swap ; oldyx dir :try-move-player