|
1 -- enable awesome translaction support so we can use loc() wherever we want |
|
2 loadfile(GetDataPath() .. "Scripts/Locale.lua")() |
|
3 |
|
4 local moveTimer = 0 |
|
5 local leftOn = false |
|
6 local rightOn = false |
|
7 local upOn = false |
|
8 local downOn = false |
|
9 |
|
10 local shotsMax = 10 |
|
11 local shotsLeft = 50 |
|
12 |
|
13 local TimeLeftCounter = 0 |
|
14 local TimeLeft = 30--000 |
|
15 local stopMovement = false |
|
16 local tumbleStarted = false |
|
17 |
|
18 ------------------------ |
|
19 |
|
20 function GetSpeed() |
|
21 |
|
22 dx, dy = GetGearVelocity(CurrentHedgehog) |
|
23 |
|
24 x = dx*dx |
|
25 y = dy*dy |
|
26 z = x+y |
|
27 |
|
28 z = z*100 |
|
29 |
|
30 k = z%1 |
|
31 |
|
32 if k ~= 0 then |
|
33 z = z - k |
|
34 end |
|
35 |
|
36 return(z) |
|
37 |
|
38 end |
|
39 |
|
40 function onGameInit() |
|
41 --Theme = "Hell" |
|
42 end |
|
43 |
|
44 |
|
45 function onGameStart() |
|
46 ShowMission(loc("TUMBLER"), "a Hedgewars mini-game", "- Use the arrow keys to move|- Use [enter] and [backspace] to fire", 4, 4000) |
|
47 end |
|
48 |
|
49 function onHJump() |
|
50 if (shotsLeft > 0) and (CurrentHedgehog ~= nil) and (stopMovement == false) and (tumbleStarted == true) then -- seems to not work with a hedgehog nil chek |
|
51 shotsLeft = shotsLeft - 1 |
|
52 AddGear(GetX(CurrentHedgehog), GetY(CurrentHedgehog), gtMortar, 0, 0, 0, 1) |
|
53 AddCaption(loc("Shots Left: ") .. shotsLeft) |
|
54 end |
|
55 end |
|
56 |
|
57 function onLJump() |
|
58 if (shotsLeft > 0) and (CurrentHedgehog ~= nil) and (stopMovement == false) and (tumbleStarted == true) then -- seems to not work with a hedgehog nil chek |
|
59 |
|
60 dx, dy = GetGearVelocity(CurrentHedgehog) |
|
61 |
|
62 --boosts in the direction you're already going |
|
63 --[[if dx >= 0 then |
|
64 x = -15 |
|
65 elseif dx < 0 then |
|
66 x = 15 |
|
67 end |
|
68 |
|
69 if dy >= 0 then |
|
70 y = -15 |
|
71 elseif dy < 0 then |
|
72 y = 15 |
|
73 end]] |
|
74 |
|
75 |
|
76 -- this repositions where the explosions are going to appear |
|
77 -- based on the users INTENDED (keypress) direction |
|
78 -- thus allowing to boost yourself or change direction with |
|
79 -- a blast |
|
80 |
|
81 -- naturally, it's also an anti-hog weapon |
|
82 |
|
83 x = 0 |
|
84 y = 0 |
|
85 |
|
86 if leftOn == true then |
|
87 x = x + 15 |
|
88 end |
|
89 if rightOn == true then |
|
90 x = x - 15 |
|
91 end |
|
92 |
|
93 if upOn == true then |
|
94 y = y + 15 |
|
95 end |
|
96 if downOn == true then |
|
97 y = y - 15 |
|
98 end |
|
99 |
|
100 |
|
101 shotsLeft = shotsLeft - 1 |
|
102 AddGear((GetX(CurrentHedgehog) + x), (GetY(CurrentHedgehog) + y), gtGrenade, 0, 0, 0, 1) |
|
103 AddCaption(loc("Shots Left: ") .. shotsLeft) |
|
104 |
|
105 end |
|
106 end |
|
107 |
|
108 function onLeft() |
|
109 if (CurrentHedgehog ~= nil) and (stopMovement == false) then |
|
110 leftOn = true |
|
111 end |
|
112 end |
|
113 |
|
114 function onRight() |
|
115 if (CurrentHedgehog ~= nil) and (stopMovement == false) then |
|
116 rightOn = true |
|
117 end |
|
118 end |
|
119 |
|
120 function onUp() |
|
121 if (CurrentHedgehog ~= nil) and (stopMovement == false) then |
|
122 upOn = true |
|
123 end |
|
124 end |
|
125 |
|
126 function onDown() |
|
127 if (CurrentHedgehog ~= nil) and (stopMovement == false) then |
|
128 downOn = true |
|
129 end |
|
130 end |
|
131 |
|
132 function onDownUp() |
|
133 downOn = false |
|
134 end |
|
135 function onUpUp() |
|
136 upOn = false |
|
137 end |
|
138 function onLeftUp() |
|
139 leftOn = false |
|
140 end |
|
141 function onRightUp() |
|
142 rightOn = false |
|
143 end |
|
144 |
|
145 function onNewTurn() |
|
146 shotsLeft = shotsMax |
|
147 stopMovement = false |
|
148 tumbleStarted = false |
|
149 --SetInputMask(band(0xFFFFFFFF, bnot(gmAnimate+gmAttack+gmDown+gmHJump+gmLeft+gmLJump+gmPrecise+gmRight+gmSlot+gmSwitch+gmTimer+gmUp+gmWeapon))) |
|
150 --AddGear(GetX(CurrentHedgehog), GetY(CurrentHedgehog), gtGrenade, 0, 0, 0, 1) |
|
151 end |
|
152 |
|
153 function onGameTick() |
|
154 |
|
155 -- start the player tumbling with a boom once their turn has actually begun |
|
156 if tumbleStarted == false then |
|
157 if (TurnTimeLeft > 0) and (TurnTimeLeft ~= TurnTime) then |
|
158 AddCaption("Good to go!") |
|
159 tumbleStarted = true |
|
160 TimeLeft = 45 |
|
161 AddGear(GetX(CurrentHedgehog), GetY(CurrentHedgehog), gtGrenade, 0, 0, 0, 1) |
|
162 end |
|
163 end |
|
164 |
|
165 if (CurrentHedgehog ~= nil) and (tumbleStarted == true) then |
|
166 |
|
167 --AddCaption(loc("Speed: ") .. GetSpeed()) |
|
168 |
|
169 -- Calculate and display turn time |
|
170 TimeLeftCounter = TimeLeftCounter + 1 |
|
171 if TimeLeftCounter == 1000 then |
|
172 TimeLeftCounter = 0 |
|
173 TimeLeft = TimeLeft - 1 |
|
174 |
|
175 if TimeLeft >= 0 then |
|
176 --TurnTimeLeft = TimeLeft |
|
177 AddCaption(loc("Time Left: ") .. TimeLeft) |
|
178 end |
|
179 |
|
180 end |
|
181 |
|
182 --if TimeLeft >= 0 then |
|
183 -- --TurnTimeLeft = TimeLeft |
|
184 -- AddCaption(loc("Time Left: ") .. TimeLeft) |
|
185 --end |
|
186 |
|
187 --ShowMission(loc("TUMBLER"), loc("v0.2"), loc("Speed: ") .. GetSpeed() .. "|" .. loc("Ammo: ") .. shotsLeft, 4, 0) |
|
188 |
|
189 if TimeLeft == 0 then |
|
190 stopMovement = true |
|
191 upOn = false |
|
192 down = false |
|
193 leftOn = false |
|
194 rightOn = false |
|
195 end |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 -- handle movement based on IO |
|
201 moveTimer = moveTimer + 1 |
|
202 if moveTimer == 100 then -- 100 |
|
203 moveTimer = 0 |
|
204 |
|
205 dx, dy = GetGearVelocity(CurrentHedgehog) |
|
206 |
|
207 dxlimit = 0.4 |
|
208 dylimit = 0.4 |
|
209 |
|
210 if dx > dxlimit then |
|
211 dx = dxlimit |
|
212 end |
|
213 if dy > dylimit then |
|
214 dy = dylimit |
|
215 end |
|
216 if dx < -dxlimit then |
|
217 dx = -dxlimit |
|
218 end |
|
219 if dy < -dylimit then |
|
220 dy = -dylimit |
|
221 end |
|
222 |
|
223 |
|
224 if leftOn == true then |
|
225 dx = dx - 0.1 |
|
226 end |
|
227 if rightOn == true then |
|
228 dx = dx + 0.1 |
|
229 end |
|
230 |
|
231 if upOn == true then |
|
232 dy = dy - 0.1 |
|
233 end |
|
234 if downOn == true then |
|
235 dy = dy + 0.1 |
|
236 end |
|
237 |
|
238 --if leftOn == true then |
|
239 -- dx = dx - 0.04 |
|
240 --end |
|
241 --if rightOn == true then |
|
242 -- dx = dx + 0.04 |
|
243 --end |
|
244 |
|
245 --if upOn == true then |
|
246 -- dy = dy - 0.1 |
|
247 --end |
|
248 --if downOn == true then |
|
249 -- dy = dy + 0.06 |
|
250 --end |
|
251 |
|
252 SetGearVelocity(CurrentHedgehog, dx, dy) |
|
253 |
|
254 end |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 end |
|
263 |
|
264 |
|
265 |
|
266 end |
|
267 |
|
268 |
|
269 function onGearDamage(gear, damage) |
|
270 if gear == CurrentHedgehog then |
|
271 -- You are now tumbling |
|
272 end |
|
273 end |
|
274 |
|
275 |
|
276 function onGearAdd(gear) |
|
277 end |
|
278 |
|
279 function onGearDelete(gear) |
|
280 |
|
281 if CurrentHedgehog ~= nil then |
|
282 FollowGear(CurrentHedgehog) |
|
283 end |
|
284 |
|
285 end |