author | unc0rr |
Wed, 28 Jun 2006 18:27:42 +0000 | |
changeset 71 | 5f56c6979496 |
parent 70 | 82d93eeecebe |
child 74 | 42257fee61ae |
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 |
|
53 | 38 |
Result:= Gear.Y + Gear.Radius >= cWaterLine; |
4 | 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 |
|
71 | 56 |
if Gear.dY > 0.40 then Gear.Damage:= Gear.Damage + 1 + round(70 * (abs(Gear.dY) - 0.40)); |
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; |
|
53 | 76 |
if round(Gear.Y) > Gear.Radius + cWaterLine + 48 + cVisibleWater then DeleteGear(Gear) |
4 | 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 |
|
68 | 174 |
if TestCollisionY(Gear, -1) then Gear.dY:= 0; |
4 | 175 |
|
176 |
if Gear.dY >=0 then |
|
68 | 177 |
if TestCollisionY(Gear, 1) then |
4 | 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; |
|
237 |
begin |
|
238 |
AllInactive:= false; |
|
239 |
if Gear.Timer > 0 then |
|
240 |
begin |
|
241 |
dec(Gear.Timer); |
|
242 |
if Gear.Timer = 1 then PlaySound(sndShotgunFire); |
|
243 |
exit |
|
244 |
end; |
|
245 |
i:= 200; |
|
246 |
repeat |
|
247 |
Gear.X:= Gear.X + Gear.dX; |
|
248 |
Gear.Y:= Gear.Y + Gear.dY; |
|
249 |
CheckCollision(Gear); |
|
250 |
if (Gear.State and gstCollision) <> 0 then |
|
251 |
begin |
|
53 | 252 |
AmmoShove(Gear, 25); |
42 | 253 |
doMakeExplosion(round(Gear.X), round(Gear.Y), 25, EXPLNoDamage or EXPLDoNotTouchHH); |
4 | 254 |
DeleteGear(Gear); |
255 |
exit |
|
256 |
end; |
|
257 |
dec(i) |
|
258 |
until i = 0; |
|
259 |
if (Gear.X < 0) or (Gear.Y < 0) or (Gear.X > 2048) or (Gear.Y > 1024) then |
|
260 |
DeleteGear(Gear) |
|
261 |
end; |
|
262 |
||
263 |
//////////////////////////////////////////////////////////////////////////////// |
|
38 | 264 |
procedure doStepDEagleShot(Gear: PGear); |
265 |
var i, x, y: LongWord; |
|
266 |
oX, oY: real; |
|
267 |
begin |
|
268 |
AllInactive:= false; |
|
37 | 269 |
i:= 80; |
38 | 270 |
oX:= Gear.X; |
271 |
oY:= Gear.Y; |
|
37 | 272 |
repeat |
38 | 273 |
Gear.X:= Gear.X + Gear.dX; |
274 |
Gear.Y:= Gear.Y + Gear.dY; |
|
275 |
x:= round(Gear.X); |
|
276 |
y:= round(Gear.Y); |
|
277 |
if ((y and $FFFFFC00) = 0) and ((x and $FFFFF800) = 0) |
|
278 |
and (Land[y, x] <> 0) then inc(Gear.Damage); |
|
53 | 279 |
AmmoShove(Gear, 12); |
38 | 280 |
dec(i) |
281 |
until (i = 0) or (Gear.Damage > Gear.Health); |
|
282 |
if Gear.Damage > 0 then |
|
37 | 283 |
begin |
38 | 284 |
DrawTunnel(oX, oY, Gear.dX, Gear.dY, 82 - i, 1); |
285 |
dec(Gear.Health, Gear.Damage); |
|
286 |
Gear.Damage:= 0 |
|
37 | 287 |
end; |
38 | 288 |
if (Gear.Health <= 0) or (Gear.X < 0) or (Gear.Y < 0) or (Gear.X > 2048) or (Gear.Y > 1024) then |
37 | 289 |
DeleteGear(Gear) |
290 |
end; |
|
291 |
||
292 |
//////////////////////////////////////////////////////////////////////////////// |
|
4 | 293 |
procedure doStepActionTimer(Gear: PGear); |
294 |
begin |
|
295 |
case Gear.State of |
|
296 |
gtsStartGame: begin |
|
6 | 297 |
dec(Gear.Timer); |
4 | 298 |
AllInactive:= false; |
299 |
if Gear.Timer > 0 then exit; |
|
300 |
AddCaption('Let''s fight!', $FFFFFF, capgrpStartGame); |
|
301 |
DeleteGear(Gear) |
|
302 |
end; |
|
6 | 303 |
gtsSmoothWindCh: begin |
304 |
if Gear.Timer = 0 then |
|
305 |
begin |
|
306 |
Gear.Timer:= 10; |
|
307 |
if WindBarWidth < Gear.Tag then inc(WindBarWidth) |
|
308 |
else if WindBarWidth > Gear.Tag then dec(WindBarWidth) |
|
309 |
else DeleteGear(Gear) |
|
310 |
end else dec(Gear.Timer) |
|
311 |
end; |
|
4 | 312 |
end; |
313 |
end; |
|
314 |
||
315 |
//////////////////////////////////////////////////////////////////////////////// |
|
316 |
procedure doStepPickHammerWork(Gear: PGear); |
|
317 |
var i, ei: integer; |
|
318 |
HHGear: PGear; |
|
319 |
begin |
|
70 | 320 |
AllInactive:= false; |
4 | 321 |
dec(Gear.Timer); |
322 |
if (Gear.Timer = 0)or((Gear.Message and gm_Destroy) <> 0) then |
|
323 |
begin |
|
324 |
DeleteGear(Gear); |
|
325 |
AfterAttack; |
|
326 |
exit |
|
327 |
end; |
|
328 |
HHGear:= PHedgehog(Gear.Hedgehog).Gear; |
|
329 |
if (Gear.Timer and $3F) = 0 then |
|
330 |
begin |
|
53 | 331 |
i:= round(Gear.X) - Gear.Radius - GetRandom(2); |
332 |
ei:= round(Gear.X) + Gear.Radius + GetRandom(2); |
|
4 | 333 |
while i <= ei do |
334 |
begin |
|
335 |
doMakeExplosion(i, round(Gear.Y) + 3, 3, 0); |
|
336 |
inc(i, 1) |
|
337 |
end; |
|
338 |
Gear.X:= Gear.X + Gear.dX; |
|
42 | 339 |
Gear.Y:= Gear.Y + 1.9; |
340 |
SetAllHHToActive; |
|
4 | 341 |
end; |
342 |
if TestCollisionYwithGear(Gear, 1) then |
|
343 |
begin |
|
344 |
Gear.dY:= 0; |
|
345 |
HHGear.dX:= 0.0000001 * Sign(PGear(Gear.Hedgehog).dX); |
|
346 |
HHGear.dY:= 0; |
|
347 |
end else |
|
348 |
begin |
|
349 |
Gear.dY:= Gear.dY + cGravity; |
|
350 |
Gear.Y:= Gear.Y + Gear.dY; |
|
351 |
if Gear.Y > 1024 then Gear.Timer:= 1 |
|
352 |
end; |
|
353 |
||
354 |
Gear.X:= Gear.X + HHGear.dX; |
|
355 |
HHGear.X:= Gear.X; |
|
53 | 356 |
HHGear.Y:= Gear.Y - cHHRadius; |
4 | 357 |
|
358 |
if (Gear.Message and gm_Attack) <> 0 then |
|
359 |
if (Gear.State and gsttmpFlag) <> 0 then Gear.Timer:= 1 else else |
|
360 |
if (Gear.State and gsttmpFlag) = 0 then Gear.State:= Gear.State or gsttmpFlag; |
|
361 |
if ((Gear.Message and gm_Left) <> 0) then Gear.dX:= -0.3 else |
|
362 |
if ((Gear.Message and gm_Right) <> 0) then Gear.dX:= 0.3 |
|
363 |
else Gear.dX:= 0; |
|
364 |
end; |
|
365 |
||
366 |
procedure doStepPickHammer(Gear: PGear); |
|
367 |
var i, y: integer; |
|
368 |
ar: TRangeArray; |
|
369 |
begin |
|
370 |
i:= 0; |
|
53 | 371 |
y:= round(Gear.Y) - cHHRadius*2; |
4 | 372 |
while y < round(Gear.Y) do |
373 |
begin |
|
53 | 374 |
ar[i].Left := round(Gear.X) - Gear.Radius - GetRandom(2); |
375 |
ar[i].Right:= round(Gear.X) + Gear.Radius + GetRandom(2); |
|
4 | 376 |
inc(y, 2); |
377 |
inc(i) |
|
378 |
end; |
|
53 | 379 |
DrawHLinesExplosions(@ar, 3, round(Gear.Y) - cHHRadius*2, 2, Pred(i)); |
4 | 380 |
Gear.dY:= PHedgehog(Gear.Hedgehog).Gear.dY; |
381 |
doStepPickHammerWork(Gear); |
|
382 |
Gear.doStep:= doStepPickHammerWork |
|
383 |
end; |
|
384 |
||
385 |
//////////////////////////////////////////////////////////////////////////////// |
|
386 |
procedure doStepRopeWork(Gear: PGear); |
|
70 | 387 |
const flCheck: boolean = false; |
4 | 388 |
var HHGear: PGear; |
389 |
len, cs, cc, tx, ty: real; |
|
390 |
lx, ly: integer; |
|
391 |
||
392 |
procedure DeleteMe; |
|
393 |
begin |
|
394 |
with HHGear^ do |
|
395 |
begin |
|
396 |
Message:= Message and not gm_Attack; |
|
397 |
State:= State or gstFalling; |
|
398 |
end; |
|
399 |
DeleteGear(Gear); |
|
400 |
OnUsedAmmo(PHedgehog(Gear.Hedgehog)^.Ammo); |
|
70 | 401 |
ApplyAmmoChanges(PHedgehog(Gear.Hedgehog)^) |
4 | 402 |
end; |
403 |
||
404 |
begin |
|
405 |
HHGear:= PHedgehog(Gear.Hedgehog).Gear; |
|
406 |
if (HHGear.State and gstHHDriven) = 0 then |
|
407 |
begin |
|
408 |
DeleteMe; |
|
409 |
exit |
|
410 |
end; |
|
411 |
Gear.dX:= HHGear.X - Gear.X; |
|
412 |
Gear.dY:= HHGear.Y - Gear.Y; |
|
413 |
||
414 |
if (Gear.Message and gm_Left <> 0) then HHGear.dX:= HHGear.dX - 0.0002 else |
|
415 |
if (Gear.Message and gm_Right <> 0) then HHGear.dX:= HHGear.dX + 0.0002; |
|
416 |
||
417 |
if not TestCollisionYwithGear(HHGear, 1) then HHGear.dY:= HHGear.dY + cGravity; |
|
418 |
||
419 |
HHGear.DirAngle:= arctan(Gear.dY + HHGear.dY, Gear.dX + HHGear.dX); |
|
420 |
cs:= sin(HHGear.DirAngle); |
|
421 |
cc:= cos(HHGear.DirAngle); |
|
422 |
||
423 |
flCheck:= not flCheck; |
|
424 |
if flCheck then // check whether rope needs dividing |
|
425 |
begin |
|
426 |
len:= Gear.Elasticity - 20; |
|
427 |
while len > 5 do |
|
428 |
begin |
|
429 |
tx:= cc*len; |
|
430 |
ty:= cs*len; |
|
70 | 431 |
lx:= round(Gear.X + tx) + Sign(HHGear.dX); |
432 |
ly:= round(Gear.Y + ty) + Sign(HHGear.dY); |
|
4 | 433 |
if ((ly and $FFFFFC00) = 0) and ((lx and $FFFFF800) = 0)and (Land[ly, lx] <> 0) then |
434 |
begin |
|
435 |
with RopePoints.ar[RopePoints.Count] do |
|
436 |
begin |
|
437 |
X:= Gear.X; |
|
438 |
Y:= Gear.Y; |
|
439 |
if RopePoints.Count = 0 then RopePoints.HookAngle:= DxDy2Angle32(Gear.dY, Gear.dX); |
|
440 |
b:= (cc * HHGear.dY) > (cs * HHGear.dX); |
|
441 |
dLen:= len |
|
442 |
end; |
|
443 |
Gear.X:= Gear.X + tx; |
|
444 |
Gear.Y:= Gear.Y + ty; |
|
445 |
inc(RopePoints.Count); |
|
446 |
Gear.Elasticity:= Gear.Elasticity - len; |
|
447 |
Gear.Friction:= Gear.Friction - len; |
|
448 |
break |
|
449 |
end; |
|
450 |
len:= len - 3 |
|
451 |
end; |
|
452 |
end else |
|
453 |
if RopePoints.Count > 0 then // check whether the last dividing point could be removed |
|
454 |
begin |
|
455 |
tx:= RopePoints.ar[Pred(RopePoints.Count)].X; |
|
456 |
ty:= RopePoints.ar[Pred(RopePoints.Count)].Y; |
|
457 |
if RopePoints.ar[Pred(RopePoints.Count)].b xor ((tx - Gear.X) * (ty - HHGear.Y) > (tx - HHGear.X) * (ty - Gear.Y)) then |
|
458 |
begin |
|
459 |
dec(RopePoints.Count); |
|
460 |
Gear.X:=RopePoints.ar[RopePoints.Count].X; |
|
461 |
Gear.Y:=RopePoints.ar[RopePoints.Count].Y; |
|
462 |
Gear.Elasticity:= Gear.Elasticity + RopePoints.ar[RopePoints.Count].dLen; |
|
463 |
Gear.Friction:= Gear.Friction + RopePoints.ar[RopePoints.Count].dLen |
|
464 |
end |
|
465 |
end; |
|
466 |
||
467 |
Gear.dX:= HHGear.X - Gear.X; |
|
468 |
Gear.dY:= HHGear.Y - Gear.Y; |
|
469 |
HHGear.DirAngle:= arctan(Gear.dY + HHGear.dY, Gear.dX + HHGear.dX); |
|
470 |
cs:= sin(HHGear.DirAngle); |
|
471 |
cc:= cos(HHGear.DirAngle); |
|
472 |
||
473 |
HHGear.dX:= HHGear.X; |
|
474 |
HHGear.dY:= HHGear.Y; |
|
475 |
||
476 |
if ((Gear.Message and gm_Down) <> 0) and (Gear.Elasticity < Gear.Friction) then |
|
477 |
if not (TestCollisionXwithGear(HHGear, Sign(Gear.dX)) |
|
478 |
or TestCollisionYwithGear(HHGear, Sign(Gear.dY))) then Gear.Elasticity:= Gear.Elasticity + 0.3; |
|
479 |
||
480 |
if ((Gear.Message and gm_Up) <> 0) and (Gear.Elasticity > 30) then |
|
481 |
if not (TestCollisionXwithGear(HHGear, -Sign(Gear.dX)) |
|
482 |
or TestCollisionYwithGear(HHGear, -Sign(Gear.dY))) then Gear.Elasticity:= Gear.Elasticity - 0.3; |
|
483 |
||
484 |
HHGear.X:= Gear.X + cc*Gear.Elasticity; |
|
485 |
HHGear.Y:= Gear.Y + cs*Gear.Elasticity; |
|
486 |
||
487 |
HHGear.dX:= HHGear.X - HHGear.dX; |
|
488 |
HHGear.dY:= HHGear.Y - HHGear.dY; |
|
489 |
||
490 |
if TestCollisionXwithGear(HHGear, Sign(HHGear.dX)) then |
|
491 |
HHGear.dX:= -0.9 * HHGear.dX; |
|
492 |
if TestCollisionYwithGear(HHGear, Sign(HHGear.dY)) then |
|
493 |
HHGear.dY:= -0.9 * HHGear.dY; |
|
494 |
||
495 |
if (Gear.Message and gm_Attack) <> 0 then |
|
496 |
if (Gear.State and gsttmpFlag) <> 0 then DeleteMe else |
|
497 |
else if (Gear.State and gsttmpFlag) = 0 then Gear.State:= Gear.State or gsttmpFlag; |
|
498 |
end; |
|
499 |
||
500 |
||
501 |
procedure doStepRopeAttach(Gear: PGear); |
|
502 |
var HHGear: PGear; |
|
503 |
tx, ty, tt: real; |
|
504 |
begin |
|
505 |
Gear.X:= Gear.X + Gear.dX; |
|
506 |
Gear.Y:= Gear.Y + Gear.dY; |
|
507 |
Gear.Elasticity:= Gear.Elasticity + 1.0; |
|
508 |
HHGear:= PHedgehog(Gear.Hedgehog)^.Gear; |
|
509 |
if (HHGear.State and gstFalling) <> 0 then |
|
68 | 510 |
if TestCollisionYwithGear(HHGear, 1) then |
4 | 511 |
begin |
512 |
HHGear.dY:= 0; |
|
513 |
CheckHHDamage(HHGear); |
|
514 |
HHGear.State:= HHGear.State and not (gstFalling or gstHHJumping); |
|
515 |
end else |
|
516 |
begin |
|
517 |
if TestCollisionXwithGear(HHGear, Sign(HHGear.dX)) then HHGear.dX:= 0.0000001 * Sign(HHGear.dX); |
|
518 |
HHGear.X:= HHGear.X + HHGear.dX; |
|
519 |
HHGear.Y:= HHGear.Y + HHGear.dY; |
|
520 |
Gear.X:= Gear.X + HHGear.dX; |
|
521 |
Gear.Y:= Gear.Y + HHGear.dY; |
|
522 |
HHGear.dY:= HHGear.dY + cGravity; |
|
523 |
tt:= Gear.Elasticity; |
|
524 |
tx:= 0; |
|
525 |
ty:= 0; |
|
526 |
while tt > 20 do |
|
527 |
begin |
|
528 |
if TestCollisionXwithXYShift(Gear, round(tx), round(ty), Sign(Gear.dX)) |
|
529 |
or TestCollisionYwithXYShift(Gear, round(tx), round(ty), Sign(Gear.dY)) then |
|
530 |
begin |
|
531 |
Gear.X:= Gear.X + tx; |
|
532 |
Gear.Y:= Gear.Y + ty; |
|
533 |
Gear.Elasticity:= tt; |
|
534 |
Gear.doStep:= doStepRopeWork; |
|
535 |
with HHGear^ do State:= State and not gstAttacking; |
|
536 |
tt:= 0 |
|
537 |
end; |
|
538 |
tx:= tx - Gear.dX - Gear.dX; |
|
539 |
ty:= ty - Gear.dY - Gear.dY; |
|
540 |
tt:= tt - 2.0; |
|
541 |
end; |
|
542 |
end; |
|
543 |
CheckCollision(Gear); |
|
544 |
if (Gear.State and gstCollision) <> 0 then |
|
545 |
begin |
|
546 |
Gear.doStep:= doStepRopeWork; |
|
547 |
with HHGear^ do State:= State and not gstAttacking; |
|
548 |
if Gear.Elasticity < 10 then |
|
549 |
Gear.Elasticity:= 10000; |
|
550 |
end; |
|
551 |
||
552 |
if (Gear.Elasticity >= Gear.Friction) or ((Gear.Message and gm_Attack) = 0) then |
|
553 |
begin |
|
554 |
with PHedgehog(Gear.Hedgehog).Gear^ do |
|
555 |
begin |
|
556 |
State:= State and not gstAttacking; |
|
557 |
Message:= Message and not gm_Attack |
|
558 |
end; |
|
559 |
DeleteGear(Gear) |
|
560 |
end |
|
561 |
end; |
|
562 |
||
563 |
procedure doStepRope(Gear: PGear); |
|
564 |
begin |
|
565 |
Gear.doStep:= doStepRopeAttach |
|
566 |
end; |
|
567 |
||
568 |
//////////////////////////////////////////////////////////////////////////////// |
|
569 |
procedure doStepSmokeTrace(Gear: PGear); |
|
570 |
begin |
|
571 |
inc(Gear.Timer); |
|
572 |
if Gear.Timer > 64 then |
|
573 |
begin |
|
574 |
Gear.Timer:= 0; |
|
9 | 575 |
dec(Gear.State) |
4 | 576 |
end; |
577 |
Gear.dX:= Gear.dX + cWindSpeed; |
|
578 |
Gear.X:= Gear.X + Gear.dX; |
|
9 | 579 |
if Gear.State = 0 then DeleteGear(Gear) |
4 | 580 |
end; |
9 | 581 |
|
582 |
//////////////////////////////////////////////////////////////////////////////// |
|
583 |
procedure doStepExplosion(Gear: PGear); |
|
584 |
begin |
|
585 |
inc(Gear.Timer); |
|
586 |
if Gear.Timer > 75 then |
|
587 |
begin |
|
588 |
inc(Gear.State); |
|
589 |
Gear.Timer:= 0; |
|
590 |
if Gear.State > 5 then DeleteGear(Gear) |
|
591 |
end; |
|
592 |
end; |
|
10 | 593 |
|
594 |
//////////////////////////////////////////////////////////////////////////////// |
|
595 |
procedure doStepMine(Gear: PGear); |
|
596 |
begin |
|
39 | 597 |
if (Gear.dX <> 0) or (Gear.dY <> 0) then |
10 | 598 |
begin |
53 | 599 |
if Gear.CollIndex < High(Longword) then DeleteCI(Gear); |
10 | 600 |
doStepFallingGear(Gear); |
13 | 601 |
if Gear.Active = false then |
602 |
begin |
|
53 | 603 |
if Gear.CollIndex = High(Longword) then AddGearCI(Gear); |
13 | 604 |
Gear.dX:= 0; |
605 |
Gear.dY:= 0 |
|
606 |
end; |
|
607 |
CalcRotationDirAngle(Gear); |
|
10 | 608 |
AllInactive:= false |
609 |
end; |
|
39 | 610 |
|
10 | 611 |
if ((Gear.State and gsttmpFlag) <> 0) then |
612 |
if ((Gear.State and gstAttacking) = 0) then |
|
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
613 |
begin |
39 | 614 |
if ((GameTicks and $F) = 0) then |
15 | 615 |
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
|
616 |
end else // gstAttacking <> 0 |
10 | 617 |
begin |
618 |
AllInactive:= false; |
|
37 | 619 |
if (Gear.Timer and $FF) = 0 then PlaySound(sndMineTick); |
10 | 620 |
if Gear.Timer = 0 then |
621 |
begin |
|
13 | 622 |
doMakeExplosion(round(Gear.X), round(Gear.Y), 50, EXPLAutoSound); |
10 | 623 |
DeleteGear(Gear) |
624 |
end; |
|
13 | 625 |
dec(Gear.Timer); |
626 |
end else // gsttmpFlag = 0 |
|
627 |
if TurnTimeLeft = 0 then Gear.State:= Gear.State or gsttmpFlag; |
|
10 | 628 |
end; |
57 | 629 |
|
39 | 630 |
//////////////////////////////////////////////////////////////////////////////// |
631 |
procedure doStepDynamite(Gear: PGear); |
|
632 |
begin |
|
43 | 633 |
doStepFallingGear(Gear); |
634 |
AllInactive:= false; |
|
635 |
if Gear.Timer mod 166 = 0 then inc(Gear.Tag); |
|
636 |
if Gear.Timer = 0 then |
|
39 | 637 |
begin |
46 | 638 |
doMakeExplosion(round(Gear.X), round(Gear.Y), 75, EXPLAutoSound); |
43 | 639 |
DeleteGear(Gear); |
640 |
exit |
|
39 | 641 |
end; |
43 | 642 |
dec(Gear.Timer); |
39 | 643 |
end; |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
644 |
|
15 | 645 |
//////////////////////////////////////////////////////////////////////////////// |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
646 |
procedure doStepCase(Gear: PGear); |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
647 |
begin |
15 | 648 |
if (Gear.Message and gm_Destroy) > 0 then |
649 |
begin |
|
650 |
DeleteGear(Gear); |
|
651 |
exit |
|
652 |
end; |
|
653 |
||
53 | 654 |
if (Gear.dY <> 0) or (not TestCollisionYwithGear(Gear, 1)) then |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
655 |
begin |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
656 |
AllInactive:= false; |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
657 |
Gear.dY:= Gear.dY + cGravity; |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
658 |
Gear.Y:= Gear.Y + Gear.dY; |
53 | 659 |
if (Gear.dY < 0) and TestCollisionYwithGear(Gear, -1) then Gear.dY:= 0 else |
660 |
if (Gear.dY >= 0) and TestCollisionYwithGear(Gear, 1) then |
|
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
661 |
begin |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
662 |
Gear.dY:= - Gear.dY * Gear.Elasticity; |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
663 |
if Gear.dY > - 0.001 then Gear.dY:= 0 |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
664 |
else if Gear.dY < - 0.03 then PlaySound(sndGraveImpact); |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
665 |
end; |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
666 |
CheckGearDrowning(Gear); |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
667 |
end; |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
668 |
|
53 | 669 |
if (Gear.CollIndex = High(Longword)) and (Gear.dY = 0) then AddGearCI(Gear) |
670 |
else if (Gear.CollIndex < High(Longword)) and (Gear.dY <> 0) then DeleteCI(Gear); |
|
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
671 |
|
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
672 |
if Gear.Damage > 0 then |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
673 |
begin |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
674 |
DeleteGear(Gear); |
16 | 675 |
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
|
676 |
end |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
677 |
end; |
49 | 678 |
|
679 |
//////////////////////////////////////////////////////////////////////////////// |
|
680 |
var thexchar: array[0..5] of record |
|
681 |
oy, ny: integer; |
|
682 |
team: PTeam; |
|
683 |
end; |
|
684 |
thexchcnt: Longword; |
|
685 |
||
686 |
procedure doStepTeamHealthSorterWork(Gear: PGear); |
|
687 |
var i: integer; |
|
688 |
begin |
|
689 |
AllInactive:= false; |
|
690 |
dec(Gear.Timer); |
|
691 |
if (Gear.Timer and 15) = 0 then |
|
692 |
for i:= 0 to Pred(thexchcnt) do |
|
693 |
with thexchar[i] do |
|
694 |
{$WARNINGS OFF} |
|
695 |
team.DrawHealthY:= ny + (oy - ny) * Gear.Timer div 640; |
|
696 |
{$WARNINGS ON} |
|
697 |
if Gear.Timer = 0 then |
|
698 |
DeleteGear(Gear) |
|
699 |
end; |
|
700 |
||
701 |
procedure doStepTeamHealthSorter(Gear: PGear); |
|
702 |
var team: PTeam; |
|
703 |
i, t: Longword; |
|
704 |
begin |
|
705 |
AllInactive:= false; |
|
706 |
team:= TeamsList; |
|
707 |
i:= 0; |
|
708 |
while team <> nil do |
|
709 |
begin |
|
710 |
thexchar[i].oy:= team.DrawHealthY; |
|
711 |
thexchar[i].team:= team; |
|
712 |
inc(i); |
|
713 |
team:= team.Next |
|
714 |
end; |
|
715 |
thexchcnt:= i; |
|
716 |
for i:= 1 to thexchcnt do |
|
717 |
for t:= 0 to thexchcnt - 2 do |
|
718 |
if thexchar[t].team.TeamHealth > thexchar[Succ(t)].team.TeamHealth then |
|
719 |
begin |
|
720 |
thexchar[5]:= thexchar[t]; |
|
721 |
thexchar[t]:= thexchar[Succ(t)]; |
|
722 |
thexchar[Succ(t)]:= thexchar[5] |
|
723 |
end; |
|
724 |
t:= cScreenHeight - 4; |
|
725 |
for i:= 0 to Pred(thexchcnt) do |
|
726 |
with thexchar[i] do |
|
727 |
begin |
|
728 |
dec(t, team.HealthRect.h + 2); |
|
729 |
ny:= t |
|
730 |
end; |
|
731 |
Gear.Timer:= 640; |
|
732 |
Gear.doStep:= doStepTeamHealthSorterWork |
|
733 |
end; |
|
734 |