From 2729b438e5c7ca746b7937cbdb21a9504d07e905 Mon Sep 17 00:00:00 2001 From: Jeremy Penner Date: Sun, 24 Apr 2022 23:23:52 -0400 Subject: [PATCH] help text, improve mode-swapping, fast drop, start in-game --- editor/lovemode.fnl | 6 +++--- edtris.txt | 9 ++++----- game/mode.fnl | 11 +++++++++++ game/rules.fnl | 27 ++++++++++++++++++++------- game/state.fnl | 2 +- wrap.fnl | 13 +++++++++++++ 6 files changed, 52 insertions(+), 16 deletions(-) diff --git a/editor/lovemode.fnl b/editor/lovemode.fnl index 7d5a407..0ed74e7 100644 --- a/editor/lovemode.fnl +++ b/editor/lovemode.fnl @@ -8,9 +8,9 @@ :names [] : std-handlers}) -(fn modes.cycle [self] - (set self.mode-index (+ self.mode-index 1)) - (when (> self.mode-index (length self.names)) +(fn modes.cycle [self ?name] + (set self.mode-index (if ?name (lume.find self.names ?name) (+ self.mode-index 1))) + (when (or (not self.mode-index) (> self.mode-index (length self.names))) (set self.mode-index 1)) (self:switch (self:current))) diff --git a/edtris.txt b/edtris.txt index 6b55dcc..98381a0 100644 --- a/edtris.txt +++ b/edtris.txt @@ -1,8 +1,7 @@ Welcome to Edtris, the Editable Tetris! -This game has a text editor built into it! You are looking at an editor -called "lite", which is written in Lua and has been ported to run inside -the love2d game engine. +This game has a text editor built into it! It is called "lite", and +is written in Lua and has been ported to run inside the love2d game engine. Edtris is written in Fennel, which is a language in the Lisp family that compiles to Lua. @@ -32,9 +31,9 @@ to say At any time, you can press "E" to come back to this editor and try new things. Feel free to experiment! -* What happens if you make the well bigger? +* What happens if you make the well deeper? Wider? A different shape? * What happens if you remove the walls of the well? -* Can you draw a picture in the well? +* Can you turn the well into a picture? If you like, you can also run the game and the editor at the same time! If you press Ctrl-Shift-P, type "game" and press enter, a new tab will diff --git a/game/mode.fnl b/game/mode.fnl index 1609a2f..b303e74 100644 --- a/game/mode.fnl +++ b/game/mode.fnl @@ -22,6 +22,17 @@ (let [xnext (/ dim.tilesize 2) xwell (* dim.tilesize 5) current (rules.current-tetromino)] + (love.graphics.setColor 1 1 1 1) + (love.graphics.setNewFont 22) + (love.graphics.print "Next:" dim.tilesize 0) + (love.graphics.setNewFont 18) + (love.graphics.print "Controls: +<- / -> = move +down = drop +spc = fast drop +Z/X/up = rotate +R = reset +E = edit" (/ dim.tilesize 3) (* dim.tilesize 5)) (map.draw-tilemap xwell 0 state.well tiles.tetristile) (map.draw-tilemap xnext dim.tilesize (rules.tetromino state.next-piece 1) tiles.tetristile) (when current diff --git a/game/rules.fnl b/game/rules.fnl index 0bd0632..7c5e13b 100644 --- a/game/rules.fnl +++ b/game/rules.fnl @@ -132,11 +132,18 @@ stopped (Rules.collides? tetromino x y)] (if (and stopped (not= dy 0)) ; dropping (do (Rules.place-piece tetromino state.current.x state.current.y) - (Rules.play-next-piece)) + (Rules.play-next-piece) + :placed) (not stopped) (do (set state.current.x x) - (set state.current.y y)))))) + (set state.current.y y) + :moved) + + :blocked)))) + +(fn Rules.drop-piece [] + (while (not= (Rules.try-move-piece 0 1) :placed))) (fn Rules.rotate [di] (when state.current @@ -166,14 +173,19 @@ (let [modes (require :editor.lovemode) core (require :core) filename "game/state.fnl" + ldoc (core.open_doc filename) f (io.open filename :w)] (f:write (fv state)) (f:close) - (modes:cycle) - (core.root_view:open_doc (core.open_doc filename)))) + (modes:cycle :editor) + ; ensure existing state.fnl opens + (each [_ view (ipairs (core.root_view.root_node:get_children))] + (when (= view.doc ldoc) (core.set_active_view view))) + (core.root_view:open_doc ldoc))) (set Rules.commands {:move Rules.try-move-piece + :drop Rules.drop-piece :rotate Rules.rotate :reset Rules.reset-game :edit Rules.edit-game}) @@ -182,9 +194,10 @@ {:left [:move -1 0] :right [:move 1 0] :down [:move 0 1] - :up [:rotate 1] - :z [:rotate -1] - :x [:rotate 1] + :up [:rotate -1] + :space [:drop] + :z [:rotate 1] + :x [:rotate -1] :r [:reset] :e [:edit]}) diff --git a/game/state.fnl b/game/state.fnl index 0967ef4..9e26dfe 100644 --- a/game/state.fnl +++ b/game/state.fnl @@ -1 +1 @@ -{} +{} \ No newline at end of file diff --git a/wrap.fnl b/wrap.fnl index 51ffbe4..e21c753 100644 --- a/wrap.fnl +++ b/wrap.fnl @@ -32,4 +32,17 @@ "alt+u" "fennel:unload-macro" }) +(set love.load + (fn [] + (local modes (require :editor.lovemode)) + (let [f (io.open "game/state.fnl" :w)] + (f:write "{}") + (f:close)) + + (core.root_view:open_doc (core.open_doc "edtris.txt")) + (: (core.root_view:get_active_node) :split :right) + (core.root_view:open_doc (core.open_doc "game/state.fnl")) + + (modes:cycle :game))) + {}