Example #1
0
                public override State Update()
                {
                    // Behavior:
                    player.MoveThePlayer(1); // makes the player move from sending the paramter 1

                    // transitions to other states:
                    if (player.playerHealth.health <= 0)
                    {
                        return(new States.Idle());                                 // if player is dead, goes to Idle() state
                    }
                    if (Input.GetButton("Fire3"))
                    {
                        return(new States.Sprinting());                              // if the player press sprint, goes to Sprinting() state
                    }
                    if (Input.GetKeyDown("space") && player.dashTimeToUseAgain <= 0) // Transition to Dashing when player presses space bar
                    {
                        SoundEffectBoard.DashSound();                                // plays dash sound effect
                        player.dashTrail.Play();
                        return(new States.Dashing());                                // goes to Dashing() state
                    }

                    if (!Input.GetKey("w") && !Input.GetKey("a") && !Input.GetKey("s") && !Input.GetKey("d")) // if the player is not pressing anything
                    {
                        return(new States.Idle());                                                            // goes to Idle() state
                    }
                    return(null);
                }
                public override State Update()
                {
                    // Behaviour:
                    enemy.MoveTowardTarget(); // moves toward target/player


                    // Transition:
                    // if the minion health is at or below 0 or the boss's health is at 0 or below
                    if (enemy.bossHealth.health <= 0 || enemy.enemyBasicHealth.health <= 0)
                    {
                        enemy.DeathPhase();         // starts death phase
                        return(new States.Death()); // goes to Death state
                    }

                    enemy.dashTimer -= Time.deltaTime; // counts down to be able to dash
                    // checks to see if the player is in range for a dash attack and if the timer is at 0
                    if (enemy.CanSeeThing(enemy.attackTarget, enemy.targetDistanceToDash) && enemy.dashTimer <= 0)
                    {
                        enemy.dashTimer = 5;             // resets dash timer
                        SoundEffectBoard.DashSound();    // plays dash sound
                        enemy.dashTrail.Play();
                        return(new States.DashAttack()); // goes to dash attack state
                    }

                    return(null);
                }
Example #3
0
 /// <summary>
 /// When the player has lost all health and dies
 /// </summary>
 public void Die()
 {
     SoundEffectBoard.PlayDeathSound();
     Instantiate(blowUp, transform.position, transform.rotation); // spawning the blewUp particle effect
     gameOverText.gameObject.SetActive(true);                     // showing the Game Over text
     Destroy(gameObject);                                         // destroy player
 }
                public override State Update()
                {
                    // behaviour:
                    bossAttack.MinionSpawning();             // run MinionSpawning method to spawn the minions
                    SoundEffectBoard.EnemySpawnAlarmSound(); // plays sound

                    // transition:
                    return(new States.Idle()); // goes to Idle() method
                }
 /// <summary>
 /// Makes the death action and effects happen.
 /// </summary>
 void DeathEffect()
 {
     SoundEffectBoard.BossDeathSound();                     // plays the boss death sound when the boss dies
     nav.enabled = false;                                   // turns nav off to stop moving
     if (cameraSwitching)                                   // if cameraSwitching is assigned
     {
         cameraSwitching.target           = this.transform; // moves camera to the boss position
         cameraSwitching.smoothTransition = .3f;            // sets the transition speed
     }
     // starts the particle explosion
     ParticleSystem sparks = Instantiate(deathParticleSystem, transform.position, Quaternion.identity);
 }
Example #6
0
        /// <summary>
        /// Runs when the player overlaps with a power up object
        /// </summary>
        /// <param name="pm"></param>
        public override void OnOverlap(PlayerMovement pm)
        {
            PlayerMovement doubleJump = pm.GetComponent <PlayerMovement>();

            // If the local variable has the PlayerMovement
            if (doubleJump)
            {
                doubleJump.powerUpSpeed += 2; // adds two speed to player
                SoundEffectBoard.PowerUpSound();
                Destroy(gameObject);          // destroy power up game object
            }
        }
Example #7
0
        /// <summary>
        /// When the object has been damaged
        /// </summary>
        /// <param name="damage"></param>
        public void DamageTaken(float damage)
        {
            health -= damage; // takes health away from damage

            CurrentHealth();  // sets the health for the health bar

            if (health <= 0)
            {
                Destroy(this.gameObject, 3);       // destroys the game object in 3 seconds
                SoundEffectBoard.PlayDeathSound(); // plays the deathSound
            }
        }
Example #8
0
        /// <summary>
        /// Calculating Euler physics on Y axis
        /// </summary>
        private void CalcVerticalMovement()
        {
            float gravMultiplier = 1; // gravity multiplier


            bool wantsToJump = Input.GetButtonDown("Jump"); // When the player press the space bar

            bool isHoldingJump = Input.GetButton("Jump");   // When the player holds the space bar

            // if the player is off the ground, jumped already and presses the space bar (This is Double Jump)
            if (!isGrounded && committedJump && wantsToJump)
            {
                velocity.y    = jumpImpulse;  // adds impulse to the y axis of the player
                committedJump = false;
                SoundEffectBoard.PlayJump2(); // plays sound effect for jump
            }

            // if the player presses the space bar and is on the ground (This is Jump)
            if (wantsToJump && isGrounded)
            {
                velocity.y       = jumpImpulse;
                isJumpingUpwards = true;
                isGrounded       = false;
                //soundPlayer.Play();
                committedJump = true;

                SoundEffectBoard.PlayJump2();
            }

            // if the player is not holding space bar and their y velocity is less than 0
            if (!isHoldingJump || velocity.y < 0)
            {
                isJumpingUpwards = false;
            }

            // if the player is holding space bar the gravity multiplier lessens
            if (isJumpingUpwards)
            {
                gravMultiplier = 0.5f;
            }

            checkYVelocity = velocity.y;

            // apply force of gravtiy to our velocity:
            velocity.y -= gravity * Time.deltaTime * gravMultiplier;


            // Clamp vertical speed to create terminal velocity
            if (velocity.y < -terminalVelocity)
            {
                velocity.y = -terminalVelocity;
            }
        }
 // Start is called before the first frame update
 void Start()
 {
     if (main == null)
     {
         main   = this;
         player = GetComponent <AudioSource>();
     }
     else
     {
         Destroy(this.gameObject);
     }
 }
        /// <summary>
        /// Spawns rocket
        /// </summary>
        void SpawnRocket()
        {
            if (rocketTimer > 0)
            {
                return;                            // if the rocket timer is not below 0, doesn't run
            }
            rocketTimer = maxTimeForRocket;        // sets timer for it to count down
            SoundEffectBoard.RocketMissileSound(); // plays the rocket soundeffect

            // Spawns the rocket
            RocketMechanic rocket = Instantiate(rocketPrefab, muzzle.transform.position, transform.rotation);
        }
Example #11
0
        /// <summary>
        /// Cause the missiles to fire
        /// </summary>
        void Missles()
        {
            if (missile1)                     // if missile1 is true
            {
                missile1.timeToLaunch = true; // fires the missile
            }
            if (missile2)                     // if missile 2 is true
            {
                missile2.timeToLaunch = true; // fires the missile
            }

            SoundEffectBoard.RocketMissileSound(); // missile sound
        }
Example #12
0
        /// <summary>
        /// When the player overlaps with the coins in the game:
        /// </summary>
        /// <param name="pm"></param>
        public override void OnOverlap(PlayerMovement pm)
        {
            ScoreSystem coinScore = pm.GetComponent <ScoreSystem>();

            // If the coinScore is stored
            if (coinScore)
            {
                coinScore.coinsCollected += 5; // add 5 points to the coinsCollected
                SoundEffectBoard.PlayCoinPickup();

                Destroy(gameObject); // Destroy the coin game object
            }
        }
Example #13
0
        /// <summary>
        /// When the player takes damage from a object
        /// </summary>
        /// <param name="amt"></param>
        public void TakeDamage(float amt)
        {
            if (!readyToRespawn)
            {
                if (coolDownInvulnerability > 0)
                {
                    return;                      // cooldown not finished...
                }
                coolDownInvulnerability = 0.25f; // cooldown until we can take damage again
                repawnTime = repawnTimeSet;

                if (amt < 0)
                {
                    amt = 0;   // negative numbers are ignored
                }
                health -= amt; // health = health - amt;

                SoundEffectBoard.PlayerDamaged();

                if (health <= 0)
                {
                    lives--;
                    readyToRespawn = true;

                    foreach (MeshRenderer meshPiece in playerRespawnEffect)
                    {
                        meshPiece.enabled = false;
                    }
                    exhaustPipe.Stop();
                    stopMovementWhenRespawning.enabled = false;

                    if (lives > 0)
                    {
                        health = healthMax;
                    }
                }
                healthBar.value    = health;
                livesNotifier.text = "Lives: " + lives; // Tells player the lives they have left.

                if (lives <= 0)
                {
                    Die(); // when the player has no more health
                }
            }
        }
Example #14
0
        /// <summary>
        /// Spawns new missiles to be fired when ready
        /// </summary>
        private void MissleSpawning()
        {
            if (missleRespawnTime > 0 && !misslesSpawned)   // if timer is greater than 0 and missilesSpawned is false
            {
                missleRespawnTime -= Time.deltaTime;
            }

            if (missleRespawnTime <= 0)                                                            // if timer is less than or equal to 0
            {
                missile1 = Instantiate(prefabMissile, missilePos1.position, missilePos1.rotation); // spawns missile 1
                missile1.transform.parent = missilePos1;                                           // make missilePos1 a parent of the missile prefab
                missile2 = Instantiate(prefabMissile, missilePos2.position, missilePos2.rotation); // spawns missile 2
                missile2.transform.parent = missilePos2;                                           // make missilePos2 a parent of the missile prefab
                missleRespawnTime         = 10;                                                    // time to respawn again
                misslesSpawned            = true;                                                  // missiles spawned
                SoundEffectBoard.RocketMissileSound();                                             // plays the rocket/missile sound
            }
        }
Example #15
0
        /// <summary>
        /// Fires the machine gun to shoot at target
        /// </summary>
        void MachineGun()
        {
            if (bulletAmountTime > 0)
            {
                return;                                                                                                              // rate of fire manager
            }
            EnemyProjectiles leftBullets = Instantiate(prefabMachineGunBullets, leftMuzzle.position, leftMuzzle.transform.rotation); // spawns bullet

            leftBullets.InitBullet(transform.forward * 30);                                                                          // sets velocity of the projectile

            EnemyProjectiles RightBullets = Instantiate(prefabMachineGunBullets, rightMuzzle.position, rightMuzzle.transform.rotation);

            RightBullets.InitBullet(transform.forward * 30);

            SoundEffectBoard.BossShooting();    // plays the boss shooting sound

            bulletAmountInClip--;               // removes a bullet
            bulletAmountTime = 1 / roundPerSec; // cause the rate of fire to happen
        }
        /// <summary>
        /// Spawns projectiles/bullets
        /// </summary>
        void SpawnProjectile()
        {
            if (timerSpawnBullet > 0)
            {
                return;                       // we need to wait longer...
            }
            if (roundsInClip <= 0)
            {
                return;                        // no ammo
            }
            SoundEffectBoard.PlayerShooting(); // players gunfire soundeffect

            // Spawns the bullets
            Projectile p = Instantiate(prefabProjectile, muzzle.transform.position, muzzle.transform.rotation);

            p.InitBullet(transform.forward * 30);   // sets the velocity of the projectile

            roundsInClip--;                         // removes a bullet from roundInClip
            timerSpawnBullet = 1 / roundsPerSecond; // rate of fire
        }
Example #17
0
        /// <summary>
        /// When the player takes damage from a object
        /// </summary>
        /// <param name="amt"></param>
        public void TakeDamage(float amt)
        {
            if (coolDownInvulnerability > 0)
            {
                return;                      // cooldown not finished...
            }
            coolDownInvulnerability = 0.25f; // cooldown until we can take damage again

            if (amt < 0)
            {
                amt = 0;                               // negative numbers are ignored
            }
            health -= amt;                             // health = health - amt;

            healthNotifier.text = "Health: " + health; // updates health when player takes damage
            SoundEffectBoard.PlayerDamaged();

            if (health <= 0)
            {
                Die();              // when the player has no more health
            }
        }
Example #18
0
 /// <summary>
 /// Adds force to the player when they overlap it
 /// </summary>
 /// <param name="pm"></param>
 public override void OnOverlap(PlayerMovement pm)
 {
     SoundEffectBoard.BoastSound();
     pm.LaunchPlayer(new Vector3(50, 25, 0)); // This adds force to the player and launches them up and forward
 }