hedgewars/uWorld.pas
changeset 3089 8ad00781be08
parent 3045 41732f986b4f
child 3093 ff59e61346f5
equal deleted inserted replaced
3088:b99af2ee82bf 3089:8ad00781be08
   330     glColor4f(1, 1, 1, 1); // disable coloring
   330     glColor4f(1, 1, 1, 1); // disable coloring
   331     glEnable(GL_TEXTURE_2D)
   331     glEnable(GL_TEXTURE_2D)
   332     end
   332     end
   333 end;
   333 end;
   334 
   334 
   335 procedure DrawWaves(Dir, dX, dY: LongInt);
   335 procedure DrawWaves(Dir, dX, dY: LongInt; Tint: GLfloat);
   336 var VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
   336 var VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
   337     lw, waves, shift: GLfloat;
   337     lw, waves, shift: GLfloat;
   338 begin
   338 begin
   339 lw:= cScreenWidth / cScaleFactor;
   339 lw:= cScreenWidth / cScaleFactor;
   340 waves:= lw * 2 / cWaveWidth;
   340 waves:= lw * 2 / cWaveWidth;
       
   341 
       
   342 glColor4f(
       
   343       (Tint * WaterColorArray[2].r / 255) + (1-Tint)
       
   344     , (Tint * WaterColorArray[2].g / 255) + (1-Tint)
       
   345     , (Tint * WaterColorArray[2].b / 255) + (1-Tint)
       
   346     , 1
       
   347 );
   341 
   348 
   342 glBindTexture(GL_TEXTURE_2D, SpritesData[sprWater].Texture^.id);
   349 glBindTexture(GL_TEXTURE_2D, SpritesData[sprWater].Texture^.id);
   343 
   350 
   344 VertexBuffer[0].X:= -lw;
   351 VertexBuffer[0].X:= -lw;
   345 VertexBuffer[0].Y:= cWaterLine + WorldDy + dY;
   352 VertexBuffer[0].Y:= cWaterLine + WorldDy + dY;
   367 glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
   374 glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
   368 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   375 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   369 
   376 
   370 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
   377 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
   371 glDisableClientState(GL_VERTEX_ARRAY);
   378 glDisableClientState(GL_VERTEX_ARRAY);
       
   379 glColor4f(1, 1, 1, 1);
   372 
   380 
   373 
   381 
   374 {for i:= -1 to cWaterSprCount do
   382 {for i:= -1 to cWaterSprCount do
   375     DrawSprite(sprWater,
   383     DrawSprite(sprWater,
   376         i * cWaveWidth + ((WorldDx + (RealTicks shr 6) * Dir + dX) mod cWaveWidth) - (cScreenWidth div 2),
   384         i * cWaveWidth + ((WorldDx + (RealTicks shr 6) * Dir + dX) mod cWaveWidth) - (cScreenWidth div 2),
   377         cWaterLine + WorldDy + dY,
   385         cWaterLine + WorldDy + dY,
   378         0)}
   386         0)}
   379 end;
   387 end;
   380 
   388 
   381 procedure DrawRepeated(spr, sprL, sprR: TSprite; Shift: LongInt);
   389 procedure DrawRepeated(spr, sprL, sprR: TSprite; Shift, OffsetY: LongInt);
   382 var i, w, sw: LongInt;
   390 var i, w, sw: LongInt;
   383 begin
   391 begin
   384 sw:= round(cScreenWidth / cScaleFactor);
   392 sw:= round(cScreenWidth / cScaleFactor);
   385 if (SpritesData[sprL].Texture = nil) or (SpritesData[sprR].Texture = nil) then
   393 if (SpritesData[sprL].Texture = nil) or (SpritesData[sprR].Texture = nil) then
   386     begin
   394     begin
   387     w:= SpritesData[spr].Width;
   395     w:= SpritesData[spr].Width;
   388     i:= Shift mod w;
   396     i:= Shift mod w;
   389     if i > 0 then dec(i, w);
   397     if i > 0 then dec(i, w);
   390     dec(i, w * (sw div w + 1));
   398     dec(i, w * (sw div w + 1));
   391     repeat
   399     repeat
   392         DrawSprite(spr, i, WorldDy + LAND_HEIGHT - SpritesData[spr].Height, 0);
   400         DrawSprite(spr, i, WorldDy + LAND_HEIGHT - SpritesData[spr].Height - OffsetY, 0);
   393         inc(i, w)
   401         inc(i, w)
   394     until i > sw
   402     until i > sw
   395     end else
   403     end else
   396     begin
   404     begin
   397     w:= SpritesData[spr].Width;
   405     w:= SpritesData[spr].Width;
   398     dec(Shift, w div 2);
   406     dec(Shift, w div 2);
   399     DrawSprite(spr, Shift, WorldDy + LAND_HEIGHT - SpritesData[spr].Height, 0);
   407     DrawSprite(spr, Shift, WorldDy + LAND_HEIGHT - SpritesData[spr].Height - OffsetY, 0);
   400 
   408 
   401     sw:= round(cScreenWidth / cScaleFactor);
   409     sw:= round(cScreenWidth / cScaleFactor);
   402     
   410     
   403     i:= Shift - SpritesData[sprL].Width;
   411     i:= Shift - SpritesData[sprL].Width;
   404     while i >= -sw - SpritesData[sprL].Width do
   412     while i >= -sw - SpritesData[sprL].Width do
   405         begin
   413         begin
   406         DrawSprite(sprL, i, WorldDy + LAND_HEIGHT - SpritesData[sprL].Height, 0);
   414         DrawSprite(sprL, i, WorldDy + LAND_HEIGHT - SpritesData[sprL].Height - OffsetY, 0);
   407         dec(i, SpritesData[sprL].Width);
   415         dec(i, SpritesData[sprL].Width);
   408         end;
   416         end;
   409         
   417         
   410     i:= Shift + w;
   418     i:= Shift + w;
   411     while i <= sw do
   419     while i <= sw do
   412         begin
   420         begin
   413         DrawSprite(sprR, i, WorldDy + LAND_HEIGHT - SpritesData[sprR].Height, 0);
   421         DrawSprite(sprR, i, WorldDy + LAND_HEIGHT - SpritesData[sprR].Height - OffsetY, 0);
   414         inc(i, SpritesData[sprR].Width)
   422         inc(i, SpritesData[sprR].Width)
   415         end
   423         end
   416     end
   424     end
   417 end;
   425 end;
   418 
   426 
   422     r: TSDL_Rect;
   430     r: TSDL_Rect;
   423     tdx, tdy: Double;
   431     tdx, tdy: Double;
   424     grp: TCapGroup;
   432     grp: TCapGroup;
   425     s: string[15];
   433     s: string[15];
   426     highlight: Boolean;
   434     highlight: Boolean;
   427     offset, offsetX, offsetY: LongInt;
   435     offset, offsetX, offsetY, screenBottom: LongInt;
   428     scale: GLfloat;
   436     scale: GLfloat;
   429 begin
   437 begin
   430 if ZoomValue < zoom then
   438 if ZoomValue < zoom then
   431     begin
   439     begin
   432     zoom:= zoom - 0.002 * Lag;
   440     zoom:= zoom - 0.002 * Lag;
   435 if ZoomValue > zoom then
   443 if ZoomValue > zoom then
   436     begin
   444     begin
   437     zoom:= zoom + 0.002 * Lag;
   445     zoom:= zoom + 0.002 * Lag;
   438     if ZoomValue < zoom then zoom:= ZoomValue
   446     if ZoomValue < zoom then zoom:= ZoomValue
   439     end;
   447     end;
       
   448 
       
   449 screenBottom:= WorldDy - trunc(cScreenHeight/zoom) - (cScreenHeight div 2) + cWaterLine;
   440 
   450 
   441 // Sky
   451 // Sky
   442 glClear(GL_COLOR_BUFFER_BIT);
   452 glClear(GL_COLOR_BUFFER_BIT);
   443 glEnable(GL_BLEND);
   453 glEnable(GL_BLEND);
   444 glEnable(GL_TEXTURE_2D);
   454 glEnable(GL_TEXTURE_2D);
   448 if not isPaused then MoveCamera;
   458 if not isPaused then MoveCamera;
   449 
   459 
   450 if not cReducedQuality then
   460 if not cReducedQuality then
   451     begin
   461     begin
   452     // background
   462     // background
   453     DrawRepeated(sprSky, sprSkyL, sprSkyR, (WorldDx + LAND_WIDTH div 2) * 3 div 8);
   463     DrawRepeated(sprSky, sprSkyL, sprSkyR, (WorldDx + LAND_WIDTH div 2) * 3 div 8, - cWaveHeight - screenBottom div 20);
   454     DrawRepeated(sprHorizont, sprHorizontL, sprHorizontR, (WorldDx + LAND_WIDTH div 2) * 3 div 5);
   464     DrawRepeated(sprHorizont, sprHorizontL, sprHorizontR, (WorldDx + LAND_WIDTH div 2) * 3 div 5, 0);
   455 
   465 
   456     DrawVisualGears(0);
   466     DrawVisualGears(0);
   457     end;
   467     end;
   458 
   468 
   459 // Waves
   469 // Waves
   460 DrawWaves( 1,  0, - (cWaveHeight shl 1));
   470 offsetY:= 10 * min(0, -128 - screenBottom);
   461 DrawWaves(-1, 100, - (cWaveHeight + (cWaveHeight shr 1)));
   471 DrawWaves( 1,  0 + WorldDx div 90, - cWaveHeight + offsetY div 35, 0.25);
       
   472 DrawWaves( -1,  25 + WorldDx div 80, - cWaveHeight + offsetY div 38, 0.19);
       
   473 DrawWaves( 1,  75 + WorldDx div 70, - cWaveHeight + offsetY div 45, 0.14);
       
   474 DrawWaves(-1, 100 + WorldDx div 60, - cWaveHeight + offsetY div 70, 0.09);
   462 
   475 
   463 
   476 
   464 DrawLand(WorldDx, WorldDy);
   477 DrawLand(WorldDx, WorldDy);
   465 
   478 
   466 DrawWater(255);
   479 DrawWater(255);
   494 DrawVisualGears(2);
   507 DrawVisualGears(2);
   495 
   508 
   496 DrawWater(cWaterOpacity);
   509 DrawWater(cWaterOpacity);
   497 
   510 
   498 // Waves
   511 // Waves
   499 DrawWaves( 1, 25, - cWaveHeight);
   512 DrawWaves( 1, 25 + WorldDx div 50, - cWaveHeight, 0.05);
   500 DrawWaves(-1, 50, - (cWaveHeight shr 1));
   513 DrawWaves(-1, 50 + WorldDx div 40, 1 - cWaveHeight - offsetY div 40, 0.03);
   501 DrawWaves( 1, 75, 0);
   514 DrawWaves( 1, 75 + WorldDx div 20, 3- cWaveHeight - offsetY div 20, 0.01);
       
   515 DrawWaves( -1, 25 + WorldDx div 10, 5 - cWaveHeight - offsetY div 10, 0);
   502 
   516 
   503 
   517 
   504 {$WARNINGS OFF}
   518 {$WARNINGS OFF}
   505 // Target
   519 // Target
   506 if TargetPoint.X <> NoPointX then
   520 if TargetPoint.X <> NoPointX then