author | unc0rr |
Tue, 20 Jun 2006 21:18:49 +0000 | |
changeset 66 | 9643d75baf1e |
parent 57 | e1a77ae57065 |
child 68 | cbb93eb90304 |
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 |
|
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; |
|
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 |
|
53 | 174 |
if TestCollisionYwithGear(Gear, -1) then Gear.dY:= 0; |
4 | 175 |
|
176 |
if Gear.dY >=0 then |
|
53 | 177 |
if TestCollisionYwithGear(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 |
|
320 |
Allinactive:= false; |
|
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); |
|
387 |
const pidiv2: real = pi/2; |
|
388 |
flCheck: boolean = false; |
|
389 |
var HHGear: PGear; |
|
390 |
len, cs, cc, tx, ty: real; |
|
391 |
lx, ly: integer; |
|
392 |
||
393 |
procedure DeleteMe; |
|
394 |
begin |
|
395 |
with HHGear^ do |
|
396 |
begin |
|
397 |
Message:= Message and not gm_Attack; |
|
398 |
State:= State or gstFalling; |
|
399 |
end; |
|
400 |
DeleteGear(Gear); |
|
401 |
OnUsedAmmo(PHedgehog(Gear.Hedgehog)^.Ammo); |
|
402 |
ApplyAmmoChanges(PHedgehog(Gear.Hedgehog)) |
|
403 |
end; |
|
404 |
||
405 |
begin |
|
406 |
HHGear:= PHedgehog(Gear.Hedgehog).Gear; |
|
407 |
if (HHGear.State and gstHHDriven) = 0 then |
|
408 |
begin |
|
409 |
DeleteMe; |
|
410 |
exit |
|
411 |
end; |
|
412 |
Gear.dX:= HHGear.X - Gear.X; |
|
413 |
Gear.dY:= HHGear.Y - Gear.Y; |
|
414 |
||
415 |
if (Gear.Message and gm_Left <> 0) then HHGear.dX:= HHGear.dX - 0.0002 else |
|
416 |
if (Gear.Message and gm_Right <> 0) then HHGear.dX:= HHGear.dX + 0.0002; |
|
417 |
||
418 |
if not TestCollisionYwithGear(HHGear, 1) then HHGear.dY:= HHGear.dY + cGravity; |
|
419 |
||
420 |
HHGear.DirAngle:= arctan(Gear.dY + HHGear.dY, Gear.dX + HHGear.dX); |
|
421 |
cs:= sin(HHGear.DirAngle); |
|
422 |
cc:= cos(HHGear.DirAngle); |
|
423 |
||
424 |
flCheck:= not flCheck; |
|
425 |
if flCheck then // check whether rope needs dividing |
|
426 |
begin |
|
427 |
len:= Gear.Elasticity - 20; |
|
428 |
while len > 5 do |
|
429 |
begin |
|
430 |
tx:= cc*len; |
|
431 |
ty:= cs*len; |
|
432 |
lx:= round(Gear.X + tx) + sign(HHGear.dX); |
|
433 |
ly:= round(Gear.Y + ty) + sign(HHGear.dY); |
|
434 |
if ((ly and $FFFFFC00) = 0) and ((lx and $FFFFF800) = 0)and (Land[ly, lx] <> 0) then |
|
435 |
begin |
|
436 |
with RopePoints.ar[RopePoints.Count] do |
|
437 |
begin |
|
438 |
X:= Gear.X; |
|
439 |
Y:= Gear.Y; |
|
440 |
if RopePoints.Count = 0 then RopePoints.HookAngle:= DxDy2Angle32(Gear.dY, Gear.dX); |
|
441 |
b:= (cc * HHGear.dY) > (cs * HHGear.dX); |
|
442 |
dLen:= len |
|
443 |
end; |
|
444 |
Gear.X:= Gear.X + tx; |
|
445 |
Gear.Y:= Gear.Y + ty; |
|
446 |
inc(RopePoints.Count); |
|
447 |
Gear.Elasticity:= Gear.Elasticity - len; |
|
448 |
Gear.Friction:= Gear.Friction - len; |
|
449 |
break |
|
450 |
end; |
|
451 |
len:= len - 3 |
|
452 |
end; |
|
453 |
end else |
|
454 |
if RopePoints.Count > 0 then // check whether the last dividing point could be removed |
|
455 |
begin |
|
456 |
tx:= RopePoints.ar[Pred(RopePoints.Count)].X; |
|
457 |
ty:= RopePoints.ar[Pred(RopePoints.Count)].Y; |
|
458 |
if RopePoints.ar[Pred(RopePoints.Count)].b xor ((tx - Gear.X) * (ty - HHGear.Y) > (tx - HHGear.X) * (ty - Gear.Y)) then |
|
459 |
begin |
|
460 |
dec(RopePoints.Count); |
|
461 |
Gear.X:=RopePoints.ar[RopePoints.Count].X; |
|
462 |
Gear.Y:=RopePoints.ar[RopePoints.Count].Y; |
|
463 |
Gear.Elasticity:= Gear.Elasticity + RopePoints.ar[RopePoints.Count].dLen; |
|
464 |
Gear.Friction:= Gear.Friction + RopePoints.ar[RopePoints.Count].dLen |
|
465 |
end |
|
466 |
end; |
|
467 |
||
468 |
Gear.dX:= HHGear.X - Gear.X; |
|
469 |
Gear.dY:= HHGear.Y - Gear.Y; |
|
470 |
HHGear.DirAngle:= arctan(Gear.dY + HHGear.dY, Gear.dX + HHGear.dX); |
|
471 |
cs:= sin(HHGear.DirAngle); |
|
472 |
cc:= cos(HHGear.DirAngle); |
|
473 |
||
474 |
HHGear.dX:= HHGear.X; |
|
475 |
HHGear.dY:= HHGear.Y; |
|
476 |
||
477 |
if ((Gear.Message and gm_Down) <> 0) and (Gear.Elasticity < Gear.Friction) then |
|
478 |
if not (TestCollisionXwithGear(HHGear, Sign(Gear.dX)) |
|
479 |
or TestCollisionYwithGear(HHGear, Sign(Gear.dY))) then Gear.Elasticity:= Gear.Elasticity + 0.3; |
|
480 |
||
481 |
if ((Gear.Message and gm_Up) <> 0) and (Gear.Elasticity > 30) then |
|
482 |
if not (TestCollisionXwithGear(HHGear, -Sign(Gear.dX)) |
|
483 |
or TestCollisionYwithGear(HHGear, -Sign(Gear.dY))) then Gear.Elasticity:= Gear.Elasticity - 0.3; |
|
484 |
||
485 |
HHGear.X:= Gear.X + cc*Gear.Elasticity; |
|
486 |
HHGear.Y:= Gear.Y + cs*Gear.Elasticity; |
|
487 |
||
488 |
HHGear.dX:= HHGear.X - HHGear.dX; |
|
489 |
HHGear.dY:= HHGear.Y - HHGear.dY; |
|
490 |
||
491 |
if TestCollisionXwithGear(HHGear, Sign(HHGear.dX)) then |
|
492 |
HHGear.dX:= -0.9 * HHGear.dX; |
|
493 |
if TestCollisionYwithGear(HHGear, Sign(HHGear.dY)) then |
|
494 |
HHGear.dY:= -0.9 * HHGear.dY; |
|
495 |
||
496 |
if (Gear.Message and gm_Attack) <> 0 then |
|
497 |
if (Gear.State and gsttmpFlag) <> 0 then DeleteMe else |
|
498 |
else if (Gear.State and gsttmpFlag) = 0 then Gear.State:= Gear.State or gsttmpFlag; |
|
499 |
end; |
|
500 |
||
501 |
||
502 |
procedure doStepRopeAttach(Gear: PGear); |
|
503 |
var HHGear: PGear; |
|
504 |
tx, ty, tt: real; |
|
505 |
begin |
|
506 |
Gear.X:= Gear.X + Gear.dX; |
|
507 |
Gear.Y:= Gear.Y + Gear.dY; |
|
508 |
Gear.Elasticity:= Gear.Elasticity + 1.0; |
|
509 |
HHGear:= PHedgehog(Gear.Hedgehog)^.Gear; |
|
510 |
if (HHGear.State and gstFalling) <> 0 then |
|
511 |
if HHTestCollisionYwithGear(HHGear, 1) then |
|
512 |
begin |
|
513 |
HHGear.dY:= 0; |
|
514 |
CheckHHDamage(HHGear); |
|
515 |
HHGear.State:= HHGear.State and not (gstFalling or gstHHJumping); |
|
516 |
end else |
|
517 |
begin |
|
518 |
if TestCollisionXwithGear(HHGear, Sign(HHGear.dX)) then HHGear.dX:= 0.0000001 * Sign(HHGear.dX); |
|
519 |
HHGear.X:= HHGear.X + HHGear.dX; |
|
520 |
HHGear.Y:= HHGear.Y + HHGear.dY; |
|
521 |
Gear.X:= Gear.X + HHGear.dX; |
|
522 |
Gear.Y:= Gear.Y + HHGear.dY; |
|
523 |
HHGear.dY:= HHGear.dY + cGravity; |
|
524 |
tt:= Gear.Elasticity; |
|
525 |
tx:= 0; |
|
526 |
ty:= 0; |
|
527 |
while tt > 20 do |
|
528 |
begin |
|
529 |
if TestCollisionXwithXYShift(Gear, round(tx), round(ty), Sign(Gear.dX)) |
|
530 |
or TestCollisionYwithXYShift(Gear, round(tx), round(ty), Sign(Gear.dY)) then |
|
531 |
begin |
|
532 |
Gear.X:= Gear.X + tx; |
|
533 |
Gear.Y:= Gear.Y + ty; |
|
534 |
Gear.Elasticity:= tt; |
|
535 |
Gear.doStep:= doStepRopeWork; |
|
536 |
with HHGear^ do State:= State and not gstAttacking; |
|
537 |
tt:= 0 |
|
538 |
end; |
|
539 |
tx:= tx - Gear.dX - Gear.dX; |
|
540 |
ty:= ty - Gear.dY - Gear.dY; |
|
541 |
tt:= tt - 2.0; |
|
542 |
end; |
|
543 |
end; |
|
544 |
CheckCollision(Gear); |
|
545 |
if (Gear.State and gstCollision) <> 0 then |
|
546 |
begin |
|
547 |
Gear.doStep:= doStepRopeWork; |
|
548 |
with HHGear^ do State:= State and not gstAttacking; |
|
549 |
if Gear.Elasticity < 10 then |
|
550 |
Gear.Elasticity:= 10000; |
|
551 |
end; |
|
552 |
||
553 |
if (Gear.Elasticity >= Gear.Friction) or ((Gear.Message and gm_Attack) = 0) then |
|
554 |
begin |
|
555 |
with PHedgehog(Gear.Hedgehog).Gear^ do |
|
556 |
begin |
|
557 |
State:= State and not gstAttacking; |
|
558 |
Message:= Message and not gm_Attack |
|
559 |
end; |
|
560 |
DeleteGear(Gear) |
|
561 |
end |
|
562 |
end; |
|
563 |
||
564 |
procedure doStepRope(Gear: PGear); |
|
565 |
begin |
|
566 |
Gear.doStep:= doStepRopeAttach |
|
567 |
end; |
|
568 |
||
569 |
//////////////////////////////////////////////////////////////////////////////// |
|
570 |
procedure doStepSmokeTrace(Gear: PGear); |
|
571 |
begin |
|
572 |
inc(Gear.Timer); |
|
573 |
if Gear.Timer > 64 then |
|
574 |
begin |
|
575 |
Gear.Timer:= 0; |
|
9 | 576 |
dec(Gear.State) |
4 | 577 |
end; |
578 |
Gear.dX:= Gear.dX + cWindSpeed; |
|
579 |
Gear.X:= Gear.X + Gear.dX; |
|
9 | 580 |
if Gear.State = 0 then DeleteGear(Gear) |
4 | 581 |
end; |
9 | 582 |
|
583 |
//////////////////////////////////////////////////////////////////////////////// |
|
584 |
procedure doStepExplosion(Gear: PGear); |
|
585 |
begin |
|
586 |
inc(Gear.Timer); |
|
587 |
if Gear.Timer > 75 then |
|
588 |
begin |
|
589 |
inc(Gear.State); |
|
590 |
Gear.Timer:= 0; |
|
591 |
if Gear.State > 5 then DeleteGear(Gear) |
|
592 |
end; |
|
593 |
end; |
|
10 | 594 |
|
595 |
//////////////////////////////////////////////////////////////////////////////// |
|
596 |
procedure doStepMine(Gear: PGear); |
|
597 |
begin |
|
39 | 598 |
if (Gear.dX <> 0) or (Gear.dY <> 0) then |
10 | 599 |
begin |
53 | 600 |
if Gear.CollIndex < High(Longword) then DeleteCI(Gear); |
10 | 601 |
doStepFallingGear(Gear); |
13 | 602 |
if Gear.Active = false then |
603 |
begin |
|
53 | 604 |
if Gear.CollIndex = High(Longword) then AddGearCI(Gear); |
13 | 605 |
Gear.dX:= 0; |
606 |
Gear.dY:= 0 |
|
607 |
end; |
|
608 |
CalcRotationDirAngle(Gear); |
|
10 | 609 |
AllInactive:= false |
610 |
end; |
|
39 | 611 |
|
10 | 612 |
if ((Gear.State and gsttmpFlag) <> 0) then |
613 |
if ((Gear.State and gstAttacking) = 0) then |
|
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
614 |
begin |
39 | 615 |
if ((GameTicks and $F) = 0) then |
15 | 616 |
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
|
617 |
end else // gstAttacking <> 0 |
10 | 618 |
begin |
619 |
AllInactive:= false; |
|
37 | 620 |
if (Gear.Timer and $FF) = 0 then PlaySound(sndMineTick); |
10 | 621 |
if Gear.Timer = 0 then |
622 |
begin |
|
13 | 623 |
doMakeExplosion(round(Gear.X), round(Gear.Y), 50, EXPLAutoSound); |
10 | 624 |
DeleteGear(Gear) |
625 |
end; |
|
13 | 626 |
dec(Gear.Timer); |
627 |
end else // gsttmpFlag = 0 |
|
628 |
if TurnTimeLeft = 0 then Gear.State:= Gear.State or gsttmpFlag; |
|
10 | 629 |
end; |
57 | 630 |
|
39 | 631 |
//////////////////////////////////////////////////////////////////////////////// |
632 |
procedure doStepDynamite(Gear: PGear); |
|
633 |
begin |
|
43 | 634 |
doStepFallingGear(Gear); |
635 |
AllInactive:= false; |
|
636 |
if Gear.Timer mod 166 = 0 then inc(Gear.Tag); |
|
637 |
if Gear.Timer = 0 then |
|
39 | 638 |
begin |
46 | 639 |
doMakeExplosion(round(Gear.X), round(Gear.Y), 75, EXPLAutoSound); |
43 | 640 |
DeleteGear(Gear); |
641 |
exit |
|
39 | 642 |
end; |
43 | 643 |
dec(Gear.Timer); |
39 | 644 |
end; |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
645 |
|
15 | 646 |
//////////////////////////////////////////////////////////////////////////////// |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
647 |
procedure doStepCase(Gear: PGear); |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
648 |
begin |
15 | 649 |
if (Gear.Message and gm_Destroy) > 0 then |
650 |
begin |
|
651 |
DeleteGear(Gear); |
|
652 |
exit |
|
653 |
end; |
|
654 |
||
53 | 655 |
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
|
656 |
begin |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
657 |
AllInactive:= false; |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
658 |
Gear.dY:= Gear.dY + cGravity; |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
659 |
Gear.Y:= Gear.Y + Gear.dY; |
53 | 660 |
if (Gear.dY < 0) and TestCollisionYwithGear(Gear, -1) then Gear.dY:= 0 else |
661 |
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
|
662 |
begin |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
663 |
Gear.dY:= - Gear.dY * Gear.Elasticity; |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
664 |
if Gear.dY > - 0.001 then Gear.dY:= 0 |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
665 |
else if Gear.dY < - 0.03 then PlaySound(sndGraveImpact); |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
666 |
end; |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
667 |
CheckGearDrowning(Gear); |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
668 |
end; |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
669 |
|
53 | 670 |
if (Gear.CollIndex = High(Longword)) and (Gear.dY = 0) then AddGearCI(Gear) |
671 |
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
|
672 |
|
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
673 |
if Gear.Damage > 0 then |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
674 |
begin |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
675 |
DeleteGear(Gear); |
16 | 676 |
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
|
677 |
end |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
678 |
end; |
49 | 679 |
|
680 |
//////////////////////////////////////////////////////////////////////////////// |
|
681 |
var thexchar: array[0..5] of record |
|
682 |
oy, ny: integer; |
|
683 |
team: PTeam; |
|
684 |
end; |
|
685 |
thexchcnt: Longword; |
|
686 |
||
687 |
procedure doStepTeamHealthSorterWork(Gear: PGear); |
|
688 |
var i: integer; |
|
689 |
begin |
|
690 |
AllInactive:= false; |
|
691 |
dec(Gear.Timer); |
|
692 |
if (Gear.Timer and 15) = 0 then |
|
693 |
for i:= 0 to Pred(thexchcnt) do |
|
694 |
with thexchar[i] do |
|
695 |
{$WARNINGS OFF} |
|
696 |
team.DrawHealthY:= ny + (oy - ny) * Gear.Timer div 640; |
|
697 |
{$WARNINGS ON} |
|
698 |
if Gear.Timer = 0 then |
|
699 |
DeleteGear(Gear) |
|
700 |
end; |
|
701 |
||
702 |
procedure doStepTeamHealthSorter(Gear: PGear); |
|
703 |
var team: PTeam; |
|
704 |
i, t: Longword; |
|
705 |
begin |
|
706 |
AllInactive:= false; |
|
707 |
team:= TeamsList; |
|
708 |
i:= 0; |
|
709 |
while team <> nil do |
|
710 |
begin |
|
711 |
thexchar[i].oy:= team.DrawHealthY; |
|
712 |
thexchar[i].team:= team; |
|
713 |
inc(i); |
|
714 |
team:= team.Next |
|
715 |
end; |
|
716 |
thexchcnt:= i; |
|
717 |
for i:= 1 to thexchcnt do |
|
718 |
for t:= 0 to thexchcnt - 2 do |
|
719 |
if thexchar[t].team.TeamHealth > thexchar[Succ(t)].team.TeamHealth then |
|
720 |
begin |
|
721 |
thexchar[5]:= thexchar[t]; |
|
722 |
thexchar[t]:= thexchar[Succ(t)]; |
|
723 |
thexchar[Succ(t)]:= thexchar[5] |
|
724 |
end; |
|
725 |
t:= cScreenHeight - 4; |
|
726 |
for i:= 0 to Pred(thexchcnt) do |
|
727 |
with thexchar[i] do |
|
728 |
begin |
|
729 |
dec(t, team.HealthRect.h + 2); |
|
730 |
ny:= t |
|
731 |
end; |
|
732 |
Gear.Timer:= 640; |
|
733 |
Gear.doStep:= doStepTeamHealthSorterWork |
|
734 |
end; |
|
735 |