author | unc0rr |
Sun, 28 Aug 2005 19:00:20 +0000 | |
changeset 8 | 24048039955c |
parent 7 | b472e4b1a106 |
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 |
procedure doStepHedgehog(Gear: PGear); forward; |
|
35 |
//////////////////////////////////////////////////////////////////////////////// |
|
36 |
procedure doStepHedgehogDriven(Gear: PGear); |
|
37 |
const StepTicks: LongWord = 0; |
|
38 |
begin |
|
39 |
if isinMultiShoot and (Gear.Damage = 0) then exit; |
|
40 |
AllInactive:= false; |
|
41 |
if (TurnTimeLeft = 0) or (Gear.Damage > 0) then |
|
42 |
begin |
|
43 |
if ((Gear.State and (gstMoving or gstFalling)) = 0) |
|
44 |
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
|
45 |
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
|
46 |
if Gear.Damage > 0 then |
b472e4b1a106
Fixed problem with hedgehog physics when turn is over and hedgehog is jumping
unc0rr
parents:
4
diff
changeset
|
47 |
Gear.State:= Gear.State and not gstHHJumping; |
4 | 48 |
exit |
49 |
end; |
|
50 |
||
51 |
if CurAmmoGear <> nil then |
|
52 |
begin |
|
53 |
CurAmmoGear.Message:= Gear.Message; |
|
54 |
exit |
|
55 |
end; |
|
56 |
||
57 |
if (Gear.Message and gm_Attack)<>0 then |
|
58 |
if (Gear.State and (gstAttacked or gstHHChooseTarget) = 0)and(CurAmmoGear = nil) then |
|
59 |
with PHedgehog(Gear.Hedgehog)^ do |
|
60 |
// if ((Gear.State and gstFalling ) = 0)or((Ammo[CurSlot, CurAmmo].Propz and ammoprop_AttackInFall) <> 0) |
|
61 |
// and((Gear.State and gstHHJumping) = 0)or((Ammo[CurSlot, CurAmmo].Propz and ammoprop_AttackInJump) <> 0) then |
|
62 |
begin |
|
63 |
Gear.State:= Gear.State or gstAttacking; |
|
64 |
if Gear.Power = cMaxPower then ParseCommand('-attack') |
|
65 |
else begin |
|
66 |
if (Ammo[CurSlot, CurAmmo].Propz and ammoprop_Power) = 0 then Gear.Power:= cMaxPower |
|
67 |
else begin |
|
68 |
if Gear.Power = 0 then |
|
69 |
begin |
|
70 |
AttackBar:= CurrentTeam.AttackBar; |
|
71 |
PlaySound(sndThrowPowerUp) |
|
72 |
end; |
|
73 |
inc(Gear.Power) |
|
74 |
end |
|
75 |
end; |
|
76 |
end else Gear.Message:= Gear.Message and not gm_Attack; |
|
77 |
||
78 |
||
79 |
if (Gear.State and gstFalling) <> 0 then |
|
80 |
begin |
|
7
b472e4b1a106
Fixed problem with hedgehog physics when turn is over and hedgehog is jumping
unc0rr
parents:
4
diff
changeset
|
81 |
// 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
|
82 |
// collision - > (abs(Gear.dX) < 0.0000002) -> backspace -> even more high jump |
4 | 83 |
if ((Gear.Message and gm_HJump) <> 0) and ((Gear.State and gstHHJumping) <> 0) then |
84 |
if (abs(Gear.dX) < 0.0000002) and (Gear.dY < -0.02) then |
|
85 |
begin |
|
86 |
Gear.dY:= -0.25; |
|
87 |
Gear.dX:= Sign(Gear.dX) * 0.02 |
|
88 |
end; |
|
7
b472e4b1a106
Fixed problem with hedgehog physics when turn is over and hedgehog is jumping
unc0rr
parents:
4
diff
changeset
|
89 |
Gear.Message:= Gear.Message and not (gm_LJump or gm_HJump); |
4 | 90 |
if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then Gear.dX:= 0.0000001 * Sign(Gear.dX); |
91 |
Gear.X:= Gear.X + Gear.dX; |
|
92 |
Gear.dY:= Gear.dY + cGravity; |
|
93 |
if (Gear.dY < 0)and TestCollisionYwithGear(Gear, -1) then Gear.dY:= 0; |
|
94 |
Gear.Y:= Gear.Y + Gear.dY; |
|
95 |
if (Gear.dY >= 0)and HHTestCollisionYwithGear(Gear, 1) then |
|
96 |
begin |
|
97 |
CheckHHDamage(Gear); |
|
98 |
if ((abs(Gear.dX) + abs(Gear.dY)) < 0.55) |
|
99 |
and ((Gear.State and gstHHJumping) <> 0) then Gear.dX:= 0.0000001 * Sign(Gear.dX); |
|
100 |
Gear.State:= Gear.State and not (gstFalling or gstHHJumping); |
|
101 |
StepTicks:= 200; |
|
102 |
Gear.dY:= 0 |
|
103 |
end; |
|
104 |
CheckGearDrowning(Gear); |
|
105 |
exit |
|
106 |
end; |
|
107 |
||
108 |
if StepTicks > 0 then dec(StepTicks); |
|
109 |
||
110 |
if ((Gear.State and (gstMoving or gstFalling)) = 0) then |
|
111 |
if (Gear.Message and gm_Up )<>0 then if Gear.Angle > 0 then dec(Gear.Angle) |
|
112 |
else else |
|
113 |
if (Gear.Message and gm_Down )<>0 then if Gear.Angle < cMaxAngle then inc(Gear.Angle); |
|
114 |
||
115 |
if ((Gear.State and (gstAttacking or gstMoving or gstFalling)) = 0)and(StepTicks = 0) then |
|
116 |
begin |
|
117 |
if ((Gear.Message and gm_LJump )<>0) then |
|
118 |
begin |
|
119 |
Gear.Message:= 0; |
|
120 |
if not HHTestCollisionYwithGear(Gear, -1) then |
|
121 |
if not TestCollisionXwithXYShift(Gear, 0, -2, Sign(Gear.dX)) then Gear.Y:= Gear.Y - 2 else |
|
122 |
if not TestCollisionXwithXYShift(Gear, 0, -1, Sign(Gear.dX)) then Gear.Y:= Gear.Y - 1; |
|
123 |
if not (TestCollisionXwithGear(Gear, Sign(Gear.dX)) |
|
124 |
or HHTestCollisionYwithGear(Gear, -1)) then |
|
125 |
begin |
|
126 |
Gear.dY:= -0.15; |
|
127 |
Gear.dX:= Sign(Gear.dX) * 0.15; |
|
128 |
Gear.State:= Gear.State or gstFalling or gstHHJumping; |
|
129 |
exit |
|
130 |
end; |
|
131 |
end; |
|
132 |
if ((Gear.Message and gm_HJump )<>0) then |
|
133 |
begin |
|
134 |
Gear.Message:= 0; |
|
135 |
if not HHTestCollisionYwithGear(Gear, -1) then |
|
136 |
begin |
|
137 |
Gear.dY:= -0.20; |
|
138 |
Gear.dX:= 0.0000001 * Sign(Gear.dX); |
|
139 |
Gear.X:= Gear.X - Sign(Gear.dX)*0.00008; // êîìïåíñàöèÿ ñäâèãà %) |
|
140 |
Gear.State:= Gear.State or gstFalling or gstHHJumping; |
|
141 |
exit |
|
142 |
end; |
|
143 |
end; |
|
144 |
if (Gear.Message and gm_Left )<>0 then Gear.dX:= -1.0 else |
|
145 |
if (Gear.Message and gm_Right )<>0 then Gear.dX:= 1.0 else exit; |
|
146 |
PHedgehog(Gear.Hedgehog).visStepPos:= (PHedgehog(Gear.Hedgehog).visStepPos + 1) and 7; |
|
147 |
StepTicks:= 40; |
|
148 |
if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then |
|
149 |
begin |
|
150 |
if not (TestCollisionXwithXYShift(Gear, 0, -6, Sign(Gear.dX)) |
|
151 |
or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1; |
|
152 |
if not (TestCollisionXwithXYShift(Gear, 0, -5, Sign(Gear.dX)) |
|
153 |
or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1; |
|
154 |
if not (TestCollisionXwithXYShift(Gear, 0, -4, Sign(Gear.dX)) |
|
155 |
or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1; |
|
156 |
if not (TestCollisionXwithXYShift(Gear, 0, -3, Sign(Gear.dX)) |
|
157 |
or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1; |
|
158 |
if not (TestCollisionXwithXYShift(Gear, 0, -2, Sign(Gear.dX)) |
|
159 |
or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1; |
|
160 |
if not (TestCollisionXwithXYShift(Gear, 0, -1, Sign(Gear.dX)) |
|
161 |
or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1; |
|
162 |
end; |
|
163 |
if not TestCollisionXwithGear(Gear, Sign(Gear.dX)) then Gear.X:= Gear.X + Gear.dX; |
|
164 |
||
165 |
if not HHTestCollisionYwithGear(Gear, 1) then |
|
166 |
begin |
|
167 |
Gear.Y:= Gear.Y + 1; |
|
168 |
if not HHTestCollisionYwithGear(Gear, 1) then |
|
169 |
begin |
|
170 |
Gear.Y:= Gear.Y + 1; |
|
171 |
if not HHTestCollisionYwithGear(Gear, 1) then |
|
172 |
begin |
|
173 |
Gear.Y:= Gear.Y + 1; |
|
174 |
if not HHTestCollisionYwithGear(Gear, 1) then |
|
175 |
begin |
|
176 |
Gear.Y:= Gear.Y + 1; |
|
177 |
if not HHTestCollisionYwithGear(Gear, 1) then |
|
178 |
begin |
|
179 |
Gear.Y:= Gear.Y + 1; |
|
180 |
if not HHTestCollisionYwithGear(Gear, 1) then |
|
181 |
begin |
|
182 |
Gear.Y:= Gear.Y + 1; |
|
183 |
if not HHTestCollisionYwithGear(Gear, 1) then |
|
184 |
begin |
|
185 |
Gear.Y:= Gear.Y - 6; |
|
186 |
Gear.dY:= 0; |
|
187 |
Gear.dX:= 0.0000001 * Sign(Gear.dX); |
|
188 |
Gear.State:= Gear.State or gstFalling |
|
189 |
end; |
|
190 |
SetAllHHToActive |
|
191 |
end |
|
192 |
end |
|
193 |
end |
|
194 |
end |
|
195 |
end |
|
196 |
end |
|
197 |
end |
|
198 |
end; |
|
199 |
||
200 |
//////////////////////////////////////////////////////////////////////////////// |
|
201 |
procedure doStepHedgehogFree(Gear: PGear); |
|
202 |
begin |
|
203 |
if not HHTestCollisionYwithGear(Gear, 1) then |
|
204 |
begin |
|
205 |
if (Gear.dY < 0) and HHTestCollisionYwithGear(Gear, -1) then Gear.dY:= 0; |
|
206 |
Gear.State:= Gear.State or gstFalling or gstMoving; |
|
207 |
Gear.dY:= Gear.dY + cGravity |
|
208 |
end else begin |
|
209 |
CheckHHDamage(Gear); |
|
7
b472e4b1a106
Fixed problem with hedgehog physics when turn is over and hedgehog is jumping
unc0rr
parents:
4
diff
changeset
|
210 |
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
|
211 |
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
|
212 |
Gear.State:= Gear.State and not (gstFalling or gstHHJumping); |
4 | 213 |
if Gear.dY > 0 then Gear.dY:= 0; |
214 |
if ((Gear.State and gstMoving) <> 0) then Gear.dX:= Gear.dX * Gear.Friction |
|
215 |
end; |
|
216 |
||
217 |
||
218 |
if (Gear.State and gstMoving) <> 0 then |
|
219 |
if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then |
|
220 |
if ((Gear.State and gstFalling) = 0) then |
|
221 |
if abs(Gear.dX) > 0.01 then |
|
222 |
if not TestCollisionXwithXYShift(Gear, 0, -1, Sign(Gear.dX)) then begin Gear.dX:= Gear.dX * 0.9; Gear.Y:= Gear.Y - 1 end else |
|
223 |
if not TestCollisionXwithXYShift(Gear, 0, -2, Sign(Gear.dX)) then begin Gear.dX:= Gear.dX * 0.9; Gear.Y:= Gear.Y - 2 end else |
|
224 |
if not TestCollisionXwithXYShift(Gear, 0, -3, Sign(Gear.dX)) then begin Gear.dX:= Gear.dX * 0.9; Gear.Y:= Gear.Y - 3 end else |
|
225 |
if not TestCollisionXwithXYShift(Gear, 0, -4, Sign(Gear.dX)) then begin Gear.dX:= Gear.dX * 0.9; Gear.Y:= Gear.Y - 4 end else |
|
226 |
if not TestCollisionXwithXYShift(Gear, 0, -5, Sign(Gear.dX)) then begin Gear.dX:= Gear.dX * 0.3; Gear.Y:= Gear.Y - 5 end else |
|
227 |
if abs(Gear.dX) > 0.02 then Gear.dX:= -0.5 * Gear.dX |
|
228 |
else begin |
|
229 |
Gear.State:= Gear.State and not gstMoving; |
|
230 |
Gear.dX:= 0.0000001 * Sign(Gear.dX) |
|
231 |
end |
|
232 |
else begin |
|
233 |
Gear.State:= Gear.State and not gstMoving; |
|
234 |
Gear.dX:= 0.0000001 * Sign(Gear.dX) |
|
235 |
end |
|
236 |
else Gear.dX:= -0.8 * Gear.dX; |
|
237 |
||
238 |
if ((Gear.State and gstFalling) = 0)and |
|
239 |
(sqr(Gear.dX) + sqr(Gear.dY) < 0.0008) then |
|
240 |
begin |
|
241 |
Gear.State:= Gear.State and not gstMoving; |
|
242 |
Gear.dX:= 0.0000001 * Sign(Gear.dX); |
|
243 |
Gear.dY:= 0 |
|
244 |
end else Gear.State:= Gear.State or gstMoving; |
|
245 |
||
246 |
if (Gear.State and gstMoving) <> 0 then |
|
247 |
begin |
|
248 |
Gear.X:= Gear.X + Gear.dX; |
|
249 |
Gear.Y:= Gear.Y + Gear.dY |
|
250 |
end else |
|
251 |
if Gear.Health = 0 then |
|
252 |
begin |
|
253 |
if AllInactive then |
|
254 |
begin |
|
255 |
doMakeExplosion(round(Gear.X), round(Gear.Y), 30, EXPLAutoSound); |
|
256 |
AddGear(round(Gear.X), round(Gear.Y), gtGrave, 0).Hedgehog:= Gear.Hedgehog; |
|
257 |
DeleteGear(Gear); |
|
258 |
SetAllToActive |
|
259 |
end; |
|
7
b472e4b1a106
Fixed problem with hedgehog physics when turn is over and hedgehog is jumping
unc0rr
parents:
4
diff
changeset
|
260 |
AllInactive:= false; |
4 | 261 |
exit |
262 |
end; |
|
263 |
||
264 |
AllInactive:= false; |
|
265 |
||
266 |
if (not CheckGearDrowning(Gear)) and |
|
267 |
((Gear.State and gstMoving) = 0) then |
|
268 |
begin |
|
269 |
Gear.State:= 0; |
|
270 |
Gear.Active:= false; |
|
271 |
AddGearCR(Gear); |
|
272 |
exit |
|
273 |
end |
|
274 |
end; |
|
275 |
||
276 |
//////////////////////////////////////////////////////////////////////////////// |
|
277 |
procedure doStepHedgehog(Gear: PGear); |
|
278 |
begin |
|
279 |
if (Gear.Message and gm_Destroy) <> 0 then |
|
280 |
begin |
|
281 |
DeleteGear(Gear); |
|
282 |
exit |
|
283 |
end; |
|
284 |
if Gear.CollIndex < High(Longword) then DeleteCR(Gear); |
|
285 |
if (Gear.State and gstHHDriven) = 0 then doStepHedgehogFree(Gear) |
|
286 |
else doStepHedgehogDriven(Gear) |
|
287 |
end; |