author | unc0rr |
Mon, 09 Jan 2006 20:33:12 +0000 | |
changeset 42 | 72ffe21f027c |
parent 39 | b78e7185ed13 |
child 43 | e297fea1a2f3 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
3 |
* Copyright (c) 2004, 2005 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
5 |
* Distributed under the terms of the BSD-modified licence: |
|
6 |
* |
|
7 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8 |
* of this software and associated documentation files (the "Software"), to deal |
|
9 |
* with the Software without restriction, including without limitation the |
|
10 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|
11 |
* sell copies of the Software, and to permit persons to whom the Software is |
|
12 |
* furnished to do so, subject to the following conditions: |
|
13 |
* |
|
14 |
* 1. Redistributions of source code must retain the above copyright notice, |
|
15 |
* this list of conditions and the following disclaimer. |
|
16 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
|
17 |
* this list of conditions and the following disclaimer in the documentation |
|
18 |
* and/or other materials provided with the distribution. |
|
19 |
* 3. The name of the author may not be used to endorse or promote products |
|
20 |
* derived from this software without specific prior written permission. |
|
21 |
* |
|
22 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
|
23 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
24 |
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
|
25 |
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
26 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
27 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
|
28 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|
29 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|
30 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
31 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
32 |
*) |
|
33 |
||
34 |
procedure doStepDrowningGear(Gear: PGear); forward; |
|
35 |
||
36 |
function CheckGearDrowning(Gear: PGear): boolean; |
|
37 |
begin |
|
38 |
Result:= Gear.Y + Gear.HalfHeight >= cWaterLine; |
|
39 |
if Result then |
|
40 |
begin |
|
41 |
Gear.State:= gstDrowning; |
|
42 |
Gear.doStep:= doStepDrowningGear; |
|
43 |
PlaySound(sndSplash) |
|
44 |
end |
|
45 |
end; |
|
46 |
||
47 |
procedure CheckCollision(Gear: PGear); |
|
48 |
begin |
|
49 |
if TestCollisionXwithGear(Gear, Sign(Gear.X)) or TestCollisionYwithGear(Gear, Sign(Gear.Y)) |
|
50 |
then Gear.State:= Gear.State or gstCollision |
|
51 |
else Gear.State:= Gear.State and not gstCollision |
|
52 |
end; |
|
53 |
||
54 |
procedure CheckHHDamage(Gear: PGear); |
|
55 |
begin |
|
38 | 56 |
if Gear.dY > 0.35 then Gear.Damage:= Gear.Damage + round(75 * (abs(Gear.dY) - 0.35)); |
4 | 57 |
end; |
58 |
||
59 |
//////////////////////////////////////////////////////////////////////////////// |
|
60 |
//////////////////////////////////////////////////////////////////////////////// |
|
61 |
procedure CalcRotationDirAngle(Gear: PGear); |
|
62 |
var dAngle: real; |
|
63 |
begin |
|
64 |
dAngle:= (abs(Gear.dX) + abs(Gear.dY))*0.1; |
|
65 |
if Gear.dX >= 0 then Gear.DirAngle:= Gear.DirAngle + dAngle |
|
66 |
else Gear.DirAngle:= Gear.DirAngle - dAngle; |
|
67 |
if Gear.DirAngle < 0 then Gear.DirAngle:= Gear.DirAngle + 16 |
|
68 |
else if Gear.DirAngle >= 16 then Gear.DirAngle:= Gear.DirAngle - 16 |
|
69 |
end; |
|
70 |
||
71 |
//////////////////////////////////////////////////////////////////////////////// |
|
72 |
procedure doStepDrowningGear(Gear: PGear); |
|
73 |
begin |
|
74 |
AllInactive:= false; |
|
75 |
Gear.Y:= Gear.Y + cDrownSpeed; |
|
76 |
if round(Gear.Y) > Gear.HalfHeight + cWaterLine + 48 + cVisibleWater then DeleteGear(Gear) |
|
77 |
end; |
|
78 |
||
79 |
//////////////////////////////////////////////////////////////////////////////// |
|
80 |
procedure doStepFallingGear(Gear: PGear); |
|
81 |
var b: boolean; |
|
82 |
begin |
|
83 |
if TestCollisionYwithGear(Gear, Sign(Gear.dY)) then |
|
84 |
begin |
|
85 |
Gear.dX:= Gear.dX * Gear.Friction; |
|
86 |
Gear.dY:= - Gear.dY * Gear.Elasticity; |
|
87 |
b:= false |
|
88 |
end else b:= true; |
|
89 |
if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then |
|
90 |
begin |
|
91 |
Gear.dX:= - Gear.dX * Gear.Elasticity; |
|
92 |
// Gear.dY:= Gear.dY; |
|
93 |
b:= false |
|
94 |
end; |
|
95 |
if b then |
|
96 |
begin |
|
97 |
Gear.dY:= Gear.dY + cGravity; |
|
98 |
Gear.State:= Gear.State and not gstCollision |
|
99 |
end else |
|
100 |
begin |
|
101 |
if sqr(Gear.dX) + sqr(Gear.dY) < 0.00001 then |
|
102 |
if (Gear.Timer = 0) then Gear.Active:= false |
|
103 |
else begin |
|
104 |
Gear.dX:= 0; |
|
105 |
Gear.dY:= 0 |
|
106 |
end; |
|
107 |
Gear.State:= Gear.State or gstCollision |
|
108 |
end; |
|
109 |
Gear.X:= Gear.X + Gear.dX; |
|
110 |
Gear.Y:= Gear.Y + Gear.dY; |
|
111 |
CheckGearDrowning(Gear); |
|
112 |
if (sqr(Gear.dX) + sqr(Gear.dY) < 0.003) then Gear.State:= Gear.State and not gstMoving |
|
113 |
else Gear.State:= Gear.State or gstMoving |
|
114 |
end; |
|
115 |
||
116 |
//////////////////////////////////////////////////////////////////////////////// |
|
117 |
procedure doStepCloud(Gear: PGear); |
|
118 |
begin |
|
119 |
Gear.X:= Gear.X + cWindSpeed * 200 + Gear.dX; |
|
120 |
if Gear.X < -cScreenWidth-256 then Gear.X:= cScreenWidth + 2048 else |
|
121 |
if Gear.X > cScreenWidth + 2048 then Gear.X:= -cScreenWidth - 256 |
|
122 |
end; |
|
123 |
||
124 |
//////////////////////////////////////////////////////////////////////////////// |
|
125 |
procedure doStepBomb(Gear: PGear); |
|
126 |
begin |
|
127 |
AllInactive:= false; |
|
128 |
doStepFallingGear(Gear); |
|
129 |
dec(Gear.Timer); |
|
130 |
if Gear.Timer = 0 then |
|
131 |
begin |
|
132 |
doMakeExplosion(round(Gear.X), round(Gear.Y), 50, EXPLAutoSound); |
|
133 |
DeleteGear(Gear); |
|
134 |
exit |
|
135 |
end; |
|
136 |
CalcRotationDirAngle(Gear); |
|
137 |
if (Gear.State and (gstCollision or gstMoving)) = (gstCollision or gstMoving) then PlaySound(sndGrenadeImpact) |
|
138 |
end; |
|
139 |
||
140 |
//////////////////////////////////////////////////////////////////////////////// |
|
141 |
procedure doStepGrenade(Gear: PGear); |
|
142 |
begin |
|
143 |
AllInactive:= false; |
|
144 |
Gear.dX:= Gear.dX + cWindSpeed; |
|
145 |
doStepFallingGear(Gear); |
|
146 |
if (Gear.State and gstCollision) <> 0 then |
|
147 |
begin |
|
148 |
doMakeExplosion(round(Gear.X), round(Gear.Y), 50, EXPLAutoSound); |
|
149 |
DeleteGear(Gear); |
|
150 |
exit |
|
151 |
end; |
|
152 |
if (GameTicks and $3F) = 0 then |
|
153 |
AddGear(round(Gear.X), round(Gear.Y), gtSmokeTrace, 0) |
|
154 |
end; |
|
155 |
||
156 |
//////////////////////////////////////////////////////////////////////////////// |
|
157 |
procedure doStepHealthTag(Gear: PGear); |
|
158 |
begin |
|
159 |
AllInactive:= false; |
|
160 |
dec(Gear.Timer); |
|
161 |
Gear.Y:= Gear.Y - 0.07; |
|
162 |
if Gear.Timer = 0 then |
|
163 |
begin |
|
164 |
PHedgehog(Gear.Hedgehog).Gear.Active:= true; |
|
165 |
DeleteGear(Gear) |
|
166 |
end |
|
167 |
end; |
|
168 |
||
169 |
//////////////////////////////////////////////////////////////////////////////// |
|
170 |
procedure doStepGrave(Gear: PGear); |
|
171 |
begin |
|
172 |
AllInactive:= false; |
|
173 |
if Gear.dY < 0 then |
|
174 |
if TestCollisionY(Gear, -1) then Gear.dY:= 0; |
|
175 |
||
176 |
if Gear.dY >=0 then |
|
177 |
if TestCollisionY(Gear, 1) then |
|
178 |
begin |
|
179 |
Gear.dY:= - Gear.dY * Gear.Elasticity; |
|
180 |
if Gear.dY > - 0.001 then |
|
181 |
begin |
|
182 |
Gear.Active:= false; |
|
183 |
exit |
|
184 |
end else if Gear.dY < - 0.03 then PlaySound(sndGraveImpact) |
|
185 |
end; |
|
186 |
Gear.Y:= Gear.Y + Gear.dY; |
|
187 |
CheckGearDrowning(Gear); |
|
188 |
Gear.dY:= Gear.dY + cGravity |
|
189 |
end; |
|
190 |
||
191 |
//////////////////////////////////////////////////////////////////////////////// |
|
192 |
procedure doStepUFOWork(Gear: PGear); |
|
193 |
var t: real; |
|
194 |
begin |
|
195 |
AllInactive:= false; |
|
196 |
t:= sqrt(sqr(Gear.dX) + sqr(Gear.dY)); |
|
197 |
Gear.dX:= Gear.Elasticity * (Gear.dX + 0.000004 * (TargetPoint.X - trunc(Gear.X))); |
|
198 |
Gear.dY:= Gear.Elasticity * (Gear.dY + 0.000004 * (TargetPoint.Y - trunc(Gear.Y))); |
|
199 |
t:= t / (sqrt(sqr(Gear.dX) + sqr(Gear.dY))); |
|
200 |
Gear.dX:= Gear.dX * t; |
|
201 |
Gear.dY:= Gear.dY * t; |
|
202 |
Gear.X:= Gear.X + Gear.dX; |
|
203 |
Gear.Y:= Gear.Y + Gear.dY; |
|
204 |
CheckCollision(Gear); |
|
205 |
dec(Gear.Timer); |
|
206 |
if ((Gear.State and gstCollision) <> 0) or (Gear.Timer = 0) then |
|
207 |
begin |
|
208 |
doMakeExplosion(round(Gear.X), round(Gear.Y), 50, EXPLAutoSound); |
|
209 |
DeleteGear(Gear); |
|
210 |
end; |
|
211 |
end; |
|
212 |
||
213 |
procedure doStepUFO(Gear: PGear); |
|
214 |
begin |
|
215 |
AllInactive:= false; |
|
216 |
Gear.X:= Gear.X + Gear.dX; |
|
217 |
Gear.Y:= Gear.Y + Gear.dY; |
|
218 |
Gear.dY:= Gear.dY + cGravity; |
|
219 |
CheckCollision(Gear); |
|
220 |
if (Gear.State and gstCollision) <> 0 then |
|
221 |
begin |
|
222 |
doMakeExplosion(round(Gear.X), round(Gear.Y), 50, EXPLAutoSound); |
|
223 |
DeleteGear(Gear); |
|
224 |
exit |
|
225 |
end; |
|
226 |
dec(Gear.Timer); |
|
227 |
if Gear.Timer = 0 then |
|
228 |
begin |
|
229 |
Gear.Timer:= 5000; |
|
230 |
Gear.doStep:= doStepUFOWork |
|
231 |
end; |
|
232 |
end; |
|
233 |
||
234 |
//////////////////////////////////////////////////////////////////////////////// |
|
235 |
procedure doStepShotgunShot(Gear: PGear); |
|
236 |
var i: LongWord; |
|
38 | 237 |
t: PGear; |
4 | 238 |
begin |
239 |
AllInactive:= false; |
|
240 |
if Gear.Timer > 0 then |
|
241 |
begin |
|
242 |
dec(Gear.Timer); |
|
243 |
if Gear.Timer = 1 then PlaySound(sndShotgunFire); |
|
244 |
exit |
|
245 |
end; |
|
246 |
i:= 200; |
|
247 |
repeat |
|
248 |
Gear.X:= Gear.X + Gear.dX; |
|
249 |
Gear.Y:= Gear.Y + Gear.dY; |
|
250 |
CheckCollision(Gear); |
|
251 |
if (Gear.State and gstCollision) <> 0 then |
|
252 |
begin |
|
38 | 253 |
t:= CheckGearsCollision(Gear, Sign(Gear.dX), true); |
254 |
if t = nil then t:= CheckGearsCollision(Gear, Sign(Gear.dY), false); |
|
255 |
if t <> nil then |
|
256 |
AmmoShove(Gear, t, 25); |
|
42 | 257 |
doMakeExplosion(round(Gear.X), round(Gear.Y), 25, EXPLNoDamage or EXPLDoNotTouchHH); |
4 | 258 |
DeleteGear(Gear); |
259 |
exit |
|
260 |
end; |
|
261 |
dec(i) |
|
262 |
until i = 0; |
|
263 |
if (Gear.X < 0) or (Gear.Y < 0) or (Gear.X > 2048) or (Gear.Y > 1024) then |
|
264 |
DeleteGear(Gear) |
|
265 |
end; |
|
266 |
||
267 |
//////////////////////////////////////////////////////////////////////////////// |
|
38 | 268 |
procedure doStepDEagleShot(Gear: PGear); |
269 |
var i, x, y: LongWord; |
|
270 |
oX, oY: real; |
|
271 |
t: PGear; |
|
272 |
begin |
|
273 |
AllInactive:= false; |
|
37 | 274 |
i:= 80; |
38 | 275 |
oX:= Gear.X; |
276 |
oY:= Gear.Y; |
|
37 | 277 |
repeat |
38 | 278 |
Gear.X:= Gear.X + Gear.dX; |
279 |
Gear.Y:= Gear.Y + Gear.dY; |
|
280 |
x:= round(Gear.X); |
|
281 |
y:= round(Gear.Y); |
|
282 |
if ((y and $FFFFFC00) = 0) and ((x and $FFFFF800) = 0) |
|
283 |
and (Land[y, x] <> 0) then inc(Gear.Damage); |
|
284 |
t:= CheckGearsCollision(Gear, Sign(Gear.dX), true); |
|
285 |
if t = nil then t:= CheckGearsCollision(Gear, Sign(Gear.dY), false); |
|
286 |
if t <> nil then |
|
287 |
begin |
|
288 |
AmmoShove(Gear, t, 12); |
|
39 | 289 |
inc(Gear.Damage, 10); |
38 | 290 |
if t.CollIndex < High(Longword) then DeleteCR(t) |
291 |
end; |
|
292 |
dec(i) |
|
293 |
until (i = 0) or (Gear.Damage > Gear.Health); |
|
294 |
if Gear.Damage > 0 then |
|
37 | 295 |
begin |
38 | 296 |
DrawTunnel(oX, oY, Gear.dX, Gear.dY, 82 - i, 1); |
297 |
dec(Gear.Health, Gear.Damage); |
|
298 |
Gear.Damage:= 0 |
|
37 | 299 |
end; |
38 | 300 |
if (Gear.Health <= 0) or (Gear.X < 0) or (Gear.Y < 0) or (Gear.X > 2048) or (Gear.Y > 1024) then |
37 | 301 |
DeleteGear(Gear) |
302 |
end; |
|
303 |
||
304 |
//////////////////////////////////////////////////////////////////////////////// |
|
4 | 305 |
procedure doStepActionTimer(Gear: PGear); |
306 |
begin |
|
307 |
case Gear.State of |
|
308 |
gtsStartGame: begin |
|
6 | 309 |
dec(Gear.Timer); |
4 | 310 |
AllInactive:= false; |
311 |
if Gear.Timer > 0 then exit; |
|
312 |
AddCaption('Let''s fight!', $FFFFFF, capgrpStartGame); |
|
313 |
DeleteGear(Gear) |
|
314 |
end; |
|
6 | 315 |
gtsSmoothWindCh: begin |
316 |
if Gear.Timer = 0 then |
|
317 |
begin |
|
318 |
Gear.Timer:= 10; |
|
319 |
if WindBarWidth < Gear.Tag then inc(WindBarWidth) |
|
320 |
else if WindBarWidth > Gear.Tag then dec(WindBarWidth) |
|
321 |
else DeleteGear(Gear) |
|
322 |
end else dec(Gear.Timer) |
|
323 |
end; |
|
4 | 324 |
end; |
325 |
end; |
|
326 |
||
327 |
//////////////////////////////////////////////////////////////////////////////// |
|
328 |
procedure doStepPickHammerWork(Gear: PGear); |
|
329 |
var i, ei: integer; |
|
330 |
HHGear: PGear; |
|
331 |
begin |
|
332 |
Allinactive:= false; |
|
333 |
dec(Gear.Timer); |
|
334 |
if (Gear.Timer = 0)or((Gear.Message and gm_Destroy) <> 0) then |
|
335 |
begin |
|
336 |
DeleteGear(Gear); |
|
337 |
AfterAttack; |
|
338 |
exit |
|
339 |
end; |
|
340 |
HHGear:= PHedgehog(Gear.Hedgehog).Gear; |
|
341 |
if (Gear.Timer and $3F) = 0 then |
|
342 |
begin |
|
343 |
i:= round(Gear.X) - Gear.HalfWidth - GetRandom(2); |
|
344 |
ei:= round(Gear.X) + Gear.HalfWidth + GetRandom(2); |
|
345 |
while i <= ei do |
|
346 |
begin |
|
347 |
doMakeExplosion(i, round(Gear.Y) + 3, 3, 0); |
|
348 |
inc(i, 1) |
|
349 |
end; |
|
350 |
Gear.X:= Gear.X + Gear.dX; |
|
42 | 351 |
Gear.Y:= Gear.Y + 1.9; |
352 |
SetAllHHToActive; |
|
4 | 353 |
end; |
354 |
if TestCollisionYwithGear(Gear, 1) then |
|
355 |
begin |
|
356 |
Gear.dY:= 0; |
|
357 |
HHGear.dX:= 0.0000001 * Sign(PGear(Gear.Hedgehog).dX); |
|
358 |
HHGear.dY:= 0; |
|
359 |
end else |
|
360 |
begin |
|
361 |
Gear.dY:= Gear.dY + cGravity; |
|
362 |
Gear.Y:= Gear.Y + Gear.dY; |
|
363 |
if Gear.Y > 1024 then Gear.Timer:= 1 |
|
364 |
end; |
|
365 |
||
366 |
Gear.X:= Gear.X + HHGear.dX; |
|
367 |
HHGear.X:= Gear.X; |
|
368 |
HHGear.Y:= Gear.Y - cHHHalfHeight; |
|
369 |
||
370 |
if (Gear.Message and gm_Attack) <> 0 then |
|
371 |
if (Gear.State and gsttmpFlag) <> 0 then Gear.Timer:= 1 else else |
|
372 |
if (Gear.State and gsttmpFlag) = 0 then Gear.State:= Gear.State or gsttmpFlag; |
|
373 |
if ((Gear.Message and gm_Left) <> 0) then Gear.dX:= -0.3 else |
|
374 |
if ((Gear.Message and gm_Right) <> 0) then Gear.dX:= 0.3 |
|
375 |
else Gear.dX:= 0; |
|
376 |
end; |
|
377 |
||
378 |
procedure doStepPickHammer(Gear: PGear); |
|
379 |
var i, y: integer; |
|
380 |
ar: TRangeArray; |
|
381 |
begin |
|
382 |
i:= 0; |
|
383 |
y:= round(Gear.Y) - cHHHalfHeight*2; |
|
384 |
while y < round(Gear.Y) do |
|
385 |
begin |
|
386 |
ar[i].Left := round(Gear.X) - Gear.HalfWidth - GetRandom(2); |
|
387 |
ar[i].Right:= round(Gear.X) + Gear.HalfWidth + GetRandom(2); |
|
388 |
inc(y, 2); |
|
389 |
inc(i) |
|
390 |
end; |
|
42 | 391 |
DrawHLinesExplosions(@ar, 3, round(Gear.Y) - cHHHalfHeight*2, 2, Pred(i)); |
4 | 392 |
Gear.dY:= PHedgehog(Gear.Hedgehog).Gear.dY; |
393 |
doStepPickHammerWork(Gear); |
|
394 |
Gear.doStep:= doStepPickHammerWork |
|
395 |
end; |
|
396 |
||
397 |
//////////////////////////////////////////////////////////////////////////////// |
|
398 |
procedure doStepRopeWork(Gear: PGear); |
|
399 |
const pidiv2: real = pi/2; |
|
400 |
flCheck: boolean = false; |
|
401 |
var HHGear: PGear; |
|
402 |
len, cs, cc, tx, ty: real; |
|
403 |
lx, ly: integer; |
|
404 |
||
405 |
procedure DeleteMe; |
|
406 |
begin |
|
407 |
with HHGear^ do |
|
408 |
begin |
|
409 |
Message:= Message and not gm_Attack; |
|
410 |
State:= State or gstFalling; |
|
411 |
end; |
|
412 |
DeleteGear(Gear); |
|
413 |
OnUsedAmmo(PHedgehog(Gear.Hedgehog)^.Ammo); |
|
414 |
ApplyAmmoChanges(PHedgehog(Gear.Hedgehog)) |
|
415 |
end; |
|
416 |
||
417 |
begin |
|
418 |
HHGear:= PHedgehog(Gear.Hedgehog).Gear; |
|
419 |
if (HHGear.State and gstHHDriven) = 0 then |
|
420 |
begin |
|
421 |
DeleteMe; |
|
422 |
exit |
|
423 |
end; |
|
424 |
Gear.dX:= HHGear.X - Gear.X; |
|
425 |
Gear.dY:= HHGear.Y - Gear.Y; |
|
426 |
||
427 |
if (Gear.Message and gm_Left <> 0) then HHGear.dX:= HHGear.dX - 0.0002 else |
|
428 |
if (Gear.Message and gm_Right <> 0) then HHGear.dX:= HHGear.dX + 0.0002; |
|
429 |
||
430 |
if not TestCollisionYwithGear(HHGear, 1) then HHGear.dY:= HHGear.dY + cGravity; |
|
431 |
||
432 |
HHGear.DirAngle:= arctan(Gear.dY + HHGear.dY, Gear.dX + HHGear.dX); |
|
433 |
cs:= sin(HHGear.DirAngle); |
|
434 |
cc:= cos(HHGear.DirAngle); |
|
435 |
||
436 |
flCheck:= not flCheck; |
|
437 |
if flCheck then // check whether rope needs dividing |
|
438 |
begin |
|
439 |
len:= Gear.Elasticity - 20; |
|
440 |
while len > 5 do |
|
441 |
begin |
|
442 |
tx:= cc*len; |
|
443 |
ty:= cs*len; |
|
444 |
lx:= round(Gear.X + tx) + sign(HHGear.dX); |
|
445 |
ly:= round(Gear.Y + ty) + sign(HHGear.dY); |
|
446 |
if ((ly and $FFFFFC00) = 0) and ((lx and $FFFFF800) = 0)and (Land[ly, lx] <> 0) then |
|
447 |
begin |
|
448 |
with RopePoints.ar[RopePoints.Count] do |
|
449 |
begin |
|
450 |
X:= Gear.X; |
|
451 |
Y:= Gear.Y; |
|
452 |
if RopePoints.Count = 0 then RopePoints.HookAngle:= DxDy2Angle32(Gear.dY, Gear.dX); |
|
453 |
b:= (cc * HHGear.dY) > (cs * HHGear.dX); |
|
454 |
dLen:= len |
|
455 |
end; |
|
456 |
Gear.X:= Gear.X + tx; |
|
457 |
Gear.Y:= Gear.Y + ty; |
|
458 |
inc(RopePoints.Count); |
|
459 |
Gear.Elasticity:= Gear.Elasticity - len; |
|
460 |
Gear.Friction:= Gear.Friction - len; |
|
461 |
break |
|
462 |
end; |
|
463 |
len:= len - 3 |
|
464 |
end; |
|
465 |
end else |
|
466 |
if RopePoints.Count > 0 then // check whether the last dividing point could be removed |
|
467 |
begin |
|
468 |
tx:= RopePoints.ar[Pred(RopePoints.Count)].X; |
|
469 |
ty:= RopePoints.ar[Pred(RopePoints.Count)].Y; |
|
470 |
if RopePoints.ar[Pred(RopePoints.Count)].b xor ((tx - Gear.X) * (ty - HHGear.Y) > (tx - HHGear.X) * (ty - Gear.Y)) then |
|
471 |
begin |
|
472 |
dec(RopePoints.Count); |
|
473 |
Gear.X:=RopePoints.ar[RopePoints.Count].X; |
|
474 |
Gear.Y:=RopePoints.ar[RopePoints.Count].Y; |
|
475 |
Gear.Elasticity:= Gear.Elasticity + RopePoints.ar[RopePoints.Count].dLen; |
|
476 |
Gear.Friction:= Gear.Friction + RopePoints.ar[RopePoints.Count].dLen |
|
477 |
end |
|
478 |
end; |
|
479 |
||
480 |
Gear.dX:= HHGear.X - Gear.X; |
|
481 |
Gear.dY:= HHGear.Y - Gear.Y; |
|
482 |
HHGear.DirAngle:= arctan(Gear.dY + HHGear.dY, Gear.dX + HHGear.dX); |
|
483 |
cs:= sin(HHGear.DirAngle); |
|
484 |
cc:= cos(HHGear.DirAngle); |
|
485 |
||
486 |
HHGear.dX:= HHGear.X; |
|
487 |
HHGear.dY:= HHGear.Y; |
|
488 |
||
489 |
if ((Gear.Message and gm_Down) <> 0) and (Gear.Elasticity < Gear.Friction) then |
|
490 |
if not (TestCollisionXwithGear(HHGear, Sign(Gear.dX)) |
|
491 |
or TestCollisionYwithGear(HHGear, Sign(Gear.dY))) then Gear.Elasticity:= Gear.Elasticity + 0.3; |
|
492 |
||
493 |
if ((Gear.Message and gm_Up) <> 0) and (Gear.Elasticity > 30) then |
|
494 |
if not (TestCollisionXwithGear(HHGear, -Sign(Gear.dX)) |
|
495 |
or TestCollisionYwithGear(HHGear, -Sign(Gear.dY))) then Gear.Elasticity:= Gear.Elasticity - 0.3; |
|
496 |
||
497 |
HHGear.X:= Gear.X + cc*Gear.Elasticity; |
|
498 |
HHGear.Y:= Gear.Y + cs*Gear.Elasticity; |
|
499 |
||
500 |
HHGear.dX:= HHGear.X - HHGear.dX; |
|
501 |
HHGear.dY:= HHGear.Y - HHGear.dY; |
|
502 |
||
503 |
if TestCollisionXwithGear(HHGear, Sign(HHGear.dX)) then |
|
504 |
HHGear.dX:= -0.9 * HHGear.dX; |
|
505 |
if TestCollisionYwithGear(HHGear, Sign(HHGear.dY)) then |
|
506 |
HHGear.dY:= -0.9 * HHGear.dY; |
|
507 |
||
508 |
if (Gear.Message and gm_Attack) <> 0 then |
|
509 |
if (Gear.State and gsttmpFlag) <> 0 then DeleteMe else |
|
510 |
else if (Gear.State and gsttmpFlag) = 0 then Gear.State:= Gear.State or gsttmpFlag; |
|
511 |
end; |
|
512 |
||
513 |
||
514 |
procedure doStepRopeAttach(Gear: PGear); |
|
515 |
var HHGear: PGear; |
|
516 |
tx, ty, tt: real; |
|
517 |
begin |
|
518 |
Gear.X:= Gear.X + Gear.dX; |
|
519 |
Gear.Y:= Gear.Y + Gear.dY; |
|
520 |
Gear.Elasticity:= Gear.Elasticity + 1.0; |
|
521 |
HHGear:= PHedgehog(Gear.Hedgehog)^.Gear; |
|
522 |
if (HHGear.State and gstFalling) <> 0 then |
|
523 |
if HHTestCollisionYwithGear(HHGear, 1) then |
|
524 |
begin |
|
525 |
HHGear.dY:= 0; |
|
526 |
CheckHHDamage(HHGear); |
|
527 |
HHGear.State:= HHGear.State and not (gstFalling or gstHHJumping); |
|
528 |
end else |
|
529 |
begin |
|
530 |
if TestCollisionXwithGear(HHGear, Sign(HHGear.dX)) then HHGear.dX:= 0.0000001 * Sign(HHGear.dX); |
|
531 |
HHGear.X:= HHGear.X + HHGear.dX; |
|
532 |
HHGear.Y:= HHGear.Y + HHGear.dY; |
|
533 |
Gear.X:= Gear.X + HHGear.dX; |
|
534 |
Gear.Y:= Gear.Y + HHGear.dY; |
|
535 |
HHGear.dY:= HHGear.dY + cGravity; |
|
536 |
tt:= Gear.Elasticity; |
|
537 |
tx:= 0; |
|
538 |
ty:= 0; |
|
539 |
while tt > 20 do |
|
540 |
begin |
|
541 |
if TestCollisionXwithXYShift(Gear, round(tx), round(ty), Sign(Gear.dX)) |
|
542 |
or TestCollisionYwithXYShift(Gear, round(tx), round(ty), Sign(Gear.dY)) then |
|
543 |
begin |
|
544 |
Gear.X:= Gear.X + tx; |
|
545 |
Gear.Y:= Gear.Y + ty; |
|
546 |
Gear.Elasticity:= tt; |
|
547 |
Gear.doStep:= doStepRopeWork; |
|
548 |
with HHGear^ do State:= State and not gstAttacking; |
|
549 |
tt:= 0 |
|
550 |
end; |
|
551 |
tx:= tx - Gear.dX - Gear.dX; |
|
552 |
ty:= ty - Gear.dY - Gear.dY; |
|
553 |
tt:= tt - 2.0; |
|
554 |
end; |
|
555 |
end; |
|
556 |
CheckCollision(Gear); |
|
557 |
if (Gear.State and gstCollision) <> 0 then |
|
558 |
begin |
|
559 |
Gear.doStep:= doStepRopeWork; |
|
560 |
with HHGear^ do State:= State and not gstAttacking; |
|
561 |
if Gear.Elasticity < 10 then |
|
562 |
Gear.Elasticity:= 10000; |
|
563 |
end; |
|
564 |
||
565 |
if (Gear.Elasticity >= Gear.Friction) or ((Gear.Message and gm_Attack) = 0) then |
|
566 |
begin |
|
567 |
with PHedgehog(Gear.Hedgehog).Gear^ do |
|
568 |
begin |
|
569 |
State:= State and not gstAttacking; |
|
570 |
Message:= Message and not gm_Attack |
|
571 |
end; |
|
572 |
DeleteGear(Gear) |
|
573 |
end |
|
574 |
end; |
|
575 |
||
576 |
procedure doStepRope(Gear: PGear); |
|
577 |
begin |
|
578 |
Gear.doStep:= doStepRopeAttach |
|
579 |
end; |
|
580 |
||
581 |
//////////////////////////////////////////////////////////////////////////////// |
|
582 |
procedure doStepSmokeTrace(Gear: PGear); |
|
583 |
begin |
|
584 |
inc(Gear.Timer); |
|
585 |
if Gear.Timer > 64 then |
|
586 |
begin |
|
587 |
Gear.Timer:= 0; |
|
9 | 588 |
dec(Gear.State) |
4 | 589 |
end; |
590 |
Gear.dX:= Gear.dX + cWindSpeed; |
|
591 |
Gear.X:= Gear.X + Gear.dX; |
|
9 | 592 |
if Gear.State = 0 then DeleteGear(Gear) |
4 | 593 |
end; |
9 | 594 |
|
595 |
//////////////////////////////////////////////////////////////////////////////// |
|
596 |
procedure doStepExplosion(Gear: PGear); |
|
597 |
begin |
|
598 |
inc(Gear.Timer); |
|
599 |
if Gear.Timer > 75 then |
|
600 |
begin |
|
601 |
inc(Gear.State); |
|
602 |
Gear.Timer:= 0; |
|
603 |
if Gear.State > 5 then DeleteGear(Gear) |
|
604 |
end; |
|
605 |
end; |
|
10 | 606 |
|
607 |
//////////////////////////////////////////////////////////////////////////////// |
|
608 |
procedure doStepMine(Gear: PGear); |
|
609 |
begin |
|
39 | 610 |
if (Gear.dX <> 0) or (Gear.dY <> 0) then |
10 | 611 |
begin |
39 | 612 |
if Gear.CollIndex < High(Longword) then DeleteCR(Gear); |
10 | 613 |
doStepFallingGear(Gear); |
13 | 614 |
if Gear.Active = false then |
615 |
begin |
|
39 | 616 |
if Gear.CollIndex = High(Longword) then AddGearCR(Gear); |
13 | 617 |
Gear.dX:= 0; |
618 |
Gear.dY:= 0 |
|
619 |
end; |
|
620 |
CalcRotationDirAngle(Gear); |
|
10 | 621 |
AllInactive:= false |
622 |
end; |
|
39 | 623 |
|
10 | 624 |
if ((Gear.State and gsttmpFlag) <> 0) then |
625 |
if ((Gear.State and gstAttacking) = 0) then |
|
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
626 |
begin |
39 | 627 |
if ((GameTicks and $F) = 0) then |
15 | 628 |
if CheckGearNear(Gear, gtHedgehog, 46, 32) <> nil then Gear.State:= Gear.State or gstAttacking |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
629 |
end else // gstAttacking <> 0 |
10 | 630 |
begin |
631 |
AllInactive:= false; |
|
37 | 632 |
if (Gear.Timer and $FF) = 0 then PlaySound(sndMineTick); |
10 | 633 |
if Gear.Timer = 0 then |
634 |
begin |
|
13 | 635 |
doMakeExplosion(round(Gear.X), round(Gear.Y), 50, EXPLAutoSound); |
10 | 636 |
DeleteGear(Gear) |
637 |
end; |
|
13 | 638 |
dec(Gear.Timer); |
639 |
end else // gsttmpFlag = 0 |
|
640 |
if TurnTimeLeft = 0 then Gear.State:= Gear.State or gsttmpFlag; |
|
10 | 641 |
end; |
39 | 642 |
//////////////////////////////////////////////////////////////////////////////// |
643 |
procedure doStepDynamite(Gear: PGear); |
|
644 |
begin |
|
645 |
if (Gear.dX <> 0) or (Gear.dY <> 0) {or not TestCollisionY(Gear, 1)} then |
|
646 |
begin |
|
647 |
doStepFallingGear(Gear); |
|
648 |
if Gear.Active = false then |
|
649 |
begin |
|
650 |
Gear.dX:= 0; |
|
651 |
Gear.dY:= 0 |
|
652 |
end; |
|
653 |
// CalcRotationDirAngle(Gear); |
|
654 |
AllInactive:= false |
|
655 |
end; |
|
656 |
//if ((Gear.State and gsttmpFlag) <> 0) then |
|
657 |
// if ((Gear.State and gstAttacking) = 0) then |
|
658 |
begin |
|
659 |
// AllInactive:= true; |
|
660 |
if (Gear.Timer and $FF) = 0 then PlaySound(sndMineTick); |
|
661 |
if Gear.Timer = 0 then |
|
662 |
begin |
|
663 |
doMakeExplosion(round(Gear.X), round(Gear.Y), 85, EXPLAutoSound); |
|
664 |
DeleteGear(Gear) |
|
665 |
end; |
|
666 |
dec(Gear.Timer); |
|
667 |
end;{ else // gsttmpFlag = 0 |
|
668 |
if TurnTimeLeft = 0 then Gear.State:= Gear.State or gsttmpFlag;} |
|
669 |
end; |
|
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
670 |
|
15 | 671 |
//////////////////////////////////////////////////////////////////////////////// |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
672 |
procedure doStepCase(Gear: PGear); |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
673 |
begin |
15 | 674 |
if (Gear.Message and gm_Destroy) > 0 then |
675 |
begin |
|
676 |
DeleteGear(Gear); |
|
677 |
exit |
|
678 |
end; |
|
679 |
||
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
680 |
if (Gear.dY <> 0) or (not TestCollisionY(Gear, 1)) then |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
681 |
begin |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
682 |
AllInactive:= false; |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
683 |
Gear.dY:= Gear.dY + cGravity; |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
684 |
Gear.Y:= Gear.Y + Gear.dY; |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
685 |
if (Gear.dY < 0) and TestCollisionY(Gear, -1) then Gear.dY:= 0 else |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
686 |
if (Gear.dY >= 0) and TestCollisionY(Gear, 1) then |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
687 |
begin |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
688 |
Gear.dY:= - Gear.dY * Gear.Elasticity; |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
689 |
if Gear.dY > - 0.001 then Gear.dY:= 0 |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
690 |
else if Gear.dY < - 0.03 then PlaySound(sndGraveImpact); |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
691 |
end; |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
692 |
CheckGearDrowning(Gear); |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
693 |
end; |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
694 |
|
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
695 |
if (Gear.CollIndex = High(Longword)) and (Gear.dY = 0) then AddGearCR(Gear) |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
696 |
else if (Gear.CollIndex < High(Longword)) and (Gear.dY <> 0) then DeleteCR(Gear); |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
697 |
|
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
698 |
if Gear.Damage > 0 then |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
699 |
begin |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
700 |
DeleteGear(Gear); |
16 | 701 |
doMakeExplosion(round(Gear.X), round(Gear.Y), 20, EXPLAutoSound) |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
702 |
end |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
703 |
end; |