void executeMovement()
    {
        // Find Path
        List <PathVertexInfo> pathAstar    = this.model.findPathAstar();
        List <PathVertexInfo> pathDijkstra = this.model.findPathDijkstra();
        // Move enemy
        List <PathVertexInfo> path = (((Enemy)this.model).AStar?pathAstar:pathDijkstra);

        if (path != null && path.Count > 1 && enemyMoveEnabled)
        {
            Map.TileInfo v = ((Map.TileInfo)path[path.Count - 2].Vertex);
            this.model.move(v.x, v.y);
            // Removing the last vertex of the path because it was used by the character
            pathAstar.RemoveAt(pathAstar.Count - 1);
            pathDijkstra.RemoveAt(pathDijkstra.Count - 1);
        }
        // Showing the path found
        if (this.showPathFlag)
        {
            List <KeyValuePair <List <PathVertexInfo>, Color> > paths = new List <KeyValuePair <List <PathVertexInfo>, Color> >();
            paths.Add(new KeyValuePair <List <PathVertexInfo>, Color>(pathAstar, this.GetComponent <EnemyView>().AStar));
            paths.Add(new KeyValuePair <List <PathVertexInfo>, Color>(pathDijkstra, this.GetComponent <EnemyView>().Dijkstra));
            this.map.includePaths(paths, this.model);
        }
    }
Exemplo n.º 2
0
    private void showPath(List <PathVertexInfo> path, Color color)
    {
        string resPath = "";

        for (int i = 0; i < path.Count - 1; i++)
        {
            Map.TileInfo vertexInfo = (Map.TileInfo)path[i].Vertex;
            resPath += vertexInfo.VertexIndex + ": (x:" + vertexInfo.x + "," + vertexInfo.y + ")\n";
            GameObject tile = this.tileGameObjects[new KeyValuePair <int, int>(vertexInfo.y, vertexInfo.x)];
            if (tile != null)
            {
                tile.GetComponent <MapTileView>().showPath(color);
            }
        }

        //Debug.Log( resPath );
    }