Esempio n. 1
0
 private void AddScore()
 {
     score += 100;                       // Adds 100pts to score
     print("MAMMA MIA " + score + "pts.");
     SoundEffectBoard.PlayPointPickup(); // plays point audio
     Destroy(pickup);                    // destroys the game object on overlap
 }
Esempio n. 2
0
        /// <summary>
        /// Do Euler physics each tick
        /// </summary>
        void Update()
        {
            if (Time.deltaTime > 0.25f)
            {
                return;                             // quit early, do nothing, if lag spike
            }
            anim.SetBool("isGrounded", isGrounded); // communicates to animation controller whether or not the payer isGrounded
            anim.SetBool("isIdle", isIdle);         // communicates to animation controller whether or not the payer isIdle

            CalcHorizontalMovement();               // Runs HorizontalMovement method
            CalcVerticalMovement();                 // Runs VerticalMovement method

            // Applies velocity to position
            transform.position += velocity * Time.deltaTime;

            aabb.RecalcAABB();
            isGrounded = false;                                  // sets isGrounded to false every frame

            if (playerLocation.position.x < cam.position.x - 14) // If the player is off the left edge of the screen they die
            {
                // Had trouble calling this function from HealthSystem so recreated it here
                Destroy(gameObject);                                     // Kills the player if they end up off the left edge of the screen
                SoundEffectBoard.PlayDie();                              // plays death audio
            }
            else if (playerLocation.position.x > cam.position.x + 12.5f) // If the player is touching the right edge of the screen restrict their movement
            {
                velocity.x = 0;                                          // Player can no longer move right if touching the right edge of the screen
            }
        }
 public void PowerUp()
 {
     print("Now we're movin!");
     camScroll.isPickedUp = true;        // tells CameraAutoScroll.cs that the bike is picked up
     cooldownBikePickup   = 1;           // sets cooldown
     SoundEffectBoard.PlayPointPickup(); // plays bike audio
     Destroy(pickup);                    // destroys the game object on overlap
 }
Esempio n. 4
0
 public override void OnOverlap(PlayerMovement pm)
 {
     pm.LaunchPlayer(new Vector3(0, 20, 0)); // Launch player upward on overlap
     if (cooldownSpringBlock > 0)
     {
         return;                         // still on cooldown, dont play audio
     }
     cooldownSpringBlock = .25f;         // cooldown till audio can play again
     SoundEffectBoard.PlaySpringBlock(); // plays springblock audio
 }
Esempio n. 5
0
 void Start()
 {
     if (main == null)
     {
         main   = this;
         player = GetComponent <AudioSource>(); // Gets a reference to the AudioSource
     }
     else
     {
         Destroy(this.gameObject); // if main doesn't = null, destory the gameObject
     }
 }
Esempio n. 6
0
 void Start()
 {
     if (main == null)
     {
         main   = this;
         player = GetComponent <AudioSource>(); // Gets a reference to the AudioSource
     }
     else
     {
         Destroy(this.gameObject);
     }
     //PlayMusic(); // Originally used to play the background music before it was given its' own AudioSource in the Inspector
 }
Esempio n. 7
0
        /// <summary>
        /// Calculates Euler physics on y axis
        /// </summary>
        private void CalcVerticalMovement()
        {
            float gravMultiplier = 1;                             // Sets the gravity Multiplier to 1

            bool wantsToJump       = Input.GetButtonDown("Jump"); // If pressing spacebar, wantsToJump = true
            bool isHoldingJump     = Input.GetButton("Jump");     // If pressing spacebar, isHoldingJump = true
            bool wantsToDoubleJump = Input.GetButton("Jump");     // If pressing spacebar, wantsToDoubleJump = true

            if (wantsToJump && isGrounded)                        // Jump
            {
                print("jump");
                velocity.y       = 0;           // sets velocity on y-axis to 0
                velocity.y       = jumpImpulse; // sets velocity on y-axis to the jumpImpulse value
                isJumpingUpwards = true;        // sets isJumpingUpwards to true
                isGrounded       = false;       // sets isGrounded to false
                canDoubleJump    = true;        // sets canDoubleJump to true

                //SoundEffectBoard.PlayJump(transform.position); // plays jump audio on jump at the player position (still considered a 3D sound so DOES NOT WORK)
                SoundEffectBoard.PlayJump2(); // plays jump audio on jump
            }
            if (!isHoldingJump || velocity.y < 0)
            {
                isJumpingUpwards = false;                                // If not holding jump, jumpingUpwards = false
            }
            if (wantsToDoubleJump && canDoubleJump && !isJumpingUpwards) // Double Jump
            {
                print("Ju-Jump");
                canDoubleJump = false;             // sets canDoubleJump to false
                velocity.y    = 0;                 // sets velocity on y-axis to 0
                velocity.y    = jumpImpulse;       // sets velocity on y-axis to jumpImpulse value
                SoundEffectBoard.PlayDoubleJump(); // plays double jump audio
            }
            if (isJumpingUpwards == true)
            {
                gravMultiplier = 0.5f;                           // if you are jumping half the gravity multiplier to allow more air time
            }
            // Apply force of gravity to velocity
            velocity.y -= gravity * Time.deltaTime * gravMultiplier;

            // clamp vertical speed to create terminal velocity
            if (velocity.y < -terminalVelocity)
            {
                velocity.y = -terminalVelocity;
            }
        }
Esempio n. 8
0
 // Health behavior:
 public void TakeDamage(float amt)
 {
     if (cooldownInvulnerability > 0)
     {
         return;                     // still have i-frames, dont take damage
     }
     cooldownInvulnerability = .25f; // cooldown till you can take damage
     if (amt < 0)
     {
         amt = 0;          // Negative numbers ignored
     }
     health -= amt;
     if (health > 0)
     {
         SoundEffectBoard.PlayDamage();             // plays damage audio
     }
     if (health <= 0)
     {
         Die();                      // if health drops to/below zero do Die method
         SoundEffectBoard.PlayDie(); // plays death audio
     }
 }