Changeset 168 for trunk/UMap.pas
- Timestamp:
- Nov 23, 2017, 10:16:50 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UMap.pas
r167 r168 21 21 function IsCellsPosNeighbor(CellPos1, CellPos2: TPoint): Boolean; 22 22 procedure GetCellPosNeighbors(CellPos: TPoint; Neighbours: TCells); 23 function GetHexagonPolygon(Pos: TPoint; Size: TPoint): TPo intArray;23 function GetHexagonPolygon(Pos: TPoint; Size: TPoint): TPolygon; 24 24 public 25 25 procedure LoadFromFile(FileName: string); override; … … 33 33 TSquareMap = class(TMap) 34 34 private 35 function GetSquarePolygon(Pos: TPoint; Size: TPoint): TPo intArray;35 function GetSquarePolygon(Pos: TPoint; Size: TPoint): TPolygon; 36 36 public 37 37 function IsValidIndex(Index: TPoint): Boolean; override; … … 43 43 TTriangleMap = class(TMap) 44 44 private 45 function GetTrianglePolygon(Pos: TPoint; Size: TPoint; Reverse: Boolean): TPo intArray;45 function GetTrianglePolygon(Pos: TPoint; Size: TPoint; Reverse: Boolean): TPolygon; 46 46 public 47 47 function IsValidIndex(Index: TPoint): Boolean; override; … … 62 62 { THexMap } 63 63 64 function THexMap.GetHexagonPolygon(Pos: TPoint; Size: TPoint): TPo intArray;64 function THexMap.GetHexagonPolygon(Pos: TPoint; Size: TPoint): TPolygon; 65 65 var 66 66 Shift: TFloatPoint; 67 67 begin 68 68 Shift := FloatPoint(0.5 * cos(30 / 180 * Pi), 0.5 * sin(30 / 180 * Pi)); 69 SetLength(Result , 6);70 Result [0] := Point(Trunc(Pos.X + 0 * Size.X), Trunc(Pos.Y - 0.5 * Size.Y));71 Result [1] := Point(Trunc(Pos.X + Shift.X * Size.X), Trunc(Pos.Y - Shift.Y * Size.Y));72 Result [2] := Point(Trunc(Pos.X + Shift.X * Size.X), Trunc(Pos.Y + Shift.Y * Size.Y));73 Result [3] := Point(Trunc(Pos.X + 0 * Size.X), Trunc(Pos.Y + 0.5 * Size.Y));74 Result [4] := Point(Trunc(Pos.X - Shift.X * Size.X), Trunc(Pos.Y + Shift.Y * Size.Y));75 Result [5] := Point(Trunc(Pos.X - Shift.X * Size.X), Trunc(Pos.Y - Shift.Y * Size.Y));69 SetLength(Result.Points, 6); 70 Result.Points[0] := Point(Trunc(Pos.X + 0 * Size.X), Trunc(Pos.Y - 0.5 * Size.Y)); 71 Result.Points[1] := Point(Trunc(Pos.X + Shift.X * Size.X), Trunc(Pos.Y - Shift.Y * Size.Y)); 72 Result.Points[2] := Point(Trunc(Pos.X + Shift.X * Size.X), Trunc(Pos.Y + Shift.Y * Size.Y)); 73 Result.Points[3] := Point(Trunc(Pos.X + 0 * Size.X), Trunc(Pos.Y + 0.5 * Size.Y)); 74 Result.Points[4] := Point(Trunc(Pos.X - Shift.X * Size.X), Trunc(Pos.Y + Shift.Y * Size.Y)); 75 Result.Points[5] := Point(Trunc(Pos.X - Shift.X * Size.X), Trunc(Pos.Y - Shift.Y * Size.Y)); 76 76 end; 77 77 … … 228 228 end; 229 229 230 function TSquareMap.GetSquarePolygon(Pos: TPoint; Size: TPoint): TPo intArray;231 begin 232 SetLength(Result , 4);233 Result [0] := Point(Trunc(Pos.X - Size.X / 2), Trunc(Pos.Y - Size.Y / 2));234 Result [1] := Point(Trunc(Pos.X + Size.X / 2), Trunc(Pos.Y - Size.Y / 2));235 Result [2] := Point(Trunc(Pos.X + Size.X / 2), Trunc(Pos.Y + Size.Y / 2));236 Result [3] := Point(Trunc(Pos.X - Size.X / 2), Trunc(Pos.Y + Size.Y / 2));230 function TSquareMap.GetSquarePolygon(Pos: TPoint; Size: TPoint): TPolygon; 231 begin 232 SetLength(Result.Points, 4); 233 Result.Points[0] := Point(Trunc(Pos.X - Size.X / 2), Trunc(Pos.Y - Size.Y / 2)); 234 Result.Points[1] := Point(Trunc(Pos.X + Size.X / 2), Trunc(Pos.Y - Size.Y / 2)); 235 Result.Points[2] := Point(Trunc(Pos.X + Size.X / 2), Trunc(Pos.Y + Size.Y / 2)); 236 Result.Points[3] := Point(Trunc(Pos.X - Size.X / 2), Trunc(Pos.Y + Size.Y / 2)); 237 237 end; 238 238 … … 311 311 NewCell.PosPx := Point(Trunc(Random * Size.X * DefaultCellSize.X), 312 312 Trunc(Random * Size.Y * DefaultCellSize.Y)); 313 SetLength(NewCell.Polygon , 1);314 NewCell.Polygon [0] := NewCell.PosPx;313 SetLength(NewCell.Polygon.Points, 1); 314 NewCell.Polygon.Points[0] := NewCell.PosPx; 315 315 NewCell.Id := GetNewCellId; 316 316 Cells[Y * Size.X + X] := NewCell; … … 435 435 Polygon.CutLine(L1, Cell.PosPx); 436 436 end; 437 Cell.Polygon := Polygon .Points;438 end else SetLength(Cell.Polygon, 0);437 Cell.Polygon := Polygon; 438 end else Cell.Polygon.Clear; 439 439 end; 440 440 … … 445 445 446 446 function TTriangleMap.GetTrianglePolygon(Pos: TPoint; Size: TPoint; 447 Reverse: Boolean): TPo intArray;447 Reverse: Boolean): TPolygon; 448 448 var 449 449 Rev: Integer; … … 451 451 if Reverse then Rev := -1 452 452 else Rev := 1; 453 SetLength(Result , 3);454 Result [0] := Point(Trunc(Pos.X - Size.X / 2), Trunc(Pos.Y - (Size.Y * 0.8) / 2 * Rev));455 Result [1] := Point(Trunc(Pos.X + Size.X / 2), Trunc(Pos.Y - (Size.Y * 0.8) / 2 * Rev));456 Result [2] := Point(Trunc(Pos.X), Trunc(Pos.Y + (Size.Y * 1.2) / 2 * Rev));453 SetLength(Result.Points, 3); 454 Result.Points[0] := Point(Trunc(Pos.X - Size.X / 2), Trunc(Pos.Y - (Size.Y * 0.8) / 2 * Rev)); 455 Result.Points[1] := Point(Trunc(Pos.X + Size.X / 2), Trunc(Pos.Y - (Size.Y * 0.8) / 2 * Rev)); 456 Result.Points[2] := Point(Trunc(Pos.X), Trunc(Pos.Y + (Size.Y * 1.2) / 2 * Rev)); 457 457 end; 458 458
Note:
See TracChangeset
for help on using the changeset viewer.