hedgewars/uGearsHandlersMess.pas
changeset 13614 c9642782778b
parent 13613 d6b79a080a3e
child 13624 6a06904c7bb8
equal deleted inserted replaced
13613:d6b79a080a3e 13614:c9642782778b
  3566     else if Gear^.Timer < 6000 then
  3566     else if Gear^.Timer < 6000 then
  3567         Gear^.RenderTimer:= true;
  3567         Gear^.RenderTimer:= true;
  3568 
  3568 
  3569     if not cakeStep(Gear) then Gear^.doStep:= @doStepCakeFall;
  3569     if not cakeStep(Gear) then Gear^.doStep:= @doStepCakeFall;
  3570 
  3570 
       
  3571     // Cake passed world edge.
  3571     if (Gear^.Karma = 1) then
  3572     if (Gear^.Karma = 1) then
  3572         begin
  3573         (* This code is not ideal, but at least not horribly broken.
  3573         // Cake hit bouncy edge, turn around
  3574         The cake tries to reach the other side and continue to walk,
       
  3575         but there are some exceptions.
       
  3576         This code is called *after* the X coordinate have been wrapped.
       
  3577         Depending on terrain on the other side, the cake does this:
       
  3578         * Cake collides horizontally (even by 1 pixel): Turn around
       
  3579         * Cake does not see walkable ground above or below: Fall
       
  3580         * Otherwise: Walk normally
       
  3581         *)
       
  3582         begin
       
  3583         // Update coordinates
       
  3584         tdx:=Gear^.X;
       
  3585         if (hwRound(Gear^.X) < LongInt(leftX)) then
       
  3586              Gear^.X:= Gear^.X + int2hwfloat(rightX - leftX)
       
  3587         else Gear^.X:= Gear^.X - int2hwfloat(rightX - leftX);
       
  3588 
       
  3589         Gear^.Tag:= 0;
       
  3590         if ((TestCollisionXwithGear(Gear, 1) <> 0) or (TestCollisionXwithGear(Gear, -1) <> 0)) then
       
  3591             // Cake collided horizontally, turn around. Prevents cake from being stuck in infinite loop.
       
  3592             // This can also happen if the terrain is just a slight slope. :-(
       
  3593             begin
       
  3594             Gear^.X := tdx;
       
  3595             Gear^.Karma := 3;
       
  3596             end
       
  3597         else
       
  3598             begin
       
  3599             // Check if cake has something to walk on the other side. If not, make it drop.
       
  3600             // There is nothing for the cake to stand on.
       
  3601             if (TestCollisionYwithGear(Gear, 1) = 0) and (TestCollisionYwithGear(Gear, -1) = 0) then
       
  3602                 Gear^.doStep:= @doStepCakeFall;
       
  3603             Gear^.Karma := 4;
       
  3604             end;
       
  3605         end;
       
  3606     // Cake bounced!
       
  3607     if (Gear^.Karma = 2) or (Gear^.Karma = 3) then
       
  3608         begin
       
  3609         // Turn cake around
  3574         Gear^.dX.isNegative := (not Gear^.dX.isNegative);
  3610         Gear^.dX.isNegative := (not Gear^.dX.isNegative);
  3575         Gear^.WDTimer := 0;
  3611         Gear^.WDTimer := 0;
  3576         Gear^.Angle := (LongInt(Gear^.Angle) + 2) and 3;
  3612         Gear^.Angle := (LongInt(Gear^.Angle) + 2) and 3;
  3577         Gear^.Karma := 0;
       
  3578 
  3613 
  3579         // Bounce effect
  3614         // Bounce effect
  3580         if (Gear^.Radius > 2) then
  3615         if (Gear^.Karma = 2) and (Gear^.Radius > 2) then
  3581             AddBounceEffectForGear(Gear, 0.55);
  3616             AddBounceEffectForGear(Gear, 0.55);
  3582 
  3617 
       
  3618         Gear^.Tag:= 0;
       
  3619         Gear^.Karma := 4;
       
  3620         end;
       
  3621     if (Gear^.Karma = 4) then
       
  3622         begin
  3583         // Reset CakePoints to fix cake angle
  3623         // Reset CakePoints to fix cake angle
  3584         cakeData:= PCakeData(Gear^.Data);
  3624         cakeData:= PCakeData(Gear^.Data);
  3585         with cakeData^ do
  3625         with cakeData^ do
  3586             begin
  3626             begin
  3587             for i:= 0 to Pred(cakeh) do
  3627             for i:= 0 to Pred(cakeh) do
  3589                 CakePoints[i].x := Gear^.X;
  3629                 CakePoints[i].x := Gear^.X;
  3590                 CakePoints[i].y := Gear^.Y;
  3630                 CakePoints[i].y := Gear^.Y;
  3591                 end;
  3631                 end;
  3592                 CakeI:= 0;
  3632                 CakeI:= 0;
  3593             end;
  3633             end;
  3594         Gear^.Tag:= 0;
       
  3595         end
       
  3596     else if (Gear^.Karma = 2) then
       
  3597         begin
       
  3598         (* Cake passed world edge.
       
  3599         Cake doesn't know yet how walk through
       
  3600         world wrap so it gives up and stops.
       
  3601         TODO: Teach cake how to deal with world wrap. *)
       
  3602         Gear^.Health := 0;
       
  3603         Gear^.Karma := 0;
  3634         Gear^.Karma := 0;
  3604         end;
  3635         end;
  3605 
  3636 
  3606     if Gear^.Tag = 0 then
  3637     if Gear^.Tag = 0 then
  3607         begin
  3638         begin