author | unc0rr |
Mon, 09 Jan 2006 20:29:14 +0000 | |
changeset 41 | 5d7a505875cd |
parent 39 | b78e7185ed13 |
child 42 | 72ffe21f027c |
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 |
||
37 | 34 |
procedure AddIntersectorsCR(Gear: PGear); |
35 |
var t: PGear; |
|
36 |
x, xw, y, yh: real; |
|
37 |
ar: array[0..Pred(cMaxHHs)] of PGear; |
|
38 |
cnt: Longword; |
|
39 |
b: boolean; |
|
40 |
begin |
|
41 |
x:= Gear.X - Gear.HalfWidth; |
|
42 |
xw:= Gear.X + Gear.HalfWidth; |
|
43 |
y:= Gear.Y - Gear.HalfHeight; |
|
44 |
yh:= Gear.Y + Gear.HalfHeight; |
|
45 |
t:= GearsList; |
|
46 |
b:= false; |
|
47 |
cnt:= 0; |
|
48 |
while (t <> nil) do |
|
49 |
begin |
|
50 |
if (t <> Gear) then |
|
51 |
if (x < t.X + t.HalfWidth ) and (t.X - t.HalfWidth < xw) and |
|
52 |
(y < t.Y + t.HalfHeight) and (t.Y - t.HalfHeight < yh) then |
|
53 |
if t.Kind = gtHedgehog then |
|
54 |
begin |
|
55 |
ar[cnt]:= t; |
|
56 |
inc(cnt) |
|
39 | 57 |
end else |
58 |
if not (t.Kind in [gtGrave, gtMine]) then b:= true; |
|
37 | 59 |
t:= t.NextGear |
60 |
end; |
|
61 |
ar[cnt]:= Gear; |
|
62 |
inc(cnt); |
|
63 |
if b then |
|
64 |
begin |
|
65 |
repeat |
|
66 |
dec(cnt); |
|
67 |
if ar[cnt].CollIndex < High(Longword) then DeleteCR(ar[cnt]) |
|
68 |
until cnt = 0; |
|
69 |
end else |
|
70 |
begin |
|
71 |
repeat |
|
72 |
dec(cnt); |
|
73 |
if ar[cnt].CollIndex = High(Longword) then AddGearCR(ar[cnt]) |
|
74 |
until cnt = 0 |
|
75 |
end |
|
76 |
end; |
|
77 |
||
78 |
procedure RemoveIntersectorsCR(Gear: PGear); |
|
79 |
var t: PGear; |
|
80 |
x, xw, y, yh: real; |
|
81 |
begin |
|
82 |
x:= Gear.X - Gear.HalfWidth; |
|
83 |
xw:= Gear.X + Gear.HalfWidth; |
|
84 |
y:= Gear.Y - Gear.HalfHeight; |
|
85 |
yh:= Gear.Y + Gear.HalfHeight; |
|
86 |
t:= GearsList; |
|
87 |
while (t <> nil) do |
|
88 |
begin |
|
89 |
if (t <> Gear) then |
|
90 |
if (x < t.X + t.HalfWidth ) and (t.X - t.HalfWidth < xw) and |
|
91 |
(y < t.Y + t.HalfHeight) and (t.Y - t.HalfHeight < yh) then |
|
92 |
if t.CollIndex < High(Longword) then DeleteCR(t); |
|
93 |
t:= t.NextGear |
|
94 |
end; |
|
95 |
if Gear.CollIndex < High(Longword) then DeleteCR(Gear); |
|
96 |
end; |
|
97 |
||
98 |
//////////////////////////////////////////////////////////////////////////////// |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
99 |
procedure Attack(Gear: PGear); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
100 |
var xx, yy: real; |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
101 |
begin |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
102 |
with Gear^, |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
103 |
CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
104 |
begin |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
105 |
{$IFDEF DEBUGFILE}AddFileLog('Attack: Gear.State = '+inttostr(State)+' CurAmmoGear = '+inttostr(longword(CurAmmoGear)));{$ENDIF} |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
106 |
if CurAmmoGear <> nil then |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
107 |
begin |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
108 |
Message:= Message and not gm_Attack; |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
109 |
if not CurrentTeam.ExtDriven then SendIPC('a') |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
110 |
end; |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
111 |
if (((State and (gstHHDriven or gstAttacking)) = (gstHHDriven or gstAttacking))and |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
112 |
((State and (gstAttacked or gstMoving or gstHHChooseTarget)) = 0)and |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
113 |
(((State and gstFalling ) = 0)or((Ammo[CurSlot, CurAmmo].Propz and ammoprop_AttackInFall) <> 0))and |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
114 |
(((State and gstHHJumping) = 0)or((Ammo[CurSlot, CurAmmo].Propz and ammoprop_AttackInJump) <> 0)))and |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
115 |
(CurAmmoGear = nil) then |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
116 |
begin |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
117 |
if (Ammo[CurSlot, CurAmmo].Propz and ammoprop_Power) <> 0 then |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
118 |
begin |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
119 |
StopTPUSound; |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
120 |
PlaySound(sndThrowRelease); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
121 |
end; |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
122 |
xx:= Sign(dX)*Sin(Angle*pi/cMaxAngle); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
123 |
yy:= -Cos(Angle*pi/cMaxAngle); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
124 |
case Ammo[CurSlot, CurAmmo].AmmoType of |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
125 |
amBazooka: FollowGear:= AddGear(round(X), round(Y), gtAmmo_Grenade, 0, xx*Power/cPowerDivisor, yy*Power/cPowerDivisor); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
126 |
amGrenade: FollowGear:= AddGear(round(X), round(Y), gtAmmo_Bomb, 0, xx*Power/cPowerDivisor, yy*Power/cPowerDivisor, Ammo[CurSlot, CurAmmo].Timer); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
127 |
amUFO: FollowGear:= AddGear(round(X), round(Y), gtUFO, 0, xx*Power/cPowerDivisor, yy*Power/cPowerDivisor); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
128 |
amShotgun: begin |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
129 |
PlaySound(sndShotgunReload); |
38 | 130 |
FollowGear:= AddGear(round(X), round(Y), gtShotgunShot, 0, xx * 0.5, yy * 0.5); |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
131 |
end; |
37 | 132 |
amDEagle: begin |
38 | 133 |
FollowGear:= AddGear(round(X), round(Y), gtDEagleShot, 0, xx * 0.5, yy * 0.5); |
37 | 134 |
end; |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
135 |
amSkip: TurnTimeLeft:= 0; |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
136 |
amPickHammer: CurAmmoGear:= AddGear(round(Gear.X), round(Gear.Y) + cHHHalfHeight, gtPickHammer, 0); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
137 |
amRope: CurAmmoGear:= AddGear(round(Gear.X), round(Gear.Y), gtRope, 0, xx, yy); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
138 |
amMine: AddGear(round(X) + Sign(dX) * 7, round(Y), gtMine, 0, Sign(dX) * 0.01, 0, 3000); |
39 | 139 |
amDynamite: AddGear(round(X) + Sign(dX) * 7, round(Y), gtDynamite, 0, Sign(dX) * 0.01, 0, 5000); |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
140 |
end; |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
141 |
Power:= 0; |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
142 |
if CurAmmoGear <> nil then |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
143 |
begin |
39 | 144 |
Gear.Message:= Gear.Message or gm_Attack; |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
145 |
CurAmmoGear.Message:= Gear.Message; |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
146 |
exit |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
147 |
end else |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
148 |
begin |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
149 |
Message:= Message and not gm_Attack; |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
150 |
if not CurrentTeam.ExtDriven then SendIPC('a') |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
151 |
end; |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
152 |
AfterAttack |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
153 |
end |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
154 |
end |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
155 |
end; |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
156 |
|
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
157 |
procedure AfterAttack; |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
158 |
begin |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
159 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^, |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
160 |
CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
161 |
begin |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
162 |
Inc(AttacksNum); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
163 |
State:= State and not gstAttacking; |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
164 |
if Ammo[CurSlot, CurAmmo].NumPerTurn >= AttacksNum then isInMultiShoot:= true |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
165 |
else begin |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
166 |
TurnTimeLeft:= Ammoz[Ammo[CurSlot, CurAmmo].AmmoType].TimeAfterTurn; |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
167 |
State:= State or gstAttacked; |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
168 |
OnUsedAmmo(Ammo) |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
169 |
end; |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
170 |
AttackBar:= 0 |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
171 |
end |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
172 |
end; |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
173 |
|
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
174 |
|
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
175 |
|
4 | 176 |
procedure doStepHedgehog(Gear: PGear); forward; |
177 |
//////////////////////////////////////////////////////////////////////////////// |
|
178 |
procedure doStepHedgehogDriven(Gear: PGear); |
|
179 |
const StepTicks: LongWord = 0; |
|
15 | 180 |
var t: PGear; |
4 | 181 |
begin |
39 | 182 |
if isinMultiShoot and (Gear.Damage = 0) then |
183 |
begin |
|
184 |
if Gear.CollIndex = High(Longword) then AddIntersectorsCR(Gear); |
|
185 |
exit |
|
186 |
end; |
|
4 | 187 |
AllInactive:= false; |
188 |
if (TurnTimeLeft = 0) or (Gear.Damage > 0) then |
|
189 |
begin |
|
190 |
if ((Gear.State and (gstMoving or gstFalling)) = 0) |
|
191 |
and (CurAmmoGear = nil) then Gear.dX:= 0.0000001 * Sign(Gear.dX); |
|
7
b472e4b1a106
Fixed problem with hedgehog physics when turn is over and hedgehog is jumping
unc0rr
parents:
4
diff
changeset
|
192 |
Gear.State:= Gear.State and not gstHHDriven; |
b472e4b1a106
Fixed problem with hedgehog physics when turn is over and hedgehog is jumping
unc0rr
parents:
4
diff
changeset
|
193 |
if Gear.Damage > 0 then |
b472e4b1a106
Fixed problem with hedgehog physics when turn is over and hedgehog is jumping
unc0rr
parents:
4
diff
changeset
|
194 |
Gear.State:= Gear.State and not gstHHJumping; |
4 | 195 |
exit |
196 |
end; |
|
37 | 197 |
|
15 | 198 |
// check for case with ammo |
16 | 199 |
t:= CheckGearNear(Gear, gtCase, 30, 30); |
15 | 200 |
if t <> nil then |
201 |
begin |
|
202 |
t.Message:= gm_Destroy; |
|
203 |
; // take ammo from it |
|
204 |
end; |
|
4 | 205 |
|
206 |
if CurAmmoGear <> nil then |
|
207 |
begin |
|
208 |
CurAmmoGear.Message:= Gear.Message; |
|
209 |
exit |
|
210 |
end; |
|
211 |
||
212 |
if (Gear.Message and gm_Attack)<>0 then |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
213 |
if (Gear.State and (gstAttacked or gstHHChooseTarget) = 0) then |
4 | 214 |
with PHedgehog(Gear.Hedgehog)^ do |
215 |
begin |
|
216 |
Gear.State:= Gear.State or gstAttacking; |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
16
diff
changeset
|
217 |
if Gear.Power = cMaxPower then Gear.Message:= Gear.Message and not gm_Attack |
37 | 218 |
else |
38 | 219 |
if (Ammo[CurSlot, CurAmmo].Propz and ammoprop_Power) = 0 then |
220 |
Gear.Message:= Gear.Message and not gm_Attack |
|
4 | 221 |
else begin |
222 |
if Gear.Power = 0 then |
|
223 |
begin |
|
224 |
AttackBar:= CurrentTeam.AttackBar; |
|
225 |
PlaySound(sndThrowPowerUp) |
|
226 |
end; |
|
227 |
inc(Gear.Power) |
|
228 |
end |
|
37 | 229 |
end |
230 |
else Gear.Message:= Gear.Message and not gm_Attack; |
|
4 | 231 |
|
37 | 232 |
if ((Gear.State and gstAttacking) <> 0) and ((Gear.Message and gm_Attack) = 0) then |
233 |
begin |
|
234 |
RemoveIntersectorsCR(Gear); |
|
235 |
Attack(Gear); |
|
38 | 236 |
StepTicks:= 40 |
37 | 237 |
end; |
4 | 238 |
|
239 |
if (Gear.State and gstFalling) <> 0 then |
|
240 |
begin |
|
7
b472e4b1a106
Fixed problem with hedgehog physics when turn is over and hedgehog is jumping
unc0rr
parents:
4
diff
changeset
|
241 |
// it could be the source to trick: double-backspace jump -> vertical wall |
b472e4b1a106
Fixed problem with hedgehog physics when turn is over and hedgehog is jumping
unc0rr
parents:
4
diff
changeset
|
242 |
// collision - > (abs(Gear.dX) < 0.0000002) -> backspace -> even more high jump |
4 | 243 |
if ((Gear.Message and gm_HJump) <> 0) and ((Gear.State and gstHHJumping) <> 0) then |
244 |
if (abs(Gear.dX) < 0.0000002) and (Gear.dY < -0.02) then |
|
245 |
begin |
|
246 |
Gear.dY:= -0.25; |
|
247 |
Gear.dX:= Sign(Gear.dX) * 0.02 |
|
248 |
end; |
|
7
b472e4b1a106
Fixed problem with hedgehog physics when turn is over and hedgehog is jumping
unc0rr
parents:
4
diff
changeset
|
249 |
Gear.Message:= Gear.Message and not (gm_LJump or gm_HJump); |
4 | 250 |
if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then Gear.dX:= 0.0000001 * Sign(Gear.dX); |
251 |
Gear.X:= Gear.X + Gear.dX; |
|
252 |
Gear.dY:= Gear.dY + cGravity; |
|
253 |
if (Gear.dY < 0)and TestCollisionYwithGear(Gear, -1) then Gear.dY:= 0; |
|
254 |
Gear.Y:= Gear.Y + Gear.dY; |
|
255 |
if (Gear.dY >= 0)and HHTestCollisionYwithGear(Gear, 1) then |
|
256 |
begin |
|
257 |
CheckHHDamage(Gear); |
|
258 |
if ((abs(Gear.dX) + abs(Gear.dY)) < 0.55) |
|
259 |
and ((Gear.State and gstHHJumping) <> 0) then Gear.dX:= 0.0000001 * Sign(Gear.dX); |
|
260 |
Gear.State:= Gear.State and not (gstFalling or gstHHJumping); |
|
39 | 261 |
StepTicks:= 300; |
4 | 262 |
Gear.dY:= 0 |
263 |
end; |
|
264 |
CheckGearDrowning(Gear); |
|
265 |
exit |
|
37 | 266 |
end else if Gear.CollIndex = High(Longword) then AddIntersectorsCR(Gear); |
4 | 267 |
|
268 |
if StepTicks > 0 then dec(StepTicks); |
|
269 |
||
270 |
if ((Gear.State and (gstMoving or gstFalling)) = 0) then |
|
271 |
if (Gear.Message and gm_Up )<>0 then if Gear.Angle > 0 then dec(Gear.Angle) |
|
272 |
else else |
|
273 |
if (Gear.Message and gm_Down )<>0 then if Gear.Angle < cMaxAngle then inc(Gear.Angle); |
|
274 |
||
275 |
if ((Gear.State and (gstAttacking or gstMoving or gstFalling)) = 0)and(StepTicks = 0) then |
|
276 |
begin |
|
277 |
if ((Gear.Message and gm_LJump )<>0) then |
|
278 |
begin |
|
279 |
Gear.Message:= 0; |
|
37 | 280 |
RemoveIntersectorsCR(Gear); |
4 | 281 |
if not HHTestCollisionYwithGear(Gear, -1) then |
282 |
if not TestCollisionXwithXYShift(Gear, 0, -2, Sign(Gear.dX)) then Gear.Y:= Gear.Y - 2 else |
|
283 |
if not TestCollisionXwithXYShift(Gear, 0, -1, Sign(Gear.dX)) then Gear.Y:= Gear.Y - 1; |
|
284 |
if not (TestCollisionXwithGear(Gear, Sign(Gear.dX)) |
|
285 |
or HHTestCollisionYwithGear(Gear, -1)) then |
|
286 |
begin |
|
287 |
Gear.dY:= -0.15; |
|
288 |
Gear.dX:= Sign(Gear.dX) * 0.15; |
|
289 |
Gear.State:= Gear.State or gstFalling or gstHHJumping; |
|
290 |
exit |
|
291 |
end; |
|
292 |
end; |
|
293 |
if ((Gear.Message and gm_HJump )<>0) then |
|
294 |
begin |
|
295 |
Gear.Message:= 0; |
|
37 | 296 |
RemoveIntersectorsCR(Gear); |
4 | 297 |
if not HHTestCollisionYwithGear(Gear, -1) then |
298 |
begin |
|
299 |
Gear.dY:= -0.20; |
|
300 |
Gear.dX:= 0.0000001 * Sign(Gear.dX); |
|
301 |
Gear.X:= Gear.X - Sign(Gear.dX)*0.00008; // êîìïåíñàöèÿ ñäâèãà %) |
|
302 |
Gear.State:= Gear.State or gstFalling or gstHHJumping; |
|
303 |
exit |
|
304 |
end; |
|
305 |
end; |
|
306 |
if (Gear.Message and gm_Left )<>0 then Gear.dX:= -1.0 else |
|
307 |
if (Gear.Message and gm_Right )<>0 then Gear.dX:= 1.0 else exit; |
|
308 |
PHedgehog(Gear.Hedgehog).visStepPos:= (PHedgehog(Gear.Hedgehog).visStepPos + 1) and 7; |
|
309 |
StepTicks:= 40; |
|
37 | 310 |
RemoveIntersectorsCR(Gear); |
4 | 311 |
if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then |
312 |
begin |
|
313 |
if not (TestCollisionXwithXYShift(Gear, 0, -6, Sign(Gear.dX)) |
|
314 |
or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1; |
|
315 |
if not (TestCollisionXwithXYShift(Gear, 0, -5, Sign(Gear.dX)) |
|
316 |
or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1; |
|
317 |
if not (TestCollisionXwithXYShift(Gear, 0, -4, Sign(Gear.dX)) |
|
318 |
or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1; |
|
319 |
if not (TestCollisionXwithXYShift(Gear, 0, -3, Sign(Gear.dX)) |
|
320 |
or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1; |
|
321 |
if not (TestCollisionXwithXYShift(Gear, 0, -2, Sign(Gear.dX)) |
|
322 |
or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1; |
|
323 |
if not (TestCollisionXwithXYShift(Gear, 0, -1, Sign(Gear.dX)) |
|
324 |
or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1; |
|
325 |
end; |
|
326 |
if not TestCollisionXwithGear(Gear, Sign(Gear.dX)) then Gear.X:= Gear.X + Gear.dX; |
|
37 | 327 |
|
4 | 328 |
if not HHTestCollisionYwithGear(Gear, 1) then |
329 |
begin |
|
330 |
Gear.Y:= Gear.Y + 1; |
|
331 |
if not HHTestCollisionYwithGear(Gear, 1) then |
|
332 |
begin |
|
333 |
Gear.Y:= Gear.Y + 1; |
|
334 |
if not HHTestCollisionYwithGear(Gear, 1) then |
|
335 |
begin |
|
336 |
Gear.Y:= Gear.Y + 1; |
|
337 |
if not HHTestCollisionYwithGear(Gear, 1) then |
|
338 |
begin |
|
339 |
Gear.Y:= Gear.Y + 1; |
|
340 |
if not HHTestCollisionYwithGear(Gear, 1) then |
|
341 |
begin |
|
342 |
Gear.Y:= Gear.Y + 1; |
|
343 |
if not HHTestCollisionYwithGear(Gear, 1) then |
|
344 |
begin |
|
345 |
Gear.Y:= Gear.Y + 1; |
|
346 |
if not HHTestCollisionYwithGear(Gear, 1) then |
|
347 |
begin |
|
348 |
Gear.Y:= Gear.Y - 6; |
|
349 |
Gear.dY:= 0; |
|
350 |
Gear.dX:= 0.0000001 * Sign(Gear.dX); |
|
351 |
Gear.State:= Gear.State or gstFalling |
|
352 |
end; |
|
353 |
end |
|
354 |
end |
|
355 |
end |
|
356 |
end |
|
357 |
end |
|
37 | 358 |
end; |
359 |
AddIntersectorsCR(Gear); |
|
360 |
SetAllHHToActive |
|
4 | 361 |
end |
362 |
end; |
|
363 |
||
364 |
//////////////////////////////////////////////////////////////////////////////// |
|
365 |
procedure doStepHedgehogFree(Gear: PGear); |
|
366 |
begin |
|
367 |
if not HHTestCollisionYwithGear(Gear, 1) then |
|
368 |
begin |
|
369 |
if (Gear.dY < 0) and HHTestCollisionYwithGear(Gear, -1) then Gear.dY:= 0; |
|
370 |
Gear.State:= Gear.State or gstFalling or gstMoving; |
|
371 |
Gear.dY:= Gear.dY + cGravity |
|
372 |
end else begin |
|
373 |
CheckHHDamage(Gear); |
|
7
b472e4b1a106
Fixed problem with hedgehog physics when turn is over and hedgehog is jumping
unc0rr
parents:
4
diff
changeset
|
374 |
if ((abs(Gear.dX) + abs(Gear.dY)) < 0.55) |
b472e4b1a106
Fixed problem with hedgehog physics when turn is over and hedgehog is jumping
unc0rr
parents:
4
diff
changeset
|
375 |
and ((Gear.State and gstHHJumping) <> 0) then Gear.dX:= 0.0000001 * Sign(Gear.dX); |
b472e4b1a106
Fixed problem with hedgehog physics when turn is over and hedgehog is jumping
unc0rr
parents:
4
diff
changeset
|
376 |
Gear.State:= Gear.State and not (gstFalling or gstHHJumping); |
4 | 377 |
if Gear.dY > 0 then Gear.dY:= 0; |
378 |
if ((Gear.State and gstMoving) <> 0) then Gear.dX:= Gear.dX * Gear.Friction |
|
379 |
end; |
|
380 |
||
38 | 381 |
if (Gear.State <> 0) and (Gear.CollIndex < High(Longword)) then DeleteCR(Gear); |
382 |
||
4 | 383 |
|
384 |
if (Gear.State and gstMoving) <> 0 then |
|
385 |
if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then |
|
386 |
if ((Gear.State and gstFalling) = 0) then |
|
387 |
if abs(Gear.dX) > 0.01 then |
|
388 |
if not TestCollisionXwithXYShift(Gear, 0, -1, Sign(Gear.dX)) then begin Gear.dX:= Gear.dX * 0.9; Gear.Y:= Gear.Y - 1 end else |
|
389 |
if not TestCollisionXwithXYShift(Gear, 0, -2, Sign(Gear.dX)) then begin Gear.dX:= Gear.dX * 0.9; Gear.Y:= Gear.Y - 2 end else |
|
390 |
if not TestCollisionXwithXYShift(Gear, 0, -3, Sign(Gear.dX)) then begin Gear.dX:= Gear.dX * 0.9; Gear.Y:= Gear.Y - 3 end else |
|
391 |
if not TestCollisionXwithXYShift(Gear, 0, -4, Sign(Gear.dX)) then begin Gear.dX:= Gear.dX * 0.9; Gear.Y:= Gear.Y - 4 end else |
|
392 |
if not TestCollisionXwithXYShift(Gear, 0, -5, Sign(Gear.dX)) then begin Gear.dX:= Gear.dX * 0.3; Gear.Y:= Gear.Y - 5 end else |
|
393 |
if abs(Gear.dX) > 0.02 then Gear.dX:= -0.5 * Gear.dX |
|
394 |
else begin |
|
395 |
Gear.State:= Gear.State and not gstMoving; |
|
396 |
Gear.dX:= 0.0000001 * Sign(Gear.dX) |
|
397 |
end |
|
398 |
else begin |
|
399 |
Gear.State:= Gear.State and not gstMoving; |
|
400 |
Gear.dX:= 0.0000001 * Sign(Gear.dX) |
|
401 |
end |
|
402 |
else Gear.dX:= -0.8 * Gear.dX; |
|
403 |
||
404 |
if ((Gear.State and gstFalling) = 0)and |
|
405 |
(sqr(Gear.dX) + sqr(Gear.dY) < 0.0008) then |
|
406 |
begin |
|
407 |
Gear.State:= Gear.State and not gstMoving; |
|
408 |
Gear.dX:= 0.0000001 * Sign(Gear.dX); |
|
409 |
Gear.dY:= 0 |
|
410 |
end else Gear.State:= Gear.State or gstMoving; |
|
411 |
||
412 |
if (Gear.State and gstMoving) <> 0 then |
|
413 |
begin |
|
414 |
Gear.X:= Gear.X + Gear.dX; |
|
415 |
Gear.Y:= Gear.Y + Gear.dY |
|
416 |
end else |
|
417 |
if Gear.Health = 0 then |
|
418 |
begin |
|
419 |
if AllInactive then |
|
420 |
begin |
|
421 |
doMakeExplosion(round(Gear.X), round(Gear.Y), 30, EXPLAutoSound); |
|
422 |
AddGear(round(Gear.X), round(Gear.Y), gtGrave, 0).Hedgehog:= Gear.Hedgehog; |
|
423 |
DeleteGear(Gear); |
|
424 |
SetAllToActive |
|
425 |
end; |
|
7
b472e4b1a106
Fixed problem with hedgehog physics when turn is over and hedgehog is jumping
unc0rr
parents:
4
diff
changeset
|
426 |
AllInactive:= false; |
4 | 427 |
exit |
428 |
end; |
|
429 |
||
430 |
AllInactive:= false; |
|
431 |
||
432 |
if (not CheckGearDrowning(Gear)) and |
|
433 |
((Gear.State and gstMoving) = 0) then |
|
434 |
begin |
|
435 |
Gear.State:= 0; |
|
436 |
Gear.Active:= false; |
|
37 | 437 |
AddIntersectorsCR(Gear); |
4 | 438 |
exit |
439 |
end |
|
440 |
end; |
|
441 |
||
442 |
//////////////////////////////////////////////////////////////////////////////// |
|
443 |
procedure doStepHedgehog(Gear: PGear); |
|
444 |
begin |
|
445 |
if (Gear.Message and gm_Destroy) <> 0 then |
|
446 |
begin |
|
447 |
DeleteGear(Gear); |
|
448 |
exit |
|
449 |
end; |
|
450 |
if (Gear.State and gstHHDriven) = 0 then doStepHedgehogFree(Gear) |
|
451 |
else doStepHedgehogDriven(Gear) |
|
452 |
end; |