Allow toggling liveness of cells
authorJC <dev@jacobcasper.com>
Mon, 31 Jul 2023 01:07:20 +0000 (20:07 -0500)
committerJC <dev@jacobcasper.com>
Mon, 31 Jul 2023 01:07:20 +0000 (20:07 -0500)
source/main.lua

index aefc258..3bab8bd 100644 (file)
@@ -1,15 +1,15 @@
 local pd <const> = playdate
 local gfx <const> = playdate.graphics
 
-local WIDTH <const> = 10
-local HEIGHT <const> = 10
+local WIDTH <const> = 12
+local HEIGHT <const> = 7
 
 local rects = {}
 for i=1, WIDTH do
     rects[i] = {}
       for j=1, HEIGHT do
           r = pd.geometry.rect.new(32 * (i-1), 32 * (j-1), 32, 32)
-          rects[i][j] = { rect = r }
+          rects[i][j] = { rect = r, live = false }
       end
 end
 
@@ -20,12 +20,19 @@ local y = 1
 function playdate.update()
     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)
             gfx.drawRect(r.rect)
+
         end
     end
 
-    gfx.fillRect(rects[x][y].rect)
-
     if playdate.buttonJustPressed("right") then
         x = math.min(WIDTH, x + 1)
     elseif playdate.buttonJustPressed("left") then
@@ -35,4 +42,8 @@ function playdate.update()
     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
+    end
 end