Exemple #1
0
    //public function which will return a list of cells which connects the two positions provided
    public List <Vector2> CreatePath(Vector2 coastPos, Vector2 startPos)
    {
        //retrieve the create grid compenent
        grid = GetComponent <CreateGrid>();
        //vector representing where the path should reach
        Goal = coastPos;
        //vector representing where the path should start
        CurrentGridPosition = startPos;
        //retreive the map structure
        Grid = grid.HexGrid;
        //initialise a value representing if a water tile is found
        waterFound = false;
        //value representing if a path is  possible
        pathNotPossible = false;
        //retrieve the generating island component
        islandState = GetComponent <GeneratingIsland>();
        //retreive the state of every tile in the map structure
        islandLandMass = islandState.hexMapIsland();
        //create a list containing all cells that have not yet been considered
        Open = new List <CalculatePath>();
        //create a list containing all cells that have been calculated
        Closed = new List <CalculatePath>();

        //find a path between the start point and the goal point
        FindingPath();

        //create a list to store the path created
        List <Vector2> lakePath = new List <Vector2>();

        //if a path was created and its length is greater than 1
        if (pathfound && AIpath.Length > 1)
        {
            //for every point in the path found
            for (int i = 0; i < AIpath.Length; i++)
            {
                //Add the current path point the list of points
                lakePath.Add(AIpath[i]);
            }
        }
        //remove all points from the open and closed lists
        resetValues();
        //return the list of points making up the path
        return(lakePath);
    }
Exemple #2
0
    //creates the grid once a button is pressed
    public void CreateGrid()
    {
        //if a grid already exists
        if (currentGrid != null)
        {
            //destroy the current map
            Destroy(currentGrid);
        }
        //if the controls UI hasnt been turned off
        if (ControlsOpen == true)
        {
            //set the controls UI to be active
            ControlsUI.gameObject.SetActive(true);
            //if the by step option has been selected
            if (byStepToggle.isOn)
            {
                //set the step counter UI to active
                StepCounter.SetActive(true);
            }
            else
            {
                //deactivate the step counter UI
                StepCounter.SetActive(false);
            }
        }
        //disactivate the map options UI
        SliderUI.gameObject.SetActive(false);
        //create the game object responsible for creating the grid in the world
        currentGrid = Instantiate(Grid, transform.position, Quaternion.identity);
        //retreive the grids Generating island component
        GeneratingIsland gridCreation = currentGrid.GetComponent <GeneratingIsland>();

        //set the grids generation values
        gridCreation.SetValues((int)cellularPasses.value, (int)landChance.value, (int)MountainAgentsSlider.value, (int)ActionsSlider.value, byStepToggle.isOn, StepCounterText, StepTaskText);
        //create the map using the set values
        gridCreation.MapCreation();
    }