author | unc0rr |
Fri, 09 Sep 2005 21:45:31 +0000 | |
changeset 14 | 81f125629b25 |
parent 10 | edf56dca1587 |
child 15 | 6200cca92480 |
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 |
unit uGears; |
|
35 |
interface |
|
36 |
uses SDLh, uConsts; |
|
37 |
{$INCLUDE options.inc} |
|
38 |
const AllInactive: boolean = false; |
|
39 |
||
40 |
type PGear = ^TGear; |
|
41 |
TGearStepProcedure = procedure (Gear: PGear); |
|
42 |
TGear = record |
|
43 |
NextGear, PrevGear: PGear; |
|
44 |
Active: Boolean; |
|
45 |
State : Cardinal; |
|
46 |
X : Real; |
|
47 |
Y : Real; |
|
48 |
dX: Real; |
|
49 |
dY: Real; |
|
50 |
Kind : TGearType; |
|
51 |
doStep: TGearStepProcedure; |
|
52 |
HalfWidth, HalfHeight: integer; |
|
53 |
Angle, Power : Cardinal; |
|
54 |
DirAngle: real; |
|
55 |
Timer : LongWord; |
|
56 |
Elasticity: Real; |
|
57 |
Friction : Real; |
|
58 |
Message : Longword; |
|
59 |
Hedgehog: pointer; |
|
60 |
Health, Damage: LongWord; |
|
61 |
CollIndex: Longword; |
|
6 | 62 |
Tag: integer; |
4 | 63 |
end; |
64 |
||
65 |
function AddGear(X, Y: integer; Kind: TGearType; State: Cardinal; const dX: real=0.0; dY: real=0.0; Timer: LongWord=0): PGear; |
|
66 |
procedure ProcessGears; |
|
67 |
procedure SetAllToActive; |
|
68 |
procedure SetAllHHToActive; |
|
69 |
procedure DrawGears(Surface: PSDL_Surface); |
|
70 |
procedure FreeGearsList; |
|
10 | 71 |
procedure AddMiscGears; |
4 | 72 |
procedure AssignHHCoords; |
73 |
||
74 |
var CurAmmoGear: PGear = nil; |
|
75 |
||
76 |
implementation |
|
77 |
uses uWorld, uMisc, uStore, uConsole, uSound, uTeams, uRandom, uCollisions, uLand; |
|
78 |
var GearsList: PGear = nil; |
|
79 |
RopePoints: record |
|
80 |
Count: Longword; |
|
81 |
HookAngle: integer; |
|
82 |
ar: array[0..300] of record |
|
83 |
X, Y: real; |
|
84 |
dLen: real; |
|
85 |
b: boolean; |
|
86 |
end; |
|
87 |
end; |
|
88 |
||
89 |
procedure DeleteGear(Gear: PGear); forward; |
|
90 |
procedure doMakeExplosion(X, Y, Radius: integer; Mask: LongWord); forward; |
|
10 | 91 |
function isGearNear(Gear: PGear; Kind: TGearType; rX, rY: integer): boolean; forward; |
4 | 92 |
|
93 |
{$INCLUDE GSHandlers.inc} |
|
94 |
{$INCLUDE HHHandlers.inc} |
|
95 |
||
96 |
const doStepHandlers: array[TGearType] of TGearStepProcedure = ( |
|
97 |
doStepCloud, |
|
98 |
doStepBomb, |
|
99 |
doStepHedgehog, |
|
100 |
doStepGrenade, |
|
101 |
doStepHealthTag, |
|
102 |
doStepGrave, |
|
103 |
doStepUFO, |
|
104 |
doStepShotgunShot, |
|
105 |
doStepActionTimer, |
|
106 |
doStepPickHammer, |
|
107 |
doStepRope, |
|
9 | 108 |
doStepSmokeTrace, |
10 | 109 |
doStepExplosion, |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
110 |
doStepMine, |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
111 |
doStepCase |
4 | 112 |
); |
113 |
||
114 |
function AddGear(X, Y: integer; Kind: TGearType; State: Cardinal; const dX: real=0.0; dY: real=0.0; Timer: LongWord=0): PGear; |
|
115 |
begin |
|
116 |
{$IFDEF DEBUGFILE}AddFileLog('AddGear: ('+inttostr(x)+','+inttostr(y)+')');{$ENDIF} |
|
117 |
New(Result); |
|
118 |
{$IFDEF DEBUGFILE}AddFileLog('AddGear: handle = '+inttostr(integer(Result)));{$ENDIF} |
|
119 |
FillChar(Result^, sizeof(TGear), 0); |
|
120 |
Result.X:= X; |
|
121 |
Result.Y:= Y; |
|
122 |
Result.Kind := Kind; |
|
123 |
Result.State:= State; |
|
124 |
Result.Active:= true; |
|
125 |
Result.dX:= dX; |
|
126 |
Result.dY:= dY; |
|
127 |
Result.doStep:= doStepHandlers[Kind]; |
|
128 |
Result.CollIndex:= High(Longword); |
|
129 |
if CurrentTeam <> nil then |
|
130 |
Result.Hedgehog:= @CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog]; |
|
131 |
case Kind of |
|
132 |
gtAmmo_Bomb: begin |
|
133 |
Result.HalfWidth:= 4; |
|
134 |
Result.HalfHeight:= 4; |
|
135 |
Result.Elasticity:= 0.6; |
|
136 |
Result.Friction:= 0.995; |
|
137 |
Result.Timer:= Timer |
|
138 |
end; |
|
139 |
gtHedgehog: begin |
|
140 |
Result.HalfWidth:= 6; |
|
141 |
Result.HalfHeight:= cHHHalfHeight; |
|
142 |
Result.Elasticity:= 0.002; |
|
143 |
Result.Friction:= 0.999; |
|
144 |
end; |
|
145 |
gtAmmo_Grenade: begin |
|
146 |
Result.HalfWidth:= 4; |
|
147 |
Result.HalfHeight:= 4; |
|
148 |
end; |
|
149 |
gtHealthTag: begin |
|
150 |
Result.Timer:= 1500; |
|
151 |
end; |
|
152 |
gtGrave: begin |
|
153 |
Result.HalfWidth:= 10; |
|
154 |
Result.HalfHeight:= 10; |
|
155 |
Result.Elasticity:= 0.6; |
|
156 |
end; |
|
157 |
gtUFO: begin |
|
158 |
Result.HalfWidth:= 5; |
|
159 |
Result.HalfHeight:= 2; |
|
160 |
Result.Timer:= 500; |
|
161 |
Result.Elasticity:= 0.9 |
|
162 |
end; |
|
163 |
gtShotgunShot: begin |
|
164 |
Result.Timer:= 900; |
|
165 |
Result.HalfWidth:= 2; |
|
166 |
Result.HalfHeight:= 2 |
|
167 |
end; |
|
168 |
gtActionTimer: begin |
|
169 |
Result.Timer:= Timer |
|
170 |
end; |
|
171 |
gtPickHammer: begin |
|
172 |
Result.HalfWidth:= 10; |
|
173 |
Result.HalfHeight:= 2; |
|
174 |
Result.Timer:= 4000 |
|
175 |
end; |
|
176 |
gtSmokeTrace: begin |
|
9 | 177 |
Result.X:= Result.X - 16; |
178 |
Result.Y:= Result.Y - 16; |
|
179 |
Result.State:= 8 |
|
4 | 180 |
end; |
181 |
gtRope: begin |
|
182 |
Result.HalfWidth:= 3; |
|
183 |
Result.HalfHeight:= 3; |
|
184 |
Result.Friction:= 500; |
|
185 |
RopePoints.Count:= 0; |
|
186 |
end; |
|
9 | 187 |
gtExplosion: begin |
188 |
Result.X:= Result.X - 25; |
|
189 |
Result.Y:= Result.Y - 25; |
|
190 |
end; |
|
10 | 191 |
gtMine: begin |
192 |
Result.HalfWidth:= 3; |
|
193 |
Result.HalfHeight:= 3; |
|
194 |
Result.Elasticity:= 0.55; |
|
195 |
Result.Friction:= 0.995; |
|
196 |
Result.Timer:= 3000; |
|
197 |
end; |
|
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
198 |
gtCase: begin |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
199 |
Result.HalfWidth:= 10; |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
200 |
Result.HalfHeight:= 10; |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
201 |
Result.Elasticity:= 0.6 |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
202 |
end; |
4 | 203 |
end; |
204 |
if GearsList = nil then GearsList:= Result |
|
205 |
else begin |
|
206 |
GearsList.PrevGear:= Result; |
|
207 |
Result.NextGear:= GearsList; |
|
208 |
GearsList:= Result |
|
209 |
end |
|
210 |
end; |
|
211 |
||
212 |
procedure DeleteGear(Gear: PGear); |
|
213 |
begin |
|
214 |
if Gear.CollIndex < High(Longword) then DeleteCR(Gear); |
|
215 |
if Gear.Kind = gtHedgehog then |
|
216 |
if CurAmmoGear <> nil then |
|
217 |
begin |
|
218 |
{$IFDEF DEBUGFILE}AddFileLog('DeleteGear: Sending gm_Destroy, hh handle = '+inttostr(integer(Gear)));{$ENDIF} |
|
219 |
Gear.Message:= gm_Destroy; |
|
220 |
CurAmmoGear.Message:= gm_Destroy; |
|
221 |
exit |
|
222 |
end else PHedgehog(Gear.Hedgehog).Gear:= nil; |
|
223 |
if CurAmmoGear = Gear then |
|
224 |
CurAmmoGear:= nil; |
|
225 |
if FollowGear = Gear then FollowGear:= nil; |
|
226 |
{$IFDEF DEBUGFILE}AddFileLog('DeleteGear: handle = '+inttostr(integer(Gear)));{$ENDIF} |
|
227 |
if Gear.NextGear <> nil then Gear.NextGear.PrevGear:= Gear.PrevGear; |
|
228 |
if Gear.PrevGear <> nil then Gear.PrevGear.NextGear:= Gear.NextGear |
|
229 |
else begin |
|
230 |
GearsList:= Gear^.NextGear; |
|
231 |
if GearsList <> nil then GearsList.PrevGear:= nil |
|
232 |
end; |
|
233 |
Dispose(Gear) |
|
234 |
end; |
|
235 |
||
236 |
function CheckNoDamage: boolean; // returns TRUE in case of no damaged hhs |
|
237 |
var Gear: PGear; |
|
238 |
begin |
|
239 |
Result:= true; |
|
240 |
Gear:= GearsList; |
|
241 |
while Gear <> nil do |
|
242 |
begin |
|
243 |
if Gear.Kind = gtHedgehog then |
|
244 |
if Gear.Damage <> 0 then |
|
245 |
begin |
|
246 |
Result:= false; |
|
247 |
if Gear.Health < Gear.Damage then Gear.Health:= 0 |
|
248 |
else dec(Gear.Health, Gear.Damage); |
|
249 |
AddGear(Round(Gear.X), Round(Gear.Y) - 32, gtHealthTag, Gear.Damage).Hedgehog:= Gear.Hedgehog; |
|
250 |
RenderHealth(PHedgehog(Gear.Hedgehog)^); |
|
251 |
||
252 |
Gear.Damage:= 0 |
|
253 |
end; |
|
254 |
Gear:= Gear.NextGear |
|
255 |
end; |
|
256 |
end; |
|
257 |
||
258 |
procedure ProcessGears; |
|
259 |
const delay: integer = cInactDelay; |
|
260 |
var Gear, t: PGear; |
|
261 |
{$IFDEF COUNTTICKS} |
|
262 |
tickcntA, tickcntB: LongWord; |
|
263 |
const cntSecTicks: LongWord = 0; |
|
264 |
{$ENDIF} |
|
265 |
begin |
|
266 |
{$IFDEF COUNTTICKS} |
|
267 |
asm |
|
268 |
push eax |
|
269 |
push edx |
|
270 |
rdtsc |
|
271 |
mov tickcntA, eax |
|
272 |
mov tickcntB, edx |
|
273 |
pop edx |
|
274 |
pop eax |
|
275 |
end; |
|
276 |
{$ENDIF} |
|
277 |
AllInactive:= true; |
|
278 |
t:= GearsList; |
|
279 |
while t<>nil do |
|
280 |
begin |
|
281 |
Gear:= t; |
|
282 |
t:= Gear.NextGear; |
|
283 |
if Gear.Active then Gear.doStep(Gear); |
|
284 |
end; |
|
285 |
if AllInactive then |
|
286 |
if (delay > 0)and not isInMultiShoot then |
|
287 |
begin |
|
288 |
if delay = cInactDelay then SetAllToActive; |
|
289 |
dec(delay) |
|
290 |
end |
|
291 |
else begin |
|
292 |
delay:= cInactDelay; |
|
293 |
if CheckNoDamage then |
|
294 |
if isInMultiShoot then isInMultiShoot:= false |
|
295 |
else ParseCommand('/nextturn'); |
|
296 |
end; |
|
297 |
if TurnTimeLeft > 0 then |
|
298 |
if CurrentTeam <> nil then |
|
299 |
if CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear <> nil then |
|
300 |
if ((CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear.State and gstAttacking) = 0) |
|
301 |
and not isInMultiShoot then dec(TurnTimeLeft); |
|
302 |
inc(GameTicks); |
|
303 |
{$IFDEF COUNTTICKS} |
|
304 |
asm |
|
305 |
push eax |
|
306 |
push edx |
|
307 |
rdtsc |
|
308 |
sub eax, [tickcntA] |
|
309 |
sbb edx, [tickcntB] |
|
310 |
add [cntSecTicks], eax |
|
311 |
pop edx |
|
312 |
pop eax |
|
313 |
end; |
|
314 |
if (GameTicks and 1023) = 0 then |
|
315 |
begin |
|
316 |
cntTicks:= cntSecTicks shr 10; |
|
317 |
{$IFDEF DEBUGFILE} |
|
318 |
AddFileLog('<' + inttostr(cntTicks) + '>x1024 ticks'); |
|
319 |
{$ENDIF} |
|
320 |
cntSecTicks:= 0 |
|
321 |
end; |
|
322 |
{$ENDIF} |
|
323 |
end; |
|
324 |
||
325 |
procedure SetAllToActive; |
|
326 |
var t: PGear; |
|
327 |
begin |
|
328 |
AllInactive:= false; |
|
329 |
t:= GearsList; |
|
330 |
while t<>nil do |
|
331 |
begin |
|
332 |
t.Active:= true; |
|
333 |
t:= t.NextGear |
|
334 |
end |
|
335 |
end; |
|
336 |
||
337 |
procedure SetAllHHToActive; |
|
338 |
var t: PGear; |
|
339 |
begin |
|
340 |
AllInactive:= false; |
|
341 |
t:= GearsList; |
|
342 |
while t<>nil do |
|
343 |
begin |
|
344 |
if t.Kind = gtHedgehog then t.Active:= true; |
|
345 |
t:= t.NextGear |
|
346 |
end |
|
347 |
end; |
|
348 |
||
349 |
procedure DrawGears(Surface: PSDL_Surface); |
|
350 |
var Gear: PGear; |
|
351 |
i: Longword; |
|
352 |
||
353 |
procedure DrawRopeLine(X1, Y1, X2, Y2: integer); |
|
354 |
var i: integer; |
|
355 |
t, k: real; |
|
356 |
r: TSDL_Rect; |
|
357 |
begin |
|
358 |
if abs(X1 - X2) > abs(Y1 - Y2) then |
|
359 |
begin |
|
360 |
if X1 > X2 then |
|
361 |
begin |
|
362 |
i:= X1; |
|
363 |
X1:= X2; |
|
364 |
X2:= i; |
|
365 |
i:= Y1; |
|
366 |
Y1:= Y2; |
|
367 |
Y2:= i |
|
368 |
end; |
|
369 |
k:= (Y2 - Y1) / (X2 - X1); |
|
370 |
if X1 < 0 then |
|
371 |
begin |
|
372 |
t:= Y1 - 2 - k * X1; |
|
373 |
X1:= 0 |
|
374 |
end else t:= Y1 - 2; |
|
375 |
if X2 > cScreenWidth then X2:= cScreenWidth; |
|
376 |
r.x:= X1; |
|
377 |
while r.x <= X2 do |
|
378 |
begin |
|
379 |
r.y:= round(t); |
|
380 |
r.w:= 4; |
|
381 |
r.h:= 4; |
|
382 |
SDL_FillRect(Surface, @r, cWhiteColor); |
|
383 |
t:= t + k*3; |
|
384 |
inc(r.x, 3) |
|
385 |
end; |
|
386 |
end else |
|
387 |
begin |
|
388 |
if Y1 > Y2 then |
|
389 |
begin |
|
390 |
i:= X1; |
|
391 |
X1:= X2; |
|
392 |
X2:= i; |
|
393 |
i:= Y1; |
|
394 |
Y1:= Y2; |
|
395 |
Y2:= i |
|
396 |
end; |
|
397 |
k:= (X2 - X1) / (Y2 - Y1); |
|
398 |
if Y1 < 0 then |
|
399 |
begin |
|
400 |
t:= X1 - 2 - k * Y1; |
|
401 |
Y1:= 0 |
|
402 |
end else t:= X1 - 2; |
|
403 |
if Y2 > cScreenHeight then Y2:= cScreenHeight; |
|
404 |
r.y:= Y1; |
|
405 |
while r.y <= Y2 do |
|
406 |
begin |
|
407 |
r.x:= round(t); |
|
408 |
r.w:= 4; |
|
409 |
r.h:= 4; |
|
410 |
SDL_FillRect(Surface, @r, cWhiteColor); |
|
411 |
t:= t + k*3; |
|
412 |
inc(r.y, 3) |
|
413 |
end; |
|
414 |
end |
|
415 |
end; |
|
416 |
||
417 |
begin |
|
418 |
Gear:= GearsList; |
|
419 |
while Gear<>nil do |
|
420 |
begin |
|
421 |
case Gear.Kind of |
|
422 |
gtCloud: DrawSprite(sprCloud , Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface); |
|
423 |
gtAmmo_Bomb: DrawSprite(sprBomb , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface); |
|
424 |
gtHedgehog: DrawHedgehog(Round(Gear.X) - 14 + WorldDx, Round(Gear.Y) - 18 + WorldDy, Sign(Gear.dX), |
|
425 |
0, PHedgehog(Gear.Hedgehog).visStepPos div 2, |
|
426 |
Surface); |
|
427 |
gtAmmo_Grenade: DrawSprite(sprGrenade , Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, DxDy2Angle32(Gear.dY, Gear.dX), Surface); |
|
428 |
gtHealthTag: DrawCaption(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, PHedgehog(Gear.Hedgehog).HealthTagRect, Surface, true); |
|
429 |
gtGrave: DrawSpriteFromRect(PHedgehog(Gear.Hedgehog).Team.GraveRect, Round(Gear.X) + WorldDx - 16, Round(Gear.Y) + WorldDy - 16, 32, (GameTicks shr 7) and 7, Surface); |
|
430 |
gtUFO: DrawSprite(sprUFO, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, (GameTicks shr 7) mod 4, Surface); |
|
9 | 431 |
gtSmokeTrace: if Gear.State < 8 then DrawSprite(sprSmokeTrace, Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface); |
4 | 432 |
gtRope: begin |
433 |
DrawRopeLine(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, |
|
434 |
Round(PHedgehog(Gear.Hedgehog).Gear.X) + WorldDx, Round(PHedgehog(Gear.Hedgehog).Gear.Y) + WorldDy); |
|
435 |
if RopePoints.Count > 0 then |
|
436 |
begin |
|
437 |
i:= 0; |
|
438 |
while i < Pred(RopePoints.Count) do |
|
439 |
begin |
|
440 |
DrawRopeLine(Round(RopePoints.ar[i].X) + WorldDx, Round(RopePoints.ar[i].Y) + WorldDy, |
|
441 |
Round(RopePoints.ar[Succ(i)].X) + WorldDx, Round(RopePoints.ar[Succ(i)].Y) + WorldDy); |
|
442 |
inc(i) |
|
443 |
end; |
|
444 |
DrawRopeLine(Round(RopePoints.ar[i].X) + WorldDx, Round(RopePoints.ar[i].Y) + WorldDy, |
|
445 |
Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy); |
|
446 |
DrawSprite(sprRopeHook, Round(RopePoints.ar[0].X) + WorldDx - 16, Round(RopePoints.ar[0].Y) + WorldDy - 16, RopePoints.HookAngle, Surface); |
|
447 |
end else |
|
448 |
DrawSprite(sprRopeHook, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, DxDy2Angle32(Gear.dY, Gear.dX), Surface); |
|
449 |
end; |
|
9 | 450 |
gtExplosion: DrawSprite(sprExplosion50, Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface); |
10 | 451 |
gtMine: if ((Gear.State and gstAttacking) = 0)or((Gear.Timer and $3FF) < 420) |
452 |
then DrawSprite(sprMineOff , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface) |
|
453 |
else DrawSprite(sprMineOn , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface); |
|
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
454 |
gtCase: DrawSprite(sprCase, Round(Gear.X) - 12 + WorldDx, Round(Gear.Y) - 12 + WorldDy, 0, Surface); |
4 | 455 |
end; |
456 |
Gear:= Gear.NextGear |
|
457 |
end; |
|
458 |
end; |
|
459 |
||
460 |
procedure FreeGearsList; |
|
461 |
var t, tt: PGear; |
|
462 |
begin |
|
463 |
tt:= GearsList; |
|
464 |
GearsList:= nil; |
|
465 |
while tt<>nil do |
|
466 |
begin |
|
467 |
t:= tt; |
|
468 |
tt:= tt.NextGear; |
|
469 |
try |
|
470 |
Dispose(t) |
|
471 |
except OutError(errmsgDynamicVar) end; |
|
472 |
end; |
|
473 |
end; |
|
474 |
||
10 | 475 |
procedure AddMiscGears; |
476 |
var i, x, y: integer; |
|
4 | 477 |
begin |
478 |
for i:= 0 to cCloudsNumber do AddGear( - cScreenWidth + i * ((cScreenWidth * 2 + 2304) div cCloudsNumber), -128, gtCloud, random(4), (0.5-random)*0.01); |
|
479 |
AddGear(0, 0, gtActionTimer, gtsStartGame, 0, 0, 2000).Health:= 3; |
|
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
480 |
for i:= 0 to 2 do |
10 | 481 |
begin |
482 |
GetHHPoint(x, y); |
|
483 |
AddGear(X, Y + 9, gtMine, 0); |
|
484 |
end; |
|
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
485 |
|
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
486 |
for i:= 0 to 0 do |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
487 |
begin |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
488 |
GetHHPoint(x, y); |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
489 |
AddGear(X, Y, gtCase, 0) |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
490 |
end; |
4 | 491 |
end; |
492 |
||
493 |
procedure doMakeExplosion(X, Y, Radius: integer; Mask: LongWord); |
|
494 |
var Gear: PGear; |
|
495 |
dmg: integer; |
|
496 |
begin |
|
497 |
TargetPoint.X:= NoPointX; |
|
498 |
{$IFDEF DEBUGFILE}if Radius > 3 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')');{$ENDIF} |
|
499 |
DrawExplosion(X, Y, Radius); |
|
9 | 500 |
if Radius = 50 then AddGear(X, Y, gtExplosion, 0); |
4 | 501 |
if (Mask and EXPLAutoSound)<>0 then PlaySound(sndExplosion); |
502 |
if (Mask and EXPLNoDamage)<>0 then exit; |
|
503 |
if (Mask and EXPLAllDamageInRadius)=0 then Radius:= Radius shl 1; |
|
504 |
Gear:= GearsList; |
|
505 |
while Gear <> nil do |
|
506 |
begin |
|
507 |
dmg:= Radius - Round(sqrt(sqr(Gear.X - X) + sqr(Gear.Y - Y))); |
|
508 |
if dmg > 0 then |
|
509 |
begin |
|
510 |
dmg:= dmg shr 1; |
|
511 |
case Gear.Kind of |
|
10 | 512 |
gtHedgehog, |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
513 |
gtMine, |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
514 |
gtCase: begin |
4 | 515 |
inc(Gear.Damage, dmg); |
516 |
Gear.dX:= Gear.dX + dmg / 200 * sign(Gear.X - X); |
|
517 |
Gear.dY:= Gear.dY + dmg / 200 * sign(Gear.Y - Y); |
|
518 |
FollowGear:= Gear |
|
519 |
end; |
|
520 |
gtGrave: Gear.dY:= - dmg / 250; |
|
521 |
end; |
|
522 |
end; |
|
523 |
Gear:= Gear.NextGear |
|
524 |
end |
|
525 |
end; |
|
526 |
||
527 |
procedure AssignHHCoords; |
|
528 |
var Gear: PGear; |
|
529 |
pX, pY: integer; |
|
530 |
begin |
|
531 |
Gear:= GearsList; |
|
532 |
while Gear <> nil do |
|
533 |
begin |
|
534 |
if Gear.Kind = gtHedgehog then |
|
535 |
begin |
|
536 |
GetHHPoint(pX, pY); |
|
537 |
Gear.X:= pX; |
|
538 |
Gear.Y:= pY |
|
539 |
end; |
|
540 |
Gear:= Gear.NextGear |
|
541 |
end |
|
542 |
end; |
|
543 |
||
10 | 544 |
function isGearNear(Gear: PGear; Kind: TGearType; rX, rY: integer): boolean; |
545 |
var t: PGear; |
|
546 |
begin |
|
547 |
t:= GearsList; |
|
548 |
rX:= sqr(rX); |
|
549 |
rY:= sqr(rY); |
|
550 |
while t <> nil do |
|
551 |
begin |
|
552 |
if (t <> Gear) and (t.Kind = Kind) then |
|
553 |
if sqr(Gear.X - t.X) / rX + sqr(Gear.Y - t.Y) / rY <= 1 then |
|
554 |
begin |
|
555 |
Result:= true; |
|
556 |
exit |
|
557 |
end; |
|
558 |
t:= t.NextGear |
|
559 |
end; |
|
560 |
Result:= false |
|
561 |
end; |
|
562 |
||
4 | 563 |
initialization |
564 |
||
565 |
finalization |
|
566 |
FreeGearsList |
|
567 |
||
568 |
end. |