-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfield.lua
More file actions
177 lines (147 loc) · 4.42 KB
/
Copy pathfield.lua
File metadata and controls
177 lines (147 loc) · 4.42 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
--require "levelGenerator"
Field = {}
function Field:load(arg1, arg2, arg3, arg4, arg5)
local i, j
cell = { width = arg1, heigth = arg2, dist = arg3}
field = {
present = {},
next = {},
size = {x = arg4, y = arg5}
}
for i = 1, field.size.y, 1 do
field.present[i] = {}
field.next[i] = {}
for j = 1, field.size.x, 1 do
field.present[i][j] = {v = 0, {lighted = false}}
field.next[i][j] = 0
--print(field.present[i][j])
end
end
allign = { x = cell.width + cell.dist, y = cell.width + cell.dist }
allign.y = cell.width + cell.dist
-- Flags
win = false
button1 = Nil
end
function Field:drawField()
local i, j
for i = 1, field.size.y, 1 do
for j = 1, field.size.x, 1 do
if field.present[i][j].v == 0 then
if field.present[i][j].lighted then
love.graphics.setColor(192,192,192)
Field:drawCell((j - 1) * allign.x, (i - 1) * allign.y, cell.width, cell.heigth)
love.graphics.setColor(255,255,255)
else
Field:drawCell((j - 1) * allign.x, (i - 1) * allign.y, cell.width, cell.heigth)
end
else
if field.present[i][j].v == 1 then
love.graphics.setColor(60,130,230)
Field:drawCell((j - 1) * allign.x, (i - 1) * allign.y, cell.width, cell.heigth)
love.graphics.setColor(255,255,255)
end
end
end
end
end
function Field:update(mouseClicked, gameStarted)
local i, j, x, y
if gameStarted then
print("chanege gen call")
return Field:changeGenertion()
end
x, y = love.mouse.getPosition()
for i = 1, field.size.x , 1 do
for j = 1, field.size.y, 1 do
Field:processMouseSignal(i, j, x, y, mouseClicked)
end
end
end
-- Pocessing scanned signals
function Field:processMouseSignal(i, j, x, y , mouseClicked)
if (j - 1) * allign.x <= x and x < j * allign.x and (i - 1) * allign.y <= y and y < i * allign.y then
if mouseClicked then
if field.present[i][j].v == 1 then
field.present[i][j].v = 0
field.present[i][j].lighted = true
else
field.present[i][j].v = 1
end
else
if field.present[i][j].v == 0 then
field.present[i][j].lighted = true
end
end
else
if field.present[i][j].lighted == true then
field.present[i][j].lighted = false
end
end
end
function Field:drawCell( posX, posY, width, heigth )
return love.graphics.rectangle("fill" ,posX, posY, width, heigth)
end
function Field:changeGenertion()
local i, j
for i = 1, field.size.y, 1 do
for j = 1, field.size.x, 1 do
field.next[i][j] = Field:checkCell( i, j)
end
end
Field:copyGenerations()
end
function Field:checkCell(i, j)
local left, right, top, bottom, amount
print(field.size.y, field.size.y)
if i == 1 then
top = field.size.y
bottom = i + 1
else
if i == field.size.y then
top = i - 1
bottom = 1
else
top = i - 1
bottom = i+1
end
end
if j == 1 then
left = field.size.x
right = j + 1
else
if j == field.size.x then
left = j - 1
right = 1
print("--")
else
left = j - 1
right = j + 1
end
end
print(i, left, right, top, bottom)
amount = field.present[top][left].v + field.present[top][j].v + field.present[top][right].v +
field.present[i][left].v + field.present[i][right].v +
field.present[bottom][left].v + field.present[bottom][j].v + field.present[bottom][right].v
if field.present[i][j].v == 1 then
if amount == 2 or amount == 3 then
return 1
else
return 0
end
else
if amount == 3 then
return 1
else
return 0
end
end
end
function Field:copyGenerations()
local i, j
for i = 1, field.size.y, 1 do
for j = 1, field.size.x, 1 do
field.present[i][j].v = field.next[i][j]
end
end
end