/// <summary> /// Checks to see if there is a tile that is unpassable in a direction from another tile. /// </summary> /// <param name="gameTile">The tile to use as the origin.</param> /// <param name="direction">The direction to check for the adjacent tile.</param> /// <returns>true if the adjacent tile is unpassable, otherwise false.</returns> public bool IsAdjacentTileUnpassable(GameTile gameTile, Directions direction) { GameTile adjacentGameTile = GetAdjacentTile(gameTile, direction); if (adjacentGameTile == null) { return(true); } //TODO:Add support for closed doors. if (adjacentGameTile.WallImageNames.Count > 0 || adjacentGameTile.UnpassableObjectImageNames.Count > 0) { return(true); } return(false); }
/// <summary> /// Checks to see if there is a tile that blocks line of sight in a drection from another tile. /// </summary> /// <param name="gameTile">The tile to use as the origin.</param> /// <param name="direction">The direction to check for the adjacent tile.</param> /// <returns>true if the adjacent tile blocks line of sight, otherwise false.</returns> public bool DoesAdjacentTileBlockSight(GameTile gameTile, Directions direction) { GameTile adjacentGameTile = GetAdjacentTile(gameTile, direction); if (adjacentGameTile == null) { return(true); } //TODO:Add support for closed doors. //Currently only walls block line of sight. if (adjacentGameTile.WallImageNames.Count > 0) { return(true); } return(false); }
/// <summary> /// Checks to see if a point is adjacent to a tile. /// </summary> /// <param name="gameTile">The tile to use as the origin to check from.</param> /// <param name="targetPoint">The relational point to check to see if it is adjacent to the origin.</param> /// <returns>true if the point is adjacent to the tile, otherwise false.</returns> private bool IsTileAdjacent(GameTile gameTile, System.Drawing.Point targetPoint) { if (this.ViewableArea != null) { foreach (GameTile viewableTile in this.ViewableArea) { if (viewableTile.Location == gameTile.Location) { return(false); } if (viewableTile.Location.X >= gameTile.Location.X - 1 && viewableTile.Location.X < -gameTile.Location.X + 1) { if (viewableTile.Location.Y >= gameTile.Location.Y - 1 && viewableTile.Location.Y < -gameTile.Location.Y + 1) { return(true); } } } } return(false); }
public bool IsTileVisible(Point start, Point end) { float xDelta = (end.X - start.X); float yDelta = (end.Y - start.Y); float unitX; float uintY; System.Drawing.Point checkPoint = start; bool previousPointBlockedLineOfSight = false; if (Math.Abs(xDelta) > Math.Abs(yDelta)) { //TODO:What the heck is this? if (end.X == 30 && end.Y == 37) { end.X = 30; } unitX = xDelta / Math.Abs(xDelta); uintY = yDelta / Math.Abs(xDelta); for (int x = 1; x <= Math.Abs(xDelta); x++) { if (previousPointBlockedLineOfSight) { return(false); } checkPoint.X = start.X + (int)Math.Round(x * unitX, 0); checkPoint.Y = start.Y + (int)Math.Round(x * uintY, 0); GameTile gameTile = this.Get(checkPoint); if (gameTile.WallImageNames.Count > 0) { previousPointBlockedLineOfSight = true; } } } else { unitX = xDelta / Math.Abs(yDelta); uintY = yDelta / Math.Abs(yDelta); for (int x = 1; x <= Math.Abs(yDelta); x++) { if (previousPointBlockedLineOfSight) { return(false); } checkPoint.X = start.X + (int)Math.Round(x * unitX, 0); checkPoint.Y = start.Y + (int)Math.Round(x * uintY, 0); GameTile gameTile = this.Get(checkPoint); if (gameTile.WallImageNames.Count > 0) { previousPointBlockedLineOfSight = true; } } } return(true); }
public void Add(GameTile gameTile) { base.Add(gameTile.Location, gameTile); }
/// <summary> /// Gets the game tile that is adjacent to another game tile in a specific direction. /// </summary> /// <param name="gameTile">The game tile to check from.</param> /// <param name="direction">The direction to check in.</param> /// <returns>The game tile that is adjacent in the given direction if there is one, otherwise null.</returns> private GameTile GetAdjacentTile(GameTile gameTile, Directions direction) { List <GameTile> adjacentGameTiles = GetAdjacentTiles(gameTile); foreach (GameTile adjacentTile in adjacentGameTiles) { switch (direction) { case Directions.North: if (adjacentTile.Location == new System.Drawing.Point(gameTile.Location.X, gameTile.Location.Y - 1)) { return(adjacentTile); } break; case Directions.South: if (adjacentTile.Location == new System.Drawing.Point(gameTile.Location.X, gameTile.Location.Y + 1)) { return(adjacentTile); } break; case Directions.East: if (adjacentTile.Location == new System.Drawing.Point(gameTile.Location.X + 1, gameTile.Location.Y)) { return(adjacentTile); } break; case Directions.West: if (adjacentTile.Location == new System.Drawing.Point(gameTile.Location.X - 1, gameTile.Location.Y)) { return(adjacentTile); } break; case Directions.NorthEast: if (adjacentTile.Location == new System.Drawing.Point(gameTile.Location.X + 1, gameTile.Location.Y - 1)) { return(adjacentTile); } break; case Directions.NorthWest: if (adjacentTile.Location == new System.Drawing.Point(gameTile.Location.X - 1, gameTile.Location.Y - 1)) { return(adjacentTile); } break; case Directions.SouthEast: if (adjacentTile.Location == new System.Drawing.Point(gameTile.Location.X + 1, gameTile.Location.Y + 1)) { return(adjacentTile); } break; case Directions.SouthWest: if (adjacentTile.Location == new System.Drawing.Point(gameTile.Location.X - 1, gameTile.Location.Y + 1)) { return(adjacentTile); } break; } } return(null); }