From: JC Date: Mon, 31 Jul 2023 00:48:38 +0000 (-0500) Subject: Encode height/width in constants X-Git-Url: https://git.jacobcasper.com/?a=commitdiff_plain;h=2b0841b24616dda1d932dfeec7203806971b959b;p=life-pd.git Encode height/width in constants --- diff --git a/source/main.lua b/source/main.lua index 913d60c..aefc258 100644 --- a/source/main.lua +++ b/source/main.lua @@ -1,10 +1,13 @@ local pd = playdate local gfx = playdate.graphics +local WIDTH = 10 +local HEIGHT = 10 + local rects = {} -for i=1, 10 do +for i=1, WIDTH do rects[i] = {} - for j=1, 10 do + for j=1, HEIGHT do r = pd.geometry.rect.new(32 * (i-1), 32 * (j-1), 32, 32) rects[i][j] = { rect = r } end @@ -24,12 +27,12 @@ function playdate.update() gfx.fillRect(rects[x][y].rect) if playdate.buttonJustPressed("right") then - x = math.min(10, x + 1) + 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(10, y + 1) + y = math.min(HEIGHT, y + 1) end end