hedgewars/GSHandlers.inc
changeset 6251 5cd33711afb9
parent 6156 baf30b1a7a75
child 6278 654eed7c6b97
equal deleted inserted replaced
6250:cd01e4f93ed9 6251:5cd33711afb9
   383         if (GameFlags and gfMoreWind) <> 0 then Gear^.dX := Gear^.dX + cWindSpeed / Gear^.Density
   383         if (GameFlags and gfMoreWind) <> 0 then Gear^.dX := Gear^.dX + cWindSpeed / Gear^.Density
   384         end;
   384         end;
   385 
   385 
   386     Gear^.X := Gear^.X + Gear^.dX;
   386     Gear^.X := Gear^.X + Gear^.dX;
   387     Gear^.Y := Gear^.Y + Gear^.dY;
   387     Gear^.Y := Gear^.Y + Gear^.dY;
   388     CheckGearDrowning(Gear);
   388     if Gear^.Kind <> gtBee then
       
   389         CheckGearDrowning(Gear);
   389     //if (hwSqr(Gear^.dX) + hwSqr(Gear^.dY) < _0_0002) and
   390     //if (hwSqr(Gear^.dX) + hwSqr(Gear^.dY) < _0_0002) and
   390     if ((Gear^.dX.QWordValue + Gear^.dY.QWordValue) < _0_02.QWordValue) and
   391     if ((Gear^.dX.QWordValue + Gear^.dY.QWordValue) < _0_02.QWordValue) and
   391        (not isFalling) then
   392        (not isFalling) then
   392         Gear^.State := Gear^.State and not gstMoving
   393         Gear^.State := Gear^.State and not gstMoving
   393     else
   394     else
   839 ////////////////////////////////////////////////////////////////////////////////
   840 ////////////////////////////////////////////////////////////////////////////////
   840 procedure doStepBeeWork(Gear: PGear);
   841 procedure doStepBeeWork(Gear: PGear);
   841 var 
   842 var 
   842     t: hwFloat;
   843     t: hwFloat;
   843     gX,gY,i: LongInt;
   844     gX,gY,i: LongInt;
   844     nuw: boolean;
   845     uw, nuw: boolean;
   845     flower: PVisualGear;
   846     flower: PVisualGear;
   846 
   847 
   847 const uw: boolean =   false;
       
   848 begin
   848 begin
   849     AllInactive := false;
   849     AllInactive := false;
   850     gX := hwRound(Gear^.X);
   850     gX := hwRound(Gear^.X);
   851     gY := hwRound(Gear^.Y);
   851     gY := hwRound(Gear^.Y);
   852     nuw := (cWaterLine < gy + Gear^.Radius);
   852     uw := (Gear^.Tag <> 0); // was bee underwater last tick?
   853     if nuw and not uw then
   853     nuw := (cWaterLine < gy + Gear^.Radius); // is bee underwater now?
       
   854 
       
   855     // if water entered or left
       
   856     if nuw <> uw then
   854     begin
   857     begin
   855         AddVisualGear(gX, cWaterLine, vgtSplash);
   858         AddVisualGear(gX, cWaterLine, vgtSplash);
   856         AddVisualGear(gX - 3 + Random(6), cWaterLine, vgtDroplet);
   859         AddVisualGear(gX - 3 + Random(6), cWaterLine, vgtDroplet);
   857         AddVisualGear(gX - 3 + Random(6), cWaterLine, vgtDroplet);
   860         AddVisualGear(gX - 3 + Random(6), cWaterLine, vgtDroplet);
   858         AddVisualGear(gX - 3 + Random(6), cWaterLine, vgtDroplet);
   861         AddVisualGear(gX - 3 + Random(6), cWaterLine, vgtDroplet);
   859         AddVisualGear(gX - 3 + Random(6), cWaterLine, vgtDroplet);
   862         AddVisualGear(gX - 3 + Random(6), cWaterLine, vgtDroplet);
   860         StopSound(Gear^.SoundChannel);
   863         StopSound(Gear^.SoundChannel);
   861         Gear^.SoundChannel := LoopSound(sndBeeWater);
   864         if nuw then
   862         uw := nuw
   865         begin
   863     end
   866             Gear^.SoundChannel := LoopSound(sndBeeWater);
   864     else if not nuw and uw then
   867             Gear^.Tag := 1;
   865         begin
   868         end
   866             AddVisualGear(gX, cWaterLine, vgtSplash);
   869         else
   867             StopSound(Gear^.SoundChannel);
   870         begin
   868             Gear^.SoundChannel := LoopSound(sndBee);
   871             Gear^.SoundChannel := LoopSound(sndBee);
   869             uw := nuw
   872             Gear^.Tag := 0;
   870         end;
   873         end;
   871 
   874     end;
   872 
   875 
   873     if (GameTicks and $F) = 0 then
   876 
   874     begin
   877     if Gear^.Timer = 0 then
   875         if (GameTicks and $30) = 0 then
   878         Gear^.RenderTimer:= false
   876             AddVisualGear(gX, gY, vgtBeeTrace);
   879     else
   877         Gear^.dX := Gear^.Elasticity * (Gear^.dX + _0_000064 * (Gear^.Target.X - gX));
   880     begin
   878         Gear^.dY := Gear^.Elasticity * (Gear^.dY + _0_000064 * (Gear^.Target.Y - gY));
   881         if (GameTicks and $F) = 0 then
   879         // make sure new speed isn't higher than original one (which we stored in Friction variable)
   882         begin
   880         t := Gear^.Friction / Distance(Gear^.dX, Gear^.dY);
   883             if (GameTicks and $30) = 0 then
   881         Gear^.dX := Gear^.dX * t;
   884                 AddVisualGear(gX, gY, vgtBeeTrace);
   882         Gear^.dY := Gear^.dY * t;
   885             Gear^.dX := Gear^.Elasticity * (Gear^.dX + _0_000064 * (Gear^.Target.X - gX));
   883     end;
   886             Gear^.dY := Gear^.Elasticity * (Gear^.dY + _0_000064 * (Gear^.Target.Y - gY));
   884 
   887             // make sure new speed isn't higher than original one (which we stored in Friction variable)
   885     Gear^.X := Gear^.X + Gear^.dX;
   888             t := Gear^.Friction / Distance(Gear^.dX, Gear^.dY);
   886     Gear^.Y := Gear^.Y + Gear^.dY;
   889             Gear^.dX := Gear^.dX * t;
       
   890             Gear^.dY := Gear^.dY * t;
       
   891         end;
       
   892 
       
   893         Gear^.X := Gear^.X + Gear^.dX;
       
   894         Gear^.Y := Gear^.Y + Gear^.dY;
       
   895 
       
   896     end;
       
   897 
   887 
   898 
   888     CheckCollision(Gear);
   899     CheckCollision(Gear);
   889     dec(Gear^.Timer);
   900     if ((Gear^.State and gstCollision) <> 0) then
   890     if ((Gear^.State and gstCollision) <> 0) or (Gear^.Timer = 0) then
       
   891     begin
   901     begin
   892         StopSound(Gear^.SoundChannel);
   902         StopSound(Gear^.SoundChannel);
   893         doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 50, Gear^.Hedgehog, EXPLAutoSound);
   903         doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 50, Gear^.Hedgehog, EXPLAutoSound);
   894         for i:= 0 to 31 do
   904         for i:= 0 to 31 do
   895             begin
   905             begin
   905                     FrameTicks:= random(250) + 250;
   915                     FrameTicks:= random(250) + 250;
   906                     State:= ord(sprTargetBee);
   916                     State:= ord(sprTargetBee);
   907                     end;
   917                     end;
   908             end;
   918             end;
   909         DeleteGear(Gear);
   919         DeleteGear(Gear);
       
   920     end;
       
   921 
       
   922     if (Gear^.Timer > 0) then
       
   923         dec(Gear^.Timer)
       
   924     else
       
   925     begin
       
   926         if nuw then
       
   927         begin
       
   928             StopSound(Gear^.SoundChannel);
       
   929             CheckGearDrowning(Gear);
       
   930         end
       
   931         else
       
   932             doStepFallingGear(Gear);
   910     end;
   933     end;
   911 end;
   934 end;
   912 
   935 
   913 procedure doStepBee(Gear: PGear);
   936 procedure doStepBee(Gear: PGear);
   914 begin
   937 begin