Пример #1
0
        //Stop time and controls
        void PauseGame()
        {
            if (Time.timeScale == 1)
            {
                Time.timeScale = 0;

                //Player cant move or shoot
                PlayerControl.stopControls = true;

                if (!LaserControl.cantShoot)
                {
                    LaserControl.cantShoot = true;
                }

                //Pause music
                AudioControl.PauseAudio();
            }
            //Reset
            else
            {
                Time.timeScale = 1;

                //Allow player to move again
                playerObject.SendMessage("ContinueControl");

                //Player cant shoot
                if (LaserControl.cantShoot)
                {
                    LaserControl.cantShoot = false;
                }

                //Resume music
                AudioControl.ResumeAudio();
            }
        }
        //Destroy sequence
        IEnumerator DestroyObject()
        {
            yield return(new WaitForSeconds(.02f));

            AudioControl.PlayAudio("Explosion");
            Instantiate(enemyExplosion, this.transform.position, this.transform.rotation);
            Destroy(this.gameObject);
        }
Пример #3
0
        //Main menu start
        IEnumerator Start()
        {
            WaveShip.positionCheck = 1;

            yield return(new WaitForSeconds(.1f));

            AudioControl.PlayAudio("MainMenu");

            playerController = GameObject.Find("PlayerShip").GetComponent <PlayerControl>();
        }
        //Multiple explode sequences
        IEnumerator Explode(float TimeBetween)
        {
            while (explosionSpawnPoint < 4)
            {
                AudioControl.PlayAudio("Explosion");

                Instantiate(enemyExplosion, bossExplosions[explosionSpawnPoint].transform.position,
                            bossExplosions[explosionSpawnPoint].transform.rotation);

                yield return(new WaitForSeconds(TimeBetween));

                explosionSpawnPoint++;
            }
        }
Пример #5
0
        //Reset all variables
        void ResetVars()
        {
            gameModes = GameModes.StartScreen;

            AudioControl.PlayAudio("MainMenu");

            StopCoroutine("Wait");
            StopCoroutine("GameWaveSwitch");

            countDownFrom    = 0f;
            asteroidInterval = .5f;

            miniBossCount            = 3;
            upgradeItem              = 0;
            shieldUpgrade            = 1;
            menuChoice               = 1;
            gameWaves                = 1;
            ScoreControl.totalScore  = 0;
            WaveShip.positionCheck   = 1;
            PlayerHealth.playerLives = 3;

            ScreenControlOn();
            GameGUIOff();
            MenuParticles();

            isCounting                = false;
            gameOver                  = false;
            canSpawn                  = true;
            menuControlOn             = true;
            AudioControl.bossMusic    = false;
            ArcturusShip.arcturusDead = false;
            PlayerHealth.lifeTaken    = false;

            PlayerControl.shieldsActive     = false;
            PlayerControl.staticShield.emit = false;

            playerController.StopControl();

            LaserControl.cantShoot       = true;
            LaserControl.multiShotSwitch = 1;

            //Reconnect collision between player and enemies
            Physics.IgnoreLayerCollision(8, 9, false);
            Physics.IgnoreLayerCollision(8, 11, false);
            Physics.IgnoreLayerCollision(10, 11, false);

            playerObject.transform.position = new Vector3(0, .55f, -2f);
            //boundaryObject.transform.position = new Vector3(5, 0, 0);
        }
Пример #6
0
        void Fire()
        {
            //Switch through each weapon level up
            switch (multiShotSwitch)
            {
            //Single bullet
            case 1:
                if (Time.time > nextLaserFire)
                {
                    nextLaserFire = Time.time + fireRate;

                    var clone1 = Instantiate(bulletObject, laserSpawn.transform.position, laserSpawn.transform.rotation) as GameObject;
                    clone1.GetComponent <Rigidbody>().velocity = transform.TransformDirection(Vector3.forward * bulletSpeed);

                    AudioControl.PlayAudio("Laser");
                }
                break;

            //Double bullets
            case 2:
                if (Time.time > nextLaserFire)
                {
                    nextLaserFire = Time.time + fireRate;

                    var clone1 = Instantiate(bulletObject, laserSpawn.transform.position, laserSpawn.transform.rotation) as GameObject;
                    clone1.GetComponent <Rigidbody>().velocity = transform.TransformDirection(Vector3.forward * bulletSpeed);
                    clone1.GetComponent <Rigidbody>().AddForce(10, 0, 0);

                    var clone2 = Instantiate(bulletObject, laserSpawn.transform.position, laserSpawn.transform.rotation) as GameObject;
                    clone2.GetComponent <Rigidbody>().velocity = transform.TransformDirection(Vector3.forward * bulletSpeed);
                    clone2.GetComponent <Rigidbody>().AddForce(-10, 0, 0);

                    AudioControl.PlayAudio("Laser");
                }
                break;

            //Triple bullets
            case 3:

                MultipleLasers();

                break;
            }
        }
Пример #7
0
        //Triple bullets
        void MultipleLasers()
        {
            if (Time.time > nextLaserFire)
            {
                nextLaserFire = Time.time + fireRate;

                var clone1 = Instantiate(bulletObject, laserSpawn.transform.position, laserSpawn.transform.rotation) as GameObject;
                clone1.GetComponent <Rigidbody>().velocity = transform.TransformDirection(Vector3.forward * bulletSpeed);

                var clone2 = Instantiate(bulletObject, laserSpawn.transform.position, laserSpawn.transform.rotation) as GameObject;
                clone2.GetComponent <Rigidbody>().velocity = transform.TransformDirection(Vector3.forward * bulletSpeed);
                clone2.GetComponent <Rigidbody>().AddForce(20, 0, 0);

                var clone3 = Instantiate(bulletObject, laserSpawn.transform.position, laserSpawn.transform.rotation) as GameObject;
                clone3.GetComponent <Rigidbody>().velocity = transform.TransformDirection(Vector3.forward * bulletSpeed);
                clone3.GetComponent <Rigidbody>().AddForce(-20, 0, 0);

                AudioControl.PlayAudio("Laser");
            }
        }
        public float xVect = 0, yVect = 0, zVect = 0;                   //Manually change position

        void OnTriggerEnter(Collider other)
        {
            //Check for collision with player or player bullets
            if (other.gameObject.tag == "PlayerBullet" || other.gameObject.tag == "Player")
            {
                ScoreControl.RaiseScore(100);

                AudioControl.PlayAudio("Explosion");

                Instantiate(enemyExplosion, this.transform.position, this.transform.rotation);

                Destroy(this.gameObject);
            }

            //Check if enemy has passed the camera and destroy it
            if (other.gameObject.tag == "EnemyBound")
            {
                Destroy(this.gameObject);
            }
        }
Пример #9
0
        //Upgradable items
        void OnTriggerEnter(Collider otherObject)
        {
            if (otherObject.gameObject.tag == "Shield")
            {
                //Shield power up collision
                AudioControl.PlayAudio("PowerPickUp");

                //Emit shield particles on ship
                staticShield.emit = true;
                shieldsActive     = true;

                //Destroy shield powerup
                Destroy(shieldObject);
            }

            if (otherObject.gameObject.tag == "SpeedBoost")
            {
                AudioControl.PlayAudio("PowerPickUp");

                //Increase player speed
                speed += .15f;

                //Speed up stars
                SendMessage("SpeedUpStars");

                //Destory speedboost powerup
                Destroy(speedBoostObject);
            }

            if (otherObject.gameObject.tag == "MultiShot")
            {
                AudioControl.PlayAudio("PowerPickUp");

                //Multi bullets
                SendMessage("UpgradeLaser");

                //Destroy multishot powerup
                Destroy(multiShotObject);
            }
        }
        void OnTriggerEnter(Collider other)
        {
            //If hit by player or player bullet, decrease health by one
            if (other.gameObject.tag == "PlayerBullet" || other.gameObject.tag == "Player")
            {
                miniBossHealth--;

                AudioControl.PlayAudio("Shield");

                //If health reaches 0, destroy and count down 1 boss
                if (miniBossHealth <= 0)
                {
                    //Only count down 1 and then cut off
                    if (miniBossDead)
                    {
                        MasterControl.miniBossCount--;
                        miniBossDead = false;
                    }

                    StartCoroutine("DestroyObject");
                }
            }
        }
Пример #11
0
        IEnumerator GameModeSwitch()
        {
            switch (gameModes)
            {
            case GameModes.StartScreen:

                //If true, keypresses are active
                if (menuControlOn)
                {
                    //Move particles up
                    if (Input.GetKeyDown(KeyCode.W))
                    {
                        AudioControl.PlayAudio("MenuBeep");

                        menuChoice--;

                        if (menuChoice < 1)
                        {
                            menuChoice = 3;
                        }

                        //Menu particles control
                        MenuParticles();
                    }

                    //Move particles down
                    else if (Input.GetKeyDown(KeyCode.S))
                    {
                        AudioControl.PlayAudio("MenuBeep");

                        menuChoice++;

                        if (menuChoice > 3)
                        {
                            menuChoice = 1;
                        }

                        //Menu particles control
                        MenuParticles();
                    }
                }

                //Menu choice 1 = Start Game, choice 2 = Controls screen, choice 3 = Credits screen
                if (Input.GetKeyDown(KeyCode.Return))
                {
                    if (menuControlOn)
                    {
                        if (menuChoice == 1)
                        {
                            //Place player in start position
                            playerObject.transform.position = new Vector3(0, .55f, -.5f);

                            //Play sound before starting game
                            AudioControl.PlayAudio("PowerPickUp");

                            //Enter can only be pressed once
                            menuControlOn = false;

                            yield return(new WaitForSeconds(1f));

                            //Start game
                            gameModes = GameModes.GameScreen;

                            //Begin spawn
                            canSpawn = true;

                            AudioControl.PlayAudio("GamePlay");

                            //Turn off any menu GUI and turn on game play GUI
                            ScreenControlOff();
                            GameGUIOn();
                            playerController.ContinueControl();

                            //Spawn player ship
                            playerObject.GetComponent <Renderer>().enabled = true;
                            rocketObject.GetComponent <Renderer>().enabled = true;

                            //Activate shooting
                            LaserControl.cantShoot = false;
                        }

                        //Turn on Controls screen
                        else if (menuChoice == 2)
                        {
                            ScreenControlOff();
                            ControlsScreenOn();

                            //Key presses disabled
                            menuControlOn = false;
                        }

                        //Turn on Credits screen
                        else if (menuChoice == 3)
                        {
                            ScreenControlOff();
                            CreditsScreenOn();

                            //Key presses disabled
                            menuControlOn = false;
                        }
                    }
                    //If Enter is pressed, return to main menu
                    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                    else if (menuChoice == 4)
                    {
                        ScreenControlOn();
                        CreditsScreenOff();

                        //Enable menu particles and key presses
                        MenuParticles();
                        menuControlOn = true;
                    }

                    else if (menuChoice == 5)
                    {
                        ScreenControlOn();
                        ControlsScreenOff();

                        MenuParticles();
                        menuControlOn = true;
                    }
                    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                }
                break;

            //Game play enum
            case GameModes.GameScreen:

                //Pause game
                if (Input.GetKeyDown(KeyCode.P))
                {
                    PauseGame();
                }

                //Display player lives
                gameGUI[1].GetComponent <GUIText>().text = "X " + PlayerHealth.playerLives;

                //Begin spawning enemies
                if (!gameOver)
                {
                    StartCoroutine("GameWaveSwitch");
                }

                //Asteroid spawn
                if (gameWaves == 6 || gameWaves == 7 || gameWaves == 8)
                {
                    asteroidInterval += Time.deltaTime;

                    //Wait .5 seconds between each spawn and make them random across the screen
                    if (asteroidInterval >= .5f)
                    {
                        asteroidInterval = 0;

                        Instantiate(shipObjects[4], shipSpawnPoints[Random.Range(0, 11)].transform.position,
                                    transform.rotation);
                    }
                }

                //When wave 6 started, wait a moment then spawn mini boss
                if (gameWaves == 6 && miniBossCount <= 0)
                {
                    gameWaves     = 7;
                    shieldUpgrade = 1;

                    yield return(new WaitForSeconds(1f));

                    canSpawn = true;
                }

                //If power up ship dead, move to next wave
                if (gameWaves == 7)
                {
                    //Reset mini boss count to 6 for wave 8
                    miniBossCount = 6;

                    if (shieldUpgrade <= 0)
                    {
                        gameWaves = 8;

                        yield return(new WaitForSeconds(1f));

                        canSpawn = true;
                    }
                }

                //If all 6 mini bosses dead, move to next wave
                if (gameWaves == 8 && miniBossCount <= 0)
                {
                    gameWaves = 9;

                    yield return(new WaitForSeconds(2f));
                }

                //If Player lives down to 0, Game Over
                if (PlayerHealth.playerLives <= 0)
                {
                    GameOver();
                }

                //If Arcturus health down to 0, Game Won
                if (ArcturusShip.arcturusDead)
                {
                    GameWon();
                }

                break;

            case GameModes.EndScreen:

                //If game is over, press Enter to go to Main Menu
                if (Input.GetKeyDown(KeyCode.Return))
                {
                    ResetVars();
                }

                //Destroy everything if Game Over
                DestroyAllEnemies();

                break;
            }
        }
        //If hit by player bullet, decrease health
        void OnTriggerEnter(Collider other)
        {
            if (other.gameObject.tag == "PlayerBullet")
            {
                arcturusHealth--;

                AudioControl.PlayAudio("Shield");

                //If health has reached 0
                if (arcturusHealth <= 0)
                {
                    //Phase 1 ship collision
                    if (isMainShip)
                    {
                        //Ignore collision while blink and explosion happen
                        if (roundOne)
                        {
                            ScoreControl.RaiseScore(1000);

                            Physics.IgnoreLayerCollision(8, 11);
                            Physics.IgnoreLayerCollision(10, 11);
                        }

                        //If final phase and dead, begin blink and explode sequence
                        else
                        {
                            ScoreControl.RaiseScore(5000);

                            blinkControl   = true;
                            startExplosion = true;
                        }

                        Physics.IgnoreLayerCollision(8, 11);
                        Physics.IgnoreLayerCollision(10, 11);

                        explosionProcess = true;
                        shipDead         = true;

                        //Stop random movement
                        bossMovementControl.CancelActiveRequest();
                    }

                    //Phase 2 ships collision
                    else if (!isMainShip)
                    {
                        ScoreControl.RaiseScore(450);

                        AudioControl.PlayAudio("Explosion");

                        Instantiate(enemyExplosion, this.transform.position, this.transform.rotation);

                        //Create 3 new ships upon each larger ship destroyed
                        if (!isLastShip)
                        {
                            for (int i = 1; i <= 3; i++)
                            {
                                Instantiate(nextPhase, this.transform.position, this.transform.rotation);
                            }
                        }

                        //Count down of smaller ships to reach before starting final phase
                        if (isLastShip)
                        {
                            ScoreControl.RaiseScore(650);

                            //Only increase by 1 then cut off
                            if (lastPhaseDead)
                            {
                                lastShipCount++;

                                lastPhaseDead = false;
                            }
                        }

                        //Destroy each smaller ship
                        Destroy(this.gameObject);
                    }
                }
            }

            //When ship goes around of view and hits colliders, stop ship in its place for the time
            if (other.gameObject.tag == "BossStopper")
            {
                GetComponent <Rigidbody>().velocity = new Vector3(0, 0, 0);
            }
        }
        void OnTriggerEnter(Collider other)
        {
            if (!lifeTaken)
            {
                //Collision with all enemy objects
                if (other.gameObject.tag == "Enemy" || other.gameObject.tag == "EnemyBullet" ||
                    other.gameObject.tag == "Asteroid")
                {
                    //If player died, reset stars to default speed
                    SendMessage("ResetStars");

                    //If shields are active, count shield life
                    if (PlayerControl.shieldsActive)
                    {
                        PlayerControl.shieldHealth--;

                        AudioControl.PlayAudio("Shield");

                        if (other.gameObject.tag == "Asteroid")
                        {
                            PlayerControl.shieldHealth = 0;
                        }

                        //If shield life has reached 0, hide shield
                        if (PlayerControl.shieldHealth <= 0)
                        {
                            PlayerControl.staticShield.emit = false;
                            PlayerControl.shieldsActive     = false;
                        }
                    }
                    //If shields are not active, destroy player and decrease life count
                    else if (!PlayerControl.shieldsActive)
                    {
                        AudioControl.PlayAudio("Explosion");

                        //Create explosion particle
                        Instantiate(explosionParticle, this.transform.position, this.transform.rotation);

                        if (playerLives > 1)
                        {
                            //Decrease lives by 1
                            playerLives--;

                            //Reset variables on player after death
                            PlayerDead();

                            //Reactivate player ship and being flash effect
                            StartCoroutine("RespawnPlayer");

                            MasterControl.upgradeItem = 0;
                        }

                        else
                        {
                            playerLives--;

                            PlayerDead();
                        }

                        //Deactivate collision while dead
                        lifeTaken = true;
                    }
                }
            }
        }