2020-12-22 04:24:39 +00:00
|
|
|
(local tile (require :game.tiles))
|
|
|
|
(local {: vm : mapw : maph : itile : controlstate} (require :game.defs))
|
|
|
|
|
2021-04-18 02:50:09 +00:00
|
|
|
(local {: walkable} tile.flag-to-bit)
|
2020-12-22 04:24:39 +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))
|
|
|
|
|
2021-04-18 02:50:09 +00:00
|
|
|
(vm:var :player-yx 0x0a0a)
|
2020-12-22 04:24:39 +00:00
|
|
|
|
|
|
|
(vm:word :draw-player ; --
|
|
|
|
:player-yx :dup (vm:if [:get :dup 0xffff := (vm:if [:drop] [:yx>screen :player-tile :drawtile])] [:drop]))
|
|
|
|
|
2021-02-12 02:38:57 +00:00
|
|
|
(vm:var :noclip)
|
|
|
|
(vm:word :move-if-clear ; yx -- f
|
|
|
|
:noclip :get (vm:if [:drop vm.false] [:movable-player-flag :flag-at? :not]))
|
|
|
|
|
2021-04-18 02:50:09 +00:00
|
|
|
(vm:const :movable-player-flag ; -- flag
|
|
|
|
walkable)
|
2020-12-22 04:24:39 +00:00
|
|
|
|
|
|
|
(vm:word :move-player-to ; yx --
|
|
|
|
:player-yx :dup :get :dup 0xffff := (vm:if [:drop] [:drawtile-at])
|
|
|
|
:set :draw-player)
|
|
|
|
|
|
|
|
(vm:word :move-noop :drop vm.false)
|
2021-01-18 04:03:15 +00:00
|
|
|
(vm:word :handle-general-move ; yx -- f
|
2021-04-18 02:50:09 +00:00
|
|
|
(vm:if-or [[:dup :map-specific-move] [:dup :move-if-clear]]
|
2020-12-22 04:24:39 +00:00
|
|
|
[:drop vm.true] [:move-noop]))
|
|
|
|
|
|
|
|
(vm:def :yxclip? ; yx -- f
|
|
|
|
[:block
|
|
|
|
[:lda vm.TOP :x]
|
|
|
|
[:cmp mapw]
|
|
|
|
[:bcs :clipped]
|
|
|
|
[:lda vm.TOPH :x]
|
|
|
|
[:cmp maph]
|
|
|
|
[:bcs :clipped]
|
|
|
|
[:lda 0] [:sta vm.TOP :x] [:sta vm.TOPH :x] (vm:ret)
|
|
|
|
:clipped
|
|
|
|
[:lda 0xff] [:sta vm.TOP :x] [:sta vm.TOPH :x]])
|
|
|
|
|
|
|
|
(vm:word :try-move-player ; dir --
|
|
|
|
:player-yx :get :yx+ ; yxnew
|
2021-01-18 04:03:15 +00:00
|
|
|
(vm:if-or [[:dup :yxclip?] [:dup :touch-entity] [:dup :handle-general-move]]
|
2020-12-22 04:24:39 +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-12-30 17:48:58 +00:00
|
|
|
(vm:word :two-frame :tick-count :get 0x1f :& 0x10 :<)
|
2021-04-18 02:50:09 +00:00
|
|
|
(vm:word :player-tile ; -- ptile
|
2021-04-18 04:09:31 +00:00
|
|
|
(itile :player-frame1) :lookup-tile)
|
2020-12-22 04:24:39 +00:00
|
|
|
|
|
|
|
(vm:word :flag-at? ; yx flag -- f
|
|
|
|
:swap :itile-at :lookup-flags :&)
|
|
|
|
|
|
|
|
(vm:word :player-key ; key --
|
|
|
|
(vm:ifchain
|
|
|
|
[:movement-dir :dup]
|
2021-04-18 15:26:39 +00:00
|
|
|
[:try-move-player :load-next-level]
|
2020-12-22 04:24:39 +00:00
|
|
|
[:drop]))
|
|
|
|
|
|
|
|
(vm:word :full-redraw :drawmap :player-redraw)
|
2021-04-18 02:50:09 +00:00
|
|
|
|
|
|
|
(vm:word :player-redraw :draw-player)
|
|
|
|
|