From 2b0841b24616dda1d932dfeec7203806971b959b Mon Sep 17 00:00:00 2001 From: JC Date: Sun, 30 Jul 2023 19:48:38 -0500 Subject: [PATCH] Encode height/width in constants --- source/main.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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 -- 2.20.1