From e2b908e358020dcd9aeff95f71be51628cfb897c Mon Sep 17 00:00:00 2001 From: JC Date: Sun, 30 Jul 2023 20:11:43 -0500 Subject: [PATCH] Allow pressing "B" to begin running automata It doesn't run yet, but pressing B saves the state of the game and prevents player input --- source/main.lua | 53 ++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/source/main.lua b/source/main.lua index 3bab8bd..2057169 100644 --- a/source/main.lua +++ b/source/main.lua @@ -16,34 +16,41 @@ end local x = 1 local y = 1 +local running = false + function playdate.update() - for i,row in ipairs(rects) do - for j,r in ipairs(row) do - if r.live then + if not running then + -- automata state setup + for i,row in ipairs(rects) do + for j,r in ipairs(row) do + if r.live then + gfx.setColor(gfx.kColorBlack) + else + gfx.setColor(gfx.kColorWhite) + end + + gfx.fillRect(r.rect) gfx.setColor(gfx.kColorBlack) - else - gfx.setColor(gfx.kColorWhite) - end - - gfx.fillRect(r.rect) - gfx.setColor(gfx.kColorBlack) - gfx.drawRect(r.rect) + gfx.drawRect(r.rect) + end end - end - - if playdate.buttonJustPressed("right") then - x = math.min(WIDTH, x + 1) - elseif playdate.buttonJustPressed("left") then - x = math.max(1, x - 1) - elseif playdate.buttonJustPressed("up") then - y = math.max(1, y - 1) - elseif playdate.buttonJustPressed("down") then - y = math.min(HEIGHT, y + 1) - end - if playdate.buttonJustPressed("a") then - rects[x][y].live = not rects[x][y].live + if playdate.buttonJustPressed("right") then + x = math.min(WIDTH, x + 1) + elseif playdate.buttonJustPressed("left") then + x = math.max(1, x - 1) + elseif playdate.buttonJustPressed("up") then + y = math.max(1, y - 1) + elseif playdate.buttonJustPressed("down") then + y = math.min(HEIGHT, y + 1) + elseif playdate.buttonJustPressed("a") then + rects[x][y].live = not rects[x][y].live + elseif playdate.buttonJustPressed("b") then + running = true + end + else + -- running end end -- 2.20.1