Move water waves rendering to a separate procedure
authorunc0rr
Thu, 30 Jul 2009 09:35:09 +0000
changeset 2288 c01b8258918d
parent 2287 e34b5363ae91
child 2289 cb850ba733bd
Move water waves rendering to a separate procedure
hedgewars/uWorld.pas
--- a/hedgewars/uWorld.pas	Thu Jul 30 09:32:56 2009 +0000
+++ b/hedgewars/uWorld.pas	Thu Jul 30 09:35:09 2009 +0000
@@ -224,6 +224,16 @@
 	end
 end;
 
+procedure DrawWaves(Dir, dX, dY: LongInt);
+var i: LongInt;
+begin
+for i:= -1 to cWaterSprCount do
+	DrawSprite(sprWater,
+		i * cWaveWidth + ((WorldDx + (RealTicks shr 6) * Dir + dX) mod cWaveWidth) - (cScreenWidth div 2),
+		cWaterLine + WorldDy + dY,
+		0)
+end;
+
 procedure DrawWorld(Lag: LongInt);
 var i, t: LongInt;
     r: TSDL_Rect;
@@ -263,13 +273,11 @@
     DrawRepeated(sprHorizont, WorldDx * 3 div 5);
 
     DrawVisualGears(0);
+    end;
 
-    // Waves
-    {$WARNINGS OFF}
-    for i:= -1 to cWaterSprCount do DrawSprite(sprWater,  i * cWaveWidth  + ((WorldDx + (RealTicks shr 6)      ) mod cWaveWidth) - (cScreenWidth div 2), cWaterLine + WorldDy - (cWaveHeight*2), 0);
-    for i:= -1 to cWaterSprCount do DrawSprite(sprWater,  i * cWaveWidth + ((WorldDx - (RealTicks shr 6) + 100) mod cWaveWidth) - (cScreenWidth div 2), cWaterLine + WorldDy - (cWaveHeight + cWaveHeight div 2), 0);
-    {$WARNINGS ON}
-    end;
+// Waves
+DrawWaves( 1,  0, - (cWaveHeight * 2));
+DrawWaves(-1, 100, - (cWaveHeight + cWaveHeight div 2));
 
 
 DrawLand(WorldDx, WorldDy);
@@ -305,12 +313,12 @@
 DrawWater(cWaterOpacity);
 
 // Waves
-{$WARNINGS OFF}
-for i:= -1 to cWaterSprCount do DrawSprite(sprWater,  i * cWaveWidth  + ((WorldDx + (RealTicks shr 6) +  25) mod cWaveWidth) - (cScreenWidth div 2), cWaterLine + WorldDy - cWaveHeight, 0);
-for i:= -1 to cWaterSprCount do DrawSprite(sprWater,  i * cWaveWidth  + ((WorldDx - (RealTicks shr 6) +  50) mod cWaveWidth) - (cScreenWidth div 2), cWaterLine + WorldDy - (cWaveHeight div 2), 0);
-for i:= -1 to cWaterSprCount do DrawSprite(sprWater,  i * cWaveWidth  + ((WorldDx + (RealTicks shr 6) +  75) mod cWaveWidth) - (cScreenWidth div 2), cWaterLine + WorldDy     , 0);
+DrawWaves( 1, 25, - cWaveHeight);
+DrawWaves(-1, 50, - (cWaveHeight div 2));
+DrawWaves( 1, 75, 0);
 
 
+{$WARNINGS OFF}
 // Target
 if TargetPoint.X <> NoPointX then DrawSprite(sprTargetP, TargetPoint.X + WorldDx - 16, TargetPoint.Y + WorldDy - 16, 0);