Implement Rexx

This commit is contained in:
Jeremy Penner 2020-12-02 17:19:23 -05:00
parent 03a5711086
commit d2e9214355
5 changed files with 42 additions and 15 deletions

View file

@ -103,6 +103,17 @@
[:else]) [:else])
] [:drop])) ] [:drop]))
(vm:word :rexx ; ev --
ev.touch := (vm:when
(vm:if-and [[:is-neut?] [:responder-itile (itile :t-rexx)]]
[0xffff :move-player-to
(itile :t-rexxstop) :set-respondertile
:get-responder :set-rexx]
[(vm:if-and [[:is-rexx?] [:responder-itile (itile :t-rexxstop)]]
[0xffff :move-player-to
(itile :t-rexx) :set-respondertile
0 :set-rexx :move-to-responder])])))
(fn append-from-map [map entity-org] (fn append-from-map [map entity-org]
(each [_ entity (ipairs map.objects)] (each [_ entity (ipairs map.objects)]
(when entity.name (when entity.name

View file

@ -2,14 +2,14 @@
(local {: lo : hi : readjson} util) (local {: lo : hi : readjson} util)
(local lume (require :lib.lume)) (local lume (require :lib.lume))
(local tile (util.reload :game.tiles)) (local tile (util.reload :game.tiles))
(local {: prg : vm : org : mapw : maph} (util.reload :game.defs)) (local {: prg : vm : org : mapw : maph : itile} (util.reload :game.defs))
(util.reload :game.gfx) (util.reload :game.gfx)
(util.reload :game.footer) (util.reload :game.footer)
(util.reload :game.map) (util.reload :game.map)
(util.reload :game.entity) (util.reload :game.entity)
(local {: walkable : neutable} tile.flag-to-bit) (local {: walkable : neutable : debris} tile.flag-to-bit)
(vm:word :movement-dir ; key -- dyx (vm:word :movement-dir ; key -- dyx
(vm:case [(string.byte "I") 0xff00] (vm:case [(string.byte "I") 0xff00]
@ -30,7 +30,7 @@
(vm:var :jaye-yx 0x0a0a) (vm:var :jaye-yx 0x0a0a)
(vm:var :jaye-dir 0xff00) (vm:var :jaye-dir 0xff00)
(vm:var :neut-yx 0x0b08) (vm:var :neut-yx 0x0b08)
(vm:var :current-rexx 0) (vm:var :rexx-yx 0xffff)
(local controlstate { (local controlstate {
:jaye 0 :jaye 0
@ -45,6 +45,11 @@
(vm:word :is-rexx? :controlstate :bget controlstate.rexx :=) (vm:word :is-rexx? :controlstate :bget controlstate.rexx :=)
(vm:word :is-prog? :is-neut? :is-rexx? :|) (vm:word :is-prog? :is-neut? :is-rexx? :|)
(vm:word :neut-hidden? :neut-yx :get 0xffff :=) (vm:word :neut-hidden? :neut-yx :get 0xffff :=)
(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)
(vm:word :player-tile ; -- ptile (vm:word :player-tile ; -- ptile
:controlstate :bget :controlstate :bget
@ -56,7 +61,7 @@
:controlstate :bget :controlstate :bget
(vm:case [controlstate.jaye :jaye-yx] (vm:case [controlstate.jaye :jaye-yx]
[controlstate.neut :neut-yx] [controlstate.neut :neut-yx]
[:else :current-rexx :dup (vm:when :get)])) [:else :rexx-yx]))
(vm:word :draw-player ; -- (vm:word :draw-player ; --
:player-yx :dup (vm:if [:get :dup 0xffff := (vm:if [:drop] [:yx>screen :player-tile :drawtile])] [:drop])) :player-yx :dup (vm:if [:get :dup 0xffff := (vm:if [:drop] [:yx>screen :player-tile :drawtile])] [:drop]))
@ -68,13 +73,18 @@
:is-neut? (vm:if [neutable] [walkable])) :is-neut? (vm:if [neutable] [walkable]))
(vm:word :move-player-to ; yx -- (vm:word :move-player-to ; yx --
:player-yx :dup :get :drawtile-at :player-yx :dup :get :dup 0xffff := (vm:if [:drop] [:drawtile-at])
:set :draw-player) :set :draw-player)
(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]))
(vm:word :try-move-player ; dir -- (vm:word :try-move-player ; dir --
:dup :set-player-dir ; dir :dup :set-player-dir ; dir
:player-yx :get :yx+ ; yxnew :player-yx :get :yx+ ; yxnew
(vm:if-or [[:dup :touch-entity] [:dup :movable-player-flag :flag-at? :not]] (vm:if-or [[:dup :touch-entity] [:dup :handle-special-move] [:dup :movable-player-flag :flag-at? :not]]
[:drop :player-yx :get]) [:drop :player-yx :get])
; always "move" so that player can visibly change direction ; always "move" so that player can visibly change direction
; touch-entity can modify player-yx so we have to refetch ; touch-entity can modify player-yx so we have to refetch
@ -92,15 +102,15 @@
(vm:word :flag-at? ; yx flag -- f (vm:word :flag-at? ; yx flag -- f
:swap :itile-at :lookup-flags :&) :swap :itile-at :lookup-flags :&)
(vm:word :swap-player (vm:word :toggle-player
(vm:ifchain [:is-prog?] [controlstate.jaye] (vm:ifchain [:is-prog?] [controlstate.jaye]
[:neut-hidden?] [controlstate.jaye] [:rexx-active?] [controlstate.rexx]
[:current-rexx :get] [controlstate.rexx] [:neut-hidden?] [controlstate.jaye]
[controlstate.neut]) :controlstate :bset) [controlstate.neut]) :controlstate :bset)
(vm:word :player-key ; key -- (vm:word :player-key ; key --
(vm:ifchain (vm:ifchain
[:dup (string.byte " ") :=] [:drop :swap-player] [:dup (string.byte " ") :=] [:drop :toggle-player]
[:movement-dir :dup] [:movement-dir :dup]
[:player-yx :get :swap ; oldyx dir [:player-yx :get :swap ; oldyx dir
:try-move-player :try-move-player
@ -135,7 +145,7 @@
) )
:quit]) :quit])
(util.reload :game.level2) (util.reload :game.level3)
(prg:assemble) (prg:assemble)

6
game/level3.fnl Normal file
View file

@ -0,0 +1,6 @@
(local {: deflevel : say : itile} (require :game.defs))
(local {: ev} (require :game.entity))
(local level (deflevel "game/map3.json"))
(local vm level.vm)
level

View file

@ -1 +1 @@
{"map":"616161616161616181616161616161616161612161C063C0C0C0C0C0C0C06143C0E0C2C0C043022161C0C0C0C0C0C0C0C0C022C0C0C0C0C0C0C0612161C0C0C2C0C0C0C0C0C081C0C0C0C0C0C0C0612161C08282A2C0C0C0C0436123C0C0C0C0C0030221616161616161616261616161618161616161612161C063C0C02301C0C163C0C0C0C0C0822363022122C0C0C0C0C0C0A2A1C0C0C0C0C0C0C2C0C0612181C0C0C0C0E2C0C061C0C0C0C0C0C0C0C2C061216123C0C0C0C083C061E0C2C0C0C0C0438203022161610261610261616161026161026161026161212121212121212121212121212121212121212121","objects":[{"link":2,"y":5,"func":"scan","name":"","linkword":"","x":1},{"x":1,"func":"door","y":4,"linkword":"","name":""},{"link":4,"y":6,"func":"term","name":"","linkword":"","x":7},{"link":7,"y":11,"func":"term","name":"","linkword":"","x":14},{"link":6,"y":6,"func":"switch","name":"","linkword":"","x":9},{"x":11,"func":"door","y":9,"linkword":"","name":""},{"link":3,"y":3,"func":"term","name":"","linkword":"","x":10},{"link":9,"y":10,"func":"scan","name":"","linkword":"","x":11},{"x":14,"func":"door","y":7,"linkword":"","name":""}]} {"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}]}

View file

@ -1 +1 @@
[{"gfx":"7F7F1F03090923436943230909031F7F7F7F784111104542174245101141787F","word":"","label":"neut1","flags":[]},{"gfx":"7F1F03090923436943230909031F7F7F7F784111104542174245101141787F7F","word":"","label":"neut2","flags":[]},{"gfx":"808080C0C0C0E0C0D0C8C04040404080808083058585828A9282820A08081980","word":"","label":"jaye-e","flags":[]},{"gfx":"8080C020A0A0C0C0D0C8C0501010188080808183838782828A8A920202020380","word":"","label":"jaye-w","flags":[]},{"gfx":"8080E030B0B098C0D0D0C840404060808080870D8D8D99828A8A920202020780","word":"","label":"jaye-s","flags":[]},{"gfx":"8080C0E0E0E0B0C0D0C8C040404060808080838787878D828A92820202020780","word":"","label":"jaye-n","flags":[]},{"gfx":"80808C8080808080B08080808C808080808C80808083B0808080808080868080","word":"","label":"","flags":{"walkable":true}},{"gfx":"007C0C0C0C0C7C007C7E7EAA88888800001F181818181F001F0F979584848400","word":"term","label":"termoff","flags":[]},{"gfx":"007C2C0C0C2C7C007C7E7EAA88888800001F18191C191F001F0F979584848400","word":"term","label":"termon","flags":{"neutable":true}},{"gfx":"D5D5D5D5D5D5D5D5D5D5D5D5D5D5D5D5AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","word":"","label":"","flags":[]},{"gfx":"D5D5D5D5D5F5F5FDDDD5D5D5D5D5D5D5AAAAAAAAAEAEBFBFBFABAAAAAAAAAAAA","word":"","label":"","flags":[]},{"gfx":"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF","word":"","label":"","flags":{"neutable":true}},{"gfx":"FF8FA7B3B3B3B3B3B3B3B3B3B3B383FFFFF8F2E6E6E6E6E6E6E6E6E6E6E6E0FF","word":"door","label":"doorclosed","flags":[]},{"gfx":"FF8F87838383838383838383838383FFFFF8F0E0E0E0E0E0E0E0E0E0E0E0E0FF","word":"door","label":"dooropen","flags":{"walkable":true}},{"gfx":"FFFFCFCFCFCF898183838787878FFFFFFFFCE4E4E4E4E0E0E0E0E0E0F0F8FFFF","word":"switch","label":"switchoff","flags":{"neutable":true}},{"gfx":"FFFFCFCFCFCF898123232727878FFFFFFFFCE4E4E4E0E0616565656571F8FFFF","word":"switch","label":"switchon","flags":{"neutable":true}},{"gfx":"FFFF83D3D3D3D3D3D3D3D3D3D383FFFFFFFFC0CACACECACBCACACACACAC0FFFF","word":"","label":"","flags":[]},{"gfx":"FFFFAFEBFBFBFBBBBBFBFBFBEBAFFFFFFFFFF5D7DFDFDFDDDDDFDFDFD7F5FFFF","word":"scan","label":"scanoff","flags":{"neutable":true}},{"gfx":"FFFF2F2B2B2B6B6B6B6B2B2B2B2FFFFFFFFF755555555757575755555575FFFF","word":"scan","label":"scanon","flags":{"neutable":true}},{"gfx":"FFF3C78FBFFCF98187BFFFFFBF9F9FC7FFCFE1F1FCFCF8FEFEFCF9F0E6CE8F9F","word":"","label":"","flags":[]},{"gfx":"80808C80808080A8AAAAAAA888888880808C8080808380859595958584848480","word":"","label":"","flags":[]},{"gfx":"80808C8080A0A0A8AAAA8AA0A8808080808C8081919090848594959585858080","word":"","label":"","flags":{"debris":true}},{"gfx":"00005054545450404054545010383800000C0A2A2A2A0A03032A2A0A081C1C00","word":"","label":"","flags":[]},{"gfx":"0000001C1C10545040606010545454000030070702020A0A0100020A080A0200","word":"","label":"","flags":{"debris":true}},{"gfx":"80A0A8AA92D2D2AAC2C2AA92D2AA808080959595949494959494959494858080","word":"","label":"","flags":[]},{"gfx":"80808C808080A8C292AAAAAAAA8AC0D0808C80808083959290959194948580A8","word":"","label":"","flags":{"debris":true}},{"gfx":"80806008282A0800202880A8A8A8A08080980000141501051511819595958580","word":"","label":"","flags":[]},{"gfx":"80808C808080A0A8AAAA8AA2AAAAAA80808C0000000330010105051511010514","word":"","label":"","flags":{"debris":true}},{"gfx":"80D0D0D0C0D4C4C4CECAC0E0A0808080808A8B8A82AAA2A2F2D2828785808080","word":"","label":"t-rexx","flags":[]},{"gfx":"F8989898BE8686868686BEB098F880809F989898FCE0E0E0E0E0FC8C989F8080","word":"","label":"","flags":[]}] [{"gfx":"7F7F1F03090923436943230909031F7F7F7F784111104542174245101141787F","word":"","label":"neut1","flags":[]},{"gfx":"7F1F03090923436943230909031F7F7F7F784111104542174245101141787F7F","word":"","label":"neut2","flags":[]},{"gfx":"808080C0C0C0E0C0D0C8C04040404080808083058585828A9282820A08081980","word":"","label":"jaye-e","flags":[]},{"gfx":"8080C020A0A0C0C0D0C8C0501010188080808183838782828A8A920202020380","word":"","label":"jaye-w","flags":[]},{"gfx":"8080E030B0B098C0D0D0C840404060808080870D8D8D99828A8A920202020780","word":"","label":"jaye-s","flags":[]},{"gfx":"8080C0E0E0E0B0C0D0C8C040404060808080838787878D828A92820202020780","word":"","label":"jaye-n","flags":[]},{"gfx":"80808C8080808080B08080808C808080808C80808083B0808080808080868080","word":"","label":"t-floor","flags":{"walkable":true}},{"gfx":"007C0C0C0C0C7C007C7E7EAA88888800001F181818181F001F0F979584848400","word":"term","label":"termoff","flags":[]},{"gfx":"007C2C0C0C2C7C007C7E7EAA88888800001F18191C191F001F0F979584848400","word":"term","label":"termon","flags":{"neutable":true}},{"gfx":"D5D5D5D5D5D5D5D5D5D5D5D5D5D5D5D5AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","word":"","label":"","flags":[]},{"gfx":"D5D5D5D5D5F5F5FDDDD5D5D5D5D5D5D5AAAAAAAAAEAEBFBFBFABAAAAAAAAAAAA","word":"","label":"","flags":[]},{"gfx":"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF","word":"","label":"","flags":{"neutable":true}},{"gfx":"FF8FA7B3B3B3B3B3B3B3B3B3B3B383FFFFF8F2E6E6E6E6E6E6E6E6E6E6E6E0FF","word":"door","label":"doorclosed","flags":[]},{"gfx":"FF8F87838383838383838383838383FFFFF8F0E0E0E0E0E0E0E0E0E0E0E0E0FF","word":"door","label":"dooropen","flags":{"walkable":true}},{"gfx":"FFFFCFCFCFCF898183838787878FFFFFFFFCE4E4E4E4E0E0E0E0E0E0F0F8FFFF","word":"switch","label":"switchoff","flags":{"neutable":true}},{"gfx":"FFFFCFCFCFCF898123232727878FFFFFFFFCE4E4E4E0E0616565656571F8FFFF","word":"switch","label":"switchon","flags":{"neutable":true}},{"gfx":"FFFF83D3D3D3D3D3D3D3D3D3D383FFFFFFFFC0CACACECACBCACACACACAC0FFFF","word":"","label":"","flags":[]},{"gfx":"FFFFAFEBFBFBFBBBBBFBFBFBEBAFFFFFFFFFF5D7DFDFDFDDDDDFDFDFD7F5FFFF","word":"scan","label":"scanoff","flags":{"neutable":true}},{"gfx":"FFFF2F2B2B2B6B6B6B6B2B2B2B2FFFFFFFFF755555555757575755555575FFFF","word":"scan","label":"scanon","flags":{"neutable":true}},{"gfx":"FFF3C78FBFFCF98187BFFFFFBF9F9FC7FFCFE1F1FCFCF8FEFEFCF9F0E6CE8F9F","word":"","label":"","flags":[]},{"gfx":"80808C80808080A8AAAAAAA888888880808C8080808380859595958584848480","word":"","label":"","flags":[]},{"gfx":"80808C8080A0A0A8AAAA8AA0A8808080808C8081919090848594959585858080","word":"","label":"","flags":{"debris":true}},{"gfx":"00005054545450404054545010383800000C0A2A2A2A0A03032A2A0A081C1C00","word":"","label":"","flags":[]},{"gfx":"0000001C1C10545040606010545454000030070702020A0A0100020A080A0200","word":"","label":"","flags":{"debris":true}},{"gfx":"80A0A8AA92D2D2AAC2C2AA92D2AA808080959595949494959494959494858080","word":"","label":"","flags":[]},{"gfx":"80808C808080A8C292AAAAAAAA8AC0D0808C80808083959290959194948580A8","word":"","label":"","flags":{"debris":true}},{"gfx":"80806008282A0800202880A8A8A8A08080980000141501051511819595958580","word":"","label":"","flags":[]},{"gfx":"80808C808080A0A8AAAA8AA2AAAAAA80808C0000000330010105051511010514","word":"","label":"","flags":{"debris":true}},{"gfx":"80D0D0D0C0D4C4C4CECAC0E0A0808080808A8B8A82AAA2A2F2D2828785808080","word":"rexx","label":"t-rexx","flags":[]},{"gfx":"F8989898BE8686868686BEB098F880809F989898FCE0E0E0E0E0FC8C989F8080","word":"","label":"t-rexxstop","flags":[]}]