hedgewars/uWorld.pas
changeset 83 207c85fbef51
parent 82 2f4f3236cccc
child 95 1ef5e2c41115
equal deleted inserted replaced
82:2f4f3236cccc 83:207c85fbef51
    31  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    31  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    32  *)
    32  *)
    33 
    33 
    34 unit uWorld;
    34 unit uWorld;
    35 interface
    35 interface
    36 uses SDLh, uGears;
    36 uses SDLh, uGears, uConsts;
    37 {$INCLUDE options.inc}
    37 {$INCLUDE options.inc}
    38 const WorldDx: integer = -512;
    38 const WorldDx: integer = -512;
    39       WorldDy: integer = -256;
    39       WorldDy: integer = -256;
    40 
    40 
    41 procedure InitWorld;
    41 procedure InitWorld;
    42 procedure DrawWorld(Lag: integer; Surface: PSDL_Surface);
    42 procedure DrawWorld(Lag: integer; Surface: PSDL_Surface);
    43 procedure AddCaption(s: shortstring; Color, Group: LongWord);
    43 procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup);
    44 procedure MoveCamera;
    44 procedure MoveCamera;
    45 
    45 
    46 {$IFDEF COUNTTICKS}
    46 {$IFDEF COUNTTICKS}
    47 var cntTicks: LongWord;
    47 var cntTicks: LongWord;
    48 {$ENDIF}
    48 {$ENDIF}
    49 var FollowGear: PGear = nil;
    49 var FollowGear: PGear = nil;
    50     WindBarWidth: integer = 0;
    50     WindBarWidth: integer = 0;
    51 
    51 
    52 implementation
    52 implementation
    53 uses uStore, uMisc, uConsts, uTeams, uIO;
    53 uses uStore, uMisc, uTeams, uIO, uConsole;
    54 const RealTicks: Longword = 0;
    54 const RealTicks: Longword = 0;
    55       Frames: Longword = 0;
    55       Frames: Longword = 0;
    56       FPS: Longword = 0;
    56       FPS: Longword = 0;
    57       CountTicks: Longword = 0;
    57       CountTicks: Longword = 0;
    58       prevPoint: TPoint = (X: 0; Y: 0);
    58       prevPoint: TPoint = (X: 0; Y: 0);
    59       
    59       
    60 type TCaptionStr = record
    60 type TCaptionStr = record
    61                    r: TSDL_Rect;
    61                    Surf: PSDL_Surface;
    62                    StorePos,
    62                    StorePos: Longword;
    63                    Group,
    63                    Group: TCapGroup;
    64                    EndTime: LongWord;
    64                    EndTime: LongWord;
    65                    end;
    65                    end;
    66 
    66 
    67 var cWaterSprCount: integer;
    67 var cWaterSprCount: integer;
    68     Captions: array[0..Pred(cMaxCaptions)] of TCaptionStr;
    68     Captions: array[0..Pred(cMaxCaptions)] of TCaptionStr;
   214 // Captions
   214 // Captions
   215 i:= 0;
   215 i:= 0;
   216 while (i < cMaxCaptions) do
   216 while (i < cMaxCaptions) do
   217     begin
   217     begin
   218     with Captions[i] do
   218     with Captions[i] do
   219          if EndTime > 0 then DrawCaption(cScreenWidth div 2, 8 + i * 32 + cConsoleYAdd, r, Surface, true);
   219          if EndTime > 0 then
       
   220             begin
       
   221             r.x:= (cScreenWidth - Surf.w) div 2;
       
   222             r.y:= 8 + i * (Surf.h + 2) + cConsoleYAdd;
       
   223             r.w:= Surf.w;
       
   224             r.h:= Surf.h;
       
   225             SDL_UpperBlit(Surf, nil, Surface, @r)
       
   226             end;
   220     inc(i)
   227     inc(i)
   221     end;
   228     end;
   222 while (Captions[0].EndTime > 0) and (Captions[0].EndTime <= RealTicks) do
   229 while (Captions[0].EndTime > 0) and (Captions[0].EndTime <= RealTicks) do
   223     begin
   230     begin
       
   231     SDL_FreeSurface(Captions[0].Surf);
   224     for i:= 1 to Pred(cMaxCaptions) do
   232     for i:= 1 to Pred(cMaxCaptions) do
   225         Captions[Pred(i)]:= Captions[i];
   233         Captions[Pred(i)]:= Captions[i];
   226     Captions[Pred(cMaxCaptions)].EndTime:= 0
   234     Captions[Pred(cMaxCaptions)].EndTime:= 0
   227     end;
   235     end;
   228 
   236 
   232       begin
   240       begin
   233       DrawFromStoreRect(cScreenWidth div 2 - team.NameRect.w - 3,
   241       DrawFromStoreRect(cScreenWidth div 2 - team.NameRect.w - 3,
   234                         Team.DrawHealthY,
   242                         Team.DrawHealthY,
   235                         @team.NameRect, Surface);
   243                         @team.NameRect, Surface);
   236       r:= team.HealthRect;
   244       r:= team.HealthRect;
   237       r.w:= 3 + team.TeamHealth;
   245       r.w:= 2 + team.TeamHealth;
   238       DrawFromStoreRect(cScreenWidth div 2,
   246       DrawFromStoreRect(cScreenWidth div 2,
   239                         Team.DrawHealthY,
   247                         Team.DrawHealthY,
   240                         @r, Surface);
   248                         @r, Surface);
   241       inc(r.x, cTeamHealthWidth + 3);
   249       inc(r.x, cTeamHealthWidth + 2);
   242       r.w:= 2;
   250       r.w:= 3;
   243       DrawFromStoreRect(cScreenWidth div 2 + team.TeamHealth + 3,
   251       DrawFromStoreRect(cScreenWidth div 2 + team.TeamHealth + 2,
   244                         Team.DrawHealthY,
   252                         Team.DrawHealthY,
   245                         @r, Surface);
   253                         @r, Surface);
   246       team:= team.Next
   254       team:= team.Next
   247       end;
   255       end;
   248 
   256 
   294    CountTicks:= 0;
   302    CountTicks:= 0;
   295    end;
   303    end;
   296 if cShowFPS then DXOutText(cScreenWidth - 50, 10, fnt16, inttostr(FPS) + ' fps', Surface)
   304 if cShowFPS then DXOutText(cScreenWidth - 50, 10, fnt16, inttostr(FPS) + ' fps', Surface)
   297 end;
   305 end;
   298 
   306 
   299 procedure AddCaption(s: shortstring; Color, Group: LongWord);
   307 procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup);
   300 var i, t, m, k: LongWord;
   308 var i, t, m, k: LongWord;
   301 begin
   309 begin
       
   310 if Group in [capgrpGameState, capgrpNetSay] then WriteLnToConsole(s);
   302 i:= 0;
   311 i:= 0;
   303 while (i < cMaxCaptions) and (Captions[i].Group <> Group)do inc(i);
   312 while (i < cMaxCaptions) and (Captions[i].Group <> Group) do inc(i);
   304 if i < cMaxCaptions then
   313 if i < cMaxCaptions then
   305    begin
   314    begin
   306    while (i < Pred(cMaxCaptions)) do
   315    while (i < Pred(cMaxCaptions)) do
   307          begin
   316          begin
   308          Captions[i]:= Captions[Succ(i)];
   317          Captions[i]:= Captions[Succ(i)];
   324    end;
   333    end;
   325 
   334 
   326 k:= 0;
   335 k:= 0;
   327 for i:= 0 to Pred(cMaxCaptions) do
   336 for i:= 0 to Pred(cMaxCaptions) do
   328     for t:= 0 to Pred(cMaxCaptions) do
   337     for t:= 0 to Pred(cMaxCaptions) do
   329         if (Captions[t].EndTime > 0)and(Captions[t].StorePos = k) then inc(k);
   338         if (Captions[t].EndTime > 0) and (Captions[t].StorePos = k) then inc(k);
   330 
   339 
   331 Captions[m].r:= RenderString(s, Color, k);
   340 Captions[m].Surf:= RenderString(s, Color, k);
   332 Captions[m].StorePos:= k;
   341 Captions[m].StorePos:= k;
   333 Captions[m].Group:= Group;
   342 Captions[m].Group:= Group;
   334 Captions[m].EndTime:= RealTicks + 1200
   343 Captions[m].EndTime:= RealTicks + 1200
   335 end;
   344 end;
   336 
   345