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