本文整理汇总了C#中Map.GetTerrainAt方法的典型用法代码示例。如果您正苦于以下问题:C# Map.GetTerrainAt方法的具体用法?C# Map.GetTerrainAt怎么用?C# Map.GetTerrainAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Map
的用法示例。
在下文中一共展示了Map.GetTerrainAt方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetClearPointListInRange
public static List<Point> GetClearPointListInRange(Map map, Point upperLeft, Point lowerRight)
{
List<Point> returnList = new List<Point>();
for (int i = upperLeft.X; i < lowerRight.X; ++i)
{
for (int j = upperLeft.Y; j < lowerRight.Y; ++j)
{
if (map.GetTerrainAt(i, j) == TerrainType.Floor)
returnList.Add(new Point(i, j));
}
}
return returnList;
}
示例2: IsPositionClear
private bool IsPositionClear(Map map, Point upperLeftCorner)
{
if (!map.IsPointOnMap(upperLeftCorner))
return false;
if (!map.IsPointOnMap(upperLeftCorner + new Point(Width, Height)))
return false;
for (int i = 0; i < Width; ++i)
{
for (int j = 0; j < Height; ++j)
{
Point mapPosition = upperLeftCorner + new Point(i, j);
if (map.GetTerrainAt(mapPosition) == TerrainType.Floor)
return false;
}
}
return true;
}
示例3: CountNumberOfSurroundingWallTilesOneStepAway
protected static int CountNumberOfSurroundingWallTilesOneStepAway(Map map, int x, int y)
{
int numberOfFloorTileSurrounding = 0;
for (int i = -1; i <= 1; ++i)
{
for (int j = -1; j <= 1; ++j)
{
if (map.IsPointOnMap(x + i, y + j))
{
if (map.GetTerrainAt(x + i, y + j) == TerrainType.Wall)
numberOfFloorTileSurrounding++;
}
}
}
return numberOfFloorTileSurrounding;
}
示例4: CountNumberOfSurroundingWallTilesTwoStepAway
protected static int CountNumberOfSurroundingWallTilesTwoStepAway(Map map, int x, int y)
{
int numberOfFloorTileSurrounding = 0;
for (int i = -2; i <= 2; ++i)
{
for (int j = -2; j <= 2; ++j)
{
if ((i == 2 || i == -2) && (j == 2 || j == -2))
continue;
if (map.IsPointOnMap(x + i, y + j))
{
if (map.GetTerrainAt(x + i, y + j) == TerrainType.Wall)
numberOfFloorTileSurrounding++;
}
}
}
return numberOfFloorTileSurrounding;
}
示例5: FloodFillWithContigiousNumbers
// Try to flood fill the map. Each seperate contigious spot gets a different scratch number.
protected int FloodFillWithContigiousNumbers(Map map)
{
ResetScratch(map);
byte currentScratchNumber = 1;
// First we walk the entire map, flood filling each
for (int i = 0; i < map.Width; ++i)
{
for (int j = 0; j < map.Height; ++j)
{
if (map.GetTerrainAt(i, j) == TerrainType.Floor && map.GetScratchAt(i, j) == 0)
{
FloodFill(map, i, j, currentScratchNumber);
currentScratchNumber++;
}
}
}
// If we didn't scratch any tiles, the map must be all walls, bail
if (currentScratchNumber == 1)
throw new MapGenerationFailureException("FillAllSmallerUnconnectedRooms came to a level with all walls?");
return currentScratchNumber;
}
示例6: GetFirstClearPoint
private Point GetFirstClearPoint(Map map)
{
for (int i = 0; i < map.Width; ++i)
{
for (int j = 0; j < map.Height; ++j)
{
if (map.GetTerrainAt(i, j) == TerrainType.Floor)
return new Point(i, j);
}
}
throw new System.InvalidOperationException("GetFirstClearPoint found no clear points");
}
示例7: FillAllSmallerUnconnectedRooms
protected void FillAllSmallerUnconnectedRooms(Map map)
{
int currentScratchNumber = FloodFillWithContigiousNumbers(map);
// Walk each tile, and count up the different groups.
int[] numberOfTilesWithThatScratch = new int[currentScratchNumber];
numberOfTilesWithThatScratch.Initialize();
for (int i = 0; i < map.Width; ++i)
{
for (int j = 0; j < map.Height; ++j)
{
if (map.GetTerrainAt(i, j) == TerrainType.Floor)
numberOfTilesWithThatScratch[map.GetScratchAt(i, j)]++;
}
}
if (numberOfTilesWithThatScratch[0] != 0)
throw new MapGenerationFailureException("Some valid tiles didn't get a scratch during FillAllSmallerRooms.");
// Find the largest collection
int biggestNumber = 1;
for (int i = 2; i < currentScratchNumber; ++i)
{
if (numberOfTilesWithThatScratch[i] > numberOfTilesWithThatScratch[biggestNumber])
biggestNumber = i;
}
// Now walk level, and turn every floor tile without that scratch into a wall
for (int i = 0; i < map.Width; ++i)
{
for (int j = 0; j < map.Height; ++j)
{
if (map.GetTerrainAt(i, j) == TerrainType.Floor && map.GetScratchAt(i, j) != biggestNumber)
map.SetTerrainAt(i, j, TerrainType.Wall);
// And reset the scratch while we're here
map.SetScratchAt(i, j, 0);
}
}
if (!CheckConnectivity(map))
throw new MapGenerationFailureException("FillAllSmallerUnconnectedRooms produced a non-connected map.");
}
示例8: CheckConnectivity
// Make sure map has one connected area
protected bool CheckConnectivity(Map map)
{
const int CheckConnectivityScratchValue = 42;
// Find a clear point
Point clearPoint = GetFirstClearPoint(map);
// Flood fill all connected tiles
FloodFill(map, clearPoint.X, clearPoint.Y, CheckConnectivityScratchValue);
// See if any floor tiles don't have our scratch, if so they are not connected
for (int i = 0; i < map.Width; ++i)
{
for (int j = 0; j < map.Height; ++j)
{
if (map.GetTerrainAt(i, j) == TerrainType.Floor && map.GetScratchAt(i, j) != CheckConnectivityScratchValue)
return false;
}
}
return true;
}
示例9: FloodFill
protected void FloodFill(Map map, int x, int y, byte scratchValue)
{
if (!map.IsPointOnMap(x, y))
return;
if (map.GetTerrainAt(x, y) == TerrainType.Floor && map.GetScratchAt(x, y) == 0)
{
map.SetScratchAt(x, y, scratchValue);
FloodFill(map, x + 1, y, scratchValue);
FloodFill(map, x - 1, y, scratchValue);
FloodFill(map, x, y + 1, scratchValue);
FloodFill(map, x, y - 1, scratchValue);
}
}
示例10: WallsOnOneSetOfSides
private bool WallsOnOneSetOfSides(Map map, MapDoor door)
{
return (map.GetTerrainAt(door.Position + new Point(1, 0)) == TerrainType.Wall &&
map.GetTerrainAt(door.Position + new Point(-1, 0)) == TerrainType.Wall) ||
(map.GetTerrainAt(door.Position + new Point(0, 1)) == TerrainType.Wall &&
map.GetTerrainAt(door.Position + new Point(0, -1)) == TerrainType.Wall);
}
示例11: StripImpossibleDoors
private void StripImpossibleDoors(Map map)
{
foreach (MapDoor door in map.MapObjects.OfType<MapDoor>().ToList())
{
if (!map.IsPointOnMap(door.Position) || map.GetTerrainAt(door.Position) == TerrainType.Wall ||
!WallsOnOneSetOfSides(map, door))
{
map.RemoveMapItem(door);
}
}
List<Point> doorPositions = map.MapObjects.OfType<MapDoor>().Select(x => x.Position).ToList();
foreach (MapDoor door in map.MapObjects.OfType<MapDoor>().ToList())
{
if (doorPositions.Exists(x => x != door.Position && PointDirectionUtils.NormalDistance(x, door.Position) < 2))
{
map.RemoveMapItem(door);
doorPositions.Remove(door.Position);
}
}
}