hedgewars/uWorld.pas
changeset 162 4822f6face35
parent 161 d8870bbf960e
child 165 9b9144948668
equal deleted inserted replaced
161:d8870bbf960e 162:4822f6face35
    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: string; Color: Longword; Group: TCapGroup);
    43 procedure AddCaption(s: string; Color: Longword; Group: TCapGroup);
    44 procedure MoveCamera;
       
    45 
    44 
    46 {$IFDEF COUNTTICKS}
    45 {$IFDEF COUNTTICKS}
    47 var cntTicks: LongWord;
    46 var cntTicks: LongWord;
    48 {$ENDIF}
    47 {$ENDIF}
    49 var FollowGear: PGear = nil;
    48 var FollowGear: PGear = nil;
    50     WindBarWidth: integer = 0;
    49     WindBarWidth: integer = 0;
    51     bShowAmmoMenu: boolean = false;
    50     bShowAmmoMenu: boolean = false;
       
    51     bSelected: boolean = false;
    52 
    52 
    53 implementation
    53 implementation
    54 uses uStore, uMisc, uTeams, uIO, uConsole, uKeys;
    54 uses uStore, uMisc, uTeams, uIO, uConsole, uKeys, uLocale;
    55 const RealTicks: Longword = 0;
    55 const RealTicks: Longword = 0;
    56       Frames: Longword = 0;
    56       Frames: Longword = 0;
    57       FPS: Longword = 0;
    57       FPS: Longword = 0;
    58       CountTicks: Longword = 0;
    58       CountTicks: Longword = 0;
    59       prevPoint: TPoint = (X: 0; Y: 0);
    59       prevPoint: TPoint = (X: 0; Y: 0);
    65                    EndTime: LongWord;
    65                    EndTime: LongWord;
    66                    end;
    66                    end;
    67 
    67 
    68 var cWaterSprCount: integer;
    68 var cWaterSprCount: integer;
    69     Captions: array[0..Pred(cMaxCaptions)] of TCaptionStr;
    69     Captions: array[0..Pred(cMaxCaptions)] of TCaptionStr;
    70     AMxLeft, AMxCurr: integer;
    70     AMxLeft, AMxCurr, SlotsNum: integer;
    71 
    71 
    72 procedure InitWorld;
    72 procedure InitWorld;
    73 begin
    73 begin
    74 cWaterSprCount:= 1 + cScreenWidth div (SpritesData[sprWater].Width);
    74 cWaterSprCount:= 1 + cScreenWidth div (SpritesData[sprWater].Width);
    75 cScreenEdgesDist:= Min(cScreenWidth div 4, cScreenHeight div 4);
    75 cScreenEdgesDist:= Min(cScreenWidth div 4, cScreenHeight div 4);
    83 end;
    83 end;
    84 
    84 
    85 procedure ShowAmmoMenu(Surface: PSDL_Surface);
    85 procedure ShowAmmoMenu(Surface: PSDL_Surface);
    86 const MENUSPEED = 15;
    86 const MENUSPEED = 15;
    87 var x, y, i, t: integer;
    87 var x, y, i, t: integer;
       
    88     Slot, Pos: integer;
    88 begin
    89 begin
    89 if (TurnTimeLeft = 0) or KbdKeyPressed then bShowAmmoMenu:= false;
    90 if (TurnTimeLeft = 0) or KbdKeyPressed then bShowAmmoMenu:= false;
    90 if      bShowAmmoMenu  and (AMxCurr > AMxLeft)      then dec(AMxCurr, MENUSPEED);
    91 if      bShowAmmoMenu  and (AMxCurr > AMxLeft)      then dec(AMxCurr, MENUSPEED);
    91 if (not bShowAmmoMenu) and (AMxCurr < cScreenWidth) then inc(AMxCurr, MENUSPEED);
    92 if (not bShowAmmoMenu) and (AMxCurr < cScreenWidth) then inc(AMxCurr, MENUSPEED);
    92 
    93 
    93 if CurrentTeam = nil then exit;
    94 if CurrentTeam = nil then exit;
       
    95 Slot:= 0;
       
    96 Pos:= -1;
    94 with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
    97 with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
    95      begin
    98      begin
    96      if Ammo = nil then exit;
    99      if Ammo = nil then exit;
       
   100      SlotsNum:= 0;
    97      x:= AMxCurr;
   101      x:= AMxCurr;
    98      y:= cScreenHeight - 40;
   102      y:= cScreenHeight - 40;
    99      dec(y);
   103      dec(y);
   100      DrawSprite(sprAMBorders, x, y, 0, Surface);
   104      DrawSprite(sprAMBorders, x, y, 0, Surface);
   101      dec(y);
   105      dec(y);
   103      dec(y, 33);
   107      dec(y, 33);
   104      DrawSprite(sprAMSlotName, x, y, 0, Surface);
   108      DrawSprite(sprAMSlotName, x, y, 0, Surface);
   105      for i:= cMaxSlotIndex downto 0 do
   109      for i:= cMaxSlotIndex downto 0 do
   106          if Ammo[i, 0].Count > 0 then
   110          if Ammo[i, 0].Count > 0 then
   107             begin
   111             begin
       
   112             if (CursorPoint.Y >= y - 33) and (CursorPoint.Y < y) then Slot:= i;
   108             dec(y, 33);
   113             dec(y, 33);
       
   114             inc(SlotsNum);
   109             DrawSprite(sprAMSlot, x, y, 0, Surface);
   115             DrawSprite(sprAMSlot, x, y, 0, Surface);
   110             DrawSprite(sprAMSlotKeys, x + 2, y + 1, i, Surface);
   116             DrawSprite(sprAMSlotKeys, x + 2, y + 1, i, Surface);
   111             t:= 0;
   117             t:= 0;
   112             while (t <= cMaxSlotAmmoIndex) and (Ammo[i, t].Count > 0) do
   118             while (t <= cMaxSlotAmmoIndex) and (Ammo[i, t].Count > 0) do
   113                   begin
   119                   begin
   114                   DrawSprite(sprAMAmmos, x + t * 33 + 35, y + 1, integer(Ammo[i, t].AmmoType), Surface);
   120                   DrawSprite(sprAMAmmos, x + t * 33 + 35, y + 1, integer(Ammo[i, t].AmmoType), Surface);
       
   121                   if (Slot = i) and (CursorPoint.X >= x + t * 33 + 35) and (CursorPoint.X < x + t * 33 + 68) then
       
   122                      begin
       
   123                      DrawSprite(sprAMSelection, x + t * 33 + 35, y + 1, 0, Surface);
       
   124                      Pos:= t;
       
   125                      end;
   115                   inc(t)
   126                   inc(t)
   116                   end
   127                   end
   117             end;
   128             end;
   118      dec(y, 1);
   129      dec(y, 1);
   119      DrawSprite(sprAMBorders, x, y, 0, Surface)
   130      DrawSprite(sprAMBorders, x, y, 0, Surface);
   120      end
   131 
       
   132      if (Pos >= 0) then
       
   133         if Ammo[Slot, Pos].Count > 0 then
       
   134            begin
       
   135            DXOutText(AMxCurr + 10, cScreenHeight - 68, fnt16, trAmmo[Ammoz[Ammo[Slot, Pos].AmmoType].NameId], Surface);
       
   136            if Ammo[Slot, Pos].Count < 10 then
       
   137               DXOutText(AMxCurr + 175, cScreenHeight - 68, fnt16, chr(Ammo[Slot, Pos].Count + 48) + 'x', Surface);
       
   138            if bSelected then
       
   139               begin
       
   140               CurSlot:= Slot;
       
   141               CurAmmo:= Pos;
       
   142               ApplyAmmoChanges(CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog]);
       
   143               bShowAmmoMenu:= false
       
   144               end;
       
   145            end;
       
   146      end;
       
   147 
       
   148 bSelected:= false;
       
   149 DrawSprite(sprArrow, CursorPoint.X, CursorPoint.Y, (RealTicks shr 6) mod 8, Surface)
   121 end;
   150 end;
       
   151 
       
   152 procedure MoveCamera; forward;
   122 
   153 
   123 procedure DrawWorld(Lag: integer; Surface: PSDL_Surface);
   154 procedure DrawWorld(Lag: integer; Surface: PSDL_Surface);
   124 var i, t: integer;
   155 var i, t: integer;
   125     r: TSDL_Rect;
   156     r: TSDL_Rect;
   126     team: PTeam;
   157     team: PTeam;
   137       inc(i, w)
   168       inc(i, w)
   138     until i > cScreenWidth
   169     until i > cScreenWidth
   139     end;
   170     end;
   140 
   171 
   141 begin
   172 begin
       
   173 MoveCamera;
       
   174 
   142 // Sky
   175 // Sky
   143 inc(RealTicks, Lag);
   176 inc(RealTicks, Lag);
   144 if WorldDy > 0 then
   177 if WorldDy > 0 then
   145    begin
   178    begin
   146    if WorldDy > cScreenHeight then r.h:= cScreenHeight
   179    if WorldDy > cScreenHeight then r.h:= cScreenHeight
   404       CursorPoint.y:= (CursorPoint.y * 7 + (round(FollowGear.Y) + WorldDy)) div 8
   437       CursorPoint.y:= (CursorPoint.y * 7 + (round(FollowGear.Y) + WorldDy)) div 8
   405       end;
   438       end;
   406 
   439 
   407 if ((CursorPoint.X = prevPoint.X)and(CursorPoint.Y = prevpoint.Y)) then exit;
   440 if ((CursorPoint.X = prevPoint.X)and(CursorPoint.Y = prevpoint.Y)) then exit;
   408 
   441 
       
   442 if AMxCurr < cScreenWidth then
       
   443    begin
       
   444    if CursorPoint.X < AMxCurr + 35 then CursorPoint.X:= AMxCurr + 35;
       
   445    if CursorPoint.X > AMxCurr + 200 then CursorPoint.X:= AMxCurr + 200;
       
   446    if CursorPoint.Y < cScreenHeight - 75 - SlotsNum * 33 then CursorPoint.Y:= cScreenHeight - 75 - SlotsNum * 33;
       
   447    if CursorPoint.Y > cScreenHeight - 76 then CursorPoint.Y:= cScreenHeight - 76;
       
   448    prevPoint:= CursorPoint;
       
   449    SDL_WarpMouse(CursorPoint.X, CursorPoint.Y);
       
   450    exit
       
   451    end;
       
   452 
   409 if isCursorVisible then
   453 if isCursorVisible then
   410    begin
   454    begin
   411    if (not CurrentTeam.ExtDriven)and(GameTicks >= PrevSentPointTime + cSendCursorPosTime) then
   455    if (not CurrentTeam.ExtDriven)and(GameTicks >= PrevSentPointTime + cSendCursorPosTime) then
   412       begin
   456       begin
   413       SendIPCXY('P', CursorPoint.X - WorldDx, CursorPoint.Y - WorldDy);
   457       SendIPCXY('P', CursorPoint.X - WorldDx, CursorPoint.Y - WorldDy);