From: JC Date: Mon, 31 Jul 2023 01:07:20 +0000 (-0500) Subject: Allow toggling liveness of cells X-Git-Url: https://git.jacobcasper.com/?a=commitdiff_plain;h=134c4bab2f59ec2385090e3360df91845309f151;p=life-pd.git Allow toggling liveness of cells --- diff --git a/source/main.lua b/source/main.lua index aefc258..3bab8bd 100644 --- a/source/main.lua +++ b/source/main.lua @@ -1,15 +1,15 @@ local pd = playdate local gfx = playdate.graphics -local WIDTH = 10 -local HEIGHT = 10 +local WIDTH = 12 +local HEIGHT = 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