|
1 local animPos, lastx, lasty, jumpTypes, jumpTimes, moveDirs, jumpStarted |
|
2 local backJumped, jTimer, awTime, globalWait, stageEvents, seNum |
|
3 local AnimList, AnimListNum |
|
4 local FunctionList, FunctionListNum |
|
5 local skipFuncList |
|
6 local skipping |
|
7 --------------------------------Animation--------------------------------- |
|
8 --------------------------(In-game cinematics)---------------------------- |
|
9 |
|
10 function AddSkipFunction(anim, func, args) |
|
11 skipFuncList[anim] = {sfunc = func, sargs = args} |
|
12 end |
|
13 |
|
14 function RemoveSkipFunctin(anim) |
|
15 skipFuncList[anim] = nil |
|
16 end |
|
17 |
|
18 function SetAnimSkip(bool) |
|
19 skipping = bool |
|
20 end |
|
21 |
|
22 function AnimInProgress() |
|
23 return AnimListNum ~= 0 |
|
24 end |
|
25 |
|
26 function SkipAnimation(anim) |
|
27 if skipFuncList[anim] == nil then |
|
28 return |
|
29 else |
|
30 skipFuncList[anim].sfunc(unpack(skipFuncList[anim].sargs)) |
|
31 end |
|
32 end |
|
33 |
|
34 function AddFunction(element) |
|
35 table.insert(FunctionList, element) |
|
36 FunctionListNum = FunctionListNum + 1 |
|
37 end |
|
38 |
|
39 function RemoveFunction() |
|
40 table.remove(FunctionList, 1) |
|
41 FunctionListNum = FunctionListNum - 1 |
|
42 end |
|
43 |
|
44 function ExecuteAfterAnimations() |
|
45 if FunctionListNum == 0 then |
|
46 return |
|
47 end |
|
48 FunctionList[1].func(unpack(FunctionList[1].args)) |
|
49 RemoveFunction() |
|
50 end |
|
51 |
|
52 function AnimInit() |
|
53 animPos = 1 |
|
54 lastx = 0 |
|
55 lasty = 0 |
|
56 jumpTypes = {long = gmLJump, high = gmHJump, back = gmHJump} |
|
57 jumpTimes = {long = 500, high = 500, back = 300, backback = 500} |
|
58 moveDirs = {right = gmRight, left = gmLeft} |
|
59 jumpStarted = false |
|
60 backJumped = false |
|
61 jTimer = 0 |
|
62 awTime = 0 |
|
63 globalWait = 0 |
|
64 stageEvents = {} |
|
65 seNum = 0 |
|
66 AnimList = {} |
|
67 AnimListNum = 0 |
|
68 FunctionList = {} |
|
69 FunctionListNum = 0 |
|
70 skipping = false |
|
71 skipFuncList = {} |
|
72 end |
|
73 |
|
74 function AnimSwitchHog(gear) |
|
75 SwitchHog(gear) |
|
76 FollowGear(gear) |
|
77 SetGearMessage(gear, 0) |
|
78 return true |
|
79 end |
|
80 |
|
81 function AnimGiveState(gear, state) |
|
82 SetState(gear, state) |
|
83 return true |
|
84 end |
|
85 |
|
86 function AnimRemoveState(gear, state) |
|
87 SetState(gear, band(GetState(gear), bnot(state))) |
|
88 return true |
|
89 end |
|
90 |
|
91 function AnimGearWait(gear, time) |
|
92 AnimWait(gear, time) |
|
93 return true |
|
94 end |
|
95 |
|
96 function AnimUnWait() |
|
97 if globalWait > 0 then |
|
98 globalWait = globalWait - 1 |
|
99 end |
|
100 end |
|
101 |
|
102 function AnimWait(gear, time) -- gear is for compatibility with Animate |
|
103 globalWait = globalWait + time |
|
104 return true |
|
105 end |
|
106 |
|
107 function AnimWaitLeft() |
|
108 return globalWait |
|
109 end |
|
110 |
|
111 function AnimSay(gear, text, manner, time) |
|
112 HogSay(gear, text, manner, 2) |
|
113 if time ~= nil then |
|
114 AnimWait(gear, time) |
|
115 end |
|
116 return true |
|
117 end |
|
118 |
|
119 function AnimSound(gear, sound, time) |
|
120 PlaySound(sound, gear) |
|
121 AnimWait(gear, time) |
|
122 return true |
|
123 end |
|
124 |
|
125 function AnimTurn(gear, dir) |
|
126 if dir == "Right" then |
|
127 HogTurnLeft(gear, false) |
|
128 else |
|
129 HogTurnLeft(gear, true) |
|
130 end |
|
131 return true |
|
132 end |
|
133 |
|
134 function AnimFollowGear(gear) |
|
135 FollowGear(gear) |
|
136 return true |
|
137 end |
|
138 |
|
139 function AnimMove(gear, dir, posx, posy) |
|
140 dirr = moveDirs[dir] |
|
141 SetGearMessage(gear, dirr) |
|
142 if GetX(gear) == posx or GetY(gear) == posy then |
|
143 SetGearMessage(gear, 0) |
|
144 lastx = GetX(gear) |
|
145 lasty = GetY(gear) |
|
146 return true |
|
147 end |
|
148 return false |
|
149 end |
|
150 |
|
151 function AnimJump(gear, jumpType) |
|
152 if jumpStarted == false then |
|
153 lastx = GetX(gear) |
|
154 lasty = GetY(gear) |
|
155 backJumped = false |
|
156 jumpStarted = true |
|
157 SetGearMessage(gear, jumpTypes[jumpType]) |
|
158 AnimGearWait(gear, jumpTimes[jumpType]) |
|
159 elseif jumpType == "back" and backJumped == false then |
|
160 backJumped = true |
|
161 SetGearMessage(gear, jumpTypes[jumpType]) |
|
162 AnimGearWait(gear, jumpTimes["backback"]) |
|
163 else |
|
164 curx = GetX(gear) |
|
165 cury = GetY(gear) |
|
166 if curx == lastx and cury == lasty then |
|
167 jumpStarted = false |
|
168 backJumped = false |
|
169 AnimGearWait(gear, 100) |
|
170 return true |
|
171 else |
|
172 lastx = curx |
|
173 lasty = cury |
|
174 AnimGearWait(gear, 100) |
|
175 end |
|
176 end |
|
177 return false |
|
178 end |
|
179 |
|
180 function AnimDisappear(gear, destX, destY) |
|
181 AddVisualGear(GetX(gear)-5, GetY(gear)-5, vgtSmoke, 0, false) |
|
182 AddVisualGear(GetX(gear)+5, GetY(gear)+5, vgtSmoke, 0, false) |
|
183 AddVisualGear(GetX(gear)-5, GetY(gear)+5, vgtSmoke, 0, false) |
|
184 AddVisualGear(GetX(gear)+5, GetY(gear)-5, vgtSmoke, 0, false) |
|
185 SetGearPosition(gear, destX, destY) |
|
186 return true |
|
187 end |
|
188 |
|
189 function AnimOutOfNowhere(gear, destX, destY) |
|
190 SetGearPosition(gear, destX, destY) |
|
191 AddVisualGear(destX, destY, vgtBigExplosion, 0, false) |
|
192 AnimGearWait(gear, 50) |
|
193 return true |
|
194 end |
|
195 |
|
196 function AnimTeleportGear(gear, destX, destY) |
|
197 AddVisualGear(GetX(gear)-5, GetY(gear)-5, vgtSmoke, 0, false) |
|
198 AddVisualGear(GetX(gear)+5, GetY(gear)+5, vgtSmoke, 0, false) |
|
199 AddVisualGear(GetX(gear)-5, GetY(gear)+5, vgtSmoke, 0, false) |
|
200 AddVisualGear(GetX(gear)+5, GetY(gear)-5, vgtSmoke, 0, false) |
|
201 SetGearPosition(gear, destX, destY) |
|
202 AddVisualGear(GetX(gear), GetY(gear), vgtBigExplosion, 0, false) |
|
203 FollowGear(gear) |
|
204 AnimGearWait(gear, 50) |
|
205 return true |
|
206 end |
|
207 |
|
208 function AnimSetGearPosition(gear, x, y) |
|
209 SetGearPosition(gear, x, y) |
|
210 return true |
|
211 end |
|
212 |
|
213 function AnimVisualGear(gear, x, y, vgType, state, critical) |
|
214 AddVisualGear(x, y, vgType, state, critical) |
|
215 return true |
|
216 end |
|
217 |
|
218 function AnimCaption(gear, text, time) |
|
219 AddCaption(text) |
|
220 AnimWait(gear, time) |
|
221 return true |
|
222 end |
|
223 |
|
224 function AnimCustomFunction(gear, func, args) |
|
225 if args == nil then |
|
226 args = {} |
|
227 end |
|
228 retval = func(unpack(args)) |
|
229 if retval == false then |
|
230 return false |
|
231 else |
|
232 return true |
|
233 end |
|
234 end |
|
235 |
|
236 function AnimInsertStepNext(step) |
|
237 table.insert(AnimList[1], animPos + 1, step) |
|
238 return true |
|
239 end |
|
240 |
|
241 function AnimShowMission(gear, caption, subcaption, text, icon, time) |
|
242 ShowMission(caption, subcaption, text, icon, time) |
|
243 return true |
|
244 end |
|
245 |
|
246 function RemoveAnim() |
|
247 table.remove(AnimList, 1) |
|
248 AnimListNum = AnimListNum - 1 |
|
249 end |
|
250 |
|
251 function AddAnim(animation) |
|
252 table.insert(AnimList, animation) |
|
253 AnimListNum = AnimListNum + 1 |
|
254 if AnimListNum == 1 then |
|
255 skipping = false |
|
256 end |
|
257 end |
|
258 |
|
259 function ShowAnimation() |
|
260 if AnimListNum == 0 then |
|
261 skipping = false |
|
262 return true |
|
263 else |
|
264 TurnTimeLeft = -1 |
|
265 if Animate(AnimList[1]) == true then |
|
266 RemoveAnim() |
|
267 end |
|
268 end |
|
269 return false |
|
270 end |
|
271 |
|
272 function Animate(steps) |
|
273 if skipping == true then |
|
274 animPos = 1 |
|
275 SetInputMask(0xFFFFFFFF) |
|
276 SkipAnimation(steps) |
|
277 return true |
|
278 end |
|
279 |
|
280 if globalWait ~= 0 then |
|
281 return false |
|
282 end |
|
283 |
|
284 if steps[animPos] == nil then |
|
285 animPos = 1 |
|
286 SetInputMask(0xFFFFFFFF) |
|
287 return true |
|
288 end |
|
289 |
|
290 if steps[animPos].args[1] ~= CurrentHedgehog and steps[animPos].func ~= AnimWait |
|
291 and (steps[animPos].swh == nil or steps[animPos].swh == true) then |
|
292 AnimSwitchHog(steps[animPos].args[1]) |
|
293 end |
|
294 |
|
295 SetInputMask(band(0xFFFFFFFF, bnot(gmAnimate+gmAttack+gmDown+gmHJump+gmLeft+gmLJump+gmRight+gmSlot+gmSwitch+gmTimer+gmUp+gmWeapon))) |
|
296 retVal = steps[animPos].func(unpack(steps[animPos].args)) |
|
297 if (retVal ~= false) then |
|
298 animPos = animPos + 1 |
|
299 end |
|
300 |
|
301 return false |
|
302 end |
|
303 |
|
304 ------------------------------Event Handling------------------------------ |
|
305 |
|
306 function AddEvent(condFunc, condArgs, doFunc, doArgs, evType) |
|
307 seNum = seNum + 1 |
|
308 stageEvents[seNum] = {} |
|
309 stageEvents[seNum].cFunc = condFunc |
|
310 stageEvents[seNum].cArgs = condArgs |
|
311 stageEvents[seNum].dFunc = doFunc |
|
312 stageEvents[seNum].dArgs = doArgs |
|
313 stageEvents[seNum].evType = evType |
|
314 end |
|
315 |
|
316 function RemoveEvent(evNum) |
|
317 if stageEvents[evNum] ~= nil then |
|
318 seNum = seNum - 1 |
|
319 table.remove(stageEvents, evNum) |
|
320 end |
|
321 end |
|
322 |
|
323 function RemoveEventFunc(cFunc) |
|
324 local i = 1 |
|
325 while i <= seNum do |
|
326 if stageEvents[i].cFunc == cFunc then |
|
327 RemoveEvent(i) |
|
328 i = i - 1 |
|
329 end |
|
330 i = i + 1 |
|
331 end |
|
332 end |
|
333 |
|
334 |
|
335 function CheckEvents() |
|
336 local i = 1 |
|
337 while i <= seNum do |
|
338 if stageEvents[i].cFunc(unpack(stageEvents[i].cArgs)) then |
|
339 stageEvents[i].dFunc(unpack(stageEvents[i].dArgs)) |
|
340 if stageEvents[i].evType ~= 1 then |
|
341 RemoveEvent(i) |
|
342 i = i - 1 |
|
343 end |
|
344 end |
|
345 i = i + 1 |
|
346 end |
|
347 end |
|
348 |
|
349 -------------------------------------Misc--------------------------------- |
|
350 |
|
351 function StoppedGear(gear) |
|
352 dx,dy = GetGearVelocity(gear) |
|
353 return math.abs(dx) <= 1 and math.abs(dy) <= 1 |
|
354 end |