Beispiel #1
0
 // Use this for initialization
 void Start()
 {
     health = FindObjectOfType<PlayerHealthManager>();
     GetComponent<AudioSource>().Play ();
     canPickUp = false;
     p2Check = PlayerPrefs.GetInt("PlayerTwoHasSpawned");
     if(p2Check == 1){
         health2 = FindObjectOfType<PlayerTwoHealthManager>();
     }
     CallTouchDelay();
 }
Beispiel #2
0
    //Text text;
    void Start()
    {
        //text = GetComponent<Text>();
        healthManager = FindObjectOfType<PlayerTwoHealthManager>();

        healthBar2 = GetComponent<Slider>();

        healthCount = PlayerTwoHealthManager.player2Health;

        maxHealth = healthManager.maxPlayerHealth;

        healthBar2.maxValue = maxHealth;
    }
Beispiel #3
0
    // Update is called once per frame
    void Update()
    {
        enemyCount = FindObjectsOfType<EnemyController>();//checks how many enemies are on the screen at any given time

        switch(waveCount){
        case 1:
            if(enemiesToSpawn[0] > 1 && Time.time > nextEnemySpawn){ //spawns in enemies
                nextEnemySpawn = Time.time + enemySpawnRate;
                CallSpawnEnemy();
            }

            if(enemyCount.Length > 0){
                hasWaveStarted = true;
                anEnemyHasSpawned = true;
            }

            if(enemyCount.Length < 1 && hasWaveStarted && !waveCompleted && anEnemyHasSpawned){
                //end the wave - some graphic might want to pop up here - just enable then disable it from the EndWave function
                //Debug.Log("Wave Completed");
                waveCompleted = true;
                CallEndWave (); //called once, as the last enemy dies
            }
            break;
        case 2:
            if(!hasWaveStarted){
                CreateHazard(platform1);
                hasWaveStarted = true;
            }

            if(enemiesToSpawn[1] > 1 && Time.time > nextEnemySpawn ){ //spawns in enemies
                nextEnemySpawn = Time.time + enemySpawnRate;
                CallSpawnEnemy();
            }

            if(enemyCount.Length > 0){
                anEnemyHasSpawned = true;
            }

            if(enemyCount.Length < 1 && hasWaveStarted && !waveCompleted && anEnemyHasSpawned){
                //end the wave
                //Debug.Log("Wave Completed");
                waveCompleted = true;
                CallEndWave (); //called once, as the last enemy dies
            }
            break;
        case 3:
            if(!hasWaveStarted){
                DestroyPlatform(platform2);
                hasWaveStarted = true;
            }

            if(enemiesToSpawn[2] > 1 && Time.time > nextEnemySpawn){ //spawns in enemies
                nextEnemySpawn = Time.time + enemySpawnRate;
                CallSpawnEnemy();
            }

            if(enemyCount.Length > 0){
                anEnemyHasSpawned = true;
            }

            if(enemyCount.Length < 1 && hasWaveStarted && !waveCompleted && anEnemyHasSpawned){
                //end the wave
                //Debug.Log("Wave Completed");
                waveCompleted = true;
                CallEndWave (); //called once, as the last enemy dies
            }
            break;
        case 4:
            if(!hasWaveStarted){
                CreateHazard(platform3);
                hasWaveStarted = true;
            }

            if(enemiesToSpawn[3] > 1 && Time.time > nextEnemySpawn){ //spawns in enemies
                nextEnemySpawn = Time.time + enemySpawnRate;
                CallSpawnEnemy();
            }

            if(enemyCount.Length > 0){
                anEnemyHasSpawned = true;
            }

            if(enemyCount.Length < 1 && hasWaveStarted && !waveCompleted && anEnemyHasSpawned){
                //end the wave
                //Debug.Log("Wave Completed");
                waveCompleted = true;
                CallEndWave (); //called once, as the last enemy dies
            }
            break;
        case 5:
            if(!hasWaveStarted){
                DestroyPlatform(platform4);
                hasWaveStarted = true;
            }

            if(enemiesToSpawn[4] > 1 && Time.time > nextEnemySpawn){ //spawns in enemies
                nextEnemySpawn = Time.time + enemySpawnRate;
                CallSpawnEnemy();
            }

            if(enemyCount.Length > 0){
                anEnemyHasSpawned = true;
            }

            if(enemyCount.Length < 1 && hasWaveStarted && !waveCompleted && anEnemyHasSpawned){
                //end the wave
                //Debug.Log("Wave Completed");
                waveCompleted = true;
                CallEndWave (); //called once, as the last enemy dies
            }
            break;
        case 6: //once reaching this the next level is called
                if(!hasWaveStarted && !waveCompleted)
                {
                WaveGraphic[5].SetActive(true);
                CallNextLevel();
                hasWaveStarted = true;
                waveCompleted = true;
                }
            break;
        }

        //spawnplayer two check
        if(playerTwoHasSpawned == 0 && playerTwoThisLevel == false && Input.GetKeyDown (KeyCode.Alpha2)){
            Instantiate (secondPlayer, player2Spawn.position, player2Spawn.rotation);
            player2Canvas.SetActive(true);
            body2 = GameObject.FindGameObjectWithTag("P2Body");
            lance2 = GameObject.FindGameObjectWithTag("P2Lance");
            bottom2 = GameObject.FindGameObjectWithTag("P2Bottom");
            head2 = GameObject.FindGameObjectWithTag("P2Head");
            gun1_2 = GameObject.FindGameObjectWithTag("P2Gun1");
            gun1_2.SetActive(false);
            gun2_2 = GameObject.FindGameObjectWithTag("P2Gun2");
            gun2_2.SetActive(false);
            gun3_2 = GameObject.FindGameObjectWithTag("P2Gun3");
            gun3_2.SetActive(false);
            gun4_2 = GameObject.FindGameObjectWithTag("P2Gun4");
            gun4_2.SetActive(false);
            player2 = FindObjectOfType<PlayerController2>();
            health2 = FindObjectOfType<PlayerTwoHealthManager>();
            PlayerPrefs.SetInt("PlayerTwoHasSpawned", 1); //This will now be true for the rest of the play session..
            playerTwoHasSpawned = PlayerPrefs.GetInt("PlayerTwoHasSpawned");
            playerTwoThisLevel = true;
        }
        else if(playerTwoHasSpawned == 1 && playerTwoThisLevel == false){  //automatically spawns player 2 into the next level when it loads.
            Instantiate (secondPlayer, player2Spawn.position, player2Spawn.rotation);
            player2Canvas.SetActive(true);
            body2 = GameObject.FindGameObjectWithTag("P2Body");
            lance2 = GameObject.FindGameObjectWithTag("P2Lance");
            bottom2 = GameObject.FindGameObjectWithTag("P2Bottom");
            head2 = GameObject.FindGameObjectWithTag("P2Head");
            gun1_2 = GameObject.FindGameObjectWithTag("P2Gun1");
            gun1_2.SetActive(false);
            gun2_2 = GameObject.FindGameObjectWithTag("P2Gun2");
            gun2_2.SetActive(false);
            gun3_2 = GameObject.FindGameObjectWithTag("P2Gun3");
            gun3_2.SetActive(false);
            gun4_2 = GameObject.FindGameObjectWithTag("P2Gun4");
            gun4_2.SetActive(false);
            player2 = FindObjectOfType<PlayerController2>();
            health2 = FindObjectOfType<PlayerTwoHealthManager>();
            playerTwoThisLevel = true;
        }

        //		//Game Over check
        if(gameOver == false && playerTwoHasSpawned == 0 && PlayerHealthManager.playerLives < 0){//only for player 1
            player1Canvas.SetActive	(false);
            player2Canvas.SetActive (false);
            player.enabled = false;
            player.GetComponent<Renderer>().enabled = false;
            player.GetComponent<Rigidbody2D>().velocity = Vector2.zero; //haults movement
            body.SetActive(false);
            head.SetActive(false);
            lance.SetActive(false);
            bottom.SetActive(false);
            gun1.SetActive(false);
            gun2.SetActive(false);
            gun3.SetActive(false);
            gun4.SetActive(false);
            //disable more guns if needed
            CallGameOver (); //game keeps playing in the background but player control is completely lost - should be okay
            gameOver = true;
        }
        else if(gameOver == false && playerTwoHasSpawned == 1 && PlayerHealthManager.playerLives < 0 && PlayerTwoHealthManager.player2Lives < 0){//when two players exist
            player1Canvas.SetActive	(false);
            player2Canvas.SetActive (false);

            //disable player one renders and ability to move just like when respawning
            player.enabled = false;
            player.GetComponent<Renderer>().enabled = false;
            player.GetComponent<Rigidbody2D>().velocity = Vector2.zero; //haults movement
            body.SetActive(false);
            head.SetActive(false);
            lance.SetActive(false);
            bottom.SetActive(false);
            gun1.SetActive(false);
            gun2.SetActive(false);
            gun3.SetActive(false);
            gun4.SetActive(false);
            //disable player two renders and ability to move just like when respawning
            player2.enabled = false;
            player2.GetComponent<Renderer>().enabled = false;
            player2.GetComponent<Rigidbody2D>().velocity = Vector2.zero; //haults movement
            body2.SetActive(false);
            head2.SetActive(false);
            lance2.SetActive(false);
            bottom2.SetActive(false);
            gun1_2.SetActive(false);
            gun2_2.SetActive(false);
            gun3_2.SetActive(false);
            gun4_2.SetActive(false);

            //disable more guns if needed
            CallGameOver (); //game keeps playing in the background but player control is completely lost - should be okay
            gameOver = true;
        }
    }