Allow pressing "B" to begin running automata
authorJC <dev@jacobcasper.com>
Mon, 31 Jul 2023 01:11:43 +0000 (20:11 -0500)
committerJC <dev@jacobcasper.com>
Mon, 31 Jul 2023 01:11:43 +0000 (20:11 -0500)
It doesn't run yet, but pressing B saves the state of the game and
prevents player input

source/main.lua

index 3bab8bd..2057169 100644 (file)
@@ -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