hedgewars/GSHandlers.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 doStepDrowningGear(Gear: PGear); forward;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    35
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    36
function CheckGearDrowning(Gear: PGear): boolean;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    37
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    38
Result:= Gear.Y + Gear.HalfHeight >= cWaterLine;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    39
if Result then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    40
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    41
   Gear.State:= gstDrowning;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    42
   Gear.doStep:= doStepDrowningGear;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    43
   PlaySound(sndSplash)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    44
   end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    45
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    46
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    47
procedure CheckCollision(Gear: PGear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    48
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    49
if TestCollisionXwithGear(Gear, Sign(Gear.X)) or TestCollisionYwithGear(Gear, Sign(Gear.Y))
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    50
   then Gear.State:= Gear.State or      gstCollision
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    51
   else Gear.State:= Gear.State and not gstCollision
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    52
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    53
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    54
procedure CheckHHDamage(Gear: PGear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    55
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    56
if Gear.dY > 0.35 then Gear.Damage:= Gear.Damage + round(25 * (abs(Gear.dY) - 0.35));
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    57
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    58
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    59
////////////////////////////////////////////////////////////////////////////////
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    60
////////////////////////////////////////////////////////////////////////////////
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    61
procedure CalcRotationDirAngle(Gear: PGear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    62
var dAngle: real;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    63
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    64
dAngle:= (abs(Gear.dX) + abs(Gear.dY))*0.1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    65
if Gear.dX >= 0 then Gear.DirAngle:= Gear.DirAngle + dAngle
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    66
                else Gear.DirAngle:= Gear.DirAngle - dAngle;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    67
if Gear.DirAngle < 0 then Gear.DirAngle:= Gear.DirAngle + 16
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    68
else if Gear.DirAngle >= 16 then Gear.DirAngle:= Gear.DirAngle - 16
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    69
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    70
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    71
////////////////////////////////////////////////////////////////////////////////
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    72
procedure doStepDrowningGear(Gear: PGear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    73
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    74
AllInactive:= false;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    75
Gear.Y:= Gear.Y + cDrownSpeed;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    76
if round(Gear.Y) > Gear.HalfHeight + cWaterLine + 48 + cVisibleWater then DeleteGear(Gear)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    77
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    78
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    79
////////////////////////////////////////////////////////////////////////////////
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    80
procedure doStepFallingGear(Gear: PGear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    81
var b: boolean;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    82
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    83
if TestCollisionYwithGear(Gear, Sign(Gear.dY)) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    84
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    85
   Gear.dX:=   Gear.dX * Gear.Friction;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    86
   Gear.dY:= - Gear.dY * Gear.Elasticity;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    87
   b:= false
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    88
   end else b:= true;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    89
if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    90
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    91
   Gear.dX:= - Gear.dX * Gear.Elasticity;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    92
//   Gear.dY:=   Gear.dY;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    93
   b:= false
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    94
   end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    95
if b then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    96
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    97
   Gear.dY:= Gear.dY + cGravity;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    98
   Gear.State:= Gear.State and not gstCollision
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    99
   end else
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   100
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   101
   if sqr(Gear.dX) + sqr(Gear.dY) < 0.00001 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   102
      if (Gear.Timer = 0) then Gear.Active:= false
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   103
                          else begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   104
                          Gear.dX:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   105
                          Gear.dY:= 0
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   106
                          end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   107
   Gear.State:= Gear.State or gstCollision
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   108
   end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   109
Gear.X:= Gear.X + Gear.dX;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   110
Gear.Y:= Gear.Y + Gear.dY;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   111
CheckGearDrowning(Gear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   112
if (sqr(Gear.dX) + sqr(Gear.dY) < 0.003) then Gear.State:= Gear.State and not gstMoving
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   113
                                         else Gear.State:= Gear.State or      gstMoving
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   114
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   115
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   116
////////////////////////////////////////////////////////////////////////////////
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   117
procedure doStepCloud(Gear: PGear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   118
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   119
Gear.X:= Gear.X + cWindSpeed * 200 + Gear.dX;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   120
if Gear.X < -cScreenWidth-256 then Gear.X:= cScreenWidth + 2048 else
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   121
if Gear.X > cScreenWidth + 2048 then Gear.X:= -cScreenWidth - 256
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   122
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   123
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   124
////////////////////////////////////////////////////////////////////////////////
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   125
procedure doStepBomb(Gear: PGear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   126
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   127
AllInactive:= false;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   128
doStepFallingGear(Gear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   129
dec(Gear.Timer);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   130
if Gear.Timer = 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   131
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   132
   doMakeExplosion(round(Gear.X), round(Gear.Y), 50, EXPLAutoSound);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   133
   DeleteGear(Gear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   134
   SetAllToActive;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   135
   exit
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   136
   end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   137
CalcRotationDirAngle(Gear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   138
if (Gear.State and (gstCollision or gstMoving)) = (gstCollision or gstMoving) then PlaySound(sndGrenadeImpact)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   139
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   140
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   141
////////////////////////////////////////////////////////////////////////////////
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   142
procedure doStepGrenade(Gear: PGear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   143
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   144
AllInactive:= false;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   145
Gear.dX:= Gear.dX + cWindSpeed;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   146
doStepFallingGear(Gear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   147
if (Gear.State and gstCollision) <> 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   148
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   149
   doMakeExplosion(round(Gear.X), round(Gear.Y), 50, EXPLAutoSound);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   150
   DeleteGear(Gear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   151
   SetAllToActive;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   152
   exit
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   153
   end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   154
if (GameTicks and $3F) = 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   155
   AddGear(round(Gear.X), round(Gear.Y), gtSmokeTrace, 0)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   156
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   157
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   158
////////////////////////////////////////////////////////////////////////////////
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   159
procedure doStepHealthTag(Gear: PGear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   160
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   161
AllInactive:= false;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   162
dec(Gear.Timer);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   163
Gear.Y:= Gear.Y - 0.07;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   164
if Gear.Timer = 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   165
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   166
   PHedgehog(Gear.Hedgehog).Gear.Active:= true;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   167
   DeleteGear(Gear)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   168
   end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   169
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   170
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   171
////////////////////////////////////////////////////////////////////////////////
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   172
procedure doStepGrave(Gear: PGear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   173
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   174
AllInactive:= false;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   175
if Gear.dY < 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   176
   if TestCollisionY(Gear, -1) then Gear.dY:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   177
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   178
if Gear.dY >=0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   179
   if TestCollisionY(Gear, 1) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   180
      begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   181
      Gear.dY:= - Gear.dY * Gear.Elasticity;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   182
      if Gear.dY > - 0.001 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   183
         begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   184
         Gear.Active:= false;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   185
         exit
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   186
         end else if Gear.dY < - 0.03 then PlaySound(sndGraveImpact)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   187
      end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   188
Gear.Y:= Gear.Y + Gear.dY;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   189
CheckGearDrowning(Gear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   190
Gear.dY:= Gear.dY + cGravity
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   191
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   192
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   193
////////////////////////////////////////////////////////////////////////////////
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   194
procedure doStepUFOWork(Gear: PGear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   195
var t: real;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   196
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   197
AllInactive:= false;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   198
t:= sqrt(sqr(Gear.dX) + sqr(Gear.dY));
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   199
Gear.dX:= Gear.Elasticity * (Gear.dX + 0.000004 * (TargetPoint.X - trunc(Gear.X)));
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   200
Gear.dY:= Gear.Elasticity * (Gear.dY + 0.000004 * (TargetPoint.Y - trunc(Gear.Y)));
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   201
t:= t / (sqrt(sqr(Gear.dX) + sqr(Gear.dY)));
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   202
Gear.dX:= Gear.dX * t;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   203
Gear.dY:= Gear.dY * t;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   204
Gear.X:= Gear.X + Gear.dX;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   205
Gear.Y:= Gear.Y + Gear.dY;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   206
CheckCollision(Gear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   207
dec(Gear.Timer);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   208
if ((Gear.State and gstCollision) <> 0) or (Gear.Timer = 0) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   209
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   210
   doMakeExplosion(round(Gear.X), round(Gear.Y), 50, EXPLAutoSound);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   211
   DeleteGear(Gear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   212
   SetAllToActive
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   213
   end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   214
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   215
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   216
procedure doStepUFO(Gear: PGear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   217
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   218
AllInactive:= false;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   219
Gear.X:= Gear.X + Gear.dX;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   220
Gear.Y:= Gear.Y + Gear.dY;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   221
Gear.dY:= Gear.dY + cGravity;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   222
CheckCollision(Gear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   223
if (Gear.State and gstCollision) <> 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   224
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   225
   doMakeExplosion(round(Gear.X), round(Gear.Y), 50, EXPLAutoSound);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   226
   DeleteGear(Gear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   227
   SetAllToActive;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   228
   exit
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   229
   end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   230
dec(Gear.Timer);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   231
if Gear.Timer = 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   232
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   233
   Gear.Timer:= 5000;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   234
   Gear.doStep:= doStepUFOWork
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   235
   end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   236
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   237
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   238
////////////////////////////////////////////////////////////////////////////////
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   239
procedure doStepShotgunShot(Gear: PGear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   240
var i: LongWord;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   241
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   242
AllInactive:= false;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   243
if Gear.Timer > 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   244
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   245
   dec(Gear.Timer);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   246
   if Gear.Timer = 1 then PlaySound(sndShotgunFire);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   247
   exit
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   248
   end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   249
i:= 200;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   250
repeat
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   251
Gear.X:= Gear.X + Gear.dX;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   252
Gear.Y:= Gear.Y + Gear.dY;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   253
CheckCollision(Gear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   254
if (Gear.State and gstCollision) <> 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   255
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   256
   doMakeExplosion(round(Gear.X), round(Gear.Y), 25, EXPLAllDamageInRadius);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   257
   DeleteGear(Gear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   258
   SetAllToActive;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   259
   exit
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   260
   end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   261
dec(i)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   262
until i = 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   263
if (Gear.X < 0) or (Gear.Y < 0) or (Gear.X > 2048) or (Gear.Y > 1024) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   264
   DeleteGear(Gear)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   265
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   266
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   267
////////////////////////////////////////////////////////////////////////////////
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   268
procedure doStepActionTimer(Gear: PGear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   269
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   270
dec(Gear.Timer);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   271
case Gear.State of
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   272
     gtsStartGame: begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   273
                   AllInactive:= false;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   274
                   if Gear.Timer > 0 then exit;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   275
                   AddCaption('Let''s fight!', $FFFFFF, capgrpStartGame);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   276
                   DeleteGear(Gear)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   277
                   end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   278
     end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   279
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   280
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   281
////////////////////////////////////////////////////////////////////////////////
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   282
procedure doStepPickHammerWork(Gear: PGear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   283
var i, ei: integer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   284
    HHGear: PGear;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   285
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   286
Allinactive:= false;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   287
dec(Gear.Timer);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   288
if (Gear.Timer = 0)or((Gear.Message and gm_Destroy) <> 0) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   289
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   290
   DeleteGear(Gear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   291
   AfterAttack;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   292
   SetAllToActive;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   293
   exit
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   294
   end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   295
HHGear:= PHedgehog(Gear.Hedgehog).Gear;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   296
if (Gear.Timer and $3F) = 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   297
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   298
   i:= round(Gear.X) - Gear.HalfWidth  - GetRandom(2);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   299
   ei:= round(Gear.X) + Gear.HalfWidth + GetRandom(2);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   300
   while i <= ei do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   301
         begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   302
         doMakeExplosion(i, round(Gear.Y) + 3, 3, 0);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   303
         inc(i, 1)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   304
         end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   305
   SetAllToActive;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   306
   Gear.X:= Gear.X + Gear.dX;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   307
   Gear.Y:= Gear.Y + 1.9
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   308
   end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   309
if TestCollisionYwithGear(Gear, 1) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   310
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   311
   Gear.dY:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   312
   HHGear.dX:= 0.0000001 * Sign(PGear(Gear.Hedgehog).dX);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   313
   HHGear.dY:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   314
   end else
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   315
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   316
   Gear.dY:= Gear.dY + cGravity;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   317
   Gear.Y:= Gear.Y + Gear.dY;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   318
   if Gear.Y > 1024 then Gear.Timer:= 1
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   319
   end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   320
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   321
Gear.X:= Gear.X + HHGear.dX;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   322
HHGear.X:= Gear.X;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   323
HHGear.Y:= Gear.Y - cHHHalfHeight;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   324
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   325
if (Gear.Message and gm_Attack) <> 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   326
   if (Gear.State and gsttmpFlag) <> 0 then Gear.Timer:= 1 else else
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   327
   if (Gear.State and gsttmpFlag) = 0 then Gear.State:= Gear.State or gsttmpFlag;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   328
if ((Gear.Message and gm_Left) <> 0) then Gear.dX:= -0.3 else
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   329
   if ((Gear.Message and gm_Right) <> 0) then Gear.dX:= 0.3
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   330
                                         else Gear.dX:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   331
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   332
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   333
procedure doStepPickHammer(Gear: PGear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   334
var i, y: integer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   335
    ar: TRangeArray;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   336
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   337
i:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   338
y:= round(Gear.Y) - cHHHalfHeight*2;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   339
while y < round(Gear.Y) do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   340
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   341
   ar[i].Left := round(Gear.X) - Gear.HalfWidth - GetRandom(2);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   342
   ar[i].Right:= round(Gear.X) + Gear.HalfWidth + GetRandom(2);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   343
   inc(y, 2);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   344
   inc(i)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   345
   end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   346
DrawLineExplosions(@ar, 3, round(Gear.Y) - cHHHalfHeight*2, 2, Pred(i));
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   347
Gear.dY:= PHedgehog(Gear.Hedgehog).Gear.dY;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   348
doStepPickHammerWork(Gear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   349
Gear.doStep:= doStepPickHammerWork
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   350
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   351
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   352
////////////////////////////////////////////////////////////////////////////////
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   353
procedure doStepRopeWork(Gear: PGear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   354
const pidiv2: real = pi/2;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   355
      flCheck: boolean = false;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   356
var HHGear: PGear;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   357
    len, cs, cc, tx, ty: real;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   358
    lx, ly: integer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   359
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   360
    procedure DeleteMe;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   361
    begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   362
      with HHGear^ do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   363
           begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   364
           Message:= Message and not gm_Attack;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   365
           State:= State or gstFalling;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   366
           end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   367
      DeleteGear(Gear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   368
      OnUsedAmmo(PHedgehog(Gear.Hedgehog)^.Ammo);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   369
      ApplyAmmoChanges(PHedgehog(Gear.Hedgehog))
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   370
    end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   371
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   372
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   373
HHGear:= PHedgehog(Gear.Hedgehog).Gear;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   374
if (HHGear.State and gstHHDriven) = 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   375
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   376
   DeleteMe;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   377
   exit
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   378
   end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   379
Gear.dX:= HHGear.X - Gear.X;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   380
Gear.dY:= HHGear.Y - Gear.Y;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   381
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   382
if (Gear.Message and gm_Left  <> 0) then HHGear.dX:= HHGear.dX - 0.0002 else
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   383
if (Gear.Message and gm_Right <> 0) then HHGear.dX:= HHGear.dX + 0.0002;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   384
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   385
if not TestCollisionYwithGear(HHGear, 1) then HHGear.dY:= HHGear.dY + cGravity;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   386
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   387
HHGear.DirAngle:= arctan(Gear.dY + HHGear.dY, Gear.dX + HHGear.dX);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   388
cs:= sin(HHGear.DirAngle);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   389
cc:= cos(HHGear.DirAngle);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   390
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   391
flCheck:= not flCheck;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   392
if flCheck then  // check whether rope needs dividing
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   393
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   394
   len:= Gear.Elasticity - 20;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   395
   while len > 5 do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   396
         begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   397
         tx:= cc*len;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   398
         ty:= cs*len;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   399
//         if   TestCollisionXwithXYShift(Gear, round(tx), round(ty), Sign(HHGear.dX))
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   400
///           or TestCollisionYwithXYShift(Gear, round(tx), round(ty), Sign(HHGear.dY)) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   401
         lx:= round(Gear.X + tx) + sign(HHGear.dX);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   402
         ly:= round(Gear.Y + ty) + sign(HHGear.dY);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   403
         if ((ly and $FFFFFC00) = 0) and ((lx and $FFFFF800) = 0)and (Land[ly, lx] <> 0) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   404
           begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   405
           with RopePoints.ar[RopePoints.Count] do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   406
                begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   407
                X:= Gear.X;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   408
                Y:= Gear.Y;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   409
                if RopePoints.Count = 0 then RopePoints.HookAngle:= DxDy2Angle32(Gear.dY, Gear.dX);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   410
                b:= (cc * HHGear.dY) > (cs * HHGear.dX);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   411
                dLen:= len
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   412
                end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   413
           Gear.X:= Gear.X + tx;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   414
           Gear.Y:= Gear.Y + ty;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   415
           inc(RopePoints.Count);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   416
           Gear.Elasticity:= Gear.Elasticity - len;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   417
           Gear.Friction:= Gear.Friction - len;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   418
           break
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   419
           end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   420
         len:= len - 3
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   421
         end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   422
   end else
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   423
   if RopePoints.Count > 0 then // check whether the last dividing point could be removed
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   424
      begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   425
      tx:= RopePoints.ar[Pred(RopePoints.Count)].X;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   426
      ty:= RopePoints.ar[Pred(RopePoints.Count)].Y;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   427
      if RopePoints.ar[Pred(RopePoints.Count)].b xor ((tx - Gear.X) * (ty - HHGear.Y) > (tx - HHGear.X) * (ty - Gear.Y)) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   428
         begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   429
         dec(RopePoints.Count);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   430
         Gear.X:=RopePoints.ar[RopePoints.Count].X;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   431
         Gear.Y:=RopePoints.ar[RopePoints.Count].Y;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   432
         Gear.Elasticity:= Gear.Elasticity + RopePoints.ar[RopePoints.Count].dLen;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   433
         Gear.Friction:= Gear.Friction + RopePoints.ar[RopePoints.Count].dLen
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   434
         end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   435
      end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   436
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   437
Gear.dX:= HHGear.X - Gear.X;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   438
Gear.dY:= HHGear.Y - Gear.Y;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   439
HHGear.DirAngle:= arctan(Gear.dY + HHGear.dY, Gear.dX + HHGear.dX);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   440
cs:= sin(HHGear.DirAngle);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   441
cc:= cos(HHGear.DirAngle);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   442
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   443
HHGear.dX:= HHGear.X;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   444
HHGear.dY:= HHGear.Y;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   445
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   446
if ((Gear.Message and gm_Down) <> 0) and (Gear.Elasticity < Gear.Friction) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   447
   if not (TestCollisionXwithGear(HHGear, Sign(Gear.dX))
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   448
        or TestCollisionYwithGear(HHGear, Sign(Gear.dY))) then Gear.Elasticity:= Gear.Elasticity + 0.3;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   449
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   450
if ((Gear.Message and gm_Up) <> 0) and (Gear.Elasticity > 30) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   451
   if not (TestCollisionXwithGear(HHGear, -Sign(Gear.dX))
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   452
        or TestCollisionYwithGear(HHGear, -Sign(Gear.dY))) then Gear.Elasticity:= Gear.Elasticity - 0.3;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   453
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   454
HHGear.X:= Gear.X + cc*Gear.Elasticity;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   455
HHGear.Y:= Gear.Y + cs*Gear.Elasticity;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   456
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   457
HHGear.dX:= HHGear.X - HHGear.dX;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   458
HHGear.dY:= HHGear.Y - HHGear.dY;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   459
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   460
if TestCollisionXwithGear(HHGear, Sign(HHGear.dX)) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   461
   HHGear.dX:= -0.9 * HHGear.dX;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   462
if TestCollisionYwithGear(HHGear, Sign(HHGear.dY)) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   463
   HHGear.dY:= -0.9 * HHGear.dY;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   464
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   465
if (Gear.Message and gm_Attack) <> 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   466
   if (Gear.State and gsttmpFlag) <> 0 then DeleteMe else
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   467
else if (Gear.State and gsttmpFlag) = 0 then Gear.State:= Gear.State or gsttmpFlag;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   468
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   469
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   470
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   471
procedure doStepRopeAttach(Gear: PGear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   472
var HHGear: PGear;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   473
    tx, ty, tt: real;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   474
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   475
Gear.X:= Gear.X + Gear.dX;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   476
Gear.Y:= Gear.Y + Gear.dY;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   477
Gear.Elasticity:= Gear.Elasticity + 1.0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   478
HHGear:= PHedgehog(Gear.Hedgehog)^.Gear;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   479
if (HHGear.State and gstFalling) <> 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   480
   if HHTestCollisionYwithGear(HHGear, 1) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   481
      begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   482
      HHGear.dY:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   483
      CheckHHDamage(HHGear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   484
      HHGear.State:= HHGear.State and not (gstFalling or gstHHJumping);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   485
      end else
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   486
      begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   487
      if TestCollisionXwithGear(HHGear, Sign(HHGear.dX)) then HHGear.dX:= 0.0000001 * Sign(HHGear.dX);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   488
      HHGear.X:= HHGear.X + HHGear.dX;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   489
      HHGear.Y:= HHGear.Y + HHGear.dY;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   490
      Gear.X:= Gear.X + HHGear.dX;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   491
      Gear.Y:= Gear.Y + HHGear.dY;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   492
      HHGear.dY:= HHGear.dY + cGravity;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   493
      tt:= Gear.Elasticity;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   494
      tx:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   495
      ty:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   496
      while tt > 20 do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   497
            begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   498
            if  TestCollisionXwithXYShift(Gear, round(tx), round(ty), Sign(Gear.dX))
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   499
             or TestCollisionYwithXYShift(Gear, round(tx), round(ty), Sign(Gear.dY)) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   500
                begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   501
                Gear.X:= Gear.X + tx;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   502
                Gear.Y:= Gear.Y + ty;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   503
                Gear.Elasticity:= tt;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   504
                Gear.doStep:= doStepRopeWork;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   505
                with HHGear^ do State:= State and not gstAttacking;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   506
                tt:= 0
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   507
                end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   508
            tx:= tx - Gear.dX - Gear.dX;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   509
            ty:= ty - Gear.dY - Gear.dY;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   510
            tt:= tt - 2.0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   511
            end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   512
      end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   513
CheckCollision(Gear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   514
if (Gear.State and gstCollision) <> 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   515
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   516
   Gear.doStep:= doStepRopeWork;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   517
   with HHGear^ do State:= State and not gstAttacking;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   518
   if Gear.Elasticity < 10 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   519
      Gear.Elasticity:= 10000;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   520
   end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   521
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   522
if (Gear.Elasticity >= Gear.Friction) or ((Gear.Message and gm_Attack) = 0) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   523
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   524
   with PHedgehog(Gear.Hedgehog).Gear^ do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   525
        begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   526
        State:= State and not gstAttacking;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   527
        Message:= Message and not gm_Attack
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   528
        end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   529
   DeleteGear(Gear)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   530
   end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   531
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   532
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   533
procedure doStepRope(Gear: PGear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   534
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   535
Gear.doStep:= doStepRopeAttach
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   536
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   537
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   538
////////////////////////////////////////////////////////////////////////////////
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   539
procedure doStepSmokeTrace(Gear: PGear);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   540
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   541
inc(Gear.Timer);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   542
if Gear.Timer > 64 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   543
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   544
   Gear.Timer:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   545
   dec(Gear.Tag)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   546
   end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   547
Gear.dX:= Gear.dX + cWindSpeed;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   548
Gear.X:= Gear.X + Gear.dX;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   549
if Gear.Tag = 0 then DeleteGear(Gear)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   550
end;