public bool valid(string direction, Tile t) { switch (direction) { case "above": if(t.Y -1 >= 0) return true; break; case "below": if(t.Y + 1 < this.MapHeight) return true; break; case "left": if(t.X -1 >= 0) return true; break; case "right": if (t.X + 1 < this.MapWidth) return true; break; default: return false; } return false; }
public Tile getadjacentTile(string direction, Tile t) { switch (direction) { case "above": if (t.Y - 1 >= 0) return Tiles[t.Y-1,t.X]; break; case "below": if (t.Y + 1 < this.MapHeight) return Tiles[t.Y + 1, t.X]; break; case "left": if (t.X - 1 >= 0) return Tiles[t.Y, t.X - 1]; break; case "right": if (t.X + 1 < this.MapWidth) return Tiles[t.Y, t.X + 1]; break; default: return t; } return t; }
public List<Tile> adjacentPassible(Tile t) { List<Tile> adjacentTilesPassible = new List<Tile>(); if (valid("above", t)) { Tile tile = getadjacentTile("above", t); if (tile.Passable) adjacentTilesPassible.Add(tile); } if (valid("below", t)) { Tile tile = getadjacentTile("below", t); if (tile.Passable) adjacentTilesPassible.Add(tile); } if (valid("left", t)) { Tile tile = getadjacentTile("left", t); if (tile.Passable) adjacentTilesPassible.Add(tile); } if (valid("right", t)) { Tile tile = getadjacentTile("right", t); if (tile.Passable) adjacentTilesPassible.Add(tile); } return adjacentTilesPassible; }
// Check and see if the tile collection has valid adjacent // Tile addresses (horizontal and vertical // return the a list of these tiles public List<Tile> adjacentTo(Tile t) { List<Tile> adjacentTiles = new List<Tile>(); if (valid("above", t)) adjacentTiles.Add(getadjacentTile("above", t)); if (valid("below", t)) adjacentTiles.Add(getadjacentTile("below", t)); if (valid("left", t)) adjacentTiles.Add(getadjacentTile("left", t)); if (valid("right", t)) adjacentTiles.Add(getadjacentTile("right", t)); return adjacentTiles; }
Vector2 TileDifference(Tile t1, Tile t2) { Vector2 v1 = new Vector2(t1.X, t1.Y) * tileWidth; Vector2 v2 = new Vector2(t2.X, t2.Y) * tileWidth; Vector2 result = v1 - v2; return result; }