-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrid-manager.lua
130 lines (121 loc) · 4.72 KB
/
grid-manager.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
function InitiateGrid(width,height)
local grid = {}
for i = 1,width do
grid[i] = {}
for j = 1,height do
if i == 1 or i == width or j == 1 or j == height then
grid[i][j] = "border"
else
grid[i][j] = "air"
end
end
end
return grid
end
function UpdateGrid(grid)
local newGrid = {}
local smallGrid
for i = 1,#grid do
newGrid[i] = {}
for j = 1,#grid[1] do
newGrid[i][j] = grid[i][j]
end
end
local i,j
for collumn = 2,#grid-1 do
i=collumn
for row = 2,#grid[1]-1 do
--j = #grid[1]-row -- bottom to top
j=row -- top to bottom
if CheckNoRules(grid[i][j]) and grid[i][j]==newGrid[i][j] then
smallGrid = {{newGrid[i-1][j-1],newGrid[i-1][j],newGrid[i-1][j+1]},
{newGrid[i][j-1],newGrid[i][j],newGrid[i][j+1]},
{newGrid[i+1][j-1],newGrid[i+1][j],newGrid[i+1][j+1]}}
smallGrid = MoveParticle(smallGrid)
for x = 1,3 do
for y = 1,3 do
if smallGrid[x][y] ~= "*" then
newGrid[i+x-2][j+y-2] = smallGrid[x][y]
end
end
end
end
end
end
return newGrid
end
function DrawGrid(grid,cellSize)
for i = 1,#grid do
for j = 1,#grid[1] do
love.graphics.setColor(GetColor(grid[i][j]))
love.graphics.rectangle("fill",(i-1)*cellSize,(j-1)*cellSize,cellSize,cellSize)
end
end
end
function GetSelectorObjects()
local textObjects = {}
local categories = GetCategories()
local font = love.graphics.getFont()
for i,v in ipairs(categories) do
textObjects[i] = love.graphics.newText(font,v:upper())
end
return textObjects
end
function CreateElementTexts()
local textObjexts = {}
local elements = GetElements()
local font = love.graphics.getFont()
for i,v in ipairs(elements) do
textObjexts[v] = love.graphics.newText(font,v:upper())
end
return textObjexts
end
function DrawSelector(screenWidth,screenHeight,textObjects,elementObjects,category,element)
local recWidth,recHeight = screenWidth/#textObjects-10,50
local categories = GetCategories()
local elementCategories = GetElementCategory(category)
local width,height
local elements = GetElements()
for i,v in ipairs(textObjects) do
width = v:getWidth()
height = v:getHeight()
if categories[i] == category then
love.graphics.setColor(math.sqrt(GetDisplayColor(categories[i])[1]),math.sqrt(GetDisplayColor(categories[i])[2]),math.sqrt(GetDisplayColor(categories[i])[3]),0.3)
love.graphics.rectangle("fill",(i-1)/#textObjects*screenWidth+5,screenHeight+10,recWidth,recHeight,2)
end
love.graphics.setColor(GetDisplayColor(categories[i]))
love.graphics.rectangle("line",(i-1)/#textObjects*screenWidth+5,screenHeight+10,recWidth,recHeight,2)
love.graphics.draw(v,(i-1)/#textObjects*screenWidth+(recWidth-width)/2,screenHeight+(recHeight-height)/2+10)
end
recWidth,recHeight = 100,50
local v
for i,k in ipairs(elementCategories) do
v = elementObjects[k]
width = v:getWidth()
height = v:getHeight()
if k == element then
love.graphics.setColor(math.sqrt(GetDisplayColor(k)[1]),math.sqrt(GetDisplayColor(k)[2]),math.sqrt(GetDisplayColor(k)[3]),0.3)
love.graphics.rectangle("fill",(i-1)*(recWidth+10)+screenWidth/2-(recWidth+10)/2*#elementCategories,screenHeight+80,recWidth,recHeight,10)
end
love.graphics.setColor(GetDisplayColor(k))
love.graphics.rectangle("line",(i-1)*(recWidth+10)+screenWidth/2-(recWidth+10)/2*#elementCategories,screenHeight+80,recWidth,recHeight,10)
love.graphics.draw(v,(i-1)*(recWidth+10)+screenWidth/2-(recWidth+10)/2*#elementCategories+(recWidth-width)/2,screenHeight+(recHeight-height)/2+80)
end
end
function SelectCategory(mousex,screenWidth,category)
local categories = GetCategories()
local newCategory = math.floor((mousex-2)/screenWidth*#categories+1)
if newCategory >= 1 and newCategory <= #categories then
return categories[newCategory]
end
return category
end
function SelectElement(mousex,screenWidth,category,element)
local elementCategories = GetElementCategory(category)
local recWidth = 100
local newElement=math.floor((mousex-screenWidth/2+(recWidth+10)/2*#elementCategories)/(recWidth+10)+1)
if newElement>=1 and newElement<=#elementCategories then
return elementCategories[newElement]
end
return element
end