コード例 #1
0
ファイル: UnitManager.cs プロジェクト: Ammon-Dev/AI_Capstone
    public void attackPos(Vector3Int goal)//move til you can hit the enemy
    {
        //path
        Stack <Vector3Int> path    = astar.Algorithm(activeUnit.currentPosition, goal, tilemapFloor, activeUnit.currentEnergy); //quickest path to the enemy
        Vector3Int         current = activeUnit.currentPosition;                                                                //the current step in the path
        int sum = 0;                                                                                                            //energy used

        foreach (Vector3Int pos in path)
        {
            Debug.Log(pos);
            int x = current.x - pos.x;     //used to check movement type
            int y = current.y - pos.y;
            current = pos;                 //move the step up

            if (Mathf.Abs(x - y) % 2 == 1) //move side to side/up down
            {
                sum += 10;
            }
            else//diagonal movement
            {
                sum += 14;
            }
            if (activeUnit.currentEnergy - sum >= 0)
            {                                            //if we can still move
                if (CheckAttack(pos, goal))              //if we hit
                {
                    activeUnit.TeleportPlayer(pos, sum); //move the unit
                    break;                               //end the loop
                }
            }
        }
    }