Commit | Line | Data |
---|---|---|
4e00ffe2 J |
1 | local pd <const> = playdate |
2 | local gfx <const> = playdate.graphics | |
3 | ||
134c4bab J |
4 | local WIDTH <const> = 12 |
5 | local HEIGHT <const> = 7 | |
2b0841b2 | 6 | |
52fc2291 | 7 | local rects = {} |
2b0841b2 | 8 | for i=1, WIDTH do |
62c1624b | 9 | rects[i] = {} |
2b0841b2 | 10 | for j=1, HEIGHT do |
59bc5140 | 11 | r = pd.geometry.rect.new(32 * (i-1), 32 * (j-1), 32, 32) |
134c4bab | 12 | rects[i][j] = { rect = r, live = false } |
62c1624b | 13 | end |
52fc2291 | 14 | end |
4e00ffe2 | 15 | |
3d688932 J |
16 | local x = 1 |
17 | local y = 1 | |
18 | ||
e2b908e3 J |
19 | local running = false |
20 | ||
4e00ffe2 | 21 | |
77772b8b | 22 | function playdate.update() |
e2b908e3 J |
23 | if not running then |
24 | -- automata state setup | |
25 | for i,row in ipairs(rects) do | |
26 | for j,r in ipairs(row) do | |
27 | if r.live then | |
28 | gfx.setColor(gfx.kColorBlack) | |
29 | else | |
30 | gfx.setColor(gfx.kColorWhite) | |
31 | end | |
32 | ||
33 | gfx.fillRect(r.rect) | |
134c4bab | 34 | gfx.setColor(gfx.kColorBlack) |
e2b908e3 | 35 | gfx.drawRect(r.rect) |
134c4bab | 36 | |
e2b908e3 | 37 | end |
62c1624b | 38 | end |
134c4bab | 39 | |
e2b908e3 J |
40 | if playdate.buttonJustPressed("right") then |
41 | x = math.min(WIDTH, x + 1) | |
42 | elseif playdate.buttonJustPressed("left") then | |
43 | x = math.max(1, x - 1) | |
44 | elseif playdate.buttonJustPressed("up") then | |
45 | y = math.max(1, y - 1) | |
46 | elseif playdate.buttonJustPressed("down") then | |
47 | y = math.min(HEIGHT, y + 1) | |
48 | elseif playdate.buttonJustPressed("a") then | |
49 | rects[x][y].live = not rects[x][y].live | |
50 | elseif playdate.buttonJustPressed("b") then | |
51 | running = true | |
52 | end | |
53 | else | |
54 | -- running | |
134c4bab | 55 | end |
77772b8b | 56 | end |