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