author | unc0rr |
Sun, 04 Dec 2005 19:06:56 +0000 | |
changeset 23 | 16322d14f068 |
parent 16 | b6f4b413dd41 |
child 37 | 2b7f2a43b999 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
3 |
* Copyright (c) 2004, 2005 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
5 |
* Distributed under the terms of the BSD-modified licence: |
|
6 |
* |
|
7 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8 |
* of this software and associated documentation files (the "Software"), to deal |
|
9 |
* with the Software without restriction, including without limitation the |
|
10 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|
11 |
* sell copies of the Software, and to permit persons to whom the Software is |
|
12 |
* furnished to do so, subject to the following conditions: |
|
13 |
* |
|
14 |
* 1. Redistributions of source code must retain the above copyright notice, |
|
15 |
* this list of conditions and the following disclaimer. |
|
16 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
|
17 |
* this list of conditions and the following disclaimer in the documentation |
|
18 |
* and/or other materials provided with the distribution. |
|
19 |
* 3. The name of the author may not be used to endorse or promote products |
|
20 |
* derived from this software without specific prior written permission. |
|
21 |
* |
|
22 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
|
23 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
24 |
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
|
25 |
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
26 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
27 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
|
28 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|
29 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|
30 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
31 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
32 |
*) |
|
33 |
||
34 |
procedure doStepDrowningGear(Gear: PGear); forward; |
|
35 |
||
36 |
function CheckGearDrowning(Gear: PGear): boolean; |
|
37 |
begin |
|
38 |
Result:= Gear.Y + Gear.HalfHeight >= cWaterLine; |
|
39 |
if Result then |
|
40 |
begin |
|
41 |
Gear.State:= gstDrowning; |
|
42 |
Gear.doStep:= doStepDrowningGear; |
|
43 |
PlaySound(sndSplash) |
|
44 |
end |
|
45 |
end; |
|
46 |
||
47 |
procedure CheckCollision(Gear: PGear); |
|
48 |
begin |
|
49 |
if TestCollisionXwithGear(Gear, Sign(Gear.X)) or TestCollisionYwithGear(Gear, Sign(Gear.Y)) |
|
50 |
then Gear.State:= Gear.State or gstCollision |
|
51 |
else Gear.State:= Gear.State and not gstCollision |
|
52 |
end; |
|
53 |
||
54 |
procedure CheckHHDamage(Gear: PGear); |
|
55 |
begin |
|
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 |
lx:= round(Gear.X + tx) + sign(HHGear.dX); |
|
409 |
ly:= round(Gear.Y + ty) + sign(HHGear.dY); |
|
410 |
if ((ly and $FFFFFC00) = 0) and ((lx and $FFFFF800) = 0)and (Land[ly, lx] <> 0) then |
|
411 |
begin |
|
412 |
with RopePoints.ar[RopePoints.Count] do |
|
413 |
begin |
|
414 |
X:= Gear.X; |
|
415 |
Y:= Gear.Y; |
|
416 |
if RopePoints.Count = 0 then RopePoints.HookAngle:= DxDy2Angle32(Gear.dY, Gear.dX); |
|
417 |
b:= (cc * HHGear.dY) > (cs * HHGear.dX); |
|
418 |
dLen:= len |
|
419 |
end; |
|
420 |
Gear.X:= Gear.X + tx; |
|
421 |
Gear.Y:= Gear.Y + ty; |
|
422 |
inc(RopePoints.Count); |
|
423 |
Gear.Elasticity:= Gear.Elasticity - len; |
|
424 |
Gear.Friction:= Gear.Friction - len; |
|
425 |
break |
|
426 |
end; |
|
427 |
len:= len - 3 |
|
428 |
end; |
|
429 |
end else |
|
430 |
if RopePoints.Count > 0 then // check whether the last dividing point could be removed |
|
431 |
begin |
|
432 |
tx:= RopePoints.ar[Pred(RopePoints.Count)].X; |
|
433 |
ty:= RopePoints.ar[Pred(RopePoints.Count)].Y; |
|
434 |
if RopePoints.ar[Pred(RopePoints.Count)].b xor ((tx - Gear.X) * (ty - HHGear.Y) > (tx - HHGear.X) * (ty - Gear.Y)) then |
|
435 |
begin |
|
436 |
dec(RopePoints.Count); |
|
437 |
Gear.X:=RopePoints.ar[RopePoints.Count].X; |
|
438 |
Gear.Y:=RopePoints.ar[RopePoints.Count].Y; |
|
439 |
Gear.Elasticity:= Gear.Elasticity + RopePoints.ar[RopePoints.Count].dLen; |
|
440 |
Gear.Friction:= Gear.Friction + RopePoints.ar[RopePoints.Count].dLen |
|
441 |
end |
|
442 |
end; |
|
443 |
||
444 |
Gear.dX:= HHGear.X - Gear.X; |
|
445 |
Gear.dY:= HHGear.Y - Gear.Y; |
|
446 |
HHGear.DirAngle:= arctan(Gear.dY + HHGear.dY, Gear.dX + HHGear.dX); |
|
447 |
cs:= sin(HHGear.DirAngle); |
|
448 |
cc:= cos(HHGear.DirAngle); |
|
449 |
||
450 |
HHGear.dX:= HHGear.X; |
|
451 |
HHGear.dY:= HHGear.Y; |
|
452 |
||
453 |
if ((Gear.Message and gm_Down) <> 0) and (Gear.Elasticity < Gear.Friction) then |
|
454 |
if not (TestCollisionXwithGear(HHGear, Sign(Gear.dX)) |
|
455 |
or TestCollisionYwithGear(HHGear, Sign(Gear.dY))) then Gear.Elasticity:= Gear.Elasticity + 0.3; |
|
456 |
||
457 |
if ((Gear.Message and gm_Up) <> 0) and (Gear.Elasticity > 30) then |
|
458 |
if not (TestCollisionXwithGear(HHGear, -Sign(Gear.dX)) |
|
459 |
or TestCollisionYwithGear(HHGear, -Sign(Gear.dY))) then Gear.Elasticity:= Gear.Elasticity - 0.3; |
|
460 |
||
461 |
HHGear.X:= Gear.X + cc*Gear.Elasticity; |
|
462 |
HHGear.Y:= Gear.Y + cs*Gear.Elasticity; |
|
463 |
||
464 |
HHGear.dX:= HHGear.X - HHGear.dX; |
|
465 |
HHGear.dY:= HHGear.Y - HHGear.dY; |
|
466 |
||
467 |
if TestCollisionXwithGear(HHGear, Sign(HHGear.dX)) then |
|
468 |
HHGear.dX:= -0.9 * HHGear.dX; |
|
469 |
if TestCollisionYwithGear(HHGear, Sign(HHGear.dY)) then |
|
470 |
HHGear.dY:= -0.9 * HHGear.dY; |
|
471 |
||
472 |
if (Gear.Message and gm_Attack) <> 0 then |
|
473 |
if (Gear.State and gsttmpFlag) <> 0 then DeleteMe else |
|
474 |
else if (Gear.State and gsttmpFlag) = 0 then Gear.State:= Gear.State or gsttmpFlag; |
|
475 |
end; |
|
476 |
||
477 |
||
478 |
procedure doStepRopeAttach(Gear: PGear); |
|
479 |
var HHGear: PGear; |
|
480 |
tx, ty, tt: real; |
|
481 |
begin |
|
482 |
Gear.X:= Gear.X + Gear.dX; |
|
483 |
Gear.Y:= Gear.Y + Gear.dY; |
|
484 |
Gear.Elasticity:= Gear.Elasticity + 1.0; |
|
485 |
HHGear:= PHedgehog(Gear.Hedgehog)^.Gear; |
|
486 |
if (HHGear.State and gstFalling) <> 0 then |
|
487 |
if HHTestCollisionYwithGear(HHGear, 1) then |
|
488 |
begin |
|
489 |
HHGear.dY:= 0; |
|
490 |
CheckHHDamage(HHGear); |
|
491 |
HHGear.State:= HHGear.State and not (gstFalling or gstHHJumping); |
|
492 |
end else |
|
493 |
begin |
|
494 |
if TestCollisionXwithGear(HHGear, Sign(HHGear.dX)) then HHGear.dX:= 0.0000001 * Sign(HHGear.dX); |
|
495 |
HHGear.X:= HHGear.X + HHGear.dX; |
|
496 |
HHGear.Y:= HHGear.Y + HHGear.dY; |
|
497 |
Gear.X:= Gear.X + HHGear.dX; |
|
498 |
Gear.Y:= Gear.Y + HHGear.dY; |
|
499 |
HHGear.dY:= HHGear.dY + cGravity; |
|
500 |
tt:= Gear.Elasticity; |
|
501 |
tx:= 0; |
|
502 |
ty:= 0; |
|
503 |
while tt > 20 do |
|
504 |
begin |
|
505 |
if TestCollisionXwithXYShift(Gear, round(tx), round(ty), Sign(Gear.dX)) |
|
506 |
or TestCollisionYwithXYShift(Gear, round(tx), round(ty), Sign(Gear.dY)) then |
|
507 |
begin |
|
508 |
Gear.X:= Gear.X + tx; |
|
509 |
Gear.Y:= Gear.Y + ty; |
|
510 |
Gear.Elasticity:= tt; |
|
511 |
Gear.doStep:= doStepRopeWork; |
|
512 |
with HHGear^ do State:= State and not gstAttacking; |
|
513 |
tt:= 0 |
|
514 |
end; |
|
515 |
tx:= tx - Gear.dX - Gear.dX; |
|
516 |
ty:= ty - Gear.dY - Gear.dY; |
|
517 |
tt:= tt - 2.0; |
|
518 |
end; |
|
519 |
end; |
|
520 |
CheckCollision(Gear); |
|
521 |
if (Gear.State and gstCollision) <> 0 then |
|
522 |
begin |
|
523 |
Gear.doStep:= doStepRopeWork; |
|
524 |
with HHGear^ do State:= State and not gstAttacking; |
|
525 |
if Gear.Elasticity < 10 then |
|
526 |
Gear.Elasticity:= 10000; |
|
527 |
end; |
|
528 |
||
529 |
if (Gear.Elasticity >= Gear.Friction) or ((Gear.Message and gm_Attack) = 0) then |
|
530 |
begin |
|
531 |
with PHedgehog(Gear.Hedgehog).Gear^ do |
|
532 |
begin |
|
533 |
State:= State and not gstAttacking; |
|
534 |
Message:= Message and not gm_Attack |
|
535 |
end; |
|
536 |
DeleteGear(Gear) |
|
537 |
end |
|
538 |
end; |
|
539 |
||
540 |
procedure doStepRope(Gear: PGear); |
|
541 |
begin |
|
542 |
Gear.doStep:= doStepRopeAttach |
|
543 |
end; |
|
544 |
||
545 |
//////////////////////////////////////////////////////////////////////////////// |
|
546 |
procedure doStepSmokeTrace(Gear: PGear); |
|
547 |
begin |
|
548 |
inc(Gear.Timer); |
|
549 |
if Gear.Timer > 64 then |
|
550 |
begin |
|
551 |
Gear.Timer:= 0; |
|
9 | 552 |
dec(Gear.State) |
4 | 553 |
end; |
554 |
Gear.dX:= Gear.dX + cWindSpeed; |
|
555 |
Gear.X:= Gear.X + Gear.dX; |
|
9 | 556 |
if Gear.State = 0 then DeleteGear(Gear) |
4 | 557 |
end; |
9 | 558 |
|
559 |
//////////////////////////////////////////////////////////////////////////////// |
|
560 |
procedure doStepExplosion(Gear: PGear); |
|
561 |
begin |
|
562 |
inc(Gear.Timer); |
|
563 |
if Gear.Timer > 75 then |
|
564 |
begin |
|
565 |
inc(Gear.State); |
|
566 |
Gear.Timer:= 0; |
|
567 |
if Gear.State > 5 then DeleteGear(Gear) |
|
568 |
end; |
|
569 |
end; |
|
10 | 570 |
|
571 |
//////////////////////////////////////////////////////////////////////////////// |
|
572 |
procedure doStepMine(Gear: PGear); |
|
573 |
begin |
|
23 | 574 |
if (Gear.dX <> 0) or (Gear.dY <> 0) {or not TestCollisionY(Gear, 1)} then |
10 | 575 |
begin |
576 |
doStepFallingGear(Gear); |
|
13 | 577 |
if Gear.Active = false then |
578 |
begin |
|
579 |
Gear.dX:= 0; |
|
580 |
Gear.dY:= 0 |
|
581 |
end; |
|
582 |
CalcRotationDirAngle(Gear); |
|
10 | 583 |
AllInactive:= false |
584 |
end; |
|
585 |
if ((Gear.State and gsttmpFlag) <> 0) then |
|
586 |
if ((Gear.State and gstAttacking) = 0) then |
|
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
587 |
begin |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
588 |
if (Gear.Tag = 0) then |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
589 |
begin |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
590 |
Gear.Tag:= 10; |
15 | 591 |
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
|
592 |
end else dec(Gear.Tag) |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
593 |
end else // gstAttacking <> 0 |
10 | 594 |
begin |
595 |
AllInactive:= false; |
|
13 | 596 |
if (Gear.Timer and $1FF) = 0 then PlaySound(sndMineTick); |
10 | 597 |
if Gear.Timer = 0 then |
598 |
begin |
|
13 | 599 |
doMakeExplosion(round(Gear.X), round(Gear.Y), 50, EXPLAutoSound); |
600 |
SetAllToActive; |
|
10 | 601 |
DeleteGear(Gear) |
602 |
end; |
|
13 | 603 |
dec(Gear.Timer); |
604 |
end else // gsttmpFlag = 0 |
|
605 |
if TurnTimeLeft = 0 then Gear.State:= Gear.State or gsttmpFlag; |
|
10 | 606 |
end; |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
607 |
|
15 | 608 |
//////////////////////////////////////////////////////////////////////////////// |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
609 |
procedure doStepCase(Gear: PGear); |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
610 |
begin |
15 | 611 |
if (Gear.Message and gm_Destroy) > 0 then |
612 |
begin |
|
613 |
DeleteGear(Gear); |
|
614 |
exit |
|
615 |
end; |
|
616 |
||
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
617 |
if (Gear.dY <> 0) or (not TestCollisionY(Gear, 1)) then |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
618 |
begin |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
619 |
AllInactive:= false; |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
620 |
Gear.dY:= Gear.dY + cGravity; |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
621 |
Gear.Y:= Gear.Y + Gear.dY; |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
622 |
if (Gear.dY < 0) and TestCollisionY(Gear, -1) then Gear.dY:= 0 else |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
623 |
if (Gear.dY >= 0) and TestCollisionY(Gear, 1) then |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
624 |
begin |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
625 |
Gear.dY:= - Gear.dY * Gear.Elasticity; |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
626 |
if Gear.dY > - 0.001 then Gear.dY:= 0 |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
627 |
else if Gear.dY < - 0.03 then PlaySound(sndGraveImpact); |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
628 |
end; |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
629 |
CheckGearDrowning(Gear); |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
630 |
end; |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
631 |
|
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
632 |
if (Gear.CollIndex = High(Longword)) and (Gear.dY = 0) then AddGearCR(Gear) |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
633 |
else if (Gear.CollIndex < High(Longword)) and (Gear.dY <> 0) then DeleteCR(Gear); |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
634 |
|
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
635 |
if Gear.Damage > 0 then |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
636 |
begin |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
637 |
DeleteGear(Gear); |
16 | 638 |
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
|
639 |
end |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
13
diff
changeset
|
640 |
end; |