hedgewars/uWorld.pas
changeset 3697 d5b30d6373fc
parent 3695 c11abf387a7d
child 3764 eb91c02f2d84
equal deleted inserted replaced
3695:c11abf387a7d 3697:d5b30d6373fc
    36     HorizontOffset: LongInt;
    36     HorizontOffset: LongInt;
    37 {$IFDEF COUNTTICKS}
    37 {$IFDEF COUNTTICKS}
    38     cntTicks: LongWord;
    38     cntTicks: LongWord;
    39 {$ENDIF}
    39 {$ENDIF}
    40     cOffsetY: LongInt;
    40     cOffsetY: LongInt;
    41     
    41 
    42 procedure initModule;
    42 procedure initModule;
    43 procedure freeModule;
    43 procedure freeModule;
    44 
    44 
    45 procedure InitWorld;
    45 procedure InitWorld;
    46 procedure DrawWorld(Lag: LongInt);
    46 procedure DrawWorld(Lag: LongInt);
   279         for g:= g to cMaxSlotAmmoIndex do
   279         for g:= g to cMaxSlotAmmoIndex do
   280             DrawSprite(sprAMSlot, x + g * AMSlotSize, y, 1);
   280             DrawSprite(sprAMSlot, x + g * AMSlotSize, y, 1);
   281         DrawSprite(sprAMBorderVertical, x + AMWidth - AMxOffset, y, 1);
   281         DrawSprite(sprAMBorderVertical, x + AMWidth - AMxOffset, y, 1);
   282         inc(y, AMSlotSize);
   282         inc(y, AMSlotSize);
   283         end;
   283         end;
   284         
   284 
   285 DrawSprite(sprAMCorners, x - BORDERSIZE, y, 2);
   285 DrawSprite(sprAMCorners, x - BORDERSIZE, y, 2);
   286 for i:= 0 to cMaxSlotAmmoIndex do
   286 for i:= 0 to cMaxSlotAmmoIndex do
   287 	DrawSprite(sprAMBorderHorizontal, x + i * AMSlotSize, y, 1);
   287 	DrawSprite(sprAMBorderHorizontal, x + i * AMSlotSize, y, 1);
   288 DrawSprite(sprAMCorners, x + AMWidth - AMxOffset, y, 3);
   288 DrawSprite(sprAMCorners, x + AMWidth - AMxOffset, y, 3);
   289 {$ELSE}
   289 {$ELSE}
   337             end;
   337             end;
   338         for g:= g to cMaxSlotAmmoIndex + 1 do
   338         for g:= g to cMaxSlotAmmoIndex + 1 do
   339             DrawSprite(sprAMSlot, x + g * AMSlotSize, y, 1);
   339             DrawSprite(sprAMSlot, x + g * AMSlotSize, y, 1);
   340         DrawSprite(sprAMBorderVertical, x + AMWidth - AMxOffset, y, 1);
   340         DrawSprite(sprAMBorderVertical, x + AMWidth - AMxOffset, y, 1);
   341         end;
   341         end;
   342         
   342 
   343 dec(y, BORDERSIZE);
   343 dec(y, BORDERSIZE);
   344 DrawSprite(sprAMCorners, x - BORDERSIZE, y, 0);
   344 DrawSprite(sprAMCorners, x - BORDERSIZE, y, 0);
   345 for i:= 0 to cMaxSlotAmmoIndex + 1 do
   345 for i:= 0 to cMaxSlotAmmoIndex + 1 do
   346 	DrawSprite(sprAMBorderHorizontal, x + i * AMSlotSize, y, 0);
   346 	DrawSprite(sprAMBorderHorizontal, x + i * AMSlotSize, y, 0);
   347 DrawSprite(sprAMCorners, x + AMWidth - AMxOffset, y, 1);
   347 DrawSprite(sprAMCorners, x + AMWidth - AMxOffset, y, 1);
   353         if (amSel <> Ammo^[Slot, Pos].AmmoType) or (WeaponTooltipTex = nil) then
   353         if (amSel <> Ammo^[Slot, Pos].AmmoType) or (WeaponTooltipTex = nil) then
   354             begin
   354             begin
   355             amSel:= Ammo^[Slot, Pos].AmmoType;
   355             amSel:= Ammo^[Slot, Pos].AmmoType;
   356             RenderWeaponTooltip(amSel)
   356             RenderWeaponTooltip(amSel)
   357             end;
   357             end;
   358             
   358 
   359 {$IFDEF IPHONEOS}
   359 {$IFDEF IPHONEOS}
   360         DrawTexture(cScreenWidth div 2 - (AMWidth - 10) + AMxShift, AMyOffset - 25, Ammoz[Ammo^[Slot, Pos].AmmoType].NameTex);
   360         DrawTexture(cScreenWidth div 2 - (AMWidth - 10) + AMxShift, AMyOffset - 25, Ammoz[Ammo^[Slot, Pos].AmmoType].NameTex);
   361 
   361 
   362         if Ammo^[Slot, Pos].Count < AMMO_INFINITE then
   362         if Ammo^[Slot, Pos].Count < AMMO_INFINITE then
   363             DrawTexture(cScreenWidth div 2 + AMxOffset - 45, AMyOffset - 25, CountTexz[Ammo^[Slot, Pos].Count]);
   363             DrawTexture(cScreenWidth div 2 + AMxOffset - 45, AMyOffset - 25, CountTexz[Ammo^[Slot, Pos].Count]);
   400     WaterColorArray[2].a := Alpha;
   400     WaterColorArray[2].a := Alpha;
   401     WaterColorArray[3].a := Alpha;
   401     WaterColorArray[3].a := Alpha;
   402 
   402 
   403     lw:= cScreenWidth / cScaleFactor;
   403     lw:= cScreenWidth / cScaleFactor;
   404     lh:= trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 + 16;
   404     lh:= trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 + 16;
   405     
   405 
   406     // Water
   406     // Water
   407     r.y:= OffsetY + WorldDy + cWaterLine;
   407     r.y:= OffsetY + WorldDy + cWaterLine;
   408     if WorldDy < trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - cWaterLine then
   408     if WorldDy < trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - cWaterLine then
   409     begin
   409     begin
   410         if r.y < 0 then
   410         if r.y < 0 then
   507         lh:= SpritesData[sprL].Height * SpritesData[spr].Texture^.Scale;
   507         lh:= SpritesData[sprL].Height * SpritesData[spr].Texture^.Scale;
   508         rw:= SpritesData[sprR].Width * SpritesData[spr].Texture^.Scale;
   508         rw:= SpritesData[sprR].Width * SpritesData[spr].Texture^.Scale;
   509         rh:= SpritesData[sprR].Height * SpritesData[spr].Texture^.Scale;
   509         rh:= SpritesData[sprR].Height * SpritesData[spr].Texture^.Scale;
   510         dec(Shift, w div 2);
   510         dec(Shift, w div 2);
   511         DrawTexture(Shift, WorldDy + LAND_HEIGHT + OffsetY - h, SpritesData[spr].Texture, SpritesData[spr].Texture^.Scale);
   511         DrawTexture(Shift, WorldDy + LAND_HEIGHT + OffsetY - h, SpritesData[spr].Texture, SpritesData[spr].Texture^.Scale);
   512     
   512 
   513         i:= Shift - lw;
   513         i:= Shift - lw;
   514         while i >= -sw - lw do
   514         while i >= -sw - lw do
   515         begin
   515         begin
   516             DrawTexture(i, WorldDy + LAND_HEIGHT + OffsetY - lh, SpritesData[sprL].Texture, SpritesData[sprL].Texture^.Scale);
   516             DrawTexture(i, WorldDy + LAND_HEIGHT + OffsetY - lh, SpritesData[sprL].Texture, SpritesData[sprL].Texture^.Scale);
   517             dec(i, lw);
   517             dec(i, lw);
   518         end;
   518         end;
   519         
   519 
   520         i:= Shift + w;
   520         i:= Shift + w;
   521         while i <= sw do
   521         while i <= sw do
   522         begin
   522         begin
   523             DrawTexture(i, WorldDy + LAND_HEIGHT + OffsetY - rh, SpritesData[sprR].Texture, SpritesData[sprR].Texture^.Scale);
   523             DrawTexture(i, WorldDy + LAND_HEIGHT + OffsetY - rh, SpritesData[sprR].Texture, SpritesData[sprR].Texture^.Scale);
   524             inc(i, rw)
   524             inc(i, rw)
   540     if not isPaused then
   540     if not isPaused then
   541     begin
   541     begin
   542         if ZoomValue < zoom then
   542         if ZoomValue < zoom then
   543         begin
   543         begin
   544             zoom:= zoom - 0.002 * Lag;
   544             zoom:= zoom - 0.002 * Lag;
   545             if ZoomValue > zoom then 
   545             if ZoomValue > zoom then
   546                 zoom:= ZoomValue
   546                 zoom:= ZoomValue
   547         end 
   547         end
   548     else 
   548     else
   549         if ZoomValue > zoom then
   549         if ZoomValue > zoom then
   550         begin
   550         begin
   551             zoom:= zoom + 0.002 * Lag;
   551             zoom:= zoom + 0.002 * Lag;
   552             if ZoomValue < zoom then
   552             if ZoomValue < zoom then
   553                 zoom:= ZoomValue
   553                 zoom:= ZoomValue
   578         DrawRepeated(sprSky, sprSkyL, sprSkyR, (WorldDx + LAND_WIDTH div 2) * 3 div 8, SkyOffset);
   578         DrawRepeated(sprSky, sprSkyL, sprSkyR, (WorldDx + LAND_WIDTH div 2) * 3 div 8, SkyOffset);
   579         DrawRepeated(sprHorizont, sprHorizontL, sprHorizontR, (WorldDx + LAND_WIDTH div 2) * 3 div 5, HorizontOffset);
   579         DrawRepeated(sprHorizont, sprHorizontL, sprHorizontR, (WorldDx + LAND_WIDTH div 2) * 3 div 5, HorizontOffset);
   580     end;
   580     end;
   581 
   581 
   582     DrawVisualGears(0);
   582     DrawVisualGears(0);
   583     
   583 
   584     if (cReducedQuality and rq2DWater) = 0 then
   584     if (cReducedQuality and rq2DWater) = 0 then
   585     begin
   585     begin
   586         // Waves
   586         // Waves
   587         DrawWater(255, SkyOffset); 
   587         DrawWater(255, SkyOffset);
   588         DrawWaves( 1,  0 - WorldDx div 32, - cWaveHeight + offsetY div 35, 64);
   588         DrawWaves( 1,  0 - WorldDx div 32, - cWaveHeight + offsetY div 35, 64);
   589         DrawWaves( -1,  25 + WorldDx div 25, - cWaveHeight + offsetY div 38, 48);
   589         DrawWaves( -1,  25 + WorldDx div 25, - cWaveHeight + offsetY div 38, 48);
   590         DrawWaves( 1,  75 - WorldDx div 19, - cWaveHeight + offsetY div 45, 32);
   590         DrawWaves( 1,  75 - WorldDx div 19, - cWaveHeight + offsetY div 45, 32);
   591         DrawWaves(-1, 100 + WorldDx div 14, - cWaveHeight + offsetY div 70, 24);
   591         DrawWaves(-1, 100 + WorldDx div 14, - cWaveHeight + offsetY div 70, 24);
   592     end
   592     end
   692     t:= 272;
   692     t:= 272;
   693     // right frame
   693     // right frame
   694     DrawSprite(sprFrame, -cScreenWidth div 2 + t, 8, 1);
   694     DrawSprite(sprFrame, -cScreenWidth div 2 + t, 8, 1);
   695     dec(t, 32);
   695     dec(t, 32);
   696     // 1 ms
   696     // 1 ms
   697     DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10); 
   697     DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
   698     dec(t, 32);
   698     dec(t, 32);
   699     i:= i div 10;
   699     i:= i div 10;
   700     // 10 ms
   700     // 10 ms
   701     DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
   701     DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
   702     dec(t, 32);
   702     dec(t, 32);
   755 // Teams Healths
   755 // Teams Healths
   756 for t:= 0 to Pred(TeamsCount) do
   756 for t:= 0 to Pred(TeamsCount) do
   757    with TeamsArray[t]^ do
   757    with TeamsArray[t]^ do
   758       begin
   758       begin
   759       highlight:= bShowFinger and (CurrentTeam = TeamsArray[t]) and ((RealTicks mod 1000) < 500);
   759       highlight:= bShowFinger and (CurrentTeam = TeamsArray[t]) and ((RealTicks mod 1000) < 500);
   760       
   760 
   761       if highlight then
   761       if highlight then
   762          Tint(Clan^.Color);
   762          Tint(Clan^.Color);
   763 
   763 
   764       // draw name
   764       // draw name
   765       DrawTexture(-NameTagTex^.w - 16, cScreenHeight + DrawHealthY, NameTagTex);
   765       DrawTexture(-NameTagTex^.w - 16, cScreenHeight + DrawHealthY, NameTagTex);
   766       
   766 
   767       // draw flag
   767       // draw flag
   768       DrawTexture(-14, cScreenHeight + DrawHealthY, FlagTex);
   768       DrawTexture(-14, cScreenHeight + DrawHealthY, FlagTex);
   769       
   769 
   770       // draw health bar
   770       // draw health bar
   771       r.x:= 0;
   771       r.x:= 0;
   772       r.y:= 0;
   772       r.y:= 0;
   773       r.w:= 2 + TeamHealthBarWidth;
   773       r.w:= 2 + TeamHealthBarWidth;
   774       r.h:= HealthTex^.h;
   774       r.h:= HealthTex^.h;
   874    i:= i div 60;
   874    i:= i div 60;
   875    t:= i mod 60;
   875    t:= i mod 60;
   876    s:= inttostr(t) + ':' + s;
   876    s:= inttostr(t) + ':' + s;
   877    if t < 10 then s:= '0' + s;
   877    if t < 10 then s:= '0' + s;
   878    s:= inttostr(i div 60) + ':' + s;
   878    s:= inttostr(i div 60) + ':' + s;
   879    
   879 
   880    if timeTexture <> nil then
   880    if timeTexture <> nil then
   881         FreeTexture(timeTexture);
   881         FreeTexture(timeTexture);
   882     timeTexture:= nil;
   882     timeTexture:= nil;
   883     
   883 
   884    tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), cWhiteColorChannels);
   884    tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), cWhiteColorChannels);
   885    tmpSurface:= doSurfaceConversion(tmpSurface);
   885    tmpSurface:= doSurfaceConversion(tmpSurface);
   886    timeTexture:= Surface2Tex(tmpSurface, false);
   886    timeTexture:= Surface2Tex(tmpSurface, false);
   887    SDL_FreeSurface(tmpSurface)
   887    SDL_FreeSurface(tmpSurface)
   888    end;
   888    end;
   944         begin
   944         begin
   945         case ScreenFade of
   945         case ScreenFade of
   946             sfToBlack, sfFromBlack: Tint(0, 0, 0, ScreenFadeValue * 255 div 1000);
   946             sfToBlack, sfFromBlack: Tint(0, 0, 0, ScreenFadeValue * 255 div 1000);
   947             sfToWhite, sfFromWhite: Tint($FF, $FF, $FF, ScreenFadeValue * 255 div 1000);
   947             sfToWhite, sfFromWhite: Tint($FF, $FF, $FF, ScreenFadeValue * 255 div 1000);
   948             end;
   948             end;
   949         
   949 
   950         VertexBuffer[0].X:= -cScreenWidth;
   950         VertexBuffer[0].X:= -cScreenWidth;
   951         VertexBuffer[0].Y:= cScreenHeight;
   951         VertexBuffer[0].Y:= cScreenHeight;
   952         VertexBuffer[1].X:= -cScreenWidth;
   952         VertexBuffer[1].X:= -cScreenWidth;
   953         VertexBuffer[1].Y:= 0;
   953         VertexBuffer[1].Y:= 0;
   954         VertexBuffer[2].X:= cScreenWidth;
   954         VertexBuffer[2].X:= cScreenWidth;
   955         VertexBuffer[2].Y:= 0;
   955         VertexBuffer[2].Y:= 0;
   956         VertexBuffer[3].X:= cScreenWidth;
   956         VertexBuffer[3].X:= cScreenWidth;
   957         VertexBuffer[3].Y:= cScreenHeight;
   957         VertexBuffer[3].Y:= cScreenHeight;
   958          
   958 
   959         glDisable(GL_TEXTURE_2D);
   959         glDisable(GL_TEXTURE_2D);
   960 
   960 
   961         glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
   961         glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
   962         glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   962         glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   963 
   963 
   989 end;
   989 end;
   990 
   990 
   991 procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup);
   991 procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup);
   992 begin
   992 begin
   993 //if Group in [capgrpGameState] then WriteLnToConsole(s);
   993 //if Group in [capgrpGameState] then WriteLnToConsole(s);
   994     if Captions[Group].Tex <> nil then 
   994     if Captions[Group].Tex <> nil then
   995         FreeTexture(Captions[Group].Tex);
   995         FreeTexture(Captions[Group].Tex);
   996     Captions[Group].Tex:= nil;
   996     Captions[Group].Tex:= nil;
   997 
   997 
   998     Captions[Group].Tex:= RenderStringTex(s, Color, fntBig);
   998     Captions[Group].Tex:= RenderStringTex(s, Color, fntBig);
   999 
   999 
  1115 r.w:= 32;
  1115 r.w:= 32;
  1116 r.h:= 32;
  1116 r.h:= 32;
  1117 
  1117 
  1118 if time = 0 then time:= 5000;
  1118 if time = 0 then time:= 5000;
  1119 missionTimer:= time;
  1119 missionTimer:= time;
  1120 if missionTex <> nil then 
  1120 if missionTex <> nil then
  1121     FreeTexture(missionTex);
  1121     FreeTexture(missionTex);
  1122 missionTex:= nil;
  1122 missionTex:= nil;
  1123 
  1123 
  1124 if icon > -1 then
  1124 if icon > -1 then
  1125     begin
  1125     begin
  1157     bSelected:= false;
  1157     bSelected:= false;
  1158     bShowFinger:= false;
  1158     bShowFinger:= false;
  1159     Frames:= 0;
  1159     Frames:= 0;
  1160     WorldDx:= -512;
  1160     WorldDx:= -512;
  1161     WorldDy:= -256;
  1161     WorldDy:= -256;
  1162     
  1162 
  1163     FPS:= 0;
  1163     FPS:= 0;
  1164     CountTicks:= 0;
  1164     CountTicks:= 0;
  1165     SoundTimerTicks:= 0;
  1165     SoundTimerTicks:= 0;
  1166     prevPoint.X:= 0;
  1166     prevPoint.X:= 0;
  1167     prevPoint.Y:= 0;
  1167     prevPoint.Y:= 0;
  1168     missionTimer:= 0;
  1168     missionTimer:= 0;
  1169     missionTex:= nil;
  1169     missionTex:= nil;
  1170     cOffsetY:= 0;
  1170     cOffsetY:= 0;
  1171     
  1171 
  1172     FillChar(Captions, sizeof(Captions), 0)
  1172     FillChar(Captions, sizeof(Captions), 0)
  1173 end;
  1173 end;
  1174 
  1174 
  1175 procedure freeModule;
  1175 procedure freeModule;
  1176 begin
  1176 begin