Water can now be animated
authorKoBeWi <kobewi4e@gmail.com>
Sat, 08 Apr 2017 17:17:28 +0200
changeset 12194 31184d9b9bfc
parent 12193 099e59894671
child 12195 4d818abdc00f
Water can now be animated
hedgewars/uLandObjects.pas
hedgewars/uRender.pas
hedgewars/uStore.pas
hedgewars/uVariables.pas
--- a/hedgewars/uLandObjects.pas	Sat Apr 08 06:22:43 2017 +0200
+++ b/hedgewars/uLandObjects.pas	Sat Apr 08 17:17:28 2017 +0200
@@ -769,6 +769,26 @@
             Maxcnt:= StrToInt(Trim(s));
             end;
         end
+    else if key = 'water-animation' then
+        begin
+        i:= Pos(',', s);
+        watFrames:= StrToInt(Trim(Copy(s, 1, Pred(i))));
+        Delete(s, 1, i);
+        i:= Pos(',', s);
+        watFrameTicks:= StrToInt(Trim(Copy(s, 1, Pred(i))));
+        Delete(s, 1, i);
+        watMove:= StrToInt(Trim(Copy(s, 1, Pred(i))));
+        end
+    else if key = 'sd-water-animation' then
+        begin
+        i:= Pos(',', s);
+        watSDFrames:= StrToInt(Trim(Copy(s, 1, Pred(i))));
+        Delete(s, 1, i);
+        i:= Pos(',', s);
+        watSDFrameTicks:= StrToInt(Trim(Copy(s, 1, Pred(i))));
+        Delete(s, 1, i);
+        watSDMove:= StrToInt(Trim(Copy(s, 1, Pred(i))));
+        end
     else if key = 'flakes' then
         begin
         i:= Pos(',', s);
--- a/hedgewars/uRender.pas	Sat Apr 08 06:22:43 2017 +0200
+++ b/hedgewars/uRender.pas	Sat Apr 08 17:17:28 2017 +0200
@@ -1783,19 +1783,31 @@
 end;
 
 procedure DrawWaves(Dir, dX, dY, oX: LongInt; tnt: Byte);
-var first, count, topy, lx, rx, spriteHeight, spriteWidth: LongInt;
-    lw, nWaves, shift: GLfloat;
+var first, count, topy, lx, rx, spriteHeight, spriteWidth, waterSpeed: LongInt;
+    waterFrames, waterFrameTicks, frame : LongWord;
+    lw, nWaves, shift, realHeight: GLfloat;
     sprite: TSprite;
 begin
 // note: spriteHeight is the Height of the wave sprite while
 //       cWaveHeight describes how many pixels of it will be above waterline
 
 if SuddenDeathDmg then
-    sprite:= sprSDWater
+    begin
+    sprite:= sprSDWater;
+    waterFrames:= watSDFrames;
+    waterFrameTicks:= watSDFrameTicks;
+    waterSpeed:= watSDMove;
+    end
 else
+    begin
     sprite:= sprWater;
-
+    waterFrames:= watFrames;
+    waterFrameTicks:= watFrameTicks;
+    waterSpeed:= watMove;
+    end;
+ 
 spriteHeight:= SpritesData[sprite].Height;
+realHeight:= SpritesData[sprite].Texture^.ry / waterFrames;
 
 // shift parameters by wave height
 // ( ox and dy are used to create different horizontal and vertical offsets
@@ -1856,14 +1868,19 @@
 nWaves:= lw / spriteWidth;
     shift:= - nWaves / 2;
 
-TextureBuffer[3].X:= shift + ((LongInt(RealTicks shr 6) * Dir + dX) mod spriteWidth) / (spriteWidth - 1);
-TextureBuffer[3].Y:= 0;
+if waterFrames > 1 then
+	frame:= RealTicks div waterFrameTicks mod waterFrames
+else
+	frame:= 0;
+
+TextureBuffer[3].X:= shift + ((LongInt(RealTicks shr (16 - waterSpeed)) * Dir + dX) mod spriteWidth) / (spriteWidth - 1);
+TextureBuffer[3].Y:= frame * realHeight;
 TextureBuffer[5].X:= TextureBuffer[3].X + nWaves;
-TextureBuffer[5].Y:= 0;
+TextureBuffer[5].Y:= frame * realHeight;
 TextureBuffer[4].X:= TextureBuffer[5].X;
-TextureBuffer[4].Y:= SpritesData[sprite].Texture^.ry;
+TextureBuffer[4].Y:= SpritesData[sprite].Texture^.ry / waterFrames + frame * realHeight;
 TextureBuffer[2].X:= TextureBuffer[3].X;
-TextureBuffer[2].Y:= SpritesData[sprite].Texture^.ry;
+TextureBuffer[2].Y:= SpritesData[sprite].Texture^.ry / waterFrames + frame * realHeight;
 
 if (WorldEdge = weSea) then
     begin
--- a/hedgewars/uStore.pas	Sat Apr 08 06:22:43 2017 +0200
+++ b/hedgewars/uStore.pas	Sat Apr 08 17:17:28 2017 +0200
@@ -430,10 +430,21 @@
                     imageHeight:= tmpsurf^.h
                     end;
                 if getDimensions then
-                    begin
-                    Width:= tmpsurf^.w;
-                    Height:= tmpsurf^.h
-                    end;
+                    if Height = -1 then //BlueWater
+                        begin
+                        Width:= tmpsurf^.w;
+                        Height:= tmpsurf^.h div watFrames;
+                        end
+                    else if Height = -2 then //SDWater
+                        begin
+                        Width:= tmpsurf^.w;
+                        Height:= tmpsurf^.h div watSDFrames;
+                        end
+                    else
+                        begin
+                        Width:= tmpsurf^.w;
+                        Height:= tmpsurf^.h
+                        end;
                 if (ii in [sprSky, sprSkyL, sprSkyR, sprHorizont, sprHorizontL, sprHorizontR]) then
                     begin
                     Texture:= Surface2Tex(tmpsurf, true);
--- a/hedgewars/uVariables.pas	Sat Apr 08 06:22:43 2017 +0200
+++ b/hedgewars/uVariables.pas	Sat Apr 08 17:17:28 2017 +0200
@@ -333,7 +333,7 @@
 const
     SpritesDataInit: array[TSprite] of TSpriteData = (
             (FileName:  'BlueWater'; Path: ptCurrTheme;AltPath: ptGraphics; Texture: nil; Surface: nil;
-            Width:   0; Height:  0; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpMedium; getDimensions: true; getImageDimensions: true),// sprWater
+            Width:   0; Height:  -1; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpMedium; getDimensions: true; getImageDimensions: true),// sprWater
             (FileName:     'Clouds'; Path: ptCurrTheme;AltPath: ptGraphics; Texture: nil; Surface: nil;
             Width: 256; Height:128; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpHigh; getDimensions: false; getImageDimensions: true),// sprCloud
             (FileName:       'Bomb'; Path: ptGraphics; AltPath: ptNone; Texture: nil; Surface: nil;
@@ -702,7 +702,7 @@
             (FileName:    'SDFlake'; Path: ptCurrTheme; AltPath: ptSuddenDeath; Texture: nil; Surface: nil;
             Width:  64; Height: 64; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpHighest; getDimensions: false; getImageDimensions: true),// sprSDFlake
             (FileName:    'SDWater'; Path: ptCurrTheme; AltPath: ptSuddenDeath; Texture: nil; Surface: nil;
-            Width:   0; Height:  0; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpMedium; getDimensions: true; getImageDimensions: true),// sprSDWater
+            Width:   0; Height:  -2; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpMedium; getDimensions: true; getImageDimensions: true),// sprSDWater
             (FileName:   'SDClouds'; Path: ptCurrTheme; AltPath: ptSuddenDeath; Texture: nil; Surface: nil;
             Width: 256; Height:128; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpHigh; getDimensions: false; getImageDimensions: true),// sprSDCloud
             (FileName:   'SDSplash'; Path: ptCurrTheme; AltPath: ptSuddenDeath; Texture: nil; Surface: nil;
@@ -2455,6 +2455,10 @@
     vobVelocity, vobFallSpeed: LongInt;
     vobSDFrameTicks, vobSDFramesCount, vobSDCount: Longword;
     vobSDVelocity, vobSDFallSpeed: LongInt;
+    watFrames, watFrameTicks: Longword;
+    watMove: LongInt;
+    watSDFrames, watSDFrameTicks: Longword;
+    watSDMove: LongInt;
 
     DefaultBinds : TBinds;
 
@@ -2760,12 +2764,18 @@
     vobCount:= 0;
     vobVelocity:= 10;
     vobFallSpeed:= 100;
+    watFrames:= 1;
+    watFrameTicks:= 0;
+    watMove:= 10;
 
     vobSDFrameTicks:= 0;
     vobSDFramesCount:= 4;
     vobSDCount:= 30 * cScreenSpace div LAND_WIDTH;
     vobSDVelocity:= 15;
     vobSDFallSpeed:= 250;
+    watSDFrames:= 1;
+    watSDFrameTicks:= 0;
+    watSDMove:= 10;
 
 {$IFDEF MOBILE}
     cMinScreenWidth  := min(cScreenWidth, 480);