hedgewars/uCollisions.pas
author unc0rr
Mon, 22 Aug 2005 13:35:41 +0000
changeset 1 30f2d1037d5d
child 4 bcbd7adb4e4b
permissions -rw-r--r--
Add current sources. hw, hwserv and runhelper are compilable under Windows and *nix with FreePascal (and use -Od option) and run well on these OSes Hedge.dpr can be run only in Windows... to be ported
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     1
(*
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     2
 * Hedgewars, a worms-like game
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     3
 * Copyright (c) 2005 Andrey Korotaev <unC0Rr@gmail.com>
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     4
 *
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     5
 * Distributed under the terms of the BSD-modified licence:
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     6
 *
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     8
 * of this software and associated documentation files (the "Software"), to deal
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     9
 * with the Software without restriction, including without limitation the
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    10
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    11
 * sell copies of the Software, and to permit persons to whom the Software is
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    12
 * furnished to do so, subject to the following conditions:
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    13
 *
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    14
 * 1. Redistributions of source code must retain the above copyright notice,
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    15
 *    this list of conditions and the following disclaimer.
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    16
 * 2. Redistributions in binary form must reproduce the above copyright notice,
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    17
 *    this list of conditions and the following disclaimer in the documentation
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    18
 *    and/or other materials provided with the distribution.
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    19
 * 3. The name of the author may not be used to endorse or promote products
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    20
 *    derived from this software without specific prior written permission.
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    21
 *
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    22
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    23
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    24
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    25
 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    26
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    27
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    28
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    29
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    30
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    31
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    32
 *)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    33
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    34
unit uCollisions;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    35
interface
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    36
uses uGears;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    37
{$INCLUDE options.inc}
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    38
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    39
type TCollisionEntry = record
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    40
                       X, Y, HWidth, HHeight: integer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    41
                       cGear: PGear;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    42
                       end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    43
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    44
procedure AddGearCR(Gear: PGear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    45
procedure UpdateCR(NewX, NewY: integer; Index: Longword);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    46
procedure DeleteCR(Gear: PGear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    47
function  CheckGearsCollision(Gear: PGear; Dir: integer; forX: boolean): boolean;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    48
function  HHTestCollisionYwithGear(Gear: PGear; Dir: integer): boolean;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    49
function TestCollisionXwithGear(Gear: PGear; Dir: integer): boolean;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    50
function TestCollisionYwithGear(Gear: PGear; Dir: integer): boolean;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    51
function TestCollisionXwithXYShift(Gear: PGear; ShiftX, ShiftY: integer; Dir: integer): boolean;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    52
function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: integer; Dir: integer): boolean;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    53
function TestCollisionY(Gear: PGear; Dir: integer): boolean;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    54
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    55
implementation
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    56
uses uMisc, uConsts, uLand;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    57
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    58
const MAXRECTSINDEX = 255;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    59
var Count: Longword = 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    60
    crects: array[0..MAXRECTSINDEX] of TCollisionEntry;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    61
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    62
procedure AddGearCR(Gear: PGear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    63
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    64
{$IFDEF DEBUGFILE}AddFileLog('AddCR crects count = ' + inttostr(Count));{$ENDIF}
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    65
TryDo(Count <= MAXRECTSINDEX, 'Collision rects array overflow', true);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    66
with crects[Count] do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    67
     begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    68
     X:= round(Gear.X);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    69
     Y:= round(Gear.Y);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    70
     HWidth:= Gear.HalfWidth;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    71
     HHeight:= Gear.HalfHeight;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    72
     cGear:= Gear
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    73
     end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    74
Gear.CollIndex:= Count;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    75
inc(Count)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    76
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    77
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    78
procedure UpdateCR(NewX, NewY: integer; Index: Longword);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    79
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    80
with crects[Index] do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    81
     begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    82
     X:= NewX;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    83
     Y:= NewY
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    84
     end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    85
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    86
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    87
procedure DeleteCR(Gear: PGear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    88
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    89
{$IFDEF DEBUGFILE}AddFileLog('DelCR crects count = ' + inttostr(Count) + ' deleting ' + inttostr(Gear.CollIndex));{$ENDIF}
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    90
if Gear.CollIndex < Pred(Count) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    91
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    92
   crects[Gear.CollIndex]:= crects[Pred(Count)];
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    93
   crects[Gear.CollIndex].cGear.CollIndex:= Gear.CollIndex
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    94
   end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    95
Gear.CollIndex:= High(Longword);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    96
dec(Count)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    97
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    98
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    99
function CheckGearsCollision(Gear: PGear; Dir: integer; forX: boolean): boolean;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   100
var x1, x2, y1, y2: integer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   101
    i: Longword;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   102
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   103
x1:= round(Gear.X);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   104
y1:= round(Gear.Y);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   105
{if (Gear.State and gstOutOfHH) = 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   106
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   107
   p:= PHedgehog(Gear.Hedgehog)^.Gear;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   108
   if (p <> nil) and
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   109
        ((x1 + Gear.HalfWidth < round(p.X) - p.HalfWidth)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   110
      or (x1 - Gear.HalfWidth > round(p.X) + p.HalfWidth)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   111
      or (y1 - Gear.HalfHeight > round(p.Y) + p.HalfHeight)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   112
      or (y1 + Gear.HalfHeight < round(p.Y) - p.HalfHeight)) then Gear.State:= Gear.State or gstOutOfHH;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   113
   end; }
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   114
Result:= false;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   115
if forX then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   116
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   117
   x1:= x1 + Dir*Gear.HalfWidth;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   118
   x2:= x1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   119
   y2:= y1 + Gear.HalfHeight - 1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   120
   y1:= y1 - Gear.HalfHeight + 1
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   121
   end else
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   122
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   123
   y1:= y1 + Dir*Gear.HalfHeight;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   124
   y2:= y1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   125
   x2:= x1 + Gear.HalfWidth - 1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   126
   x1:= x1 - Gear.HalfWidth + 1
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   127
   end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   128
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   129
for i:= 0 to Pred(Count) do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   130
   with crects[i] do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   131
      if  (Gear.CollIndex <> i)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   132
//      if ((p.Kind = gtHedgehog) and ((p.Hedgehog <> Gear.Hedgehog) or ((Gear.State and gstOutOfHH) <> 0)))
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   133
         and (x1 <= X + HWidth)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   134
         and (x2 >= X - HWidth)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   135
         and (y1 <= Y + HHeight)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   136
         and (y2 >= Y - HHeight) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   137
             begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   138
             Result:= true;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   139
             exit
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   140
             end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   141
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   142
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   143
function HHTestCollisionYwithGear(Gear: PGear; Dir: integer): boolean;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   144
var x, y, i: integer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   145
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   146
Result:= false;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   147
y:= round(Gear.Y);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   148
if Dir < 0 then y:= y - Gear.HalfHeight
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   149
           else y:= y + Gear.HalfHeight;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   150
           
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   151
if ((y - Dir) and $FFFFFC00) = 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   152
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   153
   x:= round(Gear.X);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   154
   if (((x - Gear.HalfWidth) and $FFFFF800) = 0)and(Land[y - Dir, x - Gear.HalfWidth] <> 0)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   155
    or(((x + Gear.HalfWidth) and $FFFFF800) = 0)and(Land[y - Dir, x + Gear.HalfWidth] <> 0) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   156
      begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   157
      Result:= true;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   158
      exit
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   159
      end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   160
    end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   161
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   162
if (y and $FFFFFC00) = 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   163
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   164
   x:= round(Gear.X) - Gear.HalfWidth + 1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   165
   i:= x + Gear.HalfWidth * 2 - 2;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   166
   repeat
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   167
     if (x and $FFFFF800) = 0 then Result:= Land[y, x]<>0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   168
     inc(x)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   169
   until (x > i) or Result;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   170
   if Result then exit;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   171
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   172
   Result:= CheckGearsCollision(Gear, Dir, false)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   173
   end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   174
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   175
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   176
function TestCollisionXwithGear(Gear: PGear; Dir: integer): boolean;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   177
var x, y, i: integer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   178
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   179
Result:= false;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   180
x:= round(Gear.X);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   181
if Dir < 0 then x:= x - Gear.HalfWidth
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   182
           else x:= x + Gear.HalfWidth;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   183
if (x and $FFFFF800) = 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   184
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   185
   y:= round(Gear.Y) - Gear.HalfHeight + 1; {*}
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   186
   i:= y + Gear.HalfHeight * 2 - 2;         {*}
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   187
   repeat
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   188
     if (y and $FFFFFC00) = 0 then Result:= Land[y, x]<>0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   189
     inc(y)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   190
   until (y > i) or Result;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   191
   if Result then exit;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   192
   Result:= CheckGearsCollision(Gear, Dir, true)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   193
   end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   194
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   195
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   196
function TestCollisionXwithXYShift(Gear: PGear; ShiftX, ShiftY: integer; Dir: integer): boolean;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   197
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   198
Gear.X:= Gear.X + ShiftX;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   199
Gear.Y:= Gear.Y + ShiftY;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   200
Result:= TestCollisionXwithGear(Gear, Dir);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   201
Gear.X:= Gear.X - ShiftX;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   202
Gear.Y:= Gear.Y - ShiftY
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   203
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   204
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   205
function TestCollisionYwithGear(Gear: PGear; Dir: integer): boolean;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   206
var x, y, i: integer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   207
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   208
Result:= false;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   209
y:= round(Gear.Y);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   210
if Dir < 0 then y:= y - Gear.HalfHeight
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   211
           else y:= y + Gear.HalfHeight;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   212
if (y and $FFFFFC00) = 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   213
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   214
   x:= round(Gear.X) - Gear.HalfWidth + 1;    {*}
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   215
   i:= x + Gear.HalfWidth * 2 - 2;            {*}
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   216
   repeat
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   217
     if (x and $FFFFF800) = 0 then Result:= Land[y, x]<>0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   218
     inc(x)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   219
   until (x > i) or Result;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   220
   if Result then exit;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   221
   Result:= CheckGearsCollision(Gear, Dir, false);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   222
   end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   223
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   224
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   225
function TestCollisionY(Gear: PGear; Dir: integer): boolean;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   226
var x, y, i: integer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   227
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   228
Result:= false;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   229
y:= round(Gear.Y);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   230
if Dir < 0 then y:= y - Gear.HalfHeight
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   231
           else y:= y + Gear.HalfHeight;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   232
if (y and $FFFFFC00) = 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   233
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   234
   x:= round(Gear.X) - Gear.HalfWidth + 1;    {*}
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   235
   i:= x + Gear.HalfWidth * 2 - 2;            {*}
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   236
   repeat
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   237
     if (x and $FFFFF800) = 0 then Result:= Land[y, x]<>0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   238
     inc(x)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   239
   until (x > i) or Result;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   240
   end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   241
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   242
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   243
function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: integer; Dir: integer): boolean;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   244
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   245
Gear.X:= Gear.X + ShiftX;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   246
Gear.Y:= Gear.Y + ShiftY;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   247
Result:= TestCollisionYwithGear(Gear, Dir);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   248
Gear.X:= Gear.X - ShiftX;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   249
Gear.Y:= Gear.Y - ShiftY
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   250
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   251
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   252
end.