Skip to content

Commit

Permalink
water can now be animated
Browse files Browse the repository at this point in the history
  • Loading branch information
KoBeWi committed Oct 9, 2016
1 parent 5d3e377 commit 65aad43
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 20 deletions.
20 changes: 20 additions & 0 deletions hedgewars/uLandObjects.pas
Expand Up @@ -739,6 +739,26 @@ procedure ReadThemeInfo(var ThemeObjects: TThemeObjects; var SprayObjects: TSpra
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);
Expand Down
34 changes: 25 additions & 9 deletions hedgewars/uRender.pas
Expand Up @@ -1733,19 +1733,31 @@ procedure DrawWater(Alpha: byte; OffsetY, OffsetX: LongInt);
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
Expand All @@ -1758,7 +1770,6 @@ procedure DrawWaves(Dir, dX, dY, oX: LongInt; tnt: Byte);

topy:= cWaterLine + WorldDy + dY;


if (WorldEdge <> weSea) then
PrepareVbForWater(false,
topy, 0,
Expand Down Expand Up @@ -1806,14 +1817,19 @@ procedure DrawWaves(Dir, dX, dY, oX: LongInt; tnt: Byte);
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
Expand Down
10 changes: 5 additions & 5 deletions hedgewars/uSound.pas
Expand Up @@ -140,7 +140,7 @@ implementation
(FileName: 'explosion.ogg'; Path: ptSounds; AltPath: ptNone),// sndExplosion
(FileName: 'throwpowerup.ogg'; Path: ptSounds; AltPath: ptNone),// sndThrowPowerUp
(FileName: 'throwrelease.ogg'; Path: ptSounds; AltPath: ptNone),// sndThrowRelease
(FileName: 'splash.ogg'; Path: ptCurrTheme; AltPath: ptSounds),// sndSplash
(FileName: 'splash.ogg'; Path: ptCurrTheme; AltPath: ptSounds),// sndSplash
(FileName: 'shotgunreload.ogg'; Path: ptSounds; AltPath: ptNone),// sndShotgunReload
(FileName: 'shotgunfire.ogg'; Path: ptSounds; AltPath: ptNone),// sndShotgunFire
(FileName: 'graveimpact.ogg'; Path: ptSounds; AltPath: ptNone),// sndGraveImpact
Expand Down Expand Up @@ -219,9 +219,9 @@ implementation
(FileName: 'hell_ow.ogg'; Path: ptSounds; AltPath: ptNone),// sndHellishImpact3
(FileName: 'hell_ugh.ogg'; Path: ptSounds; AltPath: ptNone),// sndHellishImpact4
(FileName: 'melonimpact.ogg'; Path: ptSounds; AltPath: ptNone),// sndMelonImpact
(FileName: 'Droplet1.ogg'; Path: ptCurrTheme; AltPath: ptSounds),// sndDroplet1
(FileName: 'Droplet2.ogg'; Path: ptCurrTheme; AltPath: ptSounds),// sndDroplet2
(FileName: 'Droplet3.ogg'; Path: ptCurrTheme; AltPath: ptSounds),// sndDroplet3
(FileName: 'Droplet1.ogg'; Path: ptCurrTheme; AltPath: ptSounds),// sndDroplet1
(FileName: 'Droplet2.ogg'; Path: ptCurrTheme; AltPath: ptSounds),// sndDroplet2
(FileName: 'Droplet3.ogg'; Path: ptCurrTheme; AltPath: ptSounds),// sndDroplet3
(FileName: 'egg.ogg'; Path: ptSounds; AltPath: ptNone),// sndEggBreak
(FileName: 'drillgun.ogg'; Path: ptSounds; AltPath: ptNone),// sndDrillRocket
(FileName: 'PoisonCough.ogg'; Path: ptVoices; AltPath: ptNone),// sndPoisonCough
Expand All @@ -238,7 +238,7 @@ implementation
(FileName: '7B.ogg'; Path: ptSounds; AltPath: ptNone),// sndPiano6
(FileName: '8C.ogg'; Path: ptSounds; AltPath: ptNone),// sndPiano7
(FileName: '9D.ogg'; Path: ptSounds; AltPath: ptNone),// sndPiano8
(FileName: 'skip.ogg'; Path: ptCurrTheme; AltPath: ptSounds),// sndSkip
(FileName: 'skip.ogg'; Path: ptCurrTheme; AltPath: ptSounds),// sndSkip
(FileName: 'sinegun.ogg'; Path: ptSounds; AltPath: ptNone),// sndSineGun
(FileName: 'Ooff1.ogg'; Path: ptVoices; AltPath: ptNone),// sndOoff1
(FileName: 'Ooff2.ogg'; Path: ptVoices; AltPath: ptNone),// sndOoff2
Expand Down
19 changes: 15 additions & 4 deletions hedgewars/uStore.pas
Expand Up @@ -421,10 +421,21 @@ procedure StoreLoad(reload: boolean);
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);
Expand Down
14 changes: 12 additions & 2 deletions hedgewars/uVariables.pas
Expand Up @@ -331,7 +331,7 @@ procedure initScreenSpaceVars();
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;
Expand Down Expand Up @@ -694,7 +694,7 @@ procedure initScreenSpaceVars();
(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;
Expand Down Expand Up @@ -2437,6 +2437,10 @@ TAmmozRec = record
vobVelocity, vobFallSpeed: LongInt;
vobSDFrameTicks, vobSDFramesCount, vobSDCount: Longword;
vobSDVelocity, vobSDFallSpeed: LongInt;
watFrames, watFrameTicks: Longword;
watMove: LongInt;
watSDFrames, watSDFrameTicks: Longword;
watSDMove: LongInt;

DefaultBinds : TBinds;

Expand Down Expand Up @@ -2713,12 +2717,18 @@ procedure initModule;
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);
Expand Down

0 comments on commit 65aad43

Please sign in to comment.