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