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