示例#1
0
    static void Main()
    {
        aStar       aStar     = new aStar();
        Node        startNode = new Node();
        Node        endNode   = new Node();
        List <Node> nodeList  = new List <Node>();

        aStar.setUpNodes(nodeList);

        Console.WriteLine("Enter start node: ");
        startNode.name = Console.ReadLine();
        Console.WriteLine("Enter end node: ");
        endNode.name = Console.ReadLine();
        Console.WriteLine("Your path: ");

        foreach (Node nodeFind in nodeList)
        {
            if (startNode.name.ToUpper() == nodeFind.name)
            {
                startNode = nodeFind;
            }
            if (endNode.name.ToUpper() == nodeFind.name)
            {
                endNode = nodeFind;
            }
        }

        List <Node> closedList = new List <Node>();

        aStar.testNode(startNode, startNode, endNode, closedList);
    }
示例#2
0
    private void setupPathfinder()
    {
        int[,] walkableMap = new int[(int)MapSize.x, (int)MapSize.y];
        for (int i = 0; i < MapSize.x; i++)
        {
            for (int j = 0; j < MapSize.y; j++)
            {
                walkableMap[i, j] = 0;
            }
        }
        foreach (var place in locationPositions)
        {
            walkableMap[(int)place.location.x, (int)place.location.y] = 2;
        }

        foreach (var pos in mountainPositions)
        {
            walkableMap[(int)pos.x, (int)pos.y] = 1;
        }

        Grid grid = new Grid();

        grid.setup(walkableMap, (int)MapSize.x, (int)MapSize.y);
        grid.initGrid();

        aStar pathfinder = FindObjectOfType <aStar>();

        pathfinder.grid = grid;
    }
示例#3
0
        // ******************** //

        public AI_StateFollowCharacter(Character me, Character leader, AI_StateMachine machine)
        {
            this.me     = me;
            this.leader = leader;
            Farmer f = leader as Farmer;

            if (f != null)
            {
                leaderIsFarmer = true;
            }
            this.machine = machine;

            aStar = new aStar(me.currentLocation, me, leader);

            followThreshold     = 2.25f * fullTile;
            decelerateThreshold = 1.75f * fullTile;
            deceleration        = 0.075f;
            pathNodeTolerance   = 5f;
            monsterAggroRadius  = 8f * fullTile;

            characterMoveUp    = typeof(Character).GetField("moveUp", BindingFlags.NonPublic | BindingFlags.Instance);
            characterMoveDown  = typeof(Character).GetField("moveDown", BindingFlags.NonPublic | BindingFlags.Instance);
            characterMoveLeft  = typeof(Character).GetField("moveLeft", BindingFlags.NonPublic | BindingFlags.Instance);
            characterMoveRight = typeof(Character).GetField("moveRight", BindingFlags.NonPublic | BindingFlags.Instance);
        }
示例#4
0
    // Use this for initialization
    void Start()
    {
        acceleration = Vector3.zero;
        //velocity = transform.forward;

        tempPlayer = GameObject.FindGameObjectWithTag("Player");

        path = new List <Vector3>();

        hasArrived  = true;
        pinkyScript = this.GetComponent <aStar>();
    }
        // ******************** //

        public AI_StateFollowCharacter(Character me, Character leader, AI_StateMachine machine)
        {
            this.me     = me;
            this.leader = leader;
            Farmer f = leader as Farmer;

            if (f != null)
            {
                leaderIsFarmer = true;
            }
            this.machine = machine;
            r            = new Random((int)Game1.uniqueIDForThisGame + (int)Game1.stats.DaysPlayed + Game1.timeOfDay);

            aStar = new aStar(me.currentLocation, me, leader);

            deceleration       = 0.025f;
            pathNodeTolerance  = 3f;
            monsterAggroRadius = 8f * fullTile;

            characterMoveUp    = typeof(Character).GetField("moveUp", BindingFlags.NonPublic | BindingFlags.Instance);
            characterMoveDown  = typeof(Character).GetField("moveDown", BindingFlags.NonPublic | BindingFlags.Instance);
            characterMoveLeft  = typeof(Character).GetField("moveLeft", BindingFlags.NonPublic | BindingFlags.Instance);
            characterMoveRight = typeof(Character).GetField("moveRight", BindingFlags.NonPublic | BindingFlags.Instance);
        }
示例#6
0
 // Use this for initialization
 void Start()
 {
     signals           = new List <Signal>();
     notificationQueue = new List <Notification>();
     pathfinder        = FindObjectOfType <aStar>();
 }
示例#7
0
    // Update is called once per frame
    void Update()
    {
        if(!selectedCell && !findingPath && !movingPlayer)
        {
            //Debug.Log("No Cell Selected");
            if(Input.GetMouseButtonDown(0))
            {
                Ray identifier = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hitter = new RaycastHit();

                if(Physics.Raycast(identifier,out hitter))
                {
                    if(hitter.transform.tag == "Player")
                    {
                        Player playEr;
                        playEr = hitter.transform.GetComponent<Player>();

        //						Debug.Log(playEr.transform.GetComponent<PlayerMovement

                        if(!playEr.wrongCell)
                        {
                            Ray r2 = new Ray(hitter.transform.position,Vector3.down);
                            RaycastHit d2;
                            if(Physics.Raycast(r2,out d2))
                            {
                                Cell cellHolder = d2.transform.GetComponent<Cell>();
                                astarHolder = new aStar();
                                astarHolder.startNode = cellHolder;
                                unitMovement = hitter.transform.GetComponent<PlayerMovement>();
        //								Debug.Log(unitMovement.playerType);
                                findingPath = true;
                            }
                        }
                    }
                    else if(hitter.transform.tag == "Cell" || hitter.transform.tag == "Finish")
                    {
                        selectionTime = Time.time;

                        //check mouse click position
                        selectedCellPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                        selectedCellPosition.y = 2f; //set in the grid plane

                        //define Index for emiters as 0 based
                        index.x = Mathf.Floor(selectedCellPosition.x) + 5;
                        index.y = Mathf.Floor(selectedCellPosition.z) + 3;

                        StartCoroutine(axisManager());
                    }
                }
            }
        }
        else if(selectedCell)
        {
            if(axis != 0)
            {
                if(!snappingToGrid)
                    UpdatePosition();
                else
                    SnapToGrid();
            }
            if(Input.GetMouseButtonUp(0))
            {
                //selectedCell = false;
                snappingToGrid = true;
                playerChecks.checkForDamage();
            }
        }
        else if(findingPath)
        {
            if(Input.GetMouseButtonDown(0))
            {
                Ray identifier = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hitter = new RaycastHit();

                if(Physics.Raycast(identifier,out hitter))
                {
        //					Debug.Log("beginning a*");
                    if(hitter.transform.tag == "Cell")
                    {
                        astarHolder.targetNode = hitter.transform.GetComponent<Cell>();
                        gridFill.fillCells(hitter.transform);
                        movingPlayer = true;
                        findingPath = false;
                        StartCoroutine(playerManager());
                    }
                    else if(hitter.transform.tag == "Finish")
                    {
                        Ray r2 = new Ray(hitter.transform.position,Vector3.down);
                        RaycastHit d2;
                        if(Physics.Raycast(r2,out d2))
                        {
                            astarHolder.targetNode = d2.transform.GetComponent<Cell>();
                            gridFill.fillCells(d2.transform);
                            movingPlayer = true;
                            goingFinish = true;
                            findingPath = false;
                            StartCoroutine(playerManager());
                        }
                    }
                }
        //				else
        //				{
        //					Debug.DrawRay(identifier.origin,identifier.direction*30f,Color.red,20f);
        //					Debug.Log("mouse: " + Input.mousePosition);
        //					Debug.Log("ray o:" + identifier.origin);
        //					Debug.Log("ray d:" + identifier.direction);
        //				}
            }
        }
    }
示例#8
0
	void Awake ()
	{
		//instantiate singleton
		m_instance = this;
	}