hedgewars/uWorld.pas
changeset 10312 eda8d563f677
parent 10304 7e40820b7ed6
child 10317 fe2721f870ab
equal deleted inserted replaced
10311:30b5fab302f6 10312:eda8d563f677
   790 {$ENDIF}
   790 {$ENDIF}
   791 end;
   791 end;
   792 
   792 
   793 procedure DrawWater(Alpha: byte; OffsetY: LongInt);
   793 procedure DrawWater(Alpha: byte; OffsetY: LongInt);
   794 var VertexBuffer : array [0..3] of TVertex2f;
   794 var VertexBuffer : array [0..3] of TVertex2f;
   795     r        : TSDL_Rect;
   795     topy: LongInt;
   796     lw, lh   : GLfloat;
   796 begin
   797 begin
   797     // Water
       
   798 topy:= OffsetY + WorldDy + cWaterLine;
       
   799 
       
   800 if topy > ViewBottomY then
       
   801     exit;
       
   802 
   798 if SuddenDeathDmg then
   803 if SuddenDeathDmg then
   799     begin
   804     begin
   800     SDWaterColorArray[0].a := Alpha;
   805     SDWaterColorArray[0].a := Alpha;
   801     SDWaterColorArray[1].a := Alpha;
   806     SDWaterColorArray[1].a := Alpha;
   802     SDWaterColorArray[2].a := Alpha;
   807     SDWaterColorArray[2].a := Alpha;
   808     WaterColorArray[1].a := Alpha;
   813     WaterColorArray[1].a := Alpha;
   809     WaterColorArray[2].a := Alpha;
   814     WaterColorArray[2].a := Alpha;
   810     WaterColorArray[3].a := Alpha
   815     WaterColorArray[3].a := Alpha
   811     end;
   816     end;
   812 
   817 
   813 lw:= cScreenWidth / cScaleFactor;
   818 if topy < 0 then
   814 lh:= trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 + 16;
   819     topy:= 0;
   815 
   820 
   816     // Water
   821 glDisable(GL_TEXTURE_2D);
   817 r.y:= OffsetY + WorldDy + cWaterLine;
   822 VertexBuffer[0].X:= -ViewWidth;
   818 if WorldDy < trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - cWaterLine then
   823 VertexBuffer[0].Y:=  topy;
   819     begin
   824 VertexBuffer[1].X:=  ViewWidth;
   820         if r.y < 0 then
   825 VertexBuffer[1].Y:=  topy;
   821             r.y:= 0;
   826 VertexBuffer[2].X:=  ViewWidth;
   822 
   827 VertexBuffer[2].Y:=  ViewBottomY;
   823         glDisable(GL_TEXTURE_2D);
   828 VertexBuffer[3].X:= -ViewWidth;
   824         VertexBuffer[0].X:= -lw;
   829 VertexBuffer[3].Y:=  ViewBottomY;
   825         VertexBuffer[0].Y:= r.y;
   830 
   826         VertexBuffer[1].X:= lw;
   831 DrawWaterBody(@VertexBuffer[0]);
   827         VertexBuffer[1].Y:= r.y;
       
   828         VertexBuffer[2].X:= lw;
       
   829         VertexBuffer[2].Y:= lh;
       
   830         VertexBuffer[3].X:= -lw;
       
   831         VertexBuffer[3].Y:= lh;
       
   832 
       
   833         DrawWaterBody(@VertexBuffer[0]);
       
   834 
   832 
   835 {$IFNDEF GL2}
   833 {$IFNDEF GL2}
   836         // must not be Tint() as color array seems to stay active and color reset is required
   834 // must not be Tint() as color array seems to stay active and color reset is required
   837         glColor4ub($FF, $FF, $FF, $FF);
   835 glColor4ub($FF, $FF, $FF, $FF);
   838 {$ENDIF}
   836 {$ENDIF}
   839         glEnable(GL_TEXTURE_2D);
   837 glEnable(GL_TEXTURE_2D);
   840     end;
       
   841 end;
   838 end;
   842 
   839 
   843 procedure DrawWaves(Dir, dX, dY: LongInt; tnt: Byte);
   840 procedure DrawWaves(Dir, dX, dY: LongInt; tnt: Byte);
   844 var VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
   841 var VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
   845     lw, waves, shift: GLfloat;
   842     lw, waves, shift: GLfloat;
   846     sprite: TSprite;
   843     sprite: TSprite;
   847 begin
   844     topy: LongInt;
       
   845 begin
       
   846 
       
   847 topy:= cWaterLine + WorldDy + dY;
       
   848 
       
   849 if topY > ViewBottomY then
       
   850     exit;
       
   851 
   848 if SuddenDeathDmg then
   852 if SuddenDeathDmg then
   849     sprite:= sprSDWater
   853     sprite:= sprSDWater
   850 else
   854 else
   851     sprite:= sprWater;
   855     sprite:= sprWater;
   852 
   856 
   853 cWaveWidth:= SpritesData[sprite].Width;
   857 cWaveWidth:= SpritesData[sprite].Width;
   854 
   858 
   855 lw:= cScreenWidth / cScaleFactor;
   859 lw:= ViewWidth;
   856 waves:= lw * 2 / cWaveWidth;
   860 waves:= lw * 2 / cWaveWidth;
   857 
   861 
   858 if SuddenDeathDmg then
   862 if SuddenDeathDmg then
   859     Tint(LongInt(tnt) * SDWaterColorArray[2].r div 255 + 255 - tnt,
   863     Tint(LongInt(tnt) * SDWaterColorArray[2].r div 255 + 255 - tnt,
   860          LongInt(tnt) * SDWaterColorArray[2].g div 255 + 255 - tnt,
   864          LongInt(tnt) * SDWaterColorArray[2].g div 255 + 255 - tnt,