void Start()
    {
        btnPlayAgain.SetActive(false);

        GameObject playerControllerObject = GameObject.FindGameObjectWithTag("Player");


        if (playerControllerObject != null)
        {
            playerController = playerControllerObject.GetComponent <Done_PlayerController>();
        }
        if (playerController == null)
        {
            Debug.Log("Cannot find 'GameController' script");
        }


        gameOver          = false;
        restart           = false;
        restartText.text  = "";
        gameOverText.text = "";
        score             = 0;
        live = playerController.Live;
        UpdateLive(live);
        UpdateScore();
        StartCoroutine(SpawnWaves());
    }
Example #2
0
    //private int i = 0, x;
    void Start()
    {
        GameObject gameControllerObject1 = GameObject.FindGameObjectWithTag("Player");

        if (gameControllerObject1 != null)
        {
            life = gameControllerObject1.GetComponent <Done_PlayerController>();
        }
        if (gameControllerObject1 == null)
        {
            Debug.Log("Cannot find 'GameController' script1111");
        }
        GameObject gameControllerObject21 = GameObject.FindGameObjectWithTag("boss");

        if (gameControllerObject21 != null)
        {
            boos = gameControllerObject1.GetComponent <boss>();
        }
        if (gameControllerObject21 == null)
        {
            //Debug.Log("Cannot find 'GameController' script1111");
        }
        sadvn = 2;
        //gameObject.GetComponent<Renderer>().material.color = new Color(Random.Range(0.8f, 1f), 0, 0);
        GameObject gameControllerObject = GameObject.FindGameObjectWithTag("GameController");

        if (gameControllerObject != null)
        {
            gameController = gameControllerObject.GetComponent <GameController>();
        }
        if (gameController == null)
        {
            Debug.Log("Cannot find 'GameController' script");
        }
    }
Example #3
0
 public void UnregisterPlayer(Done_PlayerController player)
 {
     for (var i = 0; i < mPlayerState.Count; ++i)
     {
         if (mPlayerState[i].NetId == netId)
         {
             Debug.Log("UnregisterPlayer");
             mPlayerState.RemoveAt(i);
             break;
         }
     }
 }
Example #4
0
    // Use this for initialization
    void Start()
    {
        GameObject playerObject = GameObject.FindGameObjectWithTag("Player");

        if (playerObject != null)
        {
            player = playerObject.GetComponent <Done_PlayerController>();
        }
        if (playerObject == null)
        {
            Debug.Log("Cannot find 'PlayerController' script");
        }
    }
Example #5
0
    void SpawnPlayers(int id, Vector3 position)
    {
        GameObject            instance = Instantiate(m_PlayerPrefab, position, Quaternion.Euler(0f, 0f, 0f)) as GameObject;
        Done_PlayerController tmp      = instance.GetComponent <Done_PlayerController>();

        tmp.playerid      = id;
        tmp.localplayerid = m_LocalNumber;
        tmp.m_sender      = this;
        tmp.m_MsgQueue    = new Queue <Message>();
        m_Players[id]     = tmp;
        PlayerNums++;
        Debug.Log("Player:" + Convert.ToString(id) + " construct");
    }
Example #6
0
    public override List <float> CollectState()
    {
        // Clear the state
        state.Clear();

        // Get the agent's player
        Done_PlayerController player = gameObject.GetComponentInChildren <Done_PlayerController>();

        // Where is the player?
        state.Add(player != null ? player.transform.position.x : gameObject.transform.position.x);
        state.Add(player != null ? player.transform.position.y : gameObject.transform.position.y);
        state.Add(player != null ? player.transform.position.z : gameObject.transform.position.z);
        // Where are the enemies?
        AddStateForward(state, Vector3.forward, player);
        return(state);
    }
Example #7
0
 private void HandleDiscreteAction(Done_PlayerController player, float[] act)
 {
     if (HasTarget(GameState.ObjectCategory.Asteroid) && act[0] == 5f)
     {
         // Fire at asteroid
         player.FireMissile();
     }
     else if (HasTarget(GameState.ObjectCategory.Alien) && act[0] == 6f)
     {
         // Fire at alien
         player.FireMissile();
     }
     else if (HasTarget(GameState.ObjectCategory.Missile) && act[0] == 7f)
     {
         // Fire at alien missile
         player.FireMissile();
     }
 }
Example #8
0
 public override void AgentStep(float[] act)
 {
     if (act != null && act.Length > 0)
     {
         // Get the agent's player
         Done_PlayerController player = GetComponentInChildren <Done_PlayerController>();
         if (player != null)
         {
             if (brain.brainParameters.actionSpaceType == StateType.continuous)
             {
                 HandleContinuousAction(player, act);
             }
             else
             {
                 HandleDiscreteAction(player, act);
             }
         }
     }
 }
Example #9
0
 private void HandleContinuousAction(Done_PlayerController player, float[] act)
 {
     if (act[0] == 3)
     {
         // Fire
         if (HasTarget(GameState.ObjectCategory.Asteroid) && act[1] == 1f)
         {
             // Fire at asteroid
             player.FireMissile();
         }
         else if (HasTarget(GameState.ObjectCategory.Alien) && act[1] == 2f)
         {
             // Fire at alien
             player.FireMissile();
         }
         else if (HasTarget(GameState.ObjectCategory.Missile) && act[1] == 3f)
         {
             // Fire at alien missile
             player.FireMissile();
         }
     }
 }
 protected override void ApplyEffect(Done_PlayerController playerController)
 {
     playerController.fireRate *= 0.9f;
 }
Example #11
0
    //Apply a powerup to the player
    public void GivePowerup(GameObject player)
    {
        Done_PlayerController playerController = player.GetComponent <Done_PlayerController> ();

        ApplyEffect(playerController);
    }
Example #12
0
 protected abstract void ApplyEffect(Done_PlayerController playerController);
Example #13
0
 protected override void ApplyEffect(Done_PlayerController playerController)
 {
     playerController.bonusShots = Mathf.Clamp(playerController.bonusShots + 1, 0, maxStack);
 }
    private void HandleDiscreteAction(Done_PlayerController player, float[] act)
    {
        float factor        = 1.0f;
        float movementLocal = movement;

        if (act[0] == 1f || act[0] == 2f)
        {
            // Assume forward movement
            if (act[0] == 2f)
            {
                // Adjust for backward movement.
                movementLocal *= -1f;
            }
            // Encourage movement.
            // But we want to encourage it to the center.
            // So we calculate a factor that is 1 in the center and 0 on the bounds.
            float zHalf = (boundaryCollider.bounds.max.z - boundaryCollider.bounds.min.z) * 0.5f;
            factor  = 1 - Mathf.Abs((zHalf - player.transform.position.z + boundaryCollider.bounds.min.z) / zHalf);
            reward += 0.8f * factor * 0.02f;
            // Forward and Backward
            float z = Mathf.Lerp(player.transform.position.z, player.transform.position.z + movementLocal, player.speed * Time.deltaTime);
            if (boundaryCollider != null && z < boundaryCollider.bounds.center.z - boundaryCollider.bounds.extents.z)
            {
                z = boundaryCollider.bounds.center.z - boundaryCollider.bounds.extents.z;
            }
            if (boundaryCollider != null && z > boundaryCollider.bounds.center.z + boundaryCollider.bounds.extents.z)
            {
                z = boundaryCollider.bounds.center.z + boundaryCollider.bounds.extents.z;
            }
            Vector3 newPosition = new Vector3(player.transform.position.x, player.transform.position.y, z);
            player.transform.position = newPosition;
        }
        else if (act[0] == 3f || act[0] == 4f)
        {
            // Assume right movement
            if (act[0] == 4f)
            {
                // Adjust for left movement.
                movementLocal *= -1f;
            }
            // Encourage movement.
            // But we want to encourage it to the center.
            // So we calculate a factor that is 1 in the center and 0 on the bounds.
            float xHalf = (boundaryCollider.bounds.max.x - boundaryCollider.bounds.min.x) * 0.5f;
            factor  = 1 - Mathf.Abs((xHalf - player.transform.position.x + boundaryCollider.bounds.min.x) / xHalf);
            reward += factor * 0.02f;
            // Left and Right
            float x = Mathf.Lerp(player.transform.position.x, player.transform.position.x + movementLocal, player.speed * Time.deltaTime);
            if (boundaryCollider != null && x < boundaryCollider.bounds.center.x - boundaryCollider.bounds.extents.x)
            {
                x = boundaryCollider.bounds.center.x - boundaryCollider.bounds.extents.x;
            }
            if (boundaryCollider != null && x > boundaryCollider.bounds.center.x + boundaryCollider.bounds.extents.x)
            {
                x = boundaryCollider.bounds.center.x + boundaryCollider.bounds.extents.x;
            }
            Vector3 newPosition = new Vector3(x, player.transform.position.y, player.transform.position.z);
            player.transform.position = newPosition;
        }
        else if (act[0] == 5f)
        {
            if (HasTarget(GameState.ObjectCategory.Asteroid))
            {
                // Fire at asteroid
                reward += 0.05f;
                player.FireMissile();
            }
        }
        else if (act[0] == 6f)
        {
            if (HasTarget(GameState.ObjectCategory.Alien))
            {
                // Fire at alien
                reward += 0.06f;
                player.FireMissile();
            }
        }
        else if (act[0] == 7f)
        {
            if (HasTarget(GameState.ObjectCategory.Missile))
            {
                // Fire at alien missile
                // These are more dangerous and should be avoided, but we still want to fire at them.
                reward += 0.07f;
                player.FireMissile();
            }
        }
    }
 // Use this for initialization
 void Start()
 {
     playerGameObject = GameObject.FindWithTag("Player");
       playerController = playerGameObject.GetComponent<Done_PlayerController>();
 }
    private void HandleContinuousAction(Done_PlayerController player, float[] act)
    {
        float factor;

        // Discourage lack of movement.
        reward -= 0.001f;

        if (act[0] == 1)
        {
            // Encourage movement.
            //// But we want to encourage it to the center.
            //// So we calculate a factor that is 1 in the center and 0 on the bounds.
            //float zHalf = (boundaryCollider.bounds.max.z - boundaryCollider.bounds.min.z) * 0.5f;
            //factor = 1 - Mathf.Abs((zHalf - player.transform.position.z + boundaryCollider.bounds.min.z) / zHalf);
            factor  = 1.0f;
            reward += factor * 0.002f;
            // Forward and Backward
            float z = Mathf.Lerp(player.transform.position.z, player.transform.position.z + act[1], player.speed * Time.deltaTime);
            if (boundaryCollider != null && z < boundaryCollider.bounds.center.z - boundaryCollider.bounds.extents.z)
            {
                z = boundaryCollider.bounds.center.z - boundaryCollider.bounds.extents.z;
            }
            if (boundaryCollider != null && z > boundaryCollider.bounds.center.z + boundaryCollider.bounds.extents.z)
            {
                z = boundaryCollider.bounds.center.z + boundaryCollider.bounds.extents.z;
            }
            Vector3 newPosition = new Vector3(player.transform.position.x, player.transform.position.y, z);
            player.transform.position = newPosition;
        }
        else if (act[0] == 2)
        {
            // Encourage movement.
            //// But we want to encourage it to the center.
            //// So we calculate a factor that is 1 in the center and 0 on the bounds.
            //float xHalf = (boundaryCollider.bounds.max.x - boundaryCollider.bounds.min.x) * 0.5f;
            //factor = 1 - Mathf.Abs((xHalf - player.transform.position.x + boundaryCollider.bounds.min.x) / xHalf);
            factor  = 1.0f;
            reward += factor * 0.002f;
            // Left and Right
            float x = Mathf.Lerp(player.transform.position.x, player.transform.position.x + act[1], player.speed * Time.deltaTime);
            if (boundaryCollider != null && x < boundaryCollider.bounds.center.x - boundaryCollider.bounds.extents.x)
            {
                x = boundaryCollider.bounds.center.x - boundaryCollider.bounds.extents.x;
            }
            if (boundaryCollider != null && x > boundaryCollider.bounds.center.x + boundaryCollider.bounds.extents.x)
            {
                x = boundaryCollider.bounds.center.x + boundaryCollider.bounds.extents.x;
            }
            Vector3 newPosition = new Vector3(x, player.transform.position.y, player.transform.position.z);
            player.transform.position = newPosition;
        }
        else if (act[0] == 3)
        {
            // Fire
            if (HasTarget(GameState.ObjectCategory.Asteroid) && act[1] == 1f)
            {
                // Fire at asteroid
                reward += 0.005f;
                player.FireMissile();
            }
            else if (HasTarget(GameState.ObjectCategory.Alien) && act[1] == 2f)
            {
                // Fire at alien
                reward += 0.006f;
                player.FireMissile();
            }
            else if (HasTarget(GameState.ObjectCategory.Missile) && act[1] == 3f)
            {
                // Fire at alien missile
                // These are more dangerous and should be avoided, but we still want to fire at them.
                reward += 0.007f;
                player.FireMissile();
            }
            else
            {
                // Discourage firing at nothing
                reward -= 0.0005f;
            }
        }
    }
 protected override void ApplyEffect(Done_PlayerController playerController)
 {
     playerController.bonusHoming++;
 }
Example #18
0
    void Start()
    {
        sc = 1;
        shot11.GetComponent <MeshCollider>().enabled = true;
        GameObject gameControllerObject = GameObject.FindGameObjectWithTag("boss");

        if (gameControllerObject != null)
        {
            booos = gameControllerObject.GetComponent <boss>();
        }
        if (booos == null)
        {
            Debug.Log("Cannot find 'boss' script");
        }
        GameObject gameControllerObject1 = GameObject.FindGameObjectWithTag("Player");

        if (gameControllerObject1 != null)
        {
            player = gameControllerObject1.GetComponent <Done_PlayerController>();
        }
        if (player == null)
        {
            Debug.Log("Cannot find 'player' script");
        }
        //story init:
        storyIndex   = 0;
        isStory      = 0;
        storyEndTime = 0.0f;


        //Operate system:
        isPause = 0;

        //order input & Chat system:
        isInput = 0;

        xgtime = xgtime + Time.time;
        Debug.Log("xtime" + xgtime);

        boss.SetActive(false);
        name.SetActive(false);
        botton1.SetActive(false);
        botton2.SetActive(false);
        botton3.SetActive(false);
        botton4.SetActive(false);
        go = 0;
        if (PlayerPrefs.GetFloat("HighScore") != null)
        {
            highscore = PlayerPrefs.GetFloat("HighScore");
        }
        gameOver          = false;
        restart           = false;
        hs                = true;
        restartText.text  = "";
        gameOverText.text = "";
        //highscore = 0;
        score = PlayerPrefs.GetFloat("scorethisgame");
        h     = 0;
        UpdateScore();
        StartCoroutine(EnemyWaves());
        StartCoroutine(SpawnWaves());
    }
Example #19
0
 void Awake()
 {
     _instance = this;
 }
Example #20
0
 // Use this for initialization
 void Start()
 {
     playerController = playerHolder.GetComponent<Done_PlayerController>();
 }
Example #21
0
    private void AddStateForward(List <float> list, Vector3 direction, Done_PlayerController player)
    {
        // Notes:	The forward raycast needs to cast a wider net.
        //			Try the ray directly in front of the player.
        //			Then try the ray slightly to the left of the player.
        //			Then try the ray slightly to the right of the player.
        // Create empty game state.
        GameState state = new GameState();

        // If player exists
        if (player != null)
        {
            direction = player.transform.TransformDirection(direction);
            // Cast ray and get distance.
            RaycastHit hit;

            if (Physics.Raycast(player.transform.position, direction, out hit, RayLength))
            {
                // In front
                state.Distance = hit.distance;
                if (hit.collider.gameObject.CompareTag("Boundary"))
                {
                    state.Category = GameState.ObjectCategory.Boundary;
                }
                else if (hit.collider.gameObject.name.Contains("Asteroid"))
                {
                    state.Category = GameState.ObjectCategory.Asteroid;
                }
                else if (hit.collider.gameObject.name.Contains("Enemy Ship"))
                {
                    state.Category = GameState.ObjectCategory.Alien;
                }
                else if (hit.collider.gameObject.name.Contains("Bolt-Enemy"))
                {
                    state.Category = GameState.ObjectCategory.Missile;
                }
            }
            else if (Physics.Raycast(new Vector3(player.transform.position.x - 0.35f, player.transform.position.y, player.transform.position.z), direction, out hit, RayLength))
            {
                // Slightly left
                state.Distance = hit.distance;
                if (hit.collider.gameObject.CompareTag("Boundary"))
                {
                    state.Category = GameState.ObjectCategory.Boundary;
                }
                else if (hit.collider.gameObject.name.Contains("Asteroid"))
                {
                    state.Category = GameState.ObjectCategory.Asteroid;
                }
                else if (hit.collider.gameObject.name.Contains("Enemy Ship"))
                {
                    state.Category = GameState.ObjectCategory.Alien;
                }
                else if (hit.collider.gameObject.name.Contains("Bolt-Enemy"))
                {
                    state.Category = GameState.ObjectCategory.Missile;
                }
            }
            else if (Physics.Raycast(new Vector3(player.transform.position.x + 0.35f, player.transform.position.y, player.transform.position.z), direction, out hit, RayLength))
            {
                // Slightly right
                state.Distance = hit.distance;
                if (hit.collider.gameObject.CompareTag("Boundary"))
                {
                    state.Category = GameState.ObjectCategory.Boundary;
                }
                else if (hit.collider.gameObject.name.Contains("Asteroid"))
                {
                    state.Category = GameState.ObjectCategory.Asteroid;
                }
                else if (hit.collider.gameObject.name.Contains("Enemy Ship"))
                {
                    state.Category = GameState.ObjectCategory.Alien;
                }
                else if (hit.collider.gameObject.name.Contains("Bolt-Enemy"))
                {
                    state.Category = GameState.ObjectCategory.Missile;
                }
            }
        }
        TransferState(list, direction, state);

        //if (gameObject.name == "Agent1" && state.Category != GameState.ObjectCategory.Boundary)
        //{
        //	Debug.Log("Direction: (" + direction + "), Category: " + state.Category + ", Distance: " + state.Distance);
        //}
    }
    public void ShipSpawn(int choice)
    {
        //Debug.Log(countPlayer);

        if (countPlayer == 1)
        {
            m_StartPos = -5;
        }
        else
        {
            m_StartPos = 5;
        }

        switch (choice)
        {
        case 0:
            m_ShipChoice = m_Ship00;

            //Done_PlayerController playerController = m_Ship00.GetComponent<Done_PlayerController>();
            //playerController.PlayerSwitch(ePlayerNumber.PlayerOne, 1);
            //if (countPlayer == 1)
            //{
            //    playerController.PlayerSwitch(ePlayerNumber.PlayerOne, 1);
            //}
            //else
            //{
            //    playerController.PlayerSwitch(ePlayerNumber.PlayerTwo, 2);
            //}

            break;

        case 1:
            m_ShipChoice = m_Ship01;
            //Done_PlayerController playerController = m_Ship01.GetComponent<Done_PlayerController>();
            //playerController.PlayerSwitch(ePlayerNumber.PlayerTwo, 2);
            //if (countPlayer == 1)
            //{
            //    playerController01.PlayerSwitch(ePlayerNumber.PlayerOne, 1);
            //}
            //else
            //{
            //    playerController01.PlayerSwitch(ePlayerNumber.PlayerTwo, 2);
            //}
            break;

        case 2:
            m_ShipChoice = m_Ship02;
            //m_ShipChoice = Instantiate(m_Ship02, new Vector3(m_StartPos , 0, 0), Quaternion.identity);
            //Done_PlayerController playerController02 = m_Ship02.GetComponent<Done_PlayerController>();
            //if (countPlayer == 1)
            //{
            //    playerController02.PlayerSwitch(ePlayerNumber.PlayerOne, 1);
            //}
            //else
            //{
            //    playerController02.PlayerSwitch(ePlayerNumber.PlayerTwo, 2);
            //}
            break;
        }

        //Instantiate(m_ShipChoice, new Vector3(m_StartPos, 0, 0), Quaternion.identity);

        //Done_PlayerController playerController = m_ShipChoice.GetComponent<Done_PlayerController>();

        if (countPlayer == 1)
        {
            GameObject            PlayerOneShip       = Instantiate(m_ShipChoice, new Vector3(m_StartPos, 0, 0), Quaternion.identity);
            Done_PlayerController PlayerOneController = PlayerOneShip.GetComponent <Done_PlayerController>();
            if (PlayerOneController != null)
            {
                PlayerOneController.PlayerSwitch(1);
            }
        }
        else
        {
            GameObject            PlayerTwoShip       = Instantiate(m_ShipChoice, new Vector3(m_StartPos, 0, 0), Quaternion.identity);
            Done_PlayerController PlayerTwoController = PlayerTwoShip.GetComponent <Done_PlayerController>();
            if (PlayerTwoController != null)
            {
                PlayerTwoController.PlayerSwitch(2);
            }
        }


        if (SCManager.Instance.PlayerNumber == 1 && countPlayer == 1)
        {
            m_UIChoiceScreen.SetActive(false);
            m_GameController.GameStart = true;
        }
        else if (SCManager.Instance.PlayerNumber == 2 && countPlayer == 2)
        {
            m_UIChoiceScreen.SetActive(false);
            m_GameController.GameStart = true;
        }
        Debug.Log("Exit");
        countPlayer++;
    }