add sentry walking cycle
authoralfadur
Fri, 26 Jun 2020 19:35:16 +0300
changeset 15662 8416b08ffdbb
parent 15661 afeffdb4a712
child 15663 8e93ce81e850
add sentry walking cycle
hedgewars/uGearsHandlersMess.pas
hedgewars/uGearsList.pas
hedgewars/uGearsRender.pas
--- a/hedgewars/uGearsHandlersMess.pas	Fri Jun 26 17:40:22 2020 +0300
+++ b/hedgewars/uGearsHandlersMess.pas	Fri Jun 26 19:35:16 2020 +0300
@@ -544,7 +544,7 @@
            // while a gear is moving, this can be rather confusing.
            // TODO: Find a way to make gfMoreWind-affected land objects settle more reliably
            // and quickler without touching wind itselvs
-           ((not (Gear^.Kind in [gtMine, gtAirMine, gtSMine, gtKnife, gtExplosives])) or (TimeNotInTurn < MaxMoreWindTime)) then
+           ((not (Gear^.Kind in [gtMine, gtAirMine, gtSMine, gtKnife, gtExplosives, gtSentry])) or (TimeNotInTurn < MaxMoreWindTime)) then
             Gear^.dX := Gear^.dX + cWindSpeed / Gear^.Density
         end;
 
@@ -7174,8 +7174,44 @@
 ////////////////////////////////////////////////////////////////////////////////
 procedure doStepSentry(Gear: PGear);
 begin
-    CheckGearDrowning(Gear);
-    doStepFallingGear(Gear);
+    if CheckGearDrowning(Gear) then
+        exit;
+
+    if (TestCollisionYKick(Gear, 1) = 0) then
+    begin
+        doStepFallingGear(Gear);
+        exit;
+    end;
+
+    if (Gear^.Timer > 0) then
+        dec(Gear^.Timer);
+
+    if (Gear^.Timer = 0) then
+    begin
+        if Gear^.Tag <> 0 then
+        begin
+            Gear^.Tag := 0;
+            Gear^.Timer := 1000 + GetRandom(1000);
+        end
+        else
+        begin
+            Gear^.Tag := GetRandom(2) * 2 - 1;
+            Gear^.Timer := 1000 + GetRandom(3000);
+            Gear^.dX.isNegative := Gear^.Tag < 0;
+            if TestCollisionX(Gear, 1) <> 0 then
+            begin
+                Gear^.Tag := not Gear^.Tag;
+                Gear^.dX.isNegative := not Gear^.dX.isNegative;
+            end
+        end
+    end;
+
+    if (Gear^.Tag <> 0) and ((GameTicks and $1F) = 0) then
+    begin
+        MakeHedgehogsStep(Gear);
+        if TestCollisionX(Gear, 1) <> 0 then
+            Gear^.Timer := 0
+    end;
 end;
 
 end.
--- a/hedgewars/uGearsList.pas	Fri Jun 26 17:40:22 2020 +0300
+++ b/hedgewars/uGearsList.pas	Fri Jun 26 19:35:16 2020 +0300
@@ -835,6 +835,10 @@
         gtSentry: begin
                 gear^.Radius:= cHHRadius;
                 gear^.Health:= 100;
+                gear^.Friction:= _0_93;
+                gear^.Elasticity:= _0_5;
+                gear^.Tag:= 0;
+                gear^.Timer:= 500;
                 end;
 gtGenericFaller:begin
                 gear^.AdvBounce:= 1;
--- a/hedgewars/uGearsRender.pas	Fri Jun 26 17:40:22 2020 +0300
+++ b/hedgewars/uGearsRender.pas	Fri Jun 26 19:35:16 2020 +0300
@@ -1743,7 +1743,10 @@
             gtCreeper: if (Gear^.Hedgehog <> nil) and (Gear^.Hedgehog^.Gear <> nil) then
                          DrawSpriteRotatedF(sprCreeper, x, y, 1, hwRound(SignAs(_1,Gear^.Hedgehog^.Gear^.X-Gear^.X)), 0)
                     else DrawSpriteRotatedF(sprCreeper, x, y, 1, hwRound(SignAs(_1,Gear^.dX)), 0);
-            gtSentry: DrawSprite(sprSentry, x, y, 0, 0);
+            gtSentry: begin
+                DrawSprite(sprSentry, x - 16, y - 16, 0, 0);
+                DrawCircle(x, y, Gear^.Radius, 1, 255, 0, 0, 255);
+            end;
             gtGenericFaller: begin
                              // DEBUG: draw gtGenericFaller
                              if Gear^.Tag <> 0 then