public static Stack<Tile> reconstructPath(Dictionary<Tile, Tile> a_cameFrom, Tile a_currentNode, Stack<Tile> a_workingList) { if (a_currentNode.getMapPosition() != a_cameFrom[a_currentNode].getMapPosition()) { a_workingList.Push(a_cameFrom[a_currentNode]); return reconstructPath(a_cameFrom, a_cameFrom[a_currentNode], a_workingList); } else { return a_workingList; } }
public void invokeAbility(Tile a_tile) { LinkedList<Tile> l_affectedTiles = ((GameState)Game.getInstance().getCurrentState()).getTileMap().getRangeOfTiles(a_tile, m_aoe); foreach (Tile l_tile in l_affectedTiles) { foreach (Effect l_effect in m_effects) { castEffect(l_effect, l_tile.p_object); } } }
public LinkedList<Tile> getRangeOfTiles(Tile a_tile, int a_range) { LinkedList<Tile> l_list1 = new LinkedList<Tile>(); LinkedList<Tile> l_list2 = new LinkedList<Tile>(); LinkedList<Tile> l_list3 = new LinkedList<Tile>(); l_list3.AddLast(a_tile); for (int i = 0; i < a_range; i++) { l_list2 = l_list3; l_list3 = new LinkedList<Tile>(); if (l_list2 != null && l_list2.Count > 0) { foreach (Tile l_tile in l_list2) { foreach (Tile l_tile2 in getSurroundingTiles(l_tile)) { if (!l_list1.Contains(l_tile2)) { l_list3.AddLast(l_tile2); l_list1.AddLast(l_tile2); } } } } } return l_list1; }
public override void load() { for (int i = 0; i < m_heightSprites.Length; i++) { m_heightSprites[i].load(); m_heightSprites[i].p_offset = new Vector2(0, (m_heightSprites[i].getTexture().Height * i / 3.5f) + TILE_HEIGHT / 2); } if (Y > 0) { m_tileAbove = m_tileMap.getTile(X, Y - 1); } m_hitbox = new Rectangle(m_position.X, m_position.Y, m_tileMap.getSpriteDict()[m_tileState].getTexture().Width, m_tileMap.getSpriteDict()[m_tileState].getTexture().Height); m_hitbox.setParent(this); }
public LinkedList<Tile> toLinkedList(Tile.TileState a_state) { LinkedList<Tile> l_list = new LinkedList<Tile>(); for (int i = 0; i < m_width; i++) { for (int j = 0; j < m_height; j++) { if (m_tileMap[i, j].p_tileState == a_state) { l_list.AddLast(m_tileMap[i, j]); } } } return l_list; }
public void load() { foreach (Sprite l_sprite in m_spriteDict.Values) { l_sprite.load(); } int l_heightIndex = MathManager.randomInt(3, 7); for (int i = 0; i < m_width; i++) { for (int j = 0; j < m_height; j++) { //m_tileMap[i, j] = new Tile(new Vector2(i, j), MathManager.randomInt(l_heightIndex - 3, l_heightIndex + 3)); m_tileMap[i, j] = new Tile(new Vector2(i, j), 1, this); m_tileMap[i, j].load(); if (MathManager.isEven(i)) { m_tileMap[i, j].move(new Vector2(0, 111)); } } } }
public Tile getTile(Tile a_tile, Vector2 a_mapOffset) { return getTile((int)(a_tile.getMapPosition().X + a_mapOffset.X), (int)(a_tile.getMapPosition().Y + a_mapOffset.Y)); }
public LinkedList<Tile> getSurroundingTiles(Tile a_tile) { int[] Xcheck = MathManager.isEven(a_tile.X) ? new[] { -1, 0, 1, 1, 0, -1 } : new[] { 1, 0, 1, -1, 0, -1 }; int[] Ycheck = MathManager.isEven(a_tile.X) ? new[] { 1, -1, 0, 1, 1, 0 } : new[] { -1, -1, 0, -1, 1, 0 }; LinkedList<Tile> l_list = new LinkedList<Tile>(); Tile l_tile; for (int i = 0; i < Xcheck.Length; i++) { for (int j = 0; j < Xcheck.Length; j++) { if ((l_tile = getTile(a_tile, new Vector2(Xcheck[i], Ycheck[i]))) != null) { if (!l_list.Contains(l_tile)) { l_list.AddLast(l_tile); } } } } return l_list; }
public void faceTile(Tile a_tile) { if (a_tile.getMapPosition().X < m_currentPosition.getMapPosition().X) { if (MathManager.isEven((int)m_currentPosition.getMapPosition().X)) { m_facingState = a_tile.getMapPosition().Y == m_currentPosition.getMapPosition().Y ? m_facingState = FacingState.TopLeft : m_facingState = FacingState.BottomLeft; } else { m_facingState = a_tile.getMapPosition().Y == m_currentPosition.getMapPosition().Y ? m_facingState = FacingState.BottomLeft : m_facingState = FacingState.TopLeft; } } else if (a_tile.getMapPosition().X > m_currentPosition.getMapPosition().X) { if (MathManager.isEven((int)m_currentPosition.getMapPosition().X)) { m_facingState = a_tile.getMapPosition().Y == m_currentPosition.getMapPosition().Y ? m_facingState = FacingState.TopRight : m_facingState = FacingState.BottomRight; } else { m_facingState = a_tile.getMapPosition().Y == m_currentPosition.getMapPosition().Y ? m_facingState = FacingState.BottomRight : m_facingState = FacingState.TopRight; } } else { m_facingState = a_tile.getMapPosition().Y < m_currentPosition.getMapPosition().Y ? m_facingState = FacingState.Up : m_facingState = FacingState.Down; } }
public override void update() { if (m_moveQueue.Count > 0) { m_currentPosition.p_object = null; if (m_lerpValue < 1.0f) { m_position = Vector2.Lerp(m_currentPosition.p_position, m_moveQueue.Peek().p_position, m_lerpValue) + m_tileOffset; m_lerpValue += 0.05f; } else { m_position = m_moveQueue.Peek().p_position + m_tileOffset; m_currentPosition = m_moveQueue.Pop(); if (m_moveQueue.Count > 0) { faceTile(m_moveQueue.Peek()); } else { m_currentPosition.p_object = this; } m_lerpValue = 0.0f; } } base.update(); }
public virtual bool moveTo(Tile a_tile) { if (m_moveQueue.Count == 0) { m_moveQueue = ((GameState)Game.getInstance().getCurrentState()).m_pathFinder.findPath(m_currentPosition.getMapPosition(), a_tile.getMapPosition()); } return true; }
private static double getPathValue(Tile a_curTile, Tile a_endTile) { return Math.Sqrt(Math.Pow(a_curTile.getMapPosition().X - a_endTile.getMapPosition().X, 2) + Math.Pow(a_curTile.getMapPosition().Y - a_endTile.getMapPosition().Y, 2)); }
private static Stack<Tile> findPath(Tile a_startTile, Tile a_endTile) { TileMap l_tileMap = ((GameState)Game.getInstance().getCurrentState()).getTileMap(); Dictionary<Tile, double> l_closedSet = new Dictionary<Tile, double>(); Dictionary<Tile, double> l_openSet = new Dictionary<Tile, double>(); Dictionary<Tile, Tile> l_cameFrom = new Dictionary<Tile, Tile>(); Tile l_neighbor; int[] Xcheck = new int[] { 0 }; int[] Ycheck = new int[] { 0 }; l_openSet.Add(a_startTile, getPathValue(a_startTile, a_endTile)); l_cameFrom.Add(a_startTile, a_startTile); while (l_openSet.Count > 0) { KeyValuePair<Tile, double> l_current = l_openSet.First(); foreach (KeyValuePair<Tile, double> l_kvPair in l_openSet) { if (l_kvPair.Value < l_current.Value) { l_current = l_kvPair; } } if (l_current.Key.getMapPosition() == a_endTile.getMapPosition()) { Stack<Tile> l_reconstructedPath = new Stack<Tile>(); l_reconstructedPath.Push(l_current.Key); return reconstructPath(l_cameFrom, l_current.Key, l_reconstructedPath); } l_openSet.Remove(l_current.Key); l_closedSet.Add(l_current.Key, l_current.Value); if (MathManager.isEven(l_current.Key.X)) { Xcheck = new[] { -1, 0, 1, 1, 0, -1 }; Ycheck = new[] { 1, -1, 0, 1, 1, 0 }; } else { Xcheck = new[] { 1, 0, 1, -1, 0, -1 }; Ycheck = new[] { -1, -1, 0, -1, 1, 0 }; } for (int i = 0; i < Xcheck.Length && i < Ycheck.Length; i++) { int l_newX = (int)l_current.Key.getMapPosition().X + Xcheck[i]; int l_newY = (int)l_current.Key.getMapPosition().Y + Ycheck[i]; l_neighbor = l_tileMap.getTile(l_newX, l_newY); if (l_neighbor != null) { //int l_heightDifference = l_current.Key.p_height + l_neighbor.p_height; if (l_closedSet.ContainsKey(l_neighbor) || l_neighbor.isObstructed()) { continue; } double l_tentativeGScore = l_current.Value + getPathValue(l_neighbor, a_endTile)/* + l_heightDifference*/; if (!l_openSet.ContainsKey(l_neighbor) || l_tentativeGScore < l_openSet[l_neighbor]) { l_openSet[l_neighbor] = l_tentativeGScore; l_cameFrom[l_neighbor] = l_current.Key; } } } } return new Stack<Tile>(); }