author | unc0rr |
Thu, 20 Jul 2006 20:11:32 +0000 | |
changeset 80 | 3c3dc6a148ca |
parent 79 | 29b477319854 |
child 81 | d74e0e914b50 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
79 | 3 |
* Copyright (c) 2004, 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 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; |
|
75 | 76 |
if round(Gear.Y) > Gear.Radius + cWaterLine + 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; |
|
74 | 120 |
if Gear.Y > -160 then Gear.dY:= Gear.dY - 0.00002 |
121 |
else Gear.dY:= Gear.dY + 0.00002; |
|
122 |
Gear.Y:= Gear.Y + Gear.dY; |
|
123 |
if Gear.X < -cScreenWidth - 256 then Gear.X:= cScreenWidth + 2048 else |
|
4 | 124 |
if Gear.X > cScreenWidth + 2048 then Gear.X:= -cScreenWidth - 256 |
125 |
end; |
|
126 |
||
127 |
//////////////////////////////////////////////////////////////////////////////// |
|
128 |
procedure doStepBomb(Gear: PGear); |
|
78 | 129 |
var i: integer; |
4 | 130 |
begin |
131 |
AllInactive:= false; |
|
132 |
doStepFallingGear(Gear); |
|
133 |
dec(Gear.Timer); |
|
134 |
if Gear.Timer = 0 then |
|
135 |
begin |
|
78 | 136 |
case Gear.Kind of |
137 |
gtAmmo_Bomb: doMakeExplosion(round(Gear.X), round(Gear.Y), 50, EXPLAutoSound); |
|
138 |
gtClusterBomb: begin |
|
139 |
doMakeExplosion(round(Gear.X), round(Gear.Y), 30, EXPLAutoSound); |
|
140 |
for i:= 0 to 4 do |
|
79 | 141 |
AddGear(round(Gear.X), round(Gear.Y), gtCluster, 0, (getrandom - 0.5)*0.2, (getrandom - 3) * 0.08); |
78 | 142 |
end |
143 |
end; |
|
4 | 144 |
DeleteGear(Gear); |
145 |
exit |
|
146 |
end; |
|
147 |
CalcRotationDirAngle(Gear); |
|
148 |
if (Gear.State and (gstCollision or gstMoving)) = (gstCollision or gstMoving) then PlaySound(sndGrenadeImpact) |
|
149 |
end; |
|
150 |
||
78 | 151 |
procedure doStepCluster(Gear: PGear); |
152 |
begin |
|
153 |
AllInactive:= false; |
|
154 |
doStepFallingGear(Gear); |
|
155 |
if (Gear.State and gstCollision) <> 0 then |
|
156 |
begin |
|
157 |
doMakeExplosion(round(Gear.X), round(Gear.Y), 20, EXPLAutoSound); |
|
158 |
DeleteGear(Gear); |
|
159 |
exit |
|
160 |
end; |
|
161 |
if (GameTicks and $1F) = 0 then |
|
162 |
AddGear(round(Gear.X), round(Gear.Y), gtSmokeTrace, 0) |
|
163 |
end; |
|
164 |
||
4 | 165 |
//////////////////////////////////////////////////////////////////////////////// |
166 |
procedure doStepGrenade(Gear: PGear); |
|
167 |
begin |
|
168 |
AllInactive:= false; |
|
169 |
Gear.dX:= Gear.dX + cWindSpeed; |
|
170 |
doStepFallingGear(Gear); |
|
171 |
if (Gear.State and gstCollision) <> 0 then |
|
172 |
begin |
|
173 |
doMakeExplosion(round(Gear.X), round(Gear.Y), 50, EXPLAutoSound); |
|
174 |
DeleteGear(Gear); |
|
175 |
exit |
|
176 |
end; |
|
177 |
if (GameTicks and $3F) = 0 then |
|
178 |
AddGear(round(Gear.X), round(Gear.Y), gtSmokeTrace, 0) |
|
179 |
end; |
|
180 |
||
181 |
//////////////////////////////////////////////////////////////////////////////// |
|
182 |
procedure doStepHealthTag(Gear: PGear); |
|
183 |
begin |
|
184 |
AllInactive:= false; |
|
185 |
dec(Gear.Timer); |
|
186 |
Gear.Y:= Gear.Y - 0.07; |
|
187 |
if Gear.Timer = 0 then |
|
188 |
begin |
|
189 |
PHedgehog(Gear.Hedgehog).Gear.Active:= true; |
|
190 |
DeleteGear(Gear) |
|
191 |
end |
|
192 |
end; |
|
193 |
||
194 |
//////////////////////////////////////////////////////////////////////////////// |
|
195 |
procedure doStepGrave(Gear: PGear); |
|
196 |
begin |
|
197 |
AllInactive:= false; |
|
198 |
if Gear.dY < 0 then |
|
68 | 199 |
if TestCollisionY(Gear, -1) then Gear.dY:= 0; |
4 | 200 |
|
201 |
if Gear.dY >=0 then |
|
68 | 202 |
if TestCollisionY(Gear, 1) then |
4 | 203 |
begin |
204 |
Gear.dY:= - Gear.dY * Gear.Elasticity; |
|
205 |
if Gear.dY > - 0.001 then |
|
206 |
begin |
|
207 |
Gear.Active:= false; |
|
208 |
exit |
|
209 |
end else if Gear.dY < - 0.03 then PlaySound(sndGraveImpact) |
|
210 |
end; |
|
211 |
Gear.Y:= Gear.Y + Gear.dY; |
|
212 |
CheckGearDrowning(Gear); |
|
213 |
Gear.dY:= Gear.dY + cGravity |
|
214 |
end; |
|
215 |
||
216 |
//////////////////////////////////////////////////////////////////////////////// |
|
217 |
procedure doStepUFOWork(Gear: PGear); |
|
218 |
var t: real; |
|
219 |
begin |
|
220 |
AllInactive:= false; |
|
221 |
t:= sqrt(sqr(Gear.dX) + sqr(Gear.dY)); |
|
222 |
Gear.dX:= Gear.Elasticity * (Gear.dX + 0.000004 * (TargetPoint.X - trunc(Gear.X))); |
|
223 |
Gear.dY:= Gear.Elasticity * (Gear.dY + 0.000004 * (TargetPoint.Y - trunc(Gear.Y))); |
|
224 |
t:= t / (sqrt(sqr(Gear.dX) + sqr(Gear.dY))); |
|
225 |
Gear.dX:= Gear.dX * t; |
|
226 |
Gear.dY:= Gear.dY * t; |
|
227 |
Gear.X:= Gear.X + Gear.dX; |
|
228 |
Gear.Y:= Gear.Y + Gear.dY; |
|
229 |
CheckCollision(Gear); |
|
230 |
dec(Gear.Timer); |
|
231 |
if ((Gear.State and gstCollision) <> 0) or (Gear.Timer = 0) then |
|
232 |
begin |
|
233 |
doMakeExplosion(round(Gear.X), round(Gear.Y), 50, EXPLAutoSound); |
|
234 |
DeleteGear(Gear); |
|
235 |
end; |
|
236 |
end; |
|
237 |
||
238 |
procedure doStepUFO(Gear: PGear); |
|
239 |
begin |
|
240 |
AllInactive:= false; |
|
241 |
Gear.X:= Gear.X + Gear.dX; |
|
242 |
Gear.Y:= Gear.Y + Gear.dY; |
|
243 |
Gear.dY:= Gear.dY + cGravity; |
|
244 |
CheckCollision(Gear); |
|
245 |
if (Gear.State and gstCollision) <> 0 then |
|
246 |
begin |
|
247 |
doMakeExplosion(round(Gear.X), round(Gear.Y), 50, EXPLAutoSound); |
|
248 |
DeleteGear(Gear); |
|
249 |
exit |
|
250 |
end; |
|
251 |
dec(Gear.Timer); |
|
252 |
if Gear.Timer = 0 then |
|
253 |
begin |
|
254 |
Gear.Timer:= 5000; |
|
255 |
Gear.doStep:= doStepUFOWork |
|
256 |
end; |
|
257 |
end; |
|
258 |
||
259 |
//////////////////////////////////////////////////////////////////////////////// |
|
260 |
procedure doStepShotgunShot(Gear: PGear); |
|
261 |
var i: LongWord; |
|
262 |
begin |
|
263 |
AllInactive:= false; |
|
264 |
if Gear.Timer > 0 then |
|
265 |
begin |
|
266 |
dec(Gear.Timer); |
|
267 |
if Gear.Timer = 1 then PlaySound(sndShotgunFire); |
|
268 |
exit |
|
269 |
end; |
|
270 |
i:= 200; |
|
271 |
repeat |
|
272 |
Gear.X:= Gear.X + Gear.dX; |
|
273 |
Gear.Y:= Gear.Y + Gear.dY; |
|
274 |
CheckCollision(Gear); |
|
275 |
if (Gear.State and gstCollision) <> 0 then |
|
276 |
begin |
|
75 | 277 |
AmmoShove(Gear, 25, 25); |
42 | 278 |
doMakeExplosion(round(Gear.X), round(Gear.Y), 25, EXPLNoDamage or EXPLDoNotTouchHH); |
4 | 279 |
DeleteGear(Gear); |
75 | 280 |
AfterAttack; |
4 | 281 |
exit |
282 |
end; |
|
283 |
dec(i) |
|
284 |
until i = 0; |
|
285 |
if (Gear.X < 0) or (Gear.Y < 0) or (Gear.X > 2048) or (Gear.Y > 1024) then |
|
286 |
DeleteGear(Gear) |
|
287 |
end; |
|
288 |
||
289 |
//////////////////////////////////////////////////////////////////////////////// |
|
38 | 290 |
procedure doStepDEagleShot(Gear: PGear); |
291 |
var i, x, y: LongWord; |
|
292 |
oX, oY: real; |
|
293 |
begin |
|
294 |
AllInactive:= false; |
|
37 | 295 |
i:= 80; |
38 | 296 |
oX:= Gear.X; |
297 |
oY:= Gear.Y; |
|
37 | 298 |
repeat |
38 | 299 |
Gear.X:= Gear.X + Gear.dX; |
300 |
Gear.Y:= Gear.Y + Gear.dY; |
|
301 |
x:= round(Gear.X); |
|
302 |
y:= round(Gear.Y); |
|
303 |
if ((y and $FFFFFC00) = 0) and ((x and $FFFFF800) = 0) |
|
304 |
and (Land[y, x] <> 0) then inc(Gear.Damage); |
|
75 | 305 |
AmmoShove(Gear, 7, 20); |
38 | 306 |
dec(i) |
307 |
until (i = 0) or (Gear.Damage > Gear.Health); |
|
308 |
if Gear.Damage > 0 then |
|
37 | 309 |
begin |
38 | 310 |
DrawTunnel(oX, oY, Gear.dX, Gear.dY, 82 - i, 1); |
311 |
dec(Gear.Health, Gear.Damage); |
|
312 |
Gear.Damage:= 0 |
|
37 | 313 |
end; |
38 | 314 |
if (Gear.Health <= 0) or (Gear.X < 0) or (Gear.Y < 0) or (Gear.X > 2048) or (Gear.Y > 1024) then |
37 | 315 |
DeleteGear(Gear) |
316 |
end; |
|
317 |
||
318 |
//////////////////////////////////////////////////////////////////////////////// |
|
4 | 319 |
procedure doStepActionTimer(Gear: PGear); |
320 |
begin |
|
321 |
case Gear.State of |
|
322 |
gtsStartGame: begin |
|
6 | 323 |
dec(Gear.Timer); |
4 | 324 |
AllInactive:= false; |
325 |
if Gear.Timer > 0 then exit; |
|
326 |
AddCaption('Let''s fight!', $FFFFFF, capgrpStartGame); |
|
327 |
DeleteGear(Gear) |
|
328 |
end; |
|
6 | 329 |
gtsSmoothWindCh: begin |
330 |
if Gear.Timer = 0 then |
|
331 |
begin |
|
332 |
Gear.Timer:= 10; |
|
333 |
if WindBarWidth < Gear.Tag then inc(WindBarWidth) |
|
334 |
else if WindBarWidth > Gear.Tag then dec(WindBarWidth) |
|
335 |
else DeleteGear(Gear) |
|
336 |
end else dec(Gear.Timer) |
|
337 |
end; |
|
4 | 338 |
end; |
339 |
end; |
|
340 |
||
341 |
//////////////////////////////////////////////////////////////////////////////// |
|
342 |
procedure doStepPickHammerWork(Gear: PGear); |
|
343 |
var i, ei: integer; |
|
344 |
HHGear: PGear; |
|
345 |
begin |
|
70 | 346 |
AllInactive:= false; |
4 | 347 |
dec(Gear.Timer); |
348 |
if (Gear.Timer = 0)or((Gear.Message and gm_Destroy) <> 0) then |
|
349 |
begin |
|
350 |
DeleteGear(Gear); |
|
351 |
AfterAttack; |
|
352 |
exit |
|
353 |
end; |
|
354 |
HHGear:= PHedgehog(Gear.Hedgehog).Gear; |
|
355 |
if (Gear.Timer and $3F) = 0 then |
|
356 |
begin |
|
53 | 357 |
i:= round(Gear.X) - Gear.Radius - GetRandom(2); |
358 |
ei:= round(Gear.X) + Gear.Radius + GetRandom(2); |
|
4 | 359 |
while i <= ei do |
360 |
begin |
|
361 |
doMakeExplosion(i, round(Gear.Y) + 3, 3, 0); |
|
362 |
inc(i, 1) |
|
363 |
end; |
|
364 |
Gear.X:= Gear.X + Gear.dX; |
|
42 | 365 |
Gear.Y:= Gear.Y + 1.9; |
366 |
SetAllHHToActive; |
|
4 | 367 |
end; |
368 |
if TestCollisionYwithGear(Gear, 1) then |
|
369 |
begin |
|
370 |
Gear.dY:= 0; |
|
371 |
HHGear.dX:= 0.0000001 * Sign(PGear(Gear.Hedgehog).dX); |
|
372 |
HHGear.dY:= 0; |
|
373 |
end else |
|
374 |
begin |
|
375 |
Gear.dY:= Gear.dY + cGravity; |
|
376 |
Gear.Y:= Gear.Y + Gear.dY; |
|
377 |
if Gear.Y > 1024 then Gear.Timer:= 1 |
|
378 |
end; |
|
379 |
||
380 |
Gear.X:= Gear.X + HHGear.dX; |
|
381 |
HHGear.X:= Gear.X; |
|
53 | 382 |
HHGear.Y:= Gear.Y - cHHRadius; |
4 | 383 |
|
384 |
if (Gear.Message and gm_Attack) <> 0 then |
|
385 |
if (Gear.State and gsttmpFlag) <> 0 then Gear.Timer:= 1 else else |
|
386 |
if (Gear.State and gsttmpFlag) = 0 then Gear.State:= Gear.State or gsttmpFlag; |
|
387 |
if ((Gear.Message and gm_Left) <> 0) then Gear.dX:= -0.3 else |
|
388 |
if ((Gear.Message and gm_Right) <> 0) then Gear.dX:= 0.3 |
|
389 |
else Gear.dX:= 0; |
|
390 |
end; |
|
391 |
||
392 |
procedure doStepPickHammer(Gear: PGear); |
|
393 |
var i, y: integer; |
|
394 |
ar: TRangeArray; |
|
395 |
begin |
|
396 |
i:= 0; |
|
53 | 397 |
y:= round(Gear.Y) - cHHRadius*2; |
4 | 398 |
while y < round(Gear.Y) do |
399 |
begin |
|
53 | 400 |
ar[i].Left := round(Gear.X) - Gear.Radius - GetRandom(2); |
401 |
ar[i].Right:= round(Gear.X) + Gear.Radius + GetRandom(2); |
|
4 | 402 |
inc(y, 2); |
403 |
inc(i) |
|
404 |
end; |
|
53 | 405 |
DrawHLinesExplosions(@ar, 3, round(Gear.Y) - cHHRadius*2, 2, Pred(i)); |
4 | 406 |
Gear.dY:= PHedgehog(Gear.Hedgehog).Gear.dY; |
407 |
doStepPickHammerWork(Gear); |
|
408 |
Gear.doStep:= doStepPickHammerWork |
|
409 |
end; |
|
410 |
||
411 |
//////////////////////////////////////////////////////////////////////////////// |
|
412 |
procedure doStepRopeWork(Gear: PGear); |
|
70 | 413 |
const flCheck: boolean = false; |
4 | 414 |
var HHGear: PGear; |
415 |
len, cs, cc, tx, ty: real; |
|
416 |
lx, ly: integer; |
|
417 |
||
418 |
procedure DeleteMe; |
|
419 |
begin |
|
420 |
with HHGear^ do |
|
421 |
begin |
|
422 |
Message:= Message and not gm_Attack; |
|
423 |
State:= State or gstFalling; |
|
424 |
end; |
|
425 |
DeleteGear(Gear); |
|
426 |
OnUsedAmmo(PHedgehog(Gear.Hedgehog)^.Ammo); |
|
70 | 427 |
ApplyAmmoChanges(PHedgehog(Gear.Hedgehog)^) |
4 | 428 |
end; |
429 |
||
430 |
begin |
|
431 |
HHGear:= PHedgehog(Gear.Hedgehog).Gear; |
|
80 | 432 |
if ((HHGear.State and gstHHDriven) = 0) |
433 |
or (CheckGearDrowning(HHGear)) then |
|
4 | 434 |
begin |
435 |
DeleteMe; |
|
436 |
exit |
|
437 |
end; |
|
438 |
Gear.dX:= HHGear.X - Gear.X; |
|
439 |
Gear.dY:= HHGear.Y - Gear.Y; |
|
440 |
||
441 |
if (Gear.Message and gm_Left <> 0) then HHGear.dX:= HHGear.dX - 0.0002 else |
|
442 |
if (Gear.Message and gm_Right <> 0) then HHGear.dX:= HHGear.dX + 0.0002; |
|
443 |
||
444 |
if not TestCollisionYwithGear(HHGear, 1) then HHGear.dY:= HHGear.dY + cGravity; |
|
445 |
||
446 |
HHGear.DirAngle:= arctan(Gear.dY + HHGear.dY, Gear.dX + HHGear.dX); |
|
447 |
cs:= sin(HHGear.DirAngle); |
|
448 |
cc:= cos(HHGear.DirAngle); |
|
449 |
||
450 |
flCheck:= not flCheck; |
|
451 |
if flCheck then // check whether rope needs dividing |
|
452 |
begin |
|
453 |
len:= Gear.Elasticity - 20; |
|
454 |
while len > 5 do |
|
455 |
begin |
|
456 |
tx:= cc*len; |
|
457 |
ty:= cs*len; |
|
70 | 458 |
lx:= round(Gear.X + tx) + Sign(HHGear.dX); |
459 |
ly:= round(Gear.Y + ty) + Sign(HHGear.dY); |
|
4 | 460 |
if ((ly and $FFFFFC00) = 0) and ((lx and $FFFFF800) = 0)and (Land[ly, lx] <> 0) then |
461 |
begin |
|
462 |
with RopePoints.ar[RopePoints.Count] do |
|
463 |
begin |
|
464 |
X:= Gear.X; |
|
465 |
Y:= Gear.Y; |
|
466 |
if RopePoints.Count = 0 then RopePoints.HookAngle:= DxDy2Angle32(Gear.dY, Gear.dX); |
|
467 |
b:= (cc * HHGear.dY) > (cs * HHGear.dX); |
|
468 |
dLen:= len |
|
469 |
end; |
|
470 |
Gear.X:= Gear.X + tx; |
|
471 |
Gear.Y:= Gear.Y + ty; |
|
472 |
inc(RopePoints.Count); |
|
473 |
Gear.Elasticity:= Gear.Elasticity - len; |
|
474 |
Gear.Friction:= Gear.Friction - len; |
|
475 |
break |
|
476 |
end; |
|
477 |
len:= len - 3 |
|
478 |
end; |
|
479 |
end else |
|
480 |
if RopePoints.Count > 0 then // check whether the last dividing point could be removed |
|
481 |
begin |
|
482 |
tx:= RopePoints.ar[Pred(RopePoints.Count)].X; |
|
483 |
ty:= RopePoints.ar[Pred(RopePoints.Count)].Y; |
|
484 |
if RopePoints.ar[Pred(RopePoints.Count)].b xor ((tx - Gear.X) * (ty - HHGear.Y) > (tx - HHGear.X) * (ty - Gear.Y)) then |
|
485 |
begin |
|
486 |
dec(RopePoints.Count); |
|
487 |
Gear.X:=RopePoints.ar[RopePoints.Count].X; |
|
488 |
Gear.Y:=RopePoints.ar[RopePoints.Count].Y; |
|
489 |
Gear.Elasticity:= Gear.Elasticity + RopePoints.ar[RopePoints.Count].dLen; |
|
490 |
Gear.Friction:= Gear.Friction + RopePoints.ar[RopePoints.Count].dLen |
|
491 |
end |
|
492 |
end; |
|
493 |
||
494 |
Gear.dX:= HHGear.X - Gear.X; |
|
495 |
Gear.dY:= HHGear.Y - Gear.Y; |
|
496 |
HHGear.DirAngle:= arctan(Gear.dY + HHGear.dY, Gear.dX + HHGear.dX); |
|
497 |
cs:= sin(HHGear.DirAngle); |
|
498 |
cc:= cos(HHGear.DirAngle); |
|
499 |
||
500 |
HHGear.dX:= HHGear.X; |
|
501 |
HHGear.dY:= HHGear.Y; |
|
502 |
||
503 |
if ((Gear.Message and gm_Down) <> 0) and (Gear.Elasticity < Gear.Friction) then |
|
504 |
if not (TestCollisionXwithGear(HHGear, Sign(Gear.dX)) |
|
505 |
or TestCollisionYwithGear(HHGear, Sign(Gear.dY))) then Gear.Elasticity:= Gear.Elasticity + 0.3; |
|
506 |
||
507 |
if ((Gear.Message and gm_Up) <> 0) and (Gear.Elasticity > 30) then |
|
508 |
if not (TestCollisionXwithGear(HHGear, -Sign(Gear.dX)) |
|
509 |
or TestCollisionYwithGear(HHGear, -Sign(Gear.dY))) then Gear.Elasticity:= Gear.Elasticity - 0.3; |
|
510 |
||
511 |
HHGear.X:= Gear.X + cc*Gear.Elasticity; |
|
512 |
HHGear.Y:= Gear.Y + cs*Gear.Elasticity; |
|
513 |
||
514 |
HHGear.dX:= HHGear.X - HHGear.dX; |
|
515 |
HHGear.dY:= HHGear.Y - HHGear.dY; |
|
516 |
||
517 |
if TestCollisionXwithGear(HHGear, Sign(HHGear.dX)) then |
|
75 | 518 |
HHGear.dX:= -0.6 * HHGear.dX; |
4 | 519 |
if TestCollisionYwithGear(HHGear, Sign(HHGear.dY)) then |
75 | 520 |
HHGear.dY:= -0.6 * HHGear.dY; |
4 | 521 |
|
522 |
if (Gear.Message and gm_Attack) <> 0 then |
|
523 |
if (Gear.State and gsttmpFlag) <> 0 then DeleteMe else |
|
524 |
else if (Gear.State and gsttmpFlag) = 0 then Gear.State:= Gear.State or gsttmpFlag; |
|
525 |
end; |
|
526 |
||
527 |
||
528 |
procedure doStepRopeAttach(Gear: PGear); |
|
529 |
var HHGear: PGear; |
|
530 |
tx, ty, tt: real; |
|
531 |
begin |
|
532 |
Gear.X:= Gear.X + Gear.dX; |
|
533 |
Gear.Y:= Gear.Y + Gear.dY; |
|
534 |
Gear.Elasticity:= Gear.Elasticity + 1.0; |
|
535 |
HHGear:= PHedgehog(Gear.Hedgehog)^.Gear; |
|
536 |
if (HHGear.State and gstFalling) <> 0 then |
|
68 | 537 |
if TestCollisionYwithGear(HHGear, 1) then |
4 | 538 |
begin |
539 |
HHGear.dY:= 0; |
|
540 |
CheckHHDamage(HHGear); |
|
541 |
HHGear.State:= HHGear.State and not (gstFalling or gstHHJumping); |
|
542 |
end else |
|
543 |
begin |
|
544 |
if TestCollisionXwithGear(HHGear, Sign(HHGear.dX)) then HHGear.dX:= 0.0000001 * Sign(HHGear.dX); |
|
545 |
HHGear.X:= HHGear.X + HHGear.dX; |
|
546 |
HHGear.Y:= HHGear.Y + HHGear.dY; |
|
547 |
Gear.X:= Gear.X + HHGear.dX; |
|
548 |
Gear.Y:= Gear.Y + HHGear.dY; |
|
549 |
HHGear.dY:= HHGear.dY + cGravity; |
|
550 |
tt:= Gear.Elasticity; |
|
551 |
tx:= 0; |
|
552 |
ty:= 0; |
|
553 |
while tt > 20 do |
|
554 |
begin |
|
555 |
if TestCollisionXwithXYShift(Gear, round(tx), round(ty), Sign(Gear.dX)) |
|
556 |
or TestCollisionYwithXYShift(Gear, round(tx), round(ty), Sign(Gear.dY)) then |
|
557 |
begin |
|
558 |
Gear.X:= Gear.X + tx; |
|
559 |
Gear.Y:= Gear.Y + ty; |
|
560 |
Gear.Elasticity:= tt; |
|
561 |
Gear.doStep:= doStepRopeWork; |
|
562 |
with HHGear^ do State:= State and not gstAttacking; |
|
563 |
tt:= 0 |
|
564 |
end; |
|
565 |
tx:= tx - Gear.dX - Gear.dX; |
|
566 |
ty:= ty - Gear.dY - Gear.dY; |
|
567 |
tt:= tt - 2.0; |
|
568 |
end; |
|
569 |
end; |
|
570 |
CheckCollision(Gear); |
|
571 |
if (Gear.State and gstCollision) <> 0 then |
|
572 |
begin |
|
573 |
Gear.doStep:= doStepRopeWork; |
|
574 |
with HHGear^ do State:= State and not gstAttacking; |
|
575 |
if Gear.Elasticity < 10 then |
|
576 |
Gear.Elasticity:= 10000; |
|
577 |
end; |
|
578 |
||
579 |
if (Gear.Elasticity >= Gear.Friction) or ((Gear.Message and gm_Attack) = 0) then |
|
580 |
begin |
|
581 |
with PHedgehog(Gear.Hedgehog).Gear^ do |
|
582 |
begin |
|
583 |
State:= State and not gstAttacking; |
|
584 |
Message:= Message and not gm_Attack |
|
585 |
end; |
|
586 |
DeleteGear(Gear) |
|
587 |
end |
|
588 |
end; |
|
589 |
||
590 |
procedure doStepRope(Gear: PGear); |
|
591 |
begin |
|
592 |
Gear.doStep:= doStepRopeAttach |
|
593 |
end; |
|
594 |
||
595 |
//////////////////////////////////////////////////////////////////////////////// |
|
596 |
procedure doStepSmokeTrace(Gear: PGear); |
|
597 |
begin |
|
598 |
inc(Gear.Timer); |
|
599 |
if Gear.Timer > 64 then |
|
600 |
begin |
|
601 |
Gear.Timer:= 0; |
|
9 | 602 |
dec(Gear.State) |
4 | 603 |
end; |
604 |
Gear.dX:= Gear.dX + cWindSpeed; |
|
605 |
Gear.X:= Gear.X + Gear.dX; |
|
9 | 606 |
if Gear.State = 0 then DeleteGear(Gear) |
4 | 607 |
end; |
9 | 608 |
|
609 |
//////////////////////////////////////////////////////////////////////////////// |
|
610 |
procedure doStepExplosion(Gear: PGear); |
|
611 |
begin |
|
612 |
inc(Gear.Timer); |
|
613 |
if Gear.Timer > 75 then |
|
614 |
begin |
|
615 |
inc(Gear.State); |
|
616 |
Gear.Timer:= 0; |
|
617 |
if Gear.State > 5 then DeleteGear(Gear) |
|
618 |
end; |
|
619 |
end; |
|
10 | 620 |
|
621 |
//////////////////////////////////////////////////////////////////////////////// |
|
622 |
procedure doStepMine(Gear: PGear); |
|
623 |
begin |
|
39 | 624 |
if (Gear.dX <> 0) or (Gear.dY <> 0) then |
10 | 625 |
begin |
53 | 626 |
if Gear.CollIndex < High(Longword) then DeleteCI(Gear); |
10 | 627 |
doStepFallingGear(Gear); |
13 | 628 |
if Gear.Active = false then |
629 |
begin |
|
53 | 630 |
if Gear.CollIndex = High(Longword) then AddGearCI(Gear); |
13 | 631 |
Gear.dX:= 0; |
632 |
Gear.dY:= 0 |
|
633 |
end; |
|
634 |
CalcRotationDirAngle(Gear); |
|
10 | 635 |
AllInactive:= false |
636 |
end; |
|
39 | 637 |
|
10 | 638 |
if ((Gear.State and gsttmpFlag) <> 0) then |
639 |
if ((Gear.State and gstAttacking) = 0) then |
|
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
640 |
begin |
39 | 641 |
if ((GameTicks and $F) = 0) then |
15 | 642 |
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
|
643 |
end else // gstAttacking <> 0 |
10 | 644 |
begin |
645 |
AllInactive:= false; |
|
37 | 646 |
if (Gear.Timer and $FF) = 0 then PlaySound(sndMineTick); |
10 | 647 |
if Gear.Timer = 0 then |
648 |
begin |
|
13 | 649 |
doMakeExplosion(round(Gear.X), round(Gear.Y), 50, EXPLAutoSound); |
10 | 650 |
DeleteGear(Gear) |
651 |
end; |
|
13 | 652 |
dec(Gear.Timer); |
653 |
end else // gsttmpFlag = 0 |
|
654 |
if TurnTimeLeft = 0 then Gear.State:= Gear.State or gsttmpFlag; |
|
10 | 655 |
end; |
57 | 656 |
|
39 | 657 |
//////////////////////////////////////////////////////////////////////////////// |
658 |
procedure doStepDynamite(Gear: PGear); |
|
659 |
begin |
|
43 | 660 |
doStepFallingGear(Gear); |
661 |
AllInactive:= false; |
|
662 |
if Gear.Timer mod 166 = 0 then inc(Gear.Tag); |
|
663 |
if Gear.Timer = 0 then |
|
39 | 664 |
begin |
46 | 665 |
doMakeExplosion(round(Gear.X), round(Gear.Y), 75, EXPLAutoSound); |
43 | 666 |
DeleteGear(Gear); |
667 |
exit |
|
39 | 668 |
end; |
43 | 669 |
dec(Gear.Timer); |
39 | 670 |
end; |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
671 |
|
15 | 672 |
//////////////////////////////////////////////////////////////////////////////// |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
673 |
procedure doStepCase(Gear: PGear); |
79 | 674 |
var i: integer; |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
675 |
begin |
15 | 676 |
if (Gear.Message and gm_Destroy) > 0 then |
677 |
begin |
|
678 |
DeleteGear(Gear); |
|
679 |
exit |
|
680 |
end; |
|
681 |
||
79 | 682 |
if Gear.Damage > 0 then |
683 |
begin |
|
684 |
DeleteGear(Gear); |
|
685 |
doMakeExplosion(round(Gear.X), round(Gear.Y), 25, EXPLAutoSound); |
|
686 |
for i:= 0 to 63 do |
|
687 |
AddGear(round(Gear.X), round(Gear.Y), gtFlame, 0); |
|
688 |
exit |
|
689 |
end; |
|
690 |
||
53 | 691 |
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
|
692 |
begin |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
693 |
AllInactive:= false; |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
694 |
Gear.dY:= Gear.dY + cGravity; |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
695 |
Gear.Y:= Gear.Y + Gear.dY; |
53 | 696 |
if (Gear.dY < 0) and TestCollisionYwithGear(Gear, -1) then Gear.dY:= 0 else |
697 |
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
|
698 |
begin |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
699 |
Gear.dY:= - Gear.dY * Gear.Elasticity; |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
700 |
if Gear.dY > - 0.001 then Gear.dY:= 0 |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
701 |
else if Gear.dY < - 0.03 then PlaySound(sndGraveImpact); |
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 |
CheckGearDrowning(Gear); |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
704 |
end; |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
705 |
|
53 | 706 |
if (Gear.CollIndex = High(Longword)) and (Gear.dY = 0) then AddGearCI(Gear) |
707 |
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
|
708 |
end; |
49 | 709 |
|
710 |
//////////////////////////////////////////////////////////////////////////////// |
|
711 |
var thexchar: array[0..5] of record |
|
712 |
oy, ny: integer; |
|
713 |
team: PTeam; |
|
714 |
end; |
|
715 |
thexchcnt: Longword; |
|
716 |
||
717 |
procedure doStepTeamHealthSorterWork(Gear: PGear); |
|
718 |
var i: integer; |
|
719 |
begin |
|
720 |
AllInactive:= false; |
|
721 |
dec(Gear.Timer); |
|
722 |
if (Gear.Timer and 15) = 0 then |
|
723 |
for i:= 0 to Pred(thexchcnt) do |
|
724 |
with thexchar[i] do |
|
725 |
{$WARNINGS OFF} |
|
726 |
team.DrawHealthY:= ny + (oy - ny) * Gear.Timer div 640; |
|
727 |
{$WARNINGS ON} |
|
728 |
if Gear.Timer = 0 then |
|
729 |
DeleteGear(Gear) |
|
730 |
end; |
|
731 |
||
732 |
procedure doStepTeamHealthSorter(Gear: PGear); |
|
733 |
var team: PTeam; |
|
734 |
i, t: Longword; |
|
735 |
begin |
|
736 |
AllInactive:= false; |
|
737 |
team:= TeamsList; |
|
738 |
i:= 0; |
|
739 |
while team <> nil do |
|
740 |
begin |
|
741 |
thexchar[i].oy:= team.DrawHealthY; |
|
742 |
thexchar[i].team:= team; |
|
743 |
inc(i); |
|
744 |
team:= team.Next |
|
745 |
end; |
|
746 |
thexchcnt:= i; |
|
747 |
for i:= 1 to thexchcnt do |
|
748 |
for t:= 0 to thexchcnt - 2 do |
|
749 |
if thexchar[t].team.TeamHealth > thexchar[Succ(t)].team.TeamHealth then |
|
750 |
begin |
|
751 |
thexchar[5]:= thexchar[t]; |
|
752 |
thexchar[t]:= thexchar[Succ(t)]; |
|
753 |
thexchar[Succ(t)]:= thexchar[5] |
|
754 |
end; |
|
755 |
t:= cScreenHeight - 4; |
|
756 |
for i:= 0 to Pred(thexchcnt) do |
|
757 |
with thexchar[i] do |
|
758 |
begin |
|
759 |
dec(t, team.HealthRect.h + 2); |
|
760 |
ny:= t |
|
761 |
end; |
|
762 |
Gear.Timer:= 640; |
|
763 |
Gear.doStep:= doStepTeamHealthSorterWork |
|
764 |
end; |
|
765 |
||
79 | 766 |
//////////////////////////////////////////////////////////////////////////////// |
767 |
procedure doStepShover(Gear: PGear); |
|
768 |
var HHGear: PGear; |
|
769 |
begin |
|
770 |
HHGear:= PHedgehog(Gear.Hedgehog)^.Gear; |
|
771 |
HHGear.State:= HHGear.State or gstNoDamage; |
|
772 |
AmmoShove(Gear, 30, 115); |
|
773 |
HHGear.State:= HHGear.State and not gstNoDamage; |
|
774 |
DeleteGear(Gear) |
|
775 |
end; |
|
776 |
||
777 |
//////////////////////////////////////////////////////////////////////////////// |
|
778 |
procedure doStepFlame(Gear: PGear); |
|
779 |
begin |
|
780 |
AllInactive:= false; |
|
781 |
if not TestCollisionYwithGear(Gear, 1) then |
|
782 |
begin |
|
783 |
Gear.dX:= Gear.dX + cWindSpeed; |
|
784 |
Gear.dY:= Gear.dY + cGravity; |
|
785 |
if abs(Gear.dX) > 0.12 then Gear.dX:= Gear.dX * 0.5; |
|
786 |
if Gear.dY > 0.12 then Gear.dY:= Gear.dY * 0.995; |
|
787 |
Gear.X:= Gear.X + Gear.dX; |
|
788 |
Gear.Y:= Gear.Y + Gear.dY; |
|
789 |
if Gear.Y > 1023 then |
|
790 |
begin |
|
791 |
DeleteGear(Gear); |
|
792 |
exit |
|
793 |
end |
|
794 |
end else begin |
|
795 |
if Gear.Timer > 0 then dec(Gear.Timer) |
|
796 |
else begin |
|
797 |
doMakeExplosion(round(Gear.X), round(Gear.Y), 2, 0); |
|
798 |
dec(Gear.Health); |
|
799 |
Gear.Timer:= 1250 - Gear.Angle * 12 |
|
800 |
end |
|
801 |
end; |
|
802 |
||
803 |
if (((GameTicks div 8) mod 64) = Gear.Angle) then |
|
804 |
AmmoFlameWork(Gear); |
|
805 |
||
806 |
if Gear.Health = 0 then |
|
807 |
DeleteGear(Gear) |
|
808 |
end; |