2020-11-27 02:34:05 +00:00
|
|
|
(local util (require :lib.util))
|
|
|
|
(local {: lo : hi : readjson} util)
|
2020-10-15 03:40:01 +00:00
|
|
|
(local lume (require :lib.lume))
|
2020-11-27 04:33:14 +00:00
|
|
|
(local tile (util.reload :game.tiles))
|
2020-11-27 04:46:36 +00:00
|
|
|
(local {: prg : vm : org : mapw : maph} (util.reload :game.defs))
|
|
|
|
|
2020-11-27 04:33:14 +00:00
|
|
|
(util.reload :game.gfx)
|
2020-11-29 05:44:23 +00:00
|
|
|
(util.reload :game.footer)
|
2020-11-27 04:33:14 +00:00
|
|
|
(util.reload :game.map)
|
|
|
|
(util.reload :game.entity)
|
2020-11-15 02:55:50 +00:00
|
|
|
|
2020-11-29 05:44:23 +00:00
|
|
|
(local {: walkable : neutable} tile.flag-to-bit)
|
2020-11-15 02:55:50 +00:00
|
|
|
|
|
|
|
(vm:word :movement-dir ; key -- dyx
|
|
|
|
(vm:case [(string.byte "I") 0xff00]
|
|
|
|
[(string.byte "J") 0x00ff]
|
|
|
|
[(string.byte "K") 0x0001]
|
|
|
|
[(string.byte "M") 0x0100]
|
|
|
|
[:else 0x0000]))
|
|
|
|
|
|
|
|
(vm:def :yx+ ; yx yx -- yx
|
|
|
|
[:lda vm.TOP :x]
|
|
|
|
[:clc] [:adc vm.ST1 :x]
|
|
|
|
[:sta vm.ST1 :x]
|
|
|
|
[:lda vm.TOPH :x]
|
|
|
|
[:clc] [:adc vm.ST1H :x]
|
|
|
|
[:sta vm.ST1H :x]
|
|
|
|
(vm:drop))
|
|
|
|
|
2020-11-29 05:44:23 +00:00
|
|
|
(vm:var :jaye-yx 0x080f)
|
2020-11-15 02:55:50 +00:00
|
|
|
(vm:var :jaye-dir 0xff00)
|
2020-11-29 05:44:23 +00:00
|
|
|
(vm:var :neut-yx 0xffff)
|
|
|
|
(local controlstate {
|
|
|
|
:jaye 0
|
|
|
|
:neut 1
|
|
|
|
})
|
|
|
|
(vm:var :controlstate [:db controlstate.jaye])
|
|
|
|
(vm:word :is-jaye? :controlstate :bget controlstate.jaye :=)
|
|
|
|
(vm:word :is-neut? :controlstate :bget controlstate.neut :=)
|
|
|
|
(vm:word :neut-hidden? :neut-yx :get 0xffff :=)
|
2020-11-15 02:55:50 +00:00
|
|
|
|
|
|
|
(vm:word :jaye-tile ; ptile
|
|
|
|
:jaye-dir :get
|
|
|
|
(vm:case [0xff00 :lit :jaye-n]
|
|
|
|
[0x0100 :lit :jaye-s]
|
|
|
|
[0x00ff :lit :jaye-w]
|
|
|
|
[:else :lit :jaye-e]))
|
|
|
|
|
|
|
|
(vm:word :draw-jaye-yx ; yx --
|
|
|
|
:yx>screen :jaye-tile :drawtile)
|
|
|
|
|
2020-11-29 05:44:23 +00:00
|
|
|
(vm:word :move-jaye-to ; yx --
|
2020-11-27 02:34:05 +00:00
|
|
|
:jaye-yx :get :drawtile-at
|
2020-11-29 05:44:23 +00:00
|
|
|
:dup :jaye-yx :set :draw-jaye-yx)
|
|
|
|
|
|
|
|
(vm:word :neut-tile :lit :neut1) ; todo: animate
|
|
|
|
|
|
|
|
(vm:word :draw-neut-yx ; yx --
|
|
|
|
:yx>screen :neut-tile :drawtile)
|
2020-11-27 02:34:05 +00:00
|
|
|
|
2020-11-29 05:44:23 +00:00
|
|
|
(vm:word :move-neut-to ; yx --
|
|
|
|
:neut-yx :get :drawtile-at
|
|
|
|
:dup :neut-yx :set :draw-neut-yx)
|
2020-11-16 16:09:14 +00:00
|
|
|
|
2020-11-29 05:44:23 +00:00
|
|
|
(vm:word :move-jaye ; --
|
|
|
|
:jaye-dir :get :jaye-yx :get :yx+ :move-jaye-to)
|
|
|
|
|
|
|
|
(vm:word :flag-at? ; yx flag -- f
|
|
|
|
:swap :itile-at :lookup-flags :&)
|
|
|
|
|
|
|
|
(vm:word :try-move-jaye ; dir --
|
|
|
|
:dup :jaye-dir :set ; dir
|
|
|
|
:jaye-yx :get ; dir yx
|
|
|
|
:yx+ ; yxnew
|
|
|
|
(vm:if-or [[:dup :touch-entity] [:dup walkable :flag-at? :not]]
|
|
|
|
[:drop :jaye-yx :get])
|
|
|
|
; always "move" so that jaye visibly changes direction
|
|
|
|
; touch-entity can modify jaye-yx so we have to refetch
|
|
|
|
:move-jaye-to)
|
|
|
|
|
|
|
|
(vm:word :try-move-neut ; dir --
|
|
|
|
:neut-yx :get :yx+
|
|
|
|
(vm:if-and [[:dup :touch-entity :not] [:dup neutable :flag-at?]]
|
|
|
|
[:move-neut-to] [:drop]))
|
|
|
|
|
|
|
|
(vm:word :swap-player :neut-hidden? :not :is-jaye? :& (vm:if [controlstate.neut] [controlstate.jaye]) :controlstate :bset)
|
|
|
|
|
|
|
|
(vm:word :player-key ; key --
|
|
|
|
(vm:ifchain
|
|
|
|
[:dup (string.byte " ") :=] [:drop :swap-player]
|
|
|
|
[:movement-dir :dup] [:is-jaye? (vm:if [:try-move-jaye] [:try-move-neut])]
|
|
|
|
[:drop]))
|
2020-11-15 02:55:50 +00:00
|
|
|
|
2020-11-22 19:24:46 +00:00
|
|
|
(vm:word :full-redraw :drawmap :object-redraw)
|
|
|
|
(vm:word :object-redraw :jaye-yx :get :draw-jaye-yx)
|
2020-11-22 03:50:11 +00:00
|
|
|
|
2020-11-27 04:33:14 +00:00
|
|
|
(tile.appendtiles org.tiles)
|
|
|
|
(tile.appendgfx org.font (tile.loadgfx tile.fn-font))
|
2020-10-15 03:40:01 +00:00
|
|
|
|
|
|
|
; thought:
|
|
|
|
; hotswap-safe debug stub at root of call stack
|
|
|
|
; but REPL debug stub should be very available as a task
|
2020-10-12 15:48:14 +00:00
|
|
|
|
2020-10-19 00:13:26 +00:00
|
|
|
; 20x12 means full map is 240 bytes - we have an extra 16 bytes at the end to mess with?
|
2020-11-29 05:44:23 +00:00
|
|
|
(vm:word :handle-key :read-key :player-key :hide-footer)
|
2020-11-23 00:44:56 +00:00
|
|
|
|
2020-11-27 04:33:14 +00:00
|
|
|
(vm.code:append :main
|
2020-10-06 03:47:25 +00:00
|
|
|
[:jsr :reset]
|
|
|
|
[:jsr :interpret]
|
2020-11-15 02:55:50 +00:00
|
|
|
[:vm :hires
|
|
|
|
:full-redraw
|
2020-10-15 03:40:01 +00:00
|
|
|
(vm:forever
|
2020-11-16 16:27:34 +00:00
|
|
|
(vm:hotswap-sync :full-redraw)
|
2020-11-17 20:35:41 +00:00
|
|
|
:interactive-eval-checkpoint
|
2020-11-16 16:27:34 +00:00
|
|
|
:handle-key
|
2020-10-15 03:40:01 +00:00
|
|
|
)
|
2020-10-06 03:47:25 +00:00
|
|
|
:quit])
|
|
|
|
|
2020-11-27 04:33:14 +00:00
|
|
|
(util.reload :game.level1)
|
|
|
|
|
2020-10-06 03:47:25 +00:00
|
|
|
(prg:assemble)
|
2020-11-02 00:39:31 +00:00
|
|
|
|