-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathavonlib.lua
More file actions
294 lines (233 loc) · 7.18 KB
/
avonlib.lua
File metadata and controls
294 lines (233 loc) · 7.18 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
_G.AL = {}
local LOC = {}
local CColors = require("colors")
local CVideos = require("video")
local CAudio = require("audio")
--STACK
AL.Stack = function()
local tStack = {}
tStack.tTable = {}
tStack.Push = function(item)
table.insert(tStack.tTable, item)
end
tStack.Pop = function()
return table.remove(tStack.tTable, 1)
end
tStack.PopLast = function()
return table.remove(tStack.tTable, #tStack.tTable)
end
tStack.Size = function()
return #tStack.tTable
end
return tStack
end
--//
--TIMER
local tTimers = AL.Stack()
AL.NewTimer = function(iSetTime, fCallback)
tTimers.Push({iTime = iSetTime, fCallback = fCallback})
end
AL.CountTimers = function(iTimePassed)
for i = 1, tTimers.Size() do
local tTimer = tTimers.Pop()
tTimer.iTime = tTimer.iTime - iTimePassed
if tTimer.iTime <= 0 then
local iNewTime = tTimer.fCallback()
if iNewTime then
tTimer.iTime = tTimer.iTime + iNewTime
else
tTimer = nil
end
end
if tTimer then
tTimers.Push(tTimer)
end
end
end
--//
--RECT
function AL.RectIntersects(iX1, iY1, iSize1, iX2, iY2, iSize2)
if iSize1 == 0 or iSize2 == 0 then return false; end
if iX1 > iX2+iSize2-1 or iX2 > iX1+iSize1-1 then return false; end
if iY1+iSize1-1 < iY2 or iY2+iSize2-1 < iY1 then return false; end
return true
end
function AL.RectIntersects2(iX1, iY1, iSizeX1, iSizeY1, iX2, iY2, iSizeX2, iSizeY2)
if iSize1 == 0 or iSize2 == 0 then return false; end
if iX1 > iX2+iSizeX2-1 or iX2 > iX1+iSizeX1-1 then return false; end
if iY1+iSizeY1-1 < iY2 or iY2+iSizeY2-1 < iY1 then return false; end
return true
end
--//
--NFZ - NoFeetZone / Pixel Wall Zone / Зона Пиксельной Стены
AL.NFZ = {}
local tGame = {}
AL.RoomHasNFZ = function(tGameIn)
tGame = tGameIn
if tGame and tGame.NoFeetZones ~= nil then
if #tGame.NoFeetZones > 0 then
return true;
end
end
return false;
end
AL.IsPixelInNFZ = function(iX, iY)
return AL.IsRectInNFZ(iX, iY, 1, 1)
end
AL.IsRectInNFZ = function(iX, iY, iSizeX, iSizeY)
for iNFZId = 1, #tGame.NoFeetZones do
if AL.RectIntersects2(iX, iY, iSizeX, iSizeY, tGame.NoFeetZones[iNFZId].X,tGame.NoFeetZones[iNFZId].Y, tGame.NoFeetZones[iNFZId].SizeX, tGame.NoFeetZones[iNFZId].SizeY) then
return true;
end
end
return false
end
AL.LoadNFZInfo = function()
AL.NFZ = {}
AL.NFZ.iMinX = NFZ_LoadMinX()
AL.NFZ.iMinY = NFZ_LoadMinY()
AL.NFZ.iMaxX = NFZ_LoadMaxX()
AL.NFZ.iMaxY = NFZ_LoadMaxY()
AL.NFZ.iCenterX = math.floor((AL.NFZ.iMaxX - AL.NFZ.iMinX)/2)
AL.NFZ.iCenterY = math.floor((AL.NFZ.iMaxY - AL.NFZ.iMinY)/2)
AL.NFZ.bLoaded = true
end
NFZ_LoadMinX = function()
local iMinX = 1
for iNFZId = 1, #tGame.NoFeetZones do
if tGame.NoFeetZones[iNFZId].X + tGame.NoFeetZones[iNFZId].SizeX < math.floor(tGame.Cols/2) and (tGame.NoFeetZones[iNFZId].X + tGame.NoFeetZones[iNFZId].SizeX) > iMinX then
iMinX = tGame.NoFeetZones[iNFZId].X + tGame.NoFeetZones[iNFZId].SizeX
end
end
return iMinX
end
NFZ_LoadMinY = function()
local iMinY = 1
for iNFZId = 1, #tGame.NoFeetZones do
if tGame.NoFeetZones[iNFZId].Y + tGame.NoFeetZones[iNFZId].SizeY < math.floor(tGame.Rows/2) and (tGame.NoFeetZones[iNFZId].Y + tGame.NoFeetZones[iNFZId].SizeY) > iMinY then
iMinY = tGame.NoFeetZones[iNFZId].Y + tGame.NoFeetZones[iNFZId].SizeY
end
end
return iMinY
end
NFZ_LoadMaxX = function()
local iMaxX = tGame.Cols
for iNFZId = 1, #tGame.NoFeetZones do
if tGame.NoFeetZones[iNFZId].SizeX < tGame.Cols/2 and tGame.NoFeetZones[iNFZId].X > math.floor(tGame.Cols/2) and tGame.NoFeetZones[iNFZId].X < iMaxX then
iMaxX = tGame.NoFeetZones[iNFZId].X
end
end
return iMaxX
end
NFZ_LoadMaxY = function()
local iMaxY = tGame.Rows
for iNFZId = 1, #tGame.NoFeetZones do
if tGame.NoFeetZones[iNFZId].SizeY < tGame.Rows/2 and tGame.NoFeetZones[iNFZId].Y > math.floor(tGame.Rows/2) and tGame.NoFeetZones[iNFZId].Y < iMaxY then
iMaxY = tGame.NoFeetZones[iNFZId].Y
end
end
return iMaxY
end
--//
--COLORS
AL.Colors = {}
AL.LoadColors = function()
if tGame.Colors ~= nil then
for iColor = 1, #tGame.Colors do
AL.Colors[iColor] = tonumber(tGame.Colors[iColor])
end
else
AL.Colors =
{
CColors.MAGENTA,
CColors.BLUE,
CColors.GREEN,
CColors.CYAN,
CColors.YELLOW,
CColors.RED
};
end
end
--//
--RULES
AL.NewRulesScript = true
AL.Rules = {}
AL.Rules.iCountDownTime = 20
AL.Rules.bVideoOn = false
AL.Rules.bSoundOn = false
AL.Rules.iVideoDuration = 9.5
AL.Rules.FillFloor = function(tFloor)
local tReturnFloor = {}
local iSkip = 0
if not AL.Rules.bVideoOn then
CVideos.Play("tutorial/skip.mp4")
AL.Rules.bVideoOn = true
AL.NewTimer(AL.Rules.iVideoDuration*1000, function()
CVideos.Stop()
end)
end
if not AL.Rules.bSoundOn then
CAudio.PlayVoicesSync("tutorial/skip.mp3")
AL.Rules.bSoundOn = true
end
local function redPixel(iX, iY)
tReturnFloor[iX][iY] = CColors.RED
if iSkip == 0 and (tFloor[iX][iY].Click or tFloor[iX][iY].bClick) and not tFloor[iX][iY].Defect and not tFloor[iX][iY].bDefect then
iSkip = 2
end
end
local function greenPixel(iX, iY)
tReturnFloor[iX][iY] = CColors.GREEN
if (tFloor[iX][iY].Click or tFloor[iX][iY].bClick) and not tFloor[iX][iY].Defect and not tFloor[iX][iY].bDefect then
iSkip = 1
end
end
for iX = 1, #tFloor do
tReturnFloor[iX] = {}
for iY = 1, #tFloor[iX] do
if tFloor[iX][iY] then
if iY >= (#tFloor[iX]/2) then
redPixel(iX, iY)
else
greenPixel(iX, iY)
end
end
end
end
return tReturnFloor, iSkip==2
end
--//
--LASERS
AL.bRoomHasLasers = false
AL.Lasers = {}
AL.Lasers.tLasers = {}
AL.Lasers.iLines = 0
AL.Lasers.iRows = 0
AL.InitLasers = function(tGameIn)
if not tGameIn.Lasers or tGameIn.Lasers.lines < 1 then return false; end
AL.Lasers.iLines = tGameIn.Lasers.lines
AL.Lasers.iRows = tGameIn.Lasers.rows
AL.bRoomHasLasers = true
for iLine = 1, AL.Lasers.iLines do
AL.Lasers.tLasers[iLine] = {}
for iRow = 1, AL.Lasers.iRows do
AL.Lasers.tLasers[iLine][iRow] = { Light = false }
end
end
return true
end
AL.SetLasers = function(fSetLasers)
for iLine = 1, AL.Lasers.iLines do
for iRow = 1, AL.Lasers.iRows do
fSetLasers(iLine, iRow, AL.Lasers.tLasers[iLine][iRow].Light)
end
end
end
AL.SwitchLaser = function(iLine, iRow, bLight)
if AL.Lasers.tLasers[iLine] and AL.Lasers.tLasers[iLine][iRow] then
AL.Lasers.tLasers[iLine][iRow].Light = bLight
return true
end
return false
end
--//