From da2bee11e831a60896a164917776bb20aafc3cb6 Mon Sep 17 00:00:00 2001 From: Jeremy Penner Date: Sun, 29 Nov 2020 12:12:18 -0500 Subject: [PATCH] Implement card scanner - level 1 complete-able! --- game/entity.fnl | 42 +++++++++++++++++++++++++++--------------- game/init.fnl | 8 +++++++- game/level1.fnl | 4 ++-- game/map00001.json | 2 +- game/tiles.json | 2 +- 5 files changed, 38 insertions(+), 20 deletions(-) diff --git a/game/entity.fnl b/game/entity.fnl index c9dc2f2..4045d75 100644 --- a/game/entity.fnl +++ b/game/entity.fnl @@ -16,10 +16,11 @@ ; The entity count for a level is stored after the map. (local ev { - :touch 0 - :act 1 - :deact 2 - :tog 3 + :touch 0 + :untouch 1 + :act 2 + :deact 3 + :tog 4 }) (vm:word :entity-count :lit :map-entity-count :bget) @@ -46,7 +47,9 @@ (vm:word :linked-entity :get-responder :dup 4 :+ :get :dup (vm:if [:dup :. :execute] [:drop 6 :+ :dup :. :get]) :dup :.) (vm:word :touch-entity ; yx -- f :entity-at :dup (vm:when ev.touch :entity>do vm.true)) - +(vm:word :untouch-entity ; yx -- + :entity-at :dup (vm:if [ev.untouch :entity>do] [:drop])) + (vm:word :set-entitytile ; e itile -- :swap :get :swap :update-itile) @@ -72,24 +75,33 @@ [:move-jaye :drop] [(itile :doorclosed) (itile :dooropen) :handle-onoff])) +(vm:word :move-neut-to-responder :get-responder :get :move-neut-to) (vm:word :switch ; ev -- - :dup ev.touch := (vm:when :drop ev.tog :is-neut? (vm:when :get-responder :get :move-neut-to)) + :dup ev.touch := (vm:when :drop ev.tog :is-neut? (vm:when :move-neut-to-responder)) :dup (itile :switchoff) (itile :switchon) :handle-onoff (itile :switchon) :activate-link) (vm:word :term ; ev -- :dup ev.touch := (vm:when - :is-jaye? (vm:if [ - :drop ev.act - ] [ - :linked-entity :dup :get :itile-at (itile :termon) := (vm:if [ - :get :move-neut-to - ] [ - :drop - ]) - ])) + :is-jaye? + (vm:if + [:drop ev.act] + [:linked-entity :dup :get :itile-at (itile :termon) := + (vm:if [:get :move-neut-to] [:drop])])) :dup (itile :termoff) (itile :termon) :handle-onoff) +(vm:word :handle-scan ; ev -- + :dup (itile :scanoff) (itile :scanon) :handle-onoff + :linked-entity :swap :entity>do) + +(vm:word :scan ; ev -- + :is-neut? (vm:if [ + (vm:case + [ev.touch ev.act :handle-scan :move-neut-to-responder] + [ev.untouch ev.deact :handle-scan] + [:else]) + ] [:drop])) + (fn append-from-map [map entity-org] (each [_ entity (ipairs map.objects)] (when entity.name diff --git a/game/init.fnl b/game/init.fnl index d7f3c86..6984dd8 100644 --- a/game/init.fnl +++ b/game/init.fnl @@ -68,6 +68,9 @@ (vm:word :flag-at? ; yx flag -- f :swap :itile-at :lookup-flags :&) +(vm:word :get-player-yx ; -- yx + :is-jaye? (vm:if [:jaye-yx] [:neut-yx]) :get) + (vm:word :try-move-jaye ; dir -- :dup :jaye-dir :set ; dir :jaye-yx :get ; dir yx @@ -88,7 +91,10 @@ (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])] + [:movement-dir :dup] + [:get-player-yx :swap ; oldyx dir + :is-jaye? (vm:if [:try-move-jaye] [:try-move-neut]) + :dup :get-player-yx := :not (vm:if [:untouch-entity] [:drop])] [:drop])) (vm:word :full-redraw :drawmap :object-redraw) diff --git a/game/level1.fnl b/game/level1.fnl index 472ce0e..c3aa3fc 100644 --- a/game/level1.fnl +++ b/game/level1.fnl @@ -12,7 +12,7 @@ (vm:if-and [[:is-jaye?] [:dup ev.touch :=]] [ :neut-hidden? (vm:if [ (say :jaye "MAYBE NEUT CAN HELP.") - :get-responder :get :move-neut-to + :get-responder :get :dup :neut-yx :set :draw-neut-yx (say :neut "NEUT V0.71.4RC12 ONLINE" "" "PRESS SPACE TO TAKE CONTROL") ] [ (say :jaye "NEUT IS RUNNING NOW." "I CAN HIT THE SPACE BAR" "TO CONTROL THEM.") @@ -31,6 +31,6 @@ (say :jaye "IT'S A CARD SCANNER." "IT SHOULD OPEN THIS DOOR.") (say :jaye "IT'S NOT READING MY CARD" "FOR SOME REASON." "QUAKE MUST'VE DAMAGED IT.") (say :jaye "NEUT MIGHT BE ABLE TO" "HACK IT...") - ])) + ]) :scan) level diff --git a/game/map00001.json b/game/map00001.json index e89c5ae..f63708b 100644 --- a/game/map00001.json +++ b/game/map00001.json @@ -1 +1 @@ -{"map":"212121214121212121212121212141212121212161026161610261616102616161616102616161216143C0C0E2C0C0C0C0C0C06361C0C0C0C0C0612161C0C0A282C0C0C0A2C0C0C081C0C0C0C0C2024161C0C0C0C0C0C0C0C0C2C0A2C1A2C0C0E082612161E2C08282C0C0C0C0A2C0C06161616161616121616161616161C181616161616143C0C0E282612161C0C0C0C0C0C0C0C0C0C0C061C0C0C0C0C0022161E08282A2C0C0C0C0E2C0C081C0C0C0C003612161E2C2C2C0C0C0C0C0C0C0C061C0C0C0C0C06141610303C063E2C0C0C0C0C0C061C0C0C023C061216161616161616161228161616161616161610221","objects":[{"x":7,"link":2,"func":"switch","linkword":"","name":"","y":6},{"x":8,"func":"door","linkword":"","name":"","y":6},{"x":2,"func":"firstterm","y":4,"name":"","linkword":"","link":4},{"x":17,"func":"neutterm","y":8,"name":"","linkword":"","link":3},{"x":13,"func":"switch","y":8,"name":"","linkword":"","link":6},{"x":13,"func":"firstdoor","y":9,"name":"","linkword":""},{"x":9,"func":"exitscanner","name":"","linkword":"","y":1}]} \ No newline at end of file +{"map":"212121214121212121212121212141212121212161026161610261616102616161616102616161216143C0C0E2C0C0C0C0C0C06361C0C0C0C0C0612161C0C0A282C0C0C0A2C0C0C081C0C0C0C0C2024161C0C0C0C0C0C0C0C0C2C0A2C1A2C0C0E082612161E2C08282C0C0C0C0A2C0C06161616161616121616161616161C181616161616143C0C0E282612161C0C0C0C0C0C0C0C0C0C0C061C0C0C0C0C0022161E08282A2C0C0C0C0E2C0C081C0C0C0C003612161E2C2C2C0C0C0C0C0C0C0C061C0C0C0C0C06141610303C063E2C0C0C0C0C0C061C0C0C023C061216161616161616161228161616161616161610221","objects":[{"link":2,"y":6,"func":"switch","name":"","linkword":"","x":7},{"x":8,"func":"door","y":6,"linkword":"","name":""},{"x":2,"link":4,"func":"firstterm","linkword":"","name":"","y":4},{"x":17,"link":3,"func":"neutterm","linkword":"","name":"","y":8},{"x":13,"link":6,"func":"switch","linkword":"","name":"","y":8},{"x":13,"func":"firstdoor","linkword":"","name":"","y":9},{"x":9,"link":8,"func":"exitscanner","y":1,"name":"","linkword":""},{"x":10,"func":"door","linkword":"","name":"","y":1}]} \ No newline at end of file diff --git a/game/tiles.json b/game/tiles.json index 72d4d1e..8a70533 100644 --- a/game/tiles.json +++ b/game/tiles.json @@ -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":"","flags":{"neutable":true}},{"gfx":"FFFF2F2B2B2B6B6B6B6B2B2B2B2FFFFFFFFF755555555757575755555575FFFF","word":"scan","label":"","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":"0000000000000000000000000000000000000000000000000000000000000000","word":"","label":"","flags":[]}] \ No newline at end of file +[{"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":"0000000000000000000000000000000000000000000000000000000000000000","word":"","label":"","flags":[]}] \ No newline at end of file