Mines also collide
authorunc0rr
Wed, 02 May 2007 18:41:44 +0000
changeset 503 2cfdc4bfc2be
parent 502 bc178daca088
child 504 13b6ebc53627
Mines also collide
hedgewars/GSHandlers.inc
hedgewars/uGears.pas
--- a/hedgewars/GSHandlers.inc	Wed May 02 15:21:34 2007 +0000
+++ b/hedgewars/GSHandlers.inc	Wed May 02 18:41:44 2007 +0000
@@ -64,39 +64,42 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 procedure doStepFallingGear(Gear: PGear);
-var b: boolean;
 begin
-if TestCollisionYwithGear(Gear, hwSign(Gear^.dY)) then
+Gear^.State:= Gear^.State and not gstCollision;
+
+if Gear^.dY.isNegative then
    begin
-   Gear^.dX:=   Gear^.dX * Gear^.Friction;
-   Gear^.dY:= - Gear^.dY * Gear^.Elasticity;
-   b:= false
-   end else b:= true;
+   Gear^.State:= Gear^.State or gstFalling;
+   if TestCollisionYwithGear(Gear, -1) then
+      begin
+      Gear^.dX:=   Gear^.dX * Gear^.Friction;
+      Gear^.dY:= - Gear^.dY * Gear^.Elasticity;
+      Gear^.State:= Gear^.State or gstCollision
+      end
+   end else
+   if TestCollisionYwithGear(Gear, 1) then
+      begin
+      Gear^.State:= Gear^.State and not gstFalling;
+      Gear^.dX:=   Gear^.dX * Gear^.Friction;
+      Gear^.dY:= - Gear^.dY * Gear^.Elasticity;
+      Gear^.State:= Gear^.State or gstCollision
+      end else Gear^.State:= Gear^.State or gstFalling;
+
 if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then
    begin
    Gear^.dX:= - Gear^.dX * Gear^.Elasticity;
-//   Gear^.dY:=   Gear^.dY;
-   b:= false
-   end;
-if b then
-   begin
-   Gear^.dY:= Gear^.dY + cGravity;
-   Gear^.State:= Gear^.State and not gstCollision
-   end else
-   begin
-   if hwSqr(Gear^.dX) + hwSqr(Gear^.dY) < _1div100000 then
-      if (Gear^.Timer = 0) then Gear^.Active:= false
-                          else begin
-                          Gear^.dX:= _0;
-                          Gear^.dY:= _0
-                          end;
    Gear^.State:= Gear^.State or gstCollision
    end;
+
+if (Gear^.State and gstFalling) <> 0 then Gear^.dY:= Gear^.dY + cGravity;
+
+
 Gear^.X:= Gear^.X + Gear^.dX;
 Gear^.Y:= Gear^.Y + Gear^.dY;
 CheckGearDrowning(Gear);
-if (hwSqr(Gear^.dX) + hwSqr(Gear^.dY) < _0_003) then Gear^.State:= Gear^.State and not gstMoving
-                                         else Gear^.State:= Gear^.State or      gstMoving
+if (hwSqr(Gear^.dX) + hwSqr(Gear^.dY) < _0_0002) and
+   ((Gear^.State and gstFalling) = 0) then Gear^.State:= Gear^.State and not gstMoving
+                                      else Gear^.State:= Gear^.State or      gstMoving
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -730,13 +733,13 @@
 ////////////////////////////////////////////////////////////////////////////////
 procedure doStepMine(Gear: PGear);
 begin
-if (Gear^.dX.QWordValue <> 0) or (Gear^.dY.QWordValue <> 0) then
+if (Gear^.State and (gstMoving or gstFalling)) <> 0 then
    begin
-   if Gear^.CollIndex < High(Longword) then DeleteCI(Gear);
+   DeleteCI(Gear);
    doStepFallingGear(Gear);
-   if Gear^.Active = false then
+   if (Gear^.State and (gstMoving or gstFalling)) = 0 then
       begin
-      if Gear^.CollIndex = High(Longword) then AddGearCI(Gear);
+      AddGearCI(Gear);
       Gear^.dX:= _0;
       Gear^.dY:= _0
       end;
--- a/hedgewars/uGears.pas	Wed May 02 15:21:34 2007 +0000
+++ b/hedgewars/uGears.pas	Wed May 02 18:41:44 2007 +0000
@@ -230,6 +230,7 @@
                 Result^.Y:= Result^.Y - _25;
                 end;
         gtMine: begin
+                Result^.State:= Result^.State or gstMoving;
                 Result^.Radius:= 3;
                 Result^.Elasticity:= _0_55;
                 Result^.Friction:= _0_995;
@@ -281,7 +282,7 @@
 var team: PTeam;
     t: Longword;
 begin
-if Gear^.CollIndex < High(Longword) then DeleteCI(Gear);
+DeleteCI(Gear);
 if Gear^.Surf <> nil then SDL_FreeSurface(Gear^.Surf);
 if Gear^.Kind = gtHedgehog then
    if CurAmmoGear <> nil then
@@ -450,7 +451,7 @@
 procedure DrawHH(Gear: PGear; Surface: PSDL_Surface);
 var t: LongInt;
 begin
-DrawHedgehog(hwRound(Gear^.X) - 14 + WorldDx, hwRound(Gear^.Y) - 18 + WorldDy,
+DrawHedgehog(hwRound(Gear^.X) - 15 + WorldDx, hwRound(Gear^.Y) - 18 + WorldDy,
              hwSign(Gear^.dX), 0,
              PHedgehog(Gear^.Hedgehog)^.visStepPos div 2,
              Surface);
@@ -670,6 +671,7 @@
                              begin
                              Gear^.dX:= Gear^.dX + SignAs(_0_005 * dmg + cHHKick, Gear^.X - int2hwFloat(X));
                              Gear^.dY:= Gear^.dY + SignAs(_0_005 * dmg + cHHKick, Gear^.Y - int2hwFloat(Y));
+                             Gear^.State:= Gear^.State or gstMoving;
                              Gear^.Active:= true;
                              FollowGear:= Gear
                              end;
@@ -706,6 +708,7 @@
                        t^.ar[i]^.dX:= Ammo^.dX * Power * _0_01;
                        t^.ar[i]^.dY:= Ammo^.dY * Power * _0_01;
                        t^.ar[i]^.Active:= true;
+                       t^.ar[i]^.State:= t^.ar[i]^.State or gstMoving;
                        DeleteCI(t^.ar[i]);
                        FollowGear:= t^.ar[i]
                        end;