hedgewars/uWorld.pas
changeset 3680 aaf832c6fbd7
parent 3663 8c28abf427f5
child 3693 09892cdb8f95
equal deleted inserted replaced
3678:00428183300f 3680:aaf832c6fbd7
  1017 end;
  1017 end;
  1018 {$ENDIF}
  1018 {$ENDIF}
  1019 
  1019 
  1020 if (not PlacingHogs) and (FollowGear <> nil) and (not isCursorVisible) and (not fastUntilLag) then
  1020 if (not PlacingHogs) and (FollowGear <> nil) and (not isCursorVisible) and (not fastUntilLag) then
  1021     if abs(CursorPoint.X - prevPoint.X) + abs(CursorPoint.Y - prevpoint.Y) > 4 then
  1021     if abs(CursorPoint.X - prevPoint.X) + abs(CursorPoint.Y - prevpoint.Y) > 4 then
  1022         begin
  1022     begin
  1023         FollowGear:= nil;
  1023         FollowGear:= nil;
  1024         prevPoint:= CursorPoint;
  1024         prevPoint:= CursorPoint;
  1025         exit
  1025         exit
  1026         end
  1026     end
  1027         else begin
  1027     else
       
  1028     begin
  1028         CursorPoint.X:= (prevPoint.X * 7 + hwRound(FollowGear^.X) + hwSign(FollowGear^.dX) * 100 + WorldDx) div 8;
  1029         CursorPoint.X:= (prevPoint.X * 7 + hwRound(FollowGear^.X) + hwSign(FollowGear^.dX) * 100 + WorldDx) div 8;
  1029         CursorPoint.Y:= (prevPoint.Y * 7 + cScreenHeight - (hwRound(FollowGear^.Y) + WorldDy)) div 8;
  1030         CursorPoint.Y:= (prevPoint.Y * 7 + cScreenHeight - (hwRound(FollowGear^.Y) + WorldDy)) div 8;
  1030         end;
  1031     end;
  1031 
  1032 
  1032 wdy:= trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - cWaterLine - cVisibleWater;
  1033 wdy:= trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - cWaterLine - cVisibleWater;
  1033 if WorldDy < wdy then WorldDy:= wdy;
  1034 if WorldDy < wdy then WorldDy:= wdy;
  1034 
  1035 
  1035 if ((CursorPoint.X = prevPoint.X) and (CursorPoint.Y = prevpoint.Y)) then exit;
  1036 if ((CursorPoint.X = prevPoint.X) and (CursorPoint.Y = prevpoint.Y)) then exit;
  1036 
  1037 
  1037 if AMxShift < AMWidth then
  1038 if AMxShift < AMWidth then
  1038     begin
  1039 begin
  1039 {$IFDEF IPHONEOS}
  1040 {$IFDEF IPHONEOS}
  1040     if CursorPoint.X < cScreenWidth div 2 + AMxShift - AMWidth then CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMWidth;
  1041     if CursorPoint.X < cScreenWidth div 2 + AMxShift - AMWidth then CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMWidth;
  1041     if CursorPoint.X > cScreenWidth div 2 + AMxShift - AMxOffset then CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMxOffset;
  1042     if CursorPoint.X > cScreenWidth div 2 + AMxShift - AMxOffset then CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMxOffset;
  1042     if CursorPoint.Y < cScreenHeight - AMyOffset - SlotsNum * AMSlotSize then CursorPoint.Y:= cScreenHeight - AMyOffset - SlotsNum * AMSlotSize;
  1043     if CursorPoint.Y < cScreenHeight - AMyOffset - SlotsNum * AMSlotSize then CursorPoint.Y:= cScreenHeight - AMyOffset - SlotsNum * AMSlotSize;
  1043     if CursorPoint.Y > cScreenHeight - AMyOffset then CursorPoint.Y:= cScreenHeight - AMyOffset;
  1044     if CursorPoint.Y > cScreenHeight - AMyOffset then CursorPoint.Y:= cScreenHeight - AMyOffset;
  1048     if CursorPoint.Y < AMyOffset + AMSlotSize then CursorPoint.Y:= AMyOffset + AMSlotSize;
  1049     if CursorPoint.Y < AMyOffset + AMSlotSize then CursorPoint.Y:= AMyOffset + AMSlotSize;
  1049 {$ENDIF}
  1050 {$ENDIF}
  1050     prevPoint:= CursorPoint;
  1051     prevPoint:= CursorPoint;
  1051     if cHasFocus then SDL_WarpMouse(CursorPoint.X + cScreenWidth div 2, cScreenHeight - CursorPoint.Y);
  1052     if cHasFocus then SDL_WarpMouse(CursorPoint.X + cScreenWidth div 2, cScreenHeight - CursorPoint.Y);
  1052     exit
  1053     exit
  1053     end;
  1054 end;
  1054 
  1055 
  1055 if isCursorVisible then
  1056 if isCursorVisible then
  1056     begin
  1057 begin
  1057     if (not CurrentTeam^.ExtDriven) and (GameTicks >= PrevSentPointTime + cSendCursorPosTime) then
  1058     if (not CurrentTeam^.ExtDriven) and (GameTicks >= PrevSentPointTime + cSendCursorPosTime) then
  1058         begin
  1059     begin
  1059         SendIPCXY('P', CursorPoint.X - WorldDx, cScreenHeight - CursorPoint.Y - WorldDy);
  1060         SendIPCXY('P', CursorPoint.X - WorldDx, cScreenHeight - CursorPoint.Y - WorldDy);
  1060         PrevSentPointTime:= GameTicks
  1061         PrevSentPointTime:= GameTicks
       
  1062     end;
       
  1063     EdgesDist:= cCursorEdgesDist
       
  1064 end
       
  1065 else
       
  1066     EdgesDist:= cGearScrEdgesDist;
       
  1067 
       
  1068 // this generates the border around the screen that moves the camera when cursor is near it
       
  1069 if isCursorVisible or (FollowGear <> nil) then
       
  1070 begin
       
  1071     if CursorPoint.X < - cScreenWidth div 2 + EdgesDist then
       
  1072     begin
       
  1073         WorldDx:= WorldDx - CursorPoint.X - cScreenWidth div 2 + EdgesDist;
       
  1074         CursorPoint.X:= - cScreenWidth div 2 + EdgesDist
       
  1075     end
       
  1076     else
       
  1077         if CursorPoint.X > cScreenWidth div 2 - EdgesDist then
       
  1078         begin
       
  1079             WorldDx:= WorldDx - CursorPoint.X + cScreenWidth div 2 - EdgesDist;
       
  1080             CursorPoint.X:= cScreenWidth div 2 - EdgesDist
  1061         end;
  1081         end;
  1062     end;
  1082     if CursorPoint.Y < EdgesDist then
  1063 
  1083     begin
  1064 if isCursorVisible or (FollowGear <> nil) then
  1084         WorldDy:= WorldDy + CursorPoint.Y - EdgesDist;
  1065    begin
  1085         CursorPoint.Y:= EdgesDist
  1066    if isCursorVisible then EdgesDist:= cCursorEdgesDist
  1086     end
  1067                       else EdgesDist:= cGearScrEdgesDist;
  1087     else
  1068    if CursorPoint.X < - cScreenWidth div 2 + EdgesDist then
  1088         if CursorPoint.Y > cScreenHeight - EdgesDist then
  1069          begin
  1089         begin
  1070          WorldDx:= WorldDx - CursorPoint.X - cScreenWidth div 2 + EdgesDist;
  1090            WorldDy:= WorldDy + CursorPoint.Y - cScreenHeight + EdgesDist;
  1071          CursorPoint.X:= - cScreenWidth div 2 + EdgesDist
  1091            CursorPoint.Y:= cScreenHeight - EdgesDist
  1072          end else
  1092         end;
  1073       if CursorPoint.X > cScreenWidth div 2 - EdgesDist then
  1093 end
  1074          begin
  1094 else
  1075          WorldDx:= WorldDx - CursorPoint.X + cScreenWidth div 2 - EdgesDist;
  1095     if cHasFocus then
  1076          CursorPoint.X:= cScreenWidth div 2 - EdgesDist
  1096     begin
  1077          end;
  1097         WorldDx:= WorldDx - CursorPoint.X + prevPoint.X;
  1078       if CursorPoint.Y < EdgesDist then
  1098         WorldDy:= WorldDy + CursorPoint.Y - prevPoint.Y;
  1079          begin
  1099         CursorPoint.X:= 0;
  1080          WorldDy:= WorldDy + CursorPoint.Y - EdgesDist;
  1100         CursorPoint.Y:= cScreenHeight div 2;
  1081          CursorPoint.Y:= EdgesDist
  1101     end;
  1082          end else
  1102 
  1083       if CursorPoint.Y > cScreenHeight - EdgesDist then
  1103 // this moves the camera according to CursorPoint X and Y
  1084          begin
       
  1085          WorldDy:= WorldDy + CursorPoint.Y - cScreenHeight + EdgesDist;
       
  1086          CursorPoint.Y:= cScreenHeight - EdgesDist
       
  1087          end;
       
  1088    end else
       
  1089    if cHasFocus then
       
  1090       begin
       
  1091       WorldDx:= WorldDx - CursorPoint.X + prevPoint.X;
       
  1092       WorldDy:= WorldDy + CursorPoint.Y - prevPoint.Y;
       
  1093       CursorPoint.X:= 0;
       
  1094       CursorPoint.Y:= cScreenHeight div 2;
       
  1095       end;
       
  1096 
       
  1097 prevPoint:= CursorPoint;
  1104 prevPoint:= CursorPoint;
  1098 if cHasFocus then SDL_WarpMouse(CursorPoint.X + (cScreenWidth shr 1), cScreenHeight - CursorPoint.Y);
  1105 if cHasFocus then SDL_WarpMouse(CursorPoint.X + (cScreenWidth shr 1), cScreenHeight - CursorPoint.Y);
  1099 if WorldDy > LAND_HEIGHT + 1024 then WorldDy:= LAND_HEIGHT + 1024;
  1106 if WorldDy > LAND_HEIGHT + 1024 then WorldDy:= LAND_HEIGHT + 1024;
  1100 if WorldDy < wdy then WorldDy:= wdy;
  1107 if WorldDy < wdy then WorldDy:= wdy;
  1101 if WorldDx < - LAND_WIDTH - 1024 then WorldDx:= - LAND_WIDTH - 1024;
  1108 if WorldDx < - LAND_WIDTH - 1024 then WorldDx:= - LAND_WIDTH - 1024;