-
Notifications
You must be signed in to change notification settings - Fork 0
/
stones.lua
53 lines (51 loc) · 1.12 KB
/
stones.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function generate_stones()
stones_meta = {}
stones_meta.__index = {
init = function(self)
for i = 1, SIZE do
self[i] = {}
end
end,
add = function(self, color, x, y)
self[x][y] = { color = color, x = x, y = y }
end,
get = function(self, color)
local filtered = {}
for _, row in ipairs(self) do
for _, stone in ipairs(row) do
if stone.color == color then
table.insert(filtered, stone)
end
end
end
return filtered
end,
}
local stones = {}
setmetatable(stones, stones_meta)
stones:init()
return stones
end
function draw_stones()
for _, row in pairs(STONES) do
for _, stone in pairs(row) do
if stone then
if stone.color == BLACK then
img = BLACK_STONE
else
img = WHITE_STONE
end
love.graphics.draw(
img,
stone.x - 0.5,
stone.y - 0.5,
0,
1 / STONE_WIDTH * STONE_SCALE,
1 / STONE_HEIGHT * STONE_SCALE,
STONE_WIDTH / 2,
STONE_HEIGHT / 2
)
end
end
end
end