hedgewars/uWorld.pas
changeset 2197 a02adcdaa939
parent 2178 d8b3417b2704
child 2198 6a3d40acba8b
equal deleted inserted replaced
2196:7032f286301b 2197:a02adcdaa939
    68 begin
    68 begin
    69 cWaveWidth:= SpritesData[sprWater].Width;
    69 cWaveWidth:= SpritesData[sprWater].Width;
    70 cWaveHeight:= SpritesData[sprWater].Height;
    70 cWaveHeight:= SpritesData[sprWater].Height;
    71 cGearScrEdgesDist:= Min(cScreenWidth div 2 - 100, cScreenHeight div 2 - 50);
    71 cGearScrEdgesDist:= Min(cScreenWidth div 2 - 100, cScreenHeight div 2 - 50);
    72 SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2);
    72 SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2);
    73 prevPoint.X:= cScreenWidth div 2;
    73 prevPoint.X:= 0;
    74 prevPoint.Y:= cScreenHeight div 2;
    74 prevPoint.Y:= cScreenHeight div 2;
    75 WorldDx:=  - (LAND_WIDTH div 2) + cScreenWidth div 2;
    75 WorldDx:=  - (LAND_WIDTH div 2) + cScreenWidth div 2;
    76 //WorldDy:=  - (LAND_HEIGHT div 2) + cScreenHeight div 2;
       
    77 WorldDy:=  - (LAND_HEIGHT - (playHeight div 2)) + (cScreenHeight div 2);
    76 WorldDy:=  - (LAND_HEIGHT - (playHeight div 2)) + (cScreenHeight div 2);
    78 AMxShift:= 210
    77 AMxShift:= 210
    79 end;
    78 end;
    80 
    79 
    81 procedure ShowAmmoMenu;
    80 procedure ShowAmmoMenu;
    96    if AMxShift = 0 then
    95    if AMxShift = 0 then
    97       begin
    96       begin
    98       CursorPoint.X:= cScreenWidth div 2;
    97       CursorPoint.X:= cScreenWidth div 2;
    99       CursorPoint.Y:= cScreenHeight div 2;
    98       CursorPoint.Y:= cScreenHeight div 2;
   100       prevPoint:= CursorPoint;
    99       prevPoint:= CursorPoint;
   101       SDL_WarpMouse(CursorPoint.X  + cScreenWidth div 2, CursorPoint.Y)
   100       SDL_WarpMouse(CursorPoint.X  + cScreenWidth div 2, cScreenHeight - CursorPoint.Y)
   102       end;
   101       end;
   103    if cReducedQuality then
   102    if cReducedQuality then
   104        AMxShift:= 210
   103        AMxShift:= 210
   105    else
   104    else
   106        if AMxShift < 210 then inc(AMxShift, MENUSPEED);
   105        if AMxShift < 210 then inc(AMxShift, MENUSPEED);
   122 	dec(y, 33);
   121 	dec(y, 33);
   123 	DrawSprite(sprAMSlotName, x, y, 0);
   122 	DrawSprite(sprAMSlotName, x, y, 0);
   124 	for i:= cMaxSlotIndex downto 0 do
   123 	for i:= cMaxSlotIndex downto 0 do
   125 		if Ammo^[i, 0].Count > 0 then
   124 		if Ammo^[i, 0].Count > 0 then
   126 			begin
   125 			begin
   127 			if (CursorPoint.Y >= y - 33) and (CursorPoint.Y < y) then Slot:= i;
   126 			if (cScreenHeight - CursorPoint.Y >= y - 33) and (cScreenHeight - CursorPoint.Y < y) then Slot:= i;
   128 			dec(y, 33);
   127 			dec(y, 33);
   129 			inc(SlotsNum);
   128 			inc(SlotsNum);
   130 			DrawSprite(sprAMSlot, x, y, 0);
   129 			DrawSprite(sprAMSlot, x, y, 0);
   131 			DrawSprite(sprAMSlotKeys, x + 2, y + 1, i);
   130 			DrawSprite(sprAMSlotKeys, x + 2, y + 1, i);
   132 			t:= 0;
   131 			t:= 0;
   171 			end;
   170 			end;
   172 		end;
   171 		end;
   173 	end;
   172 	end;
   174 
   173 
   175 bSelected:= false;
   174 bSelected:= false;
   176 if AMxShift = 0 then DrawSprite(sprArrow, CursorPoint.X, CursorPoint.Y, (RealTicks shr 6) mod 8)
   175 if AMxShift = 0 then DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8)
   177 end;
   176 end;
   178 
   177 
   179 procedure MoveCamera; forward;
   178 procedure MoveCamera; forward;
   180 
   179 
   181 procedure DrawWater;
   180 procedure DrawWater;
   404          begin
   403          begin
   405          i:= Ammo^[CurSlot, CurAmmo].Pos;
   404          i:= Ammo^[CurSlot, CurAmmo].Pos;
   406          with Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType] do
   405          with Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType] do
   407            if PosCount > 1 then
   406            if PosCount > 1 then
   408               DrawSprite(PosSprite, CursorPoint.X - SpritesData[PosSprite].Width div 2,
   407               DrawSprite(PosSprite, CursorPoint.X - SpritesData[PosSprite].Width div 2,
   409                                     CursorPoint.Y - SpritesData[PosSprite].Height div 2,
   408                                     cScreenHeight - CursorPoint.Y - SpritesData[PosSprite].Height div 2,
   410                                     i);
   409                                     i);
   411          end;
   410          end;
   412    DrawSprite(sprArrow, CursorPoint.X, CursorPoint.Y, (RealTicks shr 6) mod 8)
   411    DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8)
   413    end;
   412    end;
   414 
   413 
   415 if isPaused then DrawCentered(cScreenWidth div 2, cScreenHeight div 2, PauseTexture);
   414 if isPaused then DrawCentered(cScreenWidth div 2, cScreenHeight div 2, PauseTexture);
   416 
   415 
   417 inc(Frames);
   416 inc(Frames);
   479 	SDL_GetMouseState(0, @CursorPoint.X, @CursorPoint.Y);
   478 	SDL_GetMouseState(0, @CursorPoint.X, @CursorPoint.Y);
   480 {$ELSE}
   479 {$ELSE}
   481 	SDL_GetMouseState(@CursorPoint.X, @CursorPoint.Y);
   480 	SDL_GetMouseState(@CursorPoint.X, @CursorPoint.Y);
   482 {$ENDIF}
   481 {$ENDIF}
   483 	CursorPoint.X:= CursorPoint.X - cScreenWidth div 2;
   482 	CursorPoint.X:= CursorPoint.X - cScreenWidth div 2;
   484 //	CursorPoint.X:= round((CursorPoint.X - cScreenWidth / 2) * 2 / cScaleFactor);
   483 	CursorPoint.Y:= cScreenHeight - CursorPoint.Y;
   485 //	CursorPoint.Y:= round(CursorPoint.Y * 2 / cScaleFactor);
       
   486 	end;
   484 	end;
   487 
   485 
   488 if (FollowGear <> nil) and (not isCursorVisible) then
   486 if (FollowGear <> nil) and (not isCursorVisible) then
   489 	if abs(CursorPoint.X - prevPoint.X) + abs(CursorPoint.Y - prevpoint.Y) > 4 then
   487 	if abs(CursorPoint.X - prevPoint.X) + abs(CursorPoint.Y - prevpoint.Y) > 4 then
   490 		begin
   488 		begin
   491 		FollowGear:= nil;
   489 		FollowGear:= nil;
   492 		prevPoint.X:= CursorPoint.X;
   490 		prevPoint:= CursorPoint;
   493 		prevPoint.Y:= CursorPoint.Y;
       
   494 		exit
   491 		exit
   495 		end
   492 		end
   496 		else begin
   493 		else begin
   497 		//CursorPoint.x:= (prevPoint.x * 7 + (hwRound(FollowGear^.X) + hwSign(FollowGear^.dX) * 100) + WorldDx) div 8;
   494 		CursorPoint.x:= (hwRound(FollowGear^.X) + hwSign(FollowGear^.dX) * 100 + WorldDx);
   498 		//CursorPoint.y:= (prevPoint.y * 7 + (hwRound(FollowGear^.Y) + WorldDy)) div 8
   495 		//addcaption(inttostr(CursorPoint.X), $AFAFAF, capgrpGameState);
   499 		CursorPoint.x:= (hwRound(FollowGear^.X) + hwSign(FollowGear^.dX) * 100) + WorldDx;
   496 		CursorPoint.y:= (prevPoint.y * 7 + cScreenHeight - (hwRound(FollowGear^.Y) + WorldDy)) div 8;
   500 		end;
   497 		end;
   501 
   498 
   502 if ((CursorPoint.X = prevPoint.X)and(CursorPoint.Y = prevpoint.Y)) then exit;
   499 if ((CursorPoint.X = prevPoint.X) and (CursorPoint.Y = prevpoint.Y)) then exit;
   503 
   500 
   504 if AMxShift < 210 then
   501 if AMxShift < 210 then
   505 	begin
   502 	begin
   506 	if CursorPoint.X < cScreenWidth div 2 + AMxShift - 175 then CursorPoint.X:= cScreenWidth div 2 + AMxShift - 175;
   503 	if CursorPoint.X < cScreenWidth div 2 + AMxShift - 175 then CursorPoint.X:= cScreenWidth div 2 + AMxShift - 175;
   507 	if CursorPoint.X > cScreenWidth div 2 + AMxShift - 10 then CursorPoint.X:= cScreenWidth div 2 + AMxShift - 10;
   504 	if CursorPoint.X > cScreenWidth div 2 + AMxShift - 10 then CursorPoint.X:= cScreenWidth div 2 + AMxShift - 10;
   508 	if CursorPoint.Y < cScreenHeight - 75 - SlotsNum * 33 then CursorPoint.Y:= cScreenHeight - 75 - SlotsNum * 33;
   505 	if CursorPoint.Y > 75 + SlotsNum * 33 then CursorPoint.Y:= 75 + SlotsNum * 33;
   509 	if CursorPoint.Y > cScreenHeight - 76 then CursorPoint.Y:= cScreenHeight - 76;
   506 	if CursorPoint.Y < 76 then CursorPoint.Y:= 76;
   510 	prevPoint:= CursorPoint;
   507 	prevPoint:= CursorPoint;
   511 	if cHasFocus then SDL_WarpMouse(CursorPoint.X + cScreenWidth div 2, CursorPoint.Y);
   508 	if cHasFocus then SDL_WarpMouse(CursorPoint.X + cScreenWidth div 2, cScreenHeight - CursorPoint.Y);
   512 	exit
   509 	exit
   513 	end;
   510 	end;
   514 
   511 
   515 if isCursorVisible then
   512 if isCursorVisible then
   516 	begin
   513 	begin
   517 	if (not CurrentTeam^.ExtDriven)and(GameTicks >= PrevSentPointTime + cSendCursorPosTime) then
   514 	if (not CurrentTeam^.ExtDriven) and (GameTicks >= PrevSentPointTime + cSendCursorPosTime) then
   518 		begin
   515 		begin
   519 		SendIPCXY('P', CursorPoint.X - WorldDx, CursorPoint.Y - WorldDy);
   516 		SendIPCXY('P', CursorPoint.X - WorldDx, CursorPoint.Y - WorldDy);
   520 		PrevSentPointTime:= GameTicks
   517 		PrevSentPointTime:= GameTicks
   521 		end;
   518 		end;
   522 	end;
   519 	end;
   523 
   520 
   524 if isCursorVisible or (FollowGear <> nil) then
   521 if isCursorVisible or (FollowGear <> nil) then
   525    begin
   522    begin
   526    if isCursorVisible then EdgesDist:= cCursorEdgesDist
   523    if isCursorVisible then EdgesDist:= cCursorEdgesDist
   527                       else EdgesDist:= cGearScrEdgesDist;
   524                       else EdgesDist:= cGearScrEdgesDist;
   528    if CursorPoint.X < - cw + EdgesDist then
   525    if CursorPoint.X < - cScreenWidth div 2 + EdgesDist then
   529          begin
   526          begin
   530          WorldDx:= WorldDx - CursorPoint.X - cw + EdgesDist;
   527          WorldDx:= WorldDx - CursorPoint.X - cScreenWidth div 2 + EdgesDist;
   531          CursorPoint.X:= EdgesDist
   528          CursorPoint.X:= - cScreenWidth div 2 + EdgesDist
   532          end else
   529          end else
   533       if CursorPoint.X > cw - EdgesDist then
   530       if CursorPoint.X > cScreenWidth div 2 - EdgesDist then
   534          begin
   531          begin
   535          WorldDx:= WorldDx - CursorPoint.X + cw - EdgesDist;
   532          WorldDx:= WorldDx - CursorPoint.X + cScreenWidth div 2 - EdgesDist;
   536          CursorPoint.X:= cScreenWidth - EdgesDist
   533          CursorPoint.X:= cScreenWidth + cScreenWidth div 2 - EdgesDist
   537          end;
   534          end;
   538       if CursorPoint.Y < EdgesDist then
   535       if CursorPoint.Y < EdgesDist then
   539          begin
   536          begin
   540          WorldDy:= WorldDy - CursorPoint.Y + EdgesDist;
   537          WorldDy:= WorldDy + CursorPoint.Y - EdgesDist;
   541          CursorPoint.Y:= EdgesDist
   538          CursorPoint.Y:= EdgesDist
   542          end else
   539          end else
   543       if CursorPoint.Y > cScreenHeight - EdgesDist then
   540       if CursorPoint.Y > cScreenHeight - EdgesDist then
   544          begin
   541          begin
   545          WorldDy:= WorldDy - CursorPoint.Y + round(cScreenHeight * 2 / cScaleFactor) - EdgesDist;
   542          WorldDy:= WorldDy + CursorPoint.Y - cScreenHeight + EdgesDist;
   546          CursorPoint.Y:= cScreenHeight - EdgesDist
   543          CursorPoint.Y:= cScreenHeight - EdgesDist
   547          end;
   544          end;
   548    end else
   545    end else
   549    if cHasFocus then
   546    if cHasFocus then
   550       begin
   547       begin
   551       WorldDx:= WorldDx - CursorPoint.X + prevPoint.X;
   548       WorldDx:= WorldDx - CursorPoint.X + prevPoint.X;
   552       WorldDy:= WorldDy - CursorPoint.Y + prevPoint.Y;
   549       WorldDy:= WorldDy + CursorPoint.Y - prevPoint.Y;
   553       CursorPoint.X:= 0;
   550       CursorPoint.X:= 0;
   554       CursorPoint.Y:= cScreenHeight div 2;
   551       CursorPoint.Y:= cScreenHeight div 2;
   555       end;
   552       end;
   556 
   553 
   557 if cHasFocus then SDL_WarpMouse(CursorPoint.X + cScreenWidth div 2, CursorPoint.Y);
       
   558 prevPoint:= CursorPoint;
   554 prevPoint:= CursorPoint;
       
   555 if cHasFocus then SDL_WarpMouse(CursorPoint.X + cScreenWidth div 2, cScreenHeight - CursorPoint.Y);
   559 if WorldDy < cScreenHeight - cWaterLine - cVisibleWater then WorldDy:= cScreenHeight - cWaterLine - cVisibleWater;
   556 if WorldDy < cScreenHeight - cWaterLine - cVisibleWater then WorldDy:= cScreenHeight - cWaterLine - cVisibleWater;
   560 if WorldDy > LAND_HEIGHT + 1024 then WorldDy:= LAND_HEIGHT + 1024;
   557 if WorldDy > LAND_HEIGHT + 1024 then WorldDy:= LAND_HEIGHT + 1024;
   561 if WorldDx < -round(LAND_WIDTH * 2 / cScaleFactor) then WorldDx:= -round(LAND_WIDTH * 2 / cScaleFactor);
   558 if WorldDx < -round(LAND_WIDTH * 2 / cScaleFactor) then WorldDx:= -round(LAND_WIDTH * 2 / cScaleFactor);
   562 if WorldDx > cw then WorldDx:= cw;
   559 if WorldDx > cw then WorldDx:= cw;
   563 end;
   560 end;