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-12-02 22:19:23 +00:00
|
|
|
(local {: prg : vm : org : mapw : maph : itile} (util.reload :game.defs))
|
2020-11-27 04:46:36 +00:00
|
|
|
|
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-12-02 22:19:23 +00:00
|
|
|
(local {: walkable : neutable : debris} 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-12-02 13:33:27 +00:00
|
|
|
(vm:var :jaye-yx 0x0a0a)
|
2020-11-15 02:55:50 +00:00
|
|
|
(vm:var :jaye-dir 0xff00)
|
2020-12-02 13:33:27 +00:00
|
|
|
(vm:var :neut-yx 0x0b08)
|
2020-12-02 22:19:23 +00:00
|
|
|
(vm:var :rexx-yx 0xffff)
|
2020-12-02 13:33:27 +00:00
|
|
|
|
2020-11-29 05:44:23 +00:00
|
|
|
(local controlstate {
|
|
|
|
:jaye 0
|
|
|
|
:neut 1
|
2020-12-02 13:33:27 +00:00
|
|
|
:rexx 2
|
|
|
|
:count 3
|
2020-11-29 05:44:23 +00:00
|
|
|
})
|
2020-12-02 13:33:27 +00:00
|
|
|
|
2020-11-29 05:44:23 +00:00
|
|
|
(vm:var :controlstate [:db controlstate.jaye])
|
|
|
|
(vm:word :is-jaye? :controlstate :bget controlstate.jaye :=)
|
|
|
|
(vm:word :is-neut? :controlstate :bget controlstate.neut :=)
|
2020-12-02 13:33:27 +00:00
|
|
|
(vm:word :is-rexx? :controlstate :bget controlstate.rexx :=)
|
|
|
|
(vm:word :is-prog? :is-neut? :is-rexx? :|)
|
2020-11-29 05:44:23 +00:00
|
|
|
(vm:word :neut-hidden? :neut-yx :get 0xffff :=)
|
2020-12-02 22:19:23 +00:00
|
|
|
(vm:word :rexx-active? :rexx-yx :get 0xffff := :not)
|
|
|
|
|
|
|
|
(vm:word :set-rexx ; e --
|
|
|
|
:dup (vm:if [:get controlstate.rexx] [:drop 0xffff controlstate.neut])
|
|
|
|
:controlstate :bset :rexx-yx :set)
|
2020-11-15 02:55:50 +00:00
|
|
|
|
2020-12-02 13:33:27 +00:00
|
|
|
(vm:word :player-tile ; -- ptile
|
|
|
|
:controlstate :bget
|
|
|
|
(vm:case [controlstate.jaye :jaye-tile]
|
|
|
|
[controlstate.neut :neut-tile]
|
|
|
|
[:else :lit :t-rexx]))
|
|
|
|
|
|
|
|
(vm:word :player-yx ; -- pyx
|
|
|
|
:controlstate :bget
|
|
|
|
(vm:case [controlstate.jaye :jaye-yx]
|
|
|
|
[controlstate.neut :neut-yx]
|
2020-12-02 22:19:23 +00:00
|
|
|
[:else :rexx-yx]))
|
2020-12-02 13:33:27 +00:00
|
|
|
|
|
|
|
(vm:word :draw-player ; --
|
|
|
|
:player-yx :dup (vm:if [:get :dup 0xffff := (vm:if [:drop] [:yx>screen :player-tile :drawtile])] [:drop]))
|
|
|
|
|
|
|
|
(vm:word :set-player-dir ; dir --
|
|
|
|
:is-jaye? (vm:if [:jaye-dir :set] [:drop]))
|
|
|
|
|
|
|
|
(vm:word :movable-player-flag ; -- flag
|
|
|
|
:is-neut? (vm:if [neutable] [walkable]))
|
|
|
|
|
|
|
|
(vm:word :move-player-to ; yx --
|
2020-12-02 22:19:23 +00:00
|
|
|
:player-yx :dup :get :dup 0xffff := (vm:if [:drop] [:drawtile-at])
|
2020-12-02 13:33:27 +00:00
|
|
|
:set :draw-player)
|
|
|
|
|
2020-12-02 22:19:23 +00:00
|
|
|
(vm:word :handle-special-move ; yx --
|
|
|
|
(vm:if-and [[:is-rexx?] [:dup debris :flag-at?]]
|
|
|
|
[(itile :t-floor) :update-itile vm.false]
|
|
|
|
[:drop vm.false]))
|
|
|
|
|
2020-12-02 13:33:27 +00:00
|
|
|
(vm:word :try-move-player ; dir --
|
|
|
|
:dup :set-player-dir ; dir
|
|
|
|
:player-yx :get :yx+ ; yxnew
|
2020-12-02 22:19:23 +00:00
|
|
|
(vm:if-or [[:dup :touch-entity] [:dup :handle-special-move] [:dup :movable-player-flag :flag-at? :not]]
|
2020-12-02 13:33:27 +00:00
|
|
|
[:drop :player-yx :get])
|
|
|
|
; always "move" so that player can visibly change direction
|
|
|
|
; touch-entity can modify player-yx so we have to refetch
|
|
|
|
:move-player-to)
|
|
|
|
|
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]))
|
|
|
|
|
2020-11-29 05:44:23 +00:00
|
|
|
(vm:word :neut-tile :lit :neut1) ; todo: animate
|
|
|
|
|
|
|
|
(vm:word :flag-at? ; yx flag -- f
|
|
|
|
:swap :itile-at :lookup-flags :&)
|
|
|
|
|
2020-12-02 22:19:23 +00:00
|
|
|
(vm:word :toggle-player
|
|
|
|
(vm:ifchain [:is-prog?] [controlstate.jaye]
|
|
|
|
[:rexx-active?] [controlstate.rexx]
|
|
|
|
[:neut-hidden?] [controlstate.jaye]
|
|
|
|
[controlstate.neut]) :controlstate :bset)
|
2020-11-29 05:44:23 +00:00
|
|
|
|
|
|
|
(vm:word :player-key ; key --
|
|
|
|
(vm:ifchain
|
2020-12-02 22:19:23 +00:00
|
|
|
[:dup (string.byte " ") :=] [:drop :toggle-player]
|
2020-11-29 17:12:18 +00:00
|
|
|
[:movement-dir :dup]
|
2020-12-02 13:33:27 +00:00
|
|
|
[:player-yx :get :swap ; oldyx dir
|
|
|
|
:try-move-player
|
|
|
|
:dup :player-yx :get := :not (vm:if [:untouch-entity] [:drop])]
|
2020-11-29 05:44:23 +00:00
|
|
|
[:drop]))
|
2020-11-15 02:55:50 +00:00
|
|
|
|
2020-12-02 13:33:27 +00:00
|
|
|
(vm:word :full-redraw :drawmap :player-redraw)
|
|
|
|
(vm:word :player-redraw
|
|
|
|
:controlstate :bget
|
|
|
|
controlstate.count (vm:for (vm:i) :controlstate :bset :draw-player)
|
|
|
|
:controlstate :bset)
|
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-12-02 22:19:23 +00:00
|
|
|
(util.reload :game.level3)
|
2020-11-27 04:33:14 +00:00
|
|
|
|
2020-10-06 03:47:25 +00:00
|
|
|
(prg:assemble)
|
2020-11-02 00:39:31 +00:00
|
|
|
|