author | nemo |
Thu, 07 Jan 2010 16:12:26 +0000 | |
changeset 2679 | b61d25fa6c53 |
parent 2630 | 079ef82eac75 |
child 2716 | b9ca1bfca24f |
permissions | -rw-r--r-- |
4 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
883 | 3 |
* Copyright (c) 2005-2008 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 4 |
* |
183 | 5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
4 | 8 |
* |
183 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
4 | 13 |
* |
183 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
4 | 17 |
*) |
18 |
||
2630 | 19 |
{$INCLUDE "options.inc"} |
20 |
||
4 | 21 |
unit uCollisions; |
22 |
interface |
|
351 | 23 |
uses uGears, uFloat; |
2630 | 24 |
|
53 | 25 |
const cMaxGearArrayInd = 255; |
4 | 26 |
|
70 | 27 |
type PGearArray = ^TGearArray; |
1506 | 28 |
TGearArray = record |
29 |
ar: array[0..cMaxGearArrayInd] of PGear; |
|
30 |
Count: Longword |
|
31 |
end; |
|
4 | 32 |
|
53 | 33 |
procedure AddGearCI(Gear: PGear); |
34 |
procedure DeleteCI(Gear: PGear); |
|
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
35 |
|
53 | 36 |
function CheckGearsCollision(Gear: PGear): PGearArray; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
37 |
|
371 | 38 |
function TestCollisionXwithGear(Gear: PGear; Dir: LongInt): boolean; |
39 |
function TestCollisionYwithGear(Gear: PGear; Dir: LongInt): boolean; |
|
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
40 |
|
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
41 |
function TestCollisionXKick(Gear: PGear; Dir: LongInt): boolean; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
42 |
function TestCollisionYKick(Gear: PGear; Dir: LongInt): boolean; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
43 |
|
371 | 44 |
function TestCollisionY(Gear: PGear; Dir: LongInt): boolean; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
45 |
|
498 | 46 |
function TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt): boolean; |
371 | 47 |
function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt): boolean; |
4 | 48 |
|
49 |
implementation |
|
511 | 50 |
uses uMisc, uConsts, uLand, uLandGraphics, uConsole; |
4 | 51 |
|
53 | 52 |
type TCollisionEntry = record |
1506 | 53 |
X, Y, Radius: LongInt; |
54 |
cGear: PGear; |
|
55 |
end; |
|
351 | 56 |
|
906 | 57 |
const MAXRECTSINDEX = 511; |
4 | 58 |
var Count: Longword = 0; |
1506 | 59 |
cinfos: array[0..MAXRECTSINDEX] of TCollisionEntry; |
60 |
ga: TGearArray; |
|
4 | 61 |
|
53 | 62 |
procedure AddGearCI(Gear: PGear); |
63 |
begin |
|
511 | 64 |
if Gear^.CollisionIndex >= 0 then exit; |
4 | 65 |
TryDo(Count <= MAXRECTSINDEX, 'Collision rects array overflow', true); |
53 | 66 |
with cinfos[Count] do |
1506 | 67 |
begin |
68 |
X:= hwRound(Gear^.X); |
|
69 |
Y:= hwRound(Gear^.Y); |
|
70 |
Radius:= Gear^.Radius; |
|
71 |
ChangeRoundInLand(X, Y, Radius - 1, true); |
|
72 |
cGear:= Gear |
|
73 |
end; |
|
511 | 74 |
Gear^.CollisionIndex:= Count; |
4 | 75 |
inc(Count) |
76 |
end; |
|
77 |
||
53 | 78 |
procedure DeleteCI(Gear: PGear); |
4 | 79 |
begin |
511 | 80 |
if Gear^.CollisionIndex >= 0 then |
1506 | 81 |
begin |
82 |
with cinfos[Gear^.CollisionIndex] do |
|
83 |
ChangeRoundInLand(X, Y, Radius - 1, false); |
|
84 |
cinfos[Gear^.CollisionIndex]:= cinfos[Pred(Count)]; |
|
85 |
cinfos[Gear^.CollisionIndex].cGear^.CollisionIndex:= Gear^.CollisionIndex; |
|
86 |
Gear^.CollisionIndex:= -1; |
|
87 |
dec(Count) |
|
88 |
end; |
|
4 | 89 |
end; |
90 |
||
53 | 91 |
function CheckGearsCollision(Gear: PGear): PGearArray; |
371 | 92 |
var mx, my: LongInt; |
1506 | 93 |
i: Longword; |
4 | 94 |
begin |
1506 | 95 |
CheckGearsCollision:= @ga; |
53 | 96 |
ga.Count:= 0; |
12
366adfa1a727
Fix reading out of bounds of the collisions array. This fixes flying hedgehogs and not moving after explosion
unc0rr
parents:
4
diff
changeset
|
97 |
if Count = 0 then exit; |
351 | 98 |
mx:= hwRound(Gear^.X); |
99 |
my:= hwRound(Gear^.Y); |
|
4 | 100 |
|
101 |
for i:= 0 to Pred(Count) do |
|
1506 | 102 |
with cinfos[i] do |
103 |
if (Gear <> cGear) and |
|
104 |
(sqr(mx - x) + sqr(my - y) <= sqr(Radius + Gear^.Radius)) then |
|
105 |
begin |
|
106 |
ga.ar[ga.Count]:= cinfos[i].cGear; |
|
107 |
inc(ga.Count) |
|
108 |
end |
|
4 | 109 |
end; |
110 |
||
371 | 111 |
function TestCollisionXwithGear(Gear: PGear; Dir: LongInt): boolean; |
112 |
var x, y, i: LongInt; |
|
1506 | 113 |
TestWord: LongWord; |
4 | 114 |
begin |
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
115 |
if Gear^.IntersectGear <> nil then |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
116 |
with Gear^ do |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
117 |
if (hwRound(IntersectGear^.X) + IntersectGear^.Radius < hwRound(X) - Radius) or |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
118 |
(hwRound(IntersectGear^.X) - IntersectGear^.Radius > hwRound(X) + Radius) then |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
119 |
begin |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
120 |
IntersectGear:= nil; |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
121 |
TestWord:= 0 |
838 | 122 |
end else |
1966 | 123 |
TestWord:= 255 |
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
124 |
else TestWord:= 0; |
838 | 125 |
|
351 | 126 |
x:= hwRound(Gear^.X); |
127 |
if Dir < 0 then x:= x - Gear^.Radius |
|
128 |
else x:= x + Gear^.Radius; |
|
1753 | 129 |
if (x and LAND_WIDTH_MASK) = 0 then |
4 | 130 |
begin |
351 | 131 |
y:= hwRound(Gear^.Y) - Gear^.Radius + 1; |
132 |
i:= y + Gear^.Radius * 2 - 2; |
|
4 | 133 |
repeat |
1753 | 134 |
if (y and LAND_HEIGHT_MASK) = 0 then |
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
135 |
if Land[y, x] > TestWord then exit(true); |
4 | 136 |
inc(y) |
351 | 137 |
until (y > i); |
138 |
end; |
|
139 |
TestCollisionXwithGear:= false |
|
4 | 140 |
end; |
141 |
||
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
142 |
function TestCollisionYwithGear(Gear: PGear; Dir: LongInt): boolean; |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
143 |
var x, y, i: LongInt; |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
144 |
TestWord: LongWord; |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
145 |
begin |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
146 |
if Gear^.IntersectGear <> nil then |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
147 |
with Gear^ do |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
148 |
if (hwRound(IntersectGear^.Y) + IntersectGear^.Radius < hwRound(Y) - Radius) or |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
149 |
(hwRound(IntersectGear^.Y) - IntersectGear^.Radius > hwRound(Y) + Radius) then |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
150 |
begin |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
151 |
IntersectGear:= nil; |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
152 |
TestWord:= 0 |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
153 |
end else |
1966 | 154 |
TestWord:= 255 |
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
155 |
else TestWord:= 0; |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
156 |
|
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
157 |
y:= hwRound(Gear^.Y); |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
158 |
if Dir < 0 then y:= y - Gear^.Radius |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
159 |
else y:= y + Gear^.Radius; |
1753 | 160 |
if (y and LAND_HEIGHT_MASK) = 0 then |
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
161 |
begin |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
162 |
x:= hwRound(Gear^.X) - Gear^.Radius + 1; |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
163 |
i:= x + Gear^.Radius * 2 - 2; |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
164 |
repeat |
1753 | 165 |
if (x and LAND_WIDTH_MASK) = 0 then |
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
166 |
if Land[y, x] > TestWord then exit(true); |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
167 |
inc(x) |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
168 |
until (x > i); |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
169 |
end; |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
170 |
TestCollisionYwithGear:= false |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
171 |
end; |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
172 |
|
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
173 |
function TestCollisionXKick(Gear: PGear; Dir: LongInt): boolean; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
174 |
var x, y, mx, my, i: LongInt; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
175 |
flag: boolean; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
176 |
begin |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
177 |
flag:= false; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
178 |
x:= hwRound(Gear^.X); |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
179 |
if Dir < 0 then x:= x - Gear^.Radius |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
180 |
else x:= x + Gear^.Radius; |
1753 | 181 |
if (x and LAND_WIDTH_MASK) = 0 then |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
182 |
begin |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
183 |
y:= hwRound(Gear^.Y) - Gear^.Radius + 1; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
184 |
i:= y + Gear^.Radius * 2 - 2; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
185 |
repeat |
1753 | 186 |
if (y and LAND_HEIGHT_MASK) = 0 then |
1966 | 187 |
if Land[y, x] > 255 then exit(true) |
536 | 188 |
else if Land[y, x] <> 0 then flag:= true; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
189 |
inc(y) |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
190 |
until (y > i); |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
191 |
end; |
538 | 192 |
TestCollisionXKick:= flag; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
193 |
|
536 | 194 |
if flag then |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
195 |
begin |
538 | 196 |
if hwAbs(Gear^.dX) < cHHKick then exit; |
967 | 197 |
if (Gear^.State and gstHHJumping <> 0) |
198 |
and (hwAbs(Gear^.dX) < _0_4) then exit; |
|
199 |
||
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
200 |
mx:= hwRound(Gear^.X); |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
201 |
my:= hwRound(Gear^.Y); |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
202 |
|
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
203 |
for i:= 0 to Pred(Count) do |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
204 |
with cinfos[i] do |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
205 |
if (Gear <> cGear) and |
855
8842c71d16bf
- Fix too long delay between shotgun and deagle shots
unc0rr
parents:
839
diff
changeset
|
206 |
(sqr(mx - x) + sqr(my - y) <= sqr(Radius + Gear^.Radius + 2)) and |
517 | 207 |
((mx > x) xor (Dir > 0)) then |
1528 | 208 |
if (cGear^.Kind in [gtHedgehog, gtMine]) and ((Gear^.State and gstNotKickable) = 0) then |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
209 |
begin |
521 | 210 |
with cGear^ do |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
211 |
begin |
536 | 212 |
dX:= Gear^.dX; |
542 | 213 |
dY:= Gear^.dY * _0_5; |
521 | 214 |
State:= State or gstMoving; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
215 |
Active:= true |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
216 |
end; |
521 | 217 |
DeleteCI(cGear); |
538 | 218 |
exit(false) |
219 |
end |
|
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
220 |
end |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
221 |
end; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
222 |
|
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
223 |
function TestCollisionYKick(Gear: PGear; Dir: LongInt): boolean; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
224 |
var x, y, mx, my, i: LongInt; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
225 |
flag: boolean; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
226 |
begin |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
227 |
flag:= false; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
228 |
y:= hwRound(Gear^.Y); |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
229 |
if Dir < 0 then y:= y - Gear^.Radius |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
230 |
else y:= y + Gear^.Radius; |
1753 | 231 |
if (y and LAND_HEIGHT_MASK) = 0 then |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
232 |
begin |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
233 |
x:= hwRound(Gear^.X) - Gear^.Radius + 1; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
234 |
i:= x + Gear^.Radius * 2 - 2; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
235 |
repeat |
1753 | 236 |
if (x and LAND_WIDTH_MASK) = 0 then |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
237 |
if Land[y, x] > 0 then |
1966 | 238 |
if Land[y, x] > 255 then exit(true) |
536 | 239 |
else if Land[y, x] <> 0 then flag:= true; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
240 |
inc(x) |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
241 |
until (x > i); |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
242 |
end; |
538 | 243 |
TestCollisionYKick:= flag; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
244 |
|
536 | 245 |
if flag then |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
246 |
begin |
839 | 247 |
if hwAbs(Gear^.dY) < cHHKick then exit(true); |
967 | 248 |
if (Gear^.State and gstHHJumping <> 0) |
249 |
and (not Gear^.dY.isNegative) |
|
250 |
and (Gear^.dY < _0_4) then exit; |
|
251 |
||
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
252 |
mx:= hwRound(Gear^.X); |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
253 |
my:= hwRound(Gear^.Y); |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
254 |
|
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
255 |
for i:= 0 to Pred(Count) do |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
256 |
with cinfos[i] do |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
257 |
if (Gear <> cGear) and |
855
8842c71d16bf
- Fix too long delay between shotgun and deagle shots
unc0rr
parents:
839
diff
changeset
|
258 |
(sqr(mx - x) + sqr(my - y) <= sqr(Radius + Gear^.Radius + 2)) and |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
259 |
((my > y) xor (Dir > 0)) then |
1528 | 260 |
if (cGear^.Kind in [gtHedgehog, gtMine]) and ((Gear^.State and gstNotKickable) = 0) then |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
261 |
begin |
521 | 262 |
with cGear^ do |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
263 |
begin |
542 | 264 |
dX:= Gear^.dX * _0_5; |
265 |
dY:= Gear^.dY; |
|
521 | 266 |
State:= State or gstMoving; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
267 |
Active:= true |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
268 |
end; |
521 | 269 |
DeleteCI(cGear); |
538 | 270 |
exit(false) |
271 |
end |
|
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
272 |
end |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
273 |
end; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
274 |
|
498 | 275 |
function TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt): boolean; |
4 | 276 |
begin |
351 | 277 |
Gear^.X:= Gear^.X + ShiftX; |
498 | 278 |
Gear^.Y:= Gear^.Y + int2hwFloat(ShiftY); |
351 | 279 |
TestCollisionXwithXYShift:= TestCollisionXwithGear(Gear, Dir); |
280 |
Gear^.X:= Gear^.X - ShiftX; |
|
498 | 281 |
Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY) |
4 | 282 |
end; |
283 |
||
371 | 284 |
function TestCollisionY(Gear: PGear; Dir: LongInt): boolean; |
285 |
var x, y, i: LongInt; |
|
68 | 286 |
begin |
351 | 287 |
y:= hwRound(Gear^.Y); |
288 |
if Dir < 0 then y:= y - Gear^.Radius |
|
289 |
else y:= y + Gear^.Radius; |
|
1753 | 290 |
if (y and LAND_HEIGHT_MASK) = 0 then |
68 | 291 |
begin |
351 | 292 |
x:= hwRound(Gear^.X) - Gear^.Radius + 1; |
293 |
i:= x + Gear^.Radius * 2 - 2; |
|
68 | 294 |
repeat |
1753 | 295 |
if (x and LAND_WIDTH_MASK) = 0 then |
1966 | 296 |
if Land[y, x] > 255 then exit(true); |
68 | 297 |
inc(x) |
351 | 298 |
until (x > i); |
299 |
end; |
|
300 |
TestCollisionY:= false |
|
68 | 301 |
end; |
302 |
||
371 | 303 |
function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt): boolean; |
4 | 304 |
begin |
498 | 305 |
Gear^.X:= Gear^.X + int2hwFloat(ShiftX); |
306 |
Gear^.Y:= Gear^.Y + int2hwFloat(ShiftY); |
|
351 | 307 |
TestCollisionYwithXYShift:= TestCollisionYwithGear(Gear, Dir); |
498 | 308 |
Gear^.X:= Gear^.X - int2hwFloat(ShiftX); |
309 |
Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY) |
|
4 | 310 |
end; |
311 |
||
312 |
end. |