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