Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
        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>());
        }
Ejemplo n.º 3
0
        public override Stack <Tile> findPath(Vector2 a_startPos, Vector2 a_endPos)
        {
            TileMap l_tileMap = ((GameState)Game.getInstance().getCurrentState()).getTileMap();

            return(findPath(l_tileMap.getTile(a_startPos), l_tileMap.getTile(a_endPos)));
        }