author | unc0rr |
Sun, 24 Feb 2008 20:00:31 +0000 | |
changeset 789 | 3d976d2579eb |
parent 542 | ec26095f1bed |
child 838 | 1faae19f2116 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
393 | 3 |
* Copyright (c) 2005-2007 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 |
||
19 |
unit uCollisions; |
|
20 |
interface |
|
351 | 21 |
uses uGears, uFloat; |
4 | 22 |
{$INCLUDE options.inc} |
53 | 23 |
const cMaxGearArrayInd = 255; |
4 | 24 |
|
70 | 25 |
type PGearArray = ^TGearArray; |
53 | 26 |
TGearArray = record |
27 |
ar: array[0..cMaxGearArrayInd] of PGear; |
|
28 |
Count: Longword |
|
29 |
end; |
|
4 | 30 |
|
53 | 31 |
procedure AddGearCI(Gear: PGear); |
32 |
procedure DeleteCI(Gear: PGear); |
|
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
33 |
|
53 | 34 |
function CheckGearsCollision(Gear: PGear): PGearArray; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
35 |
|
371 | 36 |
function TestCollisionXwithGear(Gear: PGear; Dir: LongInt): boolean; |
37 |
function TestCollisionYwithGear(Gear: PGear; Dir: LongInt): boolean; |
|
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
38 |
|
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
39 |
function TestCollisionXKick(Gear: PGear; Dir: LongInt): boolean; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
40 |
function TestCollisionYKick(Gear: PGear; Dir: LongInt): boolean; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
41 |
|
371 | 42 |
function TestCollisionY(Gear: PGear; Dir: LongInt): boolean; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
43 |
|
498 | 44 |
function TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt): boolean; |
371 | 45 |
function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt): boolean; |
4 | 46 |
|
47 |
implementation |
|
511 | 48 |
uses uMisc, uConsts, uLand, uLandGraphics, uConsole; |
4 | 49 |
|
53 | 50 |
type TCollisionEntry = record |
371 | 51 |
X, Y, Radius: LongInt; |
53 | 52 |
cGear: PGear; |
53 |
end; |
|
351 | 54 |
|
4 | 55 |
const MAXRECTSINDEX = 255; |
56 |
var Count: Longword = 0; |
|
53 | 57 |
cinfos: array[0..MAXRECTSINDEX] of TCollisionEntry; |
58 |
ga: TGearArray; |
|
4 | 59 |
|
53 | 60 |
procedure AddGearCI(Gear: PGear); |
61 |
begin |
|
511 | 62 |
if Gear^.CollisionIndex >= 0 then exit; |
4 | 63 |
TryDo(Count <= MAXRECTSINDEX, 'Collision rects array overflow', true); |
53 | 64 |
with cinfos[Count] do |
4 | 65 |
begin |
351 | 66 |
X:= hwRound(Gear^.X); |
67 |
Y:= hwRound(Gear^.Y); |
|
68 |
Radius:= Gear^.Radius; |
|
511 | 69 |
ChangeRoundInLand(X, Y, Radius - 1, true); |
4 | 70 |
cGear:= Gear |
71 |
end; |
|
511 | 72 |
Gear^.CollisionIndex:= Count; |
4 | 73 |
inc(Count) |
74 |
end; |
|
75 |
||
53 | 76 |
procedure DeleteCI(Gear: PGear); |
4 | 77 |
begin |
511 | 78 |
if Gear^.CollisionIndex >= 0 then |
53 | 79 |
begin |
511 | 80 |
with cinfos[Gear^.CollisionIndex] do |
81 |
ChangeRoundInLand(X, Y, Radius - 1, false); |
|
82 |
cinfos[Gear^.CollisionIndex]:= cinfos[Pred(Count)]; |
|
83 |
cinfos[Gear^.CollisionIndex].cGear^.CollisionIndex:= Gear^.CollisionIndex; |
|
84 |
Gear^.CollisionIndex:= -1; |
|
53 | 85 |
dec(Count) |
86 |
end; |
|
4 | 87 |
end; |
88 |
||
53 | 89 |
function CheckGearsCollision(Gear: PGear): PGearArray; |
371 | 90 |
var mx, my: LongInt; |
4 | 91 |
i: Longword; |
351 | 92 |
Result: PGearArray; |
4 | 93 |
begin |
53 | 94 |
Result:= @ga; |
95 |
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
|
96 |
if Count = 0 then exit; |
351 | 97 |
mx:= hwRound(Gear^.X); |
98 |
my:= hwRound(Gear^.Y); |
|
4 | 99 |
|
100 |
for i:= 0 to Pred(Count) do |
|
53 | 101 |
with cinfos[i] do |
102 |
if (Gear <> cGear) and |
|
511 | 103 |
(sqr(mx - x) + sqr(my - y) <= sqr(Radius + Gear^.Radius)) then |
4 | 104 |
begin |
53 | 105 |
ga.ar[ga.Count]:= cinfos[i].cGear; |
106 |
inc(ga.Count) |
|
4 | 107 |
end; |
351 | 108 |
CheckGearsCollision:= Result |
4 | 109 |
end; |
110 |
||
371 | 111 |
function TestCollisionXwithGear(Gear: PGear; Dir: LongInt): boolean; |
112 |
var x, y, i: LongInt; |
|
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
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 |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
122 |
end else |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
123 |
TestWord:= COLOR_LAND - 1 |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
124 |
else TestWord:= 0; |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
125 |
|
351 | 126 |
x:= hwRound(Gear^.X); |
127 |
if Dir < 0 then x:= x - Gear^.Radius |
|
128 |
else x:= x + Gear^.Radius; |
|
4 | 129 |
if (x and $FFFFF800) = 0 then |
130 |
begin |
|
351 | 131 |
y:= hwRound(Gear^.Y) - Gear^.Radius + 1; |
132 |
i:= y + Gear^.Radius * 2 - 2; |
|
4 | 133 |
repeat |
351 | 134 |
if (y and $FFFFFC00) = 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 |
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
154 |
TestWord:= COLOR_LAND - 1 |
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; |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
160 |
if (y and $FFFFFC00) = 0 then |
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 |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
504
diff
changeset
|
165 |
if (x and $FFFFF800) = 0 then |
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; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
181 |
if (x and $FFFFF800) = 0 then |
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 |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
186 |
if (y and $FFFFFC00) = 0 then |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
187 |
if Land[y, x] = COLOR_LAND 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; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
197 |
mx:= hwRound(Gear^.X); |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
198 |
my:= hwRound(Gear^.Y); |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
199 |
|
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
200 |
for i:= 0 to Pred(Count) do |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
201 |
with cinfos[i] do |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
202 |
if (Gear <> cGear) and |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
203 |
(sqr(mx - x) + sqr(my - y) <= sqr(Radius + Gear^.Radius)) and |
517 | 204 |
((mx > x) xor (Dir > 0)) then |
521 | 205 |
if (cGear^.Kind in [gtHedgehog, gtMine]) then |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
206 |
begin |
521 | 207 |
with cGear^ do |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
208 |
begin |
536 | 209 |
dX:= Gear^.dX; |
542 | 210 |
dY:= Gear^.dY * _0_5; |
521 | 211 |
State:= State or gstMoving; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
212 |
Active:= true |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
213 |
end; |
521 | 214 |
DeleteCI(cGear); |
538 | 215 |
exit(false) |
216 |
end |
|
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
217 |
end |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
218 |
end; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
219 |
|
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
220 |
function TestCollisionYKick(Gear: PGear; Dir: LongInt): boolean; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
221 |
var x, y, mx, my, i: LongInt; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
222 |
flag: boolean; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
223 |
begin |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
224 |
flag:= false; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
225 |
y:= hwRound(Gear^.Y); |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
226 |
if Dir < 0 then y:= y - Gear^.Radius |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
227 |
else y:= y + Gear^.Radius; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
228 |
if (y and $FFFFFC00) = 0 then |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
229 |
begin |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
230 |
x:= hwRound(Gear^.X) - Gear^.Radius + 1; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
231 |
i:= x + Gear^.Radius * 2 - 2; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
232 |
repeat |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
233 |
if (x and $FFFFF800) = 0 then |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
234 |
if Land[y, x] > 0 then |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
235 |
if Land[y, x] = COLOR_LAND then exit(true) |
536 | 236 |
else if Land[y, x] <> 0 then flag:= true; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
237 |
inc(x) |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
238 |
until (x > i); |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
239 |
end; |
538 | 240 |
TestCollisionYKick:= flag; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
241 |
|
536 | 242 |
if flag then |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
243 |
begin |
536 | 244 |
if hwAbs(Gear^.dX) < cHHKick then exit(true); |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
245 |
mx:= hwRound(Gear^.X); |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
246 |
my:= hwRound(Gear^.Y); |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
247 |
|
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
248 |
for i:= 0 to Pred(Count) do |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
249 |
with cinfos[i] do |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
250 |
if (Gear <> cGear) and |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
251 |
(sqr(mx - x) + sqr(my - y) <= sqr(Radius + Gear^.Radius)) and |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
252 |
((my > y) xor (Dir > 0)) then |
521 | 253 |
if (cGear^.Kind in [gtHedgehog, gtMine]) then |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
254 |
begin |
521 | 255 |
with cGear^ do |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
256 |
begin |
542 | 257 |
dX:= Gear^.dX * _0_5; |
258 |
dY:= Gear^.dY; |
|
521 | 259 |
State:= State or gstMoving; |
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
260 |
Active:= true |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
261 |
end; |
521 | 262 |
DeleteCI(cGear); |
538 | 263 |
exit(false) |
264 |
end |
|
513
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
265 |
end |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
266 |
end; |
69e06d710d46
Moving hedgehog could get another hedgehog moving forward
unc0rr
parents:
511
diff
changeset
|
267 |
|
498 | 268 |
function TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt): boolean; |
4 | 269 |
begin |
351 | 270 |
Gear^.X:= Gear^.X + ShiftX; |
498 | 271 |
Gear^.Y:= Gear^.Y + int2hwFloat(ShiftY); |
351 | 272 |
TestCollisionXwithXYShift:= TestCollisionXwithGear(Gear, Dir); |
273 |
Gear^.X:= Gear^.X - ShiftX; |
|
498 | 274 |
Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY) |
4 | 275 |
end; |
276 |
||
371 | 277 |
function TestCollisionY(Gear: PGear; Dir: LongInt): boolean; |
278 |
var x, y, i: LongInt; |
|
68 | 279 |
begin |
351 | 280 |
y:= hwRound(Gear^.Y); |
281 |
if Dir < 0 then y:= y - Gear^.Radius |
|
282 |
else y:= y + Gear^.Radius; |
|
68 | 283 |
if (y and $FFFFFC00) = 0 then |
284 |
begin |
|
351 | 285 |
x:= hwRound(Gear^.X) - Gear^.Radius + 1; |
286 |
i:= x + Gear^.Radius * 2 - 2; |
|
68 | 287 |
repeat |
351 | 288 |
if (x and $FFFFF800) = 0 then |
289 |
if Land[y, x] = COLOR_LAND then exit(true); |
|
68 | 290 |
inc(x) |
351 | 291 |
until (x > i); |
292 |
end; |
|
293 |
TestCollisionY:= false |
|
68 | 294 |
end; |
295 |
||
371 | 296 |
function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt): boolean; |
4 | 297 |
begin |
498 | 298 |
Gear^.X:= Gear^.X + int2hwFloat(ShiftX); |
299 |
Gear^.Y:= Gear^.Y + int2hwFloat(ShiftY); |
|
351 | 300 |
TestCollisionYwithXYShift:= TestCollisionYwithGear(Gear, Dir); |
498 | 301 |
Gear^.X:= Gear^.X - int2hwFloat(ShiftX); |
302 |
Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY) |
|
4 | 303 |
end; |
304 |
||
305 |
end. |