Flakes: Only spawn them inside valid area
authorWuzzy <Wuzzy2@mail.ru>
Wed, 27 May 2020 01:24:50 +0200
changeset 15607 f8c1492601fe
parent 15606 b2b72fc7fc14
child 15608 19c85b010144
Flakes: Only spawn them inside valid area Also add cCloudOffset
hedgewars/uConsts.pas
hedgewars/uVisualGears.pas
hedgewars/uVisualGearsHandlers.pas
--- a/hedgewars/uConsts.pas	Wed May 27 00:02:20 2020 +0200
+++ b/hedgewars/uConsts.pas	Wed May 27 01:24:50 2020 +0200
@@ -195,6 +195,7 @@
 
     cBorderWidth = 6; // width of indestructible border
                       // width of 3 allowed hogs to be knocked through with grenade
+    cCloudOffset = 1184; // Y offset for clouds (cloud height = LAND_HEIGHT-cCloudOffset)
 
     cHHRadius = 9; // hedgehog radius
     cHHStepTicks = 29;
--- a/hedgewars/uVisualGears.pas	Wed May 27 00:02:20 2020 +0200
+++ b/hedgewars/uVisualGears.pas	Wed May 27 01:24:50 2020 +0200
@@ -463,7 +463,7 @@
 var i: LongInt;
 begin
 for i:= 0 to cCloudsNumber - 1 do
-    AddVisualGear(cLeftScreenBorder + i * LongInt(cScreenSpace div (cCloudsNumber + 1)), LAND_HEIGHT-1184, vgtCloud, 0, true)
+    AddVisualGear(cLeftScreenBorder + i * LongInt(cScreenSpace div (cCloudsNumber + 1)), LAND_HEIGHT-cCloudOffset, vgtCloud, 0, true)
 end;
 
 procedure ChangeToSDClouds;
@@ -484,10 +484,15 @@
             end
         else vg:= vg^.NextGear;
     for j:= 0 to cSDCloudsNumber - 1 do
-        AddVisualGear(cLeftScreenBorder + j * LongInt(cScreenSpace div (cSDCloudsNumber + 1)), LAND_HEIGHT-1184, vgtCloud, 0, true)
+        AddVisualGear(cLeftScreenBorder + j * LongInt(cScreenSpace div (cSDCloudsNumber + 1)), LAND_HEIGHT-cCloudOffset, vgtCloud, 0, true)
     end;
 end;
 
+procedure AddFlake; inline;
+begin
+    AddVisualGear(cLeftScreenBorder + random(cScreenSpace), LAND_HEIGHT-cCloudOffset+ random(cCloudOffset), vgtFlake);
+end;
+
 procedure AddFlakes;
 var i: LongInt;
 begin
@@ -496,10 +501,10 @@
 
 if hasBorder or (not cSnow) then
     for i:= 0 to Pred(vobCount * cScreenSpace div 4096) do
-        AddVisualGear(cLeftScreenBorder + random(cScreenSpace), random(1024+200) - 100 + LAND_HEIGHT, vgtFlake)
+        AddFlake
 else
     for i:= 0 to Pred((vobCount * cScreenSpace div 4096) div 3) do
-        AddVisualGear(cLeftScreenBorder + random(cScreenSpace), random(1024+200) - 100 + LAND_HEIGHT, vgtFlake);
+        AddFlake;
 end;
 
 procedure ChangeToSDFlakes;
@@ -526,10 +531,10 @@
     end;
 if hasBorder or (not cSnow) then
     for i:= 0 to Pred(vobSDCount * cScreenSpace div 4096) do
-        AddVisualGear(cLeftScreenBorder + random(cScreenSpace), random(1024+200) - 100 + LAND_HEIGHT, vgtFlake)
+        AddFlake
 else
     for i:= 0 to Pred((vobSDCount * cScreenSpace div 4096) div 3) do
-        AddVisualGear(cLeftScreenBorder + random(cScreenSpace), random(1024+200) - 100 + LAND_HEIGHT, vgtFlake);
+        AddFlake;
 end;
 
 procedure initModule;
--- a/hedgewars/uVisualGearsHandlers.pas	Wed May 27 00:02:20 2020 +0200
+++ b/hedgewars/uVisualGearsHandlers.pas	Wed May 27 01:24:50 2020 +0200
@@ -180,7 +180,7 @@
         // flake fell far below map?
         outside:= (not rising) and (round(Y) - spawnMargin + randMargin > LAND_HEIGHT);
         // if not, did it rise far above map?
-        outside:= outside or (rising and (round(Y) < LAND_HEIGHT - 1024 - randMargin));
+        outside:= outside or (rising and (round(Y) < LAND_HEIGHT - (cCloudOffset - 110)));
 
         // if flake left acceptable vertical area, respawn it opposite side
         if outside then
@@ -190,7 +190,7 @@
                 if State = 0 then
                     begin
                     // fade out rising flake
-                    diff:= (LAND_HEIGHT - 1024 - randMargin) - round(Y);
+                    diff:= (LAND_HEIGHT - (cCloudOffset - 110)) - round(Y);
                     diff:= Min(diff*2, $FF);
                     if diff >= $FF then
                         begin
@@ -252,7 +252,7 @@
 t := 8 * Gear^.Scale * hwFloat2Float(AngleSin(s mod 2048));
 if (s < 2048) then t := -t;
 
-Gear^.Y := LAND_HEIGHT - 1184 + LongInt(Gear^.Timer mod 8) + t;
+Gear^.Y := LAND_HEIGHT - cCloudOffset + LongInt(Gear^.Timer mod 8) + t;
 
 if round(Gear^.X) < cLeftScreenBorder then
     Gear^.X:= Gear^.X + cScreenSpace