Exemplo n.º 1
0
    void Update()
    {
        if (PlayerState.HealthPoints > 0.0f)
        {
            if (hasShoot)
            {
                myShootDelay -= Time.deltaTime;
            }

            if (myShootDelay <= 0)
            {
                hasShoot     = false;
                myShootDelay = shootDelay;
            }

            if (Input.GetAxis("Fire1") > 0.0f && hasShoot == false)
            {
                hasShoot = true;
                FXAudio.PlayClip("Shoot");
                CreateNewBullet();
                PlayerState.IsShooting = true;
            }

            if (Input.GetAxis("Fire1") == 0.0f)
            {
                PlayerState.IsShooting = false;
            }
        }
    }
    void OnTriggerStay2D(Collider2D col)
    {
        if (col.gameObject.tag == "Player")
        {
            if (Input.GetAxis("Fire2") != 0.0f && axisInUse == false)
            {
                axisInUse = true;

                if (currentState == DoorState.LOCKED)
                {
                    bool tryToUnlock = TryToUnlock();
                    if (tryToUnlock)
                    {
                        SetState(DoorState.UNLOCKED);

                        FXAudio.PlayClip("DoorUnlocked");
                    }
                    else
                    {
                        FXAudio.PlayClip("DoorLocked");
                    }
                }
                else if (currentState == DoorState.OPEN)
                {
                    GameState.SetState(GameState.ResultType.WIN);
                    SceneManager.LoadScene("Result", LoadSceneMode.Single);
                }
            }
        }
    }
Exemplo n.º 3
0
    void OnCollisionEnter2D(Collision2D col)
    {
        if (healthPoints > 0)
        {
            if (col.gameObject.tag == "ground" && col.contacts [0].collider.sharedMaterial == null)
            {
                SetMovementLimits(col.contacts [0]);
            }
            else if (col.gameObject.tag == "Player")
            {
                if (Mathf.Approximately(col.contacts [0].normal.x, 1.0f) || Mathf.Approximately(col.contacts [0].normal.x, -1.0f))
                {
                    Attack(col.gameObject, col.contacts [0].normal);
                }
            }
            else if (col.gameObject.layer == LayerMask.NameToLayer("ThrownObject"))
            {
                if (Mathf.Abs(col.rigidbody.velocity.x) > 10.0f)
                {
                    ReceiveDamage(1.0f);
                }
            }
            else
            {
                Flip();
            }
        }

        FXAudio.PlayClip("Hit");
    }
Exemplo n.º 4
0
 private void FxVolumeSliderValueChanged(float value)
 {
     if (fxVolumeSlider != null)
     {
         FXAudio.SetVolume(value / fxVolumeSlider.maxValue);
         FXAudio.PlayClip("Hit");
     }
 }
 void OnTriggerEnter2D(Collider2D col)
 {
     if (col.gameObject.tag == "Player" && PlayerState.HealthPoints > 0.0f)
     {
         PlayerState.Score += value;
         FXAudio.PlayClip("PickupCoin");
         Destroy(gameObject);
     }
 }
Exemplo n.º 6
0
    private void ProcessJump()
    {
        float jumpAxis = Input.GetAxis("Jump");

        if (jumpAxis != 0.0f && isOnGround == true && jumpAxisInUse == false)
        {
            jumpAxisInUse = true;
            FXAudio.PlayClip("Jump");
            myRigidbody.AddForce(Vector3.up * jumpForce);
        }

        jumpAxisInUse = jumpAxis > 0.0f;
    }
Exemplo n.º 7
0
    public void ReceiveImpact(Vector2 force)
    {
        if (force.y == 0.0f)
        {
            force.y = impactVerticalForce;
        }

        onStun             = true;
        myStunRecoveryTime = stunRecoveryTime;
        myRigidbody.AddForce(force);
        PlayHitParticleSystem();
        FXAudio.PlayClip("Hit");
    }
Exemplo n.º 8
0
    public void ReceiveDamage(float damage)
    {
        PlayHitParticleSystem();

        if (!onStun)
        {
            PlayerState.HealthPoints -= damage;
            if (PlayerState.HealthPoints <= 0)
            {
                PlayerState.IsDead = true;
                FXAudio.PlayClip("Explosion");
            }
        }
    }
Exemplo n.º 9
0
    public void OnCollisionEnter2D(Collision2D col)
    {
        myRigidBody.velocity = Vector2.zero;
        hasCollisioned       = true;

        myAnimator.SetTrigger("Impact");

        FXAudio.PlayClip("Explosion");

        if (col.gameObject.tag == "Enemy")
        {
            ZombieController zc = col.gameObject.GetComponent <ZombieController> ();
            zc.ReceiveDamage(1.0f);
        }
    }
Exemplo n.º 10
0
    public IEnumerator ReloadGun(float delay)
    {
        reloadingGun = true;

        FXAudio.PlayClip("reload");

        remainingAmmoPacks--;

        int amountToReload = totalAmmoPerPack - currentAmmo;

        yield return(new WaitForSecondsRealtime(delay));

        currentAmmo += amountToReload;

        reloadingGun = false;
    }
Exemplo n.º 11
0
    private void HandleMove()
    {
        float jumpAxis;
        float horizontalAxis;

        horizontalAxis = Input.GetAxis("Horizontal");
        jumpAxis       = Input.GetAxis("Jump");

        if (jumpAxisInUse)
        {
            myJumpDelay -= Time.deltaTime;
        }

        if (myJumpDelay <= 0.0f)
        {
            jumpAxisInUse = false;
            myJumpDelay   = jumpDelay;
        }

        float velocityY = 0.0f;
        float velocityX = 0.0f;

        if (jumpAxis > 0 && PlayerState.IsOnGround && jumpAxisInUse == false)
        {
            jumpAxisInUse = true;
            velocityY     = jumpForce;
            FXAudio.PlayClip("Jump");
        }
        else
        {
            velocityY = myRigidbody.velocity.y;
        }

        if (horizontalAxis != 0.0f)
        {
            velocityX = horizontalAxis * horizontalSpeed;
        }
        else
        {
            velocityX = myRigidbody.velocity.x;
        }

        myRigidbody.velocity = new Vector2(velocityX, velocityY);

        PlayerState.HorizontalDirection = horizontalAxis;
    }
Exemplo n.º 12
0
    private void Shoot(float deltaTime)
    {
        if (myShootTimer <= 0.0 || myShootTimer == shootRate)
        {
            GameplayState.TotalShoots++;

            RaycastHit hitInfo;
            bool       hasHit = Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hitInfo, shootMaxDistance, shootBitMask);

            Vector3 targetPosition;

            if (hasHit)
            {
                targetPosition = hitInfo.point;

                if (hitInfo.collider.gameObject.tag == "Enemy")
                {
                    GameplayState.SuccessShoots++;

                    HealthState enemyHealthState = hitInfo.collider.gameObject.GetComponent <HealthState> ();

                    enemyHealthState.ReceiveDamage(shootDamage);
                }

                ParticleSystem currentPS = ParticleSystemManager.GetParticleInstance("PSShootImpact", GameplayState.TotalShoots);
                currentPS.transform.position = hitInfo.point;
                currentPS.Stop();
                currentPS.Play();
            }
            else
            {
                targetPosition = Camera.main.transform.forward * shootMaxDistance;
            }

            FXAudio.PlayClip("fire");
            StartCoroutine(DrawShootLine(targetPosition, shootRate * 0.5f));

            currentAmmo--;
            myShootTimer = shootRate;
        }

        myShootTimer -= deltaTime;
    }
Exemplo n.º 13
0
    void OnCollisionEnter2D(Collision2D col)
    {
        if (PlayerState.HealthPoints > 0.0f)
        {
            if (col.gameObject.tag == "Enemy" && col.contacts [0].normal.y > 0)
            {
                col.gameObject.GetComponent <ZombieController> ().ReceiveDamage(smashEnemyHeadDamage);
                myRigidbody.AddForce(Vector2.up * smashEnemyHeadBounceForce);
                myAnimator.SetTrigger("triggerBounce");

                FXAudio.PlayClip("PickupCoin");
            }
            else if (col.gameObject.tag == "ground" || col.gameObject.layer == groundLayer)
            {
                if (Mathf.Abs(col.relativeVelocity.y) >= resistenceOnFalling)
                {
                    ReceiveDamage(PlayerState.HealthPoints);
                }
            }
        }
    }
Exemplo n.º 14
0
    void OnTriggerStay2D(Collider2D col)
    {
        if (col.gameObject.tag == "Player")
        {
            if (Input.GetAxisRaw("Fire2") != 0.0f && axisInUse == false)
            {
                axisInUse = true;
                SetState(!currentState);

                if (currentState)
                {
                    FXAudio.PlayClip("SwitchGreen");
                    PlayerState.ActivatedDoorSwitches++;
                }
                else
                {
                    FXAudio.PlayClip("SwitchRed");
                    PlayerState.ActivatedDoorSwitches--;
                }
            }
        }
    }
Exemplo n.º 15
0
 public override void OnDead()
 {
     FXAudio.PlayClip("Scream_Male_01");
 }