hedgewars/HHHandlers.inc
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) 2004, 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
procedure doStepHedgehog(Gear: PGear); forward;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    35
////////////////////////////////////////////////////////////////////////////////
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    36
procedure doStepHedgehogDriven(Gear: PGear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    37
const StepTicks: LongWord = 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    38
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    39
if isinMultiShoot and (Gear.Damage = 0) then exit;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    40
AllInactive:= false;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    41
if (TurnTimeLeft = 0) or (Gear.Damage > 0) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    42
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    43
   if ((Gear.State and (gstMoving or gstFalling)) = 0)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    44
      and (CurAmmoGear = nil) then Gear.dX:= 0.0000001 * Sign(Gear.dX);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    45
   {$WARNINGS OFF}Gear.State:= Gear.State and not gstHHDriven;{$WARNINGS ON}
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    46
   exit
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    47
   end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    48
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    49
if CurAmmoGear <> nil then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    50
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    51
   CurAmmoGear.Message:= Gear.Message;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    52
   exit
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    53
   end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    54
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    55
if (Gear.Message and gm_Attack)<>0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    56
   if (Gear.State and (gstAttacked or gstHHChooseTarget) = 0)and(CurAmmoGear = nil) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    57
      with PHedgehog(Gear.Hedgehog)^ do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    58
//        if ((Gear.State and gstFalling  ) = 0)or((Ammo[CurSlot, CurAmmo].Propz and ammoprop_AttackInFall) <> 0)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    59
//        and((Gear.State and gstHHJumping) = 0)or((Ammo[CurSlot, CurAmmo].Propz and ammoprop_AttackInJump) <> 0) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    60
            begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    61
            Gear.State:= Gear.State or gstAttacking;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    62
            if Gear.Power = cMaxPower then ParseCommand('-attack')
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    63
               else begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    64
               if (Ammo[CurSlot, CurAmmo].Propz and ammoprop_Power) = 0 then Gear.Power:= cMaxPower
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    65
                  else begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    66
                  if Gear.Power = 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    67
                     begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    68
                     AttackBar:= CurrentTeam.AttackBar;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    69
                     PlaySound(sndThrowPowerUp)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    70
                     end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    71
                  inc(Gear.Power)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    72
                  end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    73
               end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    74
            end else Gear.Message:= Gear.Message and not gm_Attack;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    75
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    76
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    77
if (Gear.State and gstFalling) <> 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    78
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    79
   if ((Gear.Message and gm_HJump) <> 0) and ((Gear.State and gstHHJumping) <> 0) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    80
      if (abs(Gear.dX) < 0.0000002) and (Gear.dY < -0.02) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    81
         begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    82
         Gear.dY:= -0.25;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    83
         Gear.dX:= Sign(Gear.dX) * 0.02
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    84
         end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    85
   Gear.Message:= Gear.Message and not (gm_LJump or gm_HJump);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    86
   if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then Gear.dX:= 0.0000001 * Sign(Gear.dX);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    87
   Gear.X:= Gear.X + Gear.dX;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    88
   Gear.dY:= Gear.dY + cGravity;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    89
   if (Gear.dY < 0)and TestCollisionYwithGear(Gear, -1) then Gear.dY:= 0; 
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    90
   Gear.Y:= Gear.Y + Gear.dY;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    91
   if (Gear.dY >= 0)and HHTestCollisionYwithGear(Gear, 1) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    92
      begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    93
      CheckHHDamage(Gear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    94
      if ((abs(Gear.dX) + abs(Gear.dY)) < 0.55)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    95
         and ((Gear.State and gstHHJumping) <> 0) then Gear.dX:= 0.0000001 * Sign(Gear.dX);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    96
      Gear.State:= Gear.State and not (gstFalling or gstHHJumping);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    97
      StepTicks:= 200;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    98
      Gear.dY:= 0
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    99
      end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   100
   CheckGearDrowning(Gear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   101
   exit
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   102
   end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   103
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   104
if StepTicks > 0 then dec(StepTicks);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   105
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   106
if ((Gear.State and (gstMoving or gstFalling)) = 0) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   107
   if (Gear.Message and gm_Up    )<>0 then if Gear.Angle > 0         then dec(Gear.Angle)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   108
      else else
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   109
   if (Gear.Message and gm_Down  )<>0 then if Gear.Angle < cMaxAngle then inc(Gear.Angle);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   110
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   111
if ((Gear.State and (gstAttacking or gstMoving or gstFalling)) = 0)and(StepTicks = 0) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   112
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   113
   if ((Gear.Message and gm_LJump )<>0) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   114
      begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   115
      Gear.Message:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   116
      if not HHTestCollisionYwithGear(Gear, -1) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   117
         if not TestCollisionXwithXYShift(Gear, 0, -2, Sign(Gear.dX)) then Gear.Y:= Gear.Y - 2 else
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   118
         if not TestCollisionXwithXYShift(Gear, 0, -1, Sign(Gear.dX)) then Gear.Y:= Gear.Y - 1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   119
      if not (TestCollisionXwithGear(Gear, Sign(Gear.dX))
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   120
         or   HHTestCollisionYwithGear(Gear, -1)) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   121
         begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   122
         Gear.dY:= -0.15;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   123
         Gear.dX:= Sign(Gear.dX) * 0.15;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   124
         Gear.State:= Gear.State or gstFalling or gstHHJumping;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   125
         exit
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   126
         end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   127
      end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   128
   if ((Gear.Message and gm_HJump )<>0) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   129
      begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   130
      Gear.Message:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   131
      if not HHTestCollisionYwithGear(Gear, -1) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   132
         begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   133
         Gear.dY:= -0.20;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   134
         Gear.dX:= 0.0000001 * Sign(Gear.dX);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   135
         Gear.X:= Gear.X - Sign(Gear.dX)*0.00008; // компенсация сдвига %)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   136
         Gear.State:= Gear.State or gstFalling or gstHHJumping;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   137
         exit
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   138
         end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   139
      end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   140
   if (Gear.Message and gm_Left  )<>0 then Gear.dX:= -1.0 else
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   141
   if (Gear.Message and gm_Right )<>0 then Gear.dX:=  1.0 else exit;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   142
   PHedgehog(Gear.Hedgehog).visStepPos:= (PHedgehog(Gear.Hedgehog).visStepPos + 1) and 7;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   143
   StepTicks:= 40;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   144
   if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   145
      begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   146
      if not (TestCollisionXwithXYShift(Gear, 0, -6, Sign(Gear.dX))
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   147
         or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   148
      if not (TestCollisionXwithXYShift(Gear, 0, -5, Sign(Gear.dX))
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   149
         or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   150
      if not (TestCollisionXwithXYShift(Gear, 0, -4, Sign(Gear.dX))
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   151
         or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   152
      if not (TestCollisionXwithXYShift(Gear, 0, -3, Sign(Gear.dX))
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   153
         or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   154
      if not (TestCollisionXwithXYShift(Gear, 0, -2, Sign(Gear.dX))
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   155
         or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   156
      if not (TestCollisionXwithXYShift(Gear, 0, -1, Sign(Gear.dX))
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   157
         or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   158
      end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   159
   if not TestCollisionXwithGear(Gear, Sign(Gear.dX)) then Gear.X:= Gear.X + Gear.dX;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   160
   
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   161
   if not HHTestCollisionYwithGear(Gear, 1) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   162
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   163
   Gear.Y:= Gear.Y + 1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   164
   if not HHTestCollisionYwithGear(Gear, 1) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   165
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   166
   Gear.Y:= Gear.Y + 1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   167
   if not HHTestCollisionYwithGear(Gear, 1) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   168
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   169
   Gear.Y:= Gear.Y + 1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   170
   if not HHTestCollisionYwithGear(Gear, 1) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   171
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   172
   Gear.Y:= Gear.Y + 1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   173
   if not HHTestCollisionYwithGear(Gear, 1) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   174
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   175
   Gear.Y:= Gear.Y + 1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   176
   if not HHTestCollisionYwithGear(Gear, 1) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   177
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   178
   Gear.Y:= Gear.Y + 1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   179
   if not HHTestCollisionYwithGear(Gear, 1) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   180
      begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   181
      Gear.Y:= Gear.Y - 6;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   182
      Gear.dY:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   183
      Gear.dX:= 0.0000001 * Sign(Gear.dX);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   184
      Gear.State:= Gear.State or gstFalling
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   185
      end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   186
   SetAllHHToActive
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   187
   end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   188
   end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   189
   end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   190
   end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   191
   end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   192
   end
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
////////////////////////////////////////////////////////////////////////////////
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   197
procedure doStepHedgehogFree(Gear: PGear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   198
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   199
if not HHTestCollisionYwithGear(Gear, 1) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   200
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   201
   if (Gear.dY < 0) and HHTestCollisionYwithGear(Gear, -1) then Gear.dY:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   202
   Gear.State:= Gear.State or gstFalling or gstMoving;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   203
   Gear.dY:= Gear.dY + cGravity
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   204
   end else begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   205
   CheckHHDamage(Gear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   206
   if Gear.dY > 0    then Gear.dY:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   207
   Gear.State:= Gear.State and not gstFalling;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   208
   if ((Gear.State and gstMoving) <> 0) then Gear.dX:= Gear.dX * Gear.Friction
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   209
   end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   210
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   211
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   212
if (Gear.State and gstMoving) <> 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   213
   if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   214
      if ((Gear.State and gstFalling) = 0) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   215
         if abs(Gear.dX) > 0.01 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   216
            if not TestCollisionXwithXYShift(Gear, 0, -1, Sign(Gear.dX)) then begin Gear.dX:= Gear.dX * 0.9; Gear.Y:= Gear.Y - 1 end else
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   217
            if not TestCollisionXwithXYShift(Gear, 0, -2, Sign(Gear.dX)) then begin Gear.dX:= Gear.dX * 0.9; Gear.Y:= Gear.Y - 2 end else
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   218
            if not TestCollisionXwithXYShift(Gear, 0, -3, Sign(Gear.dX)) then begin Gear.dX:= Gear.dX * 0.9; Gear.Y:= Gear.Y - 3 end else
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   219
            if not TestCollisionXwithXYShift(Gear, 0, -4, Sign(Gear.dX)) then begin Gear.dX:= Gear.dX * 0.9; Gear.Y:= Gear.Y - 4 end else
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   220
            if not TestCollisionXwithXYShift(Gear, 0, -5, Sign(Gear.dX)) then begin Gear.dX:= Gear.dX * 0.3; Gear.Y:= Gear.Y - 5 end else
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   221
            if abs(Gear.dX) > 0.02 then Gear.dX:= -0.5 * Gear.dX
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   222
                                   else begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   223
                                        Gear.State:= Gear.State and not gstMoving;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   224
                                        Gear.dX:= 0.0000001 * Sign(Gear.dX)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   225
                                        end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   226
                                   else begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   227
                                        Gear.State:= Gear.State and not gstMoving;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   228
                                        Gear.dX:= 0.0000001 * Sign(Gear.dX)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   229
                                        end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   230
         else Gear.dX:= -0.8 * Gear.dX;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   231
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   232
if ((Gear.State and gstFalling) = 0)and
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   233
   (sqr(Gear.dX) + sqr(Gear.dY) < 0.0008) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   234
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   235
   Gear.State:= Gear.State and not gstMoving;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   236
   Gear.dX:= 0.0000001 * Sign(Gear.dX);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   237
   Gear.dY:= 0
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   238
   end else Gear.State:= Gear.State or      gstMoving;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   239
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   240
if (Gear.State and gstMoving) <> 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   241
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   242
   Gear.X:= Gear.X + Gear.dX;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   243
   Gear.Y:= Gear.Y + Gear.dY
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   244
   end else
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   245
   if Gear.Health = 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   246
      begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   247
      if AllInactive then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   248
         begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   249
         doMakeExplosion(round(Gear.X), round(Gear.Y), 30, EXPLAutoSound);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   250
         AddGear(round(Gear.X), round(Gear.Y), gtGrave, 0).Hedgehog:= Gear.Hedgehog;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   251
         DeleteGear(Gear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   252
         SetAllToActive
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   253
         end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   254
      AllInactive:= false;  (* почему этого тут не было? *)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   255
      exit
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   256
      end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   257
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   258
AllInactive:= false;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   259
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   260
if (not CheckGearDrowning(Gear)) and
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   261
   ((Gear.State and gstMoving) = 0) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   262
      begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   263
      Gear.State:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   264
      Gear.Active:= false;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   265
      AddGearCR(Gear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   266
      exit
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   267
      end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   268
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   269
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   270
////////////////////////////////////////////////////////////////////////////////
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   271
procedure doStepHedgehog(Gear: PGear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   272
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   273
if (Gear.Message and gm_Destroy) <> 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   274
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   275
   DeleteGear(Gear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   276
   exit
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   277
   end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   278
if Gear.CollIndex < High(Longword) then DeleteCR(Gear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   279
if (Gear.State and gstHHDriven) = 0 then doStepHedgehogFree(Gear)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   280
                                    else doStepHedgehogDriven(Gear)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   281
end;