// Update is called once per frame
    public virtual void Update()
    {
        if (health <= 0)
        {
            isDead = true;
        }

        healthHud.SetHealth(health);

        //if (GamePad.GetButtonDown(GamePad.Button.Back, gamePadIndex))
        //{
        //    Camera.main.GetComponent<AdvancedCamera>().Zoom(new Vector2(gameObject.transform.position.x, gameObject.transform.position.y));
        //}

        if (gameObject.transform.parent.gameObject.GetComponent <Player>().kills >= 5)
        {
            Global.WorldObject.GameWon(controllerNumber, chosenCharacter);
            //Global.WorldObject.winnerIndex = chosenPlayerIndex;
        }

        if (!IsDead && !isDrinking && !advancedCamera.asleep)
        {
            #region ATTACKING CODE


            if ((GamePad.GetButtonDown(GamePad.Button.X, gamePadIndex) ||
                 (useMpu && mpuController.GetDigitalPressed(9))) &&
                onGround && !isDrinking)
            {
                if (playerScript.usePunchbag)
                {
                    playerScript.punchBag.GetComponent <Punchbag>().Hit(gameObject.transform.position);
                    if (punchCheck.collider2D.bounds.Intersects(playerScript.punchBag.collider2D.bounds))
                    {
                        playerScript.punchBag.GetComponent <Punchbag>().Hit(gameObject.transform.position);
                        print("check");
                    }
                }

                foreach (GameObject d in Global.drinks.ToArray())
                {
                    Drink drinkScript = d.GetComponent <Drink>();

                    if (bodyCheck.collider2D.bounds.Intersects(drinkScript.drinkCollision.collider2D.bounds))
                    {
                        sortOfDrink = drinkScript.drinkType;
                        GetDrunk(sortOfDrink);
                        drinkScript.Remove();

                        isDrinking = true;
                        playerObject.rigidbody2D.velocity = Vector2.zero;
                        SetAnimation("isDrinking_1", true);
                        SetAnimation("isDrinking_2", true);
                        SetAnimation("typeOfDrink", drinkScript.drinkNumber);
                        //Invoke("NotDrinking", .4f);
                    }
                }
            }


            if ((GamePad.GetButtonDown(GamePad.Button.X, gamePadIndex) ||
                 (useMpu && mpuController.GetDigitalPressed(9))) && onGround &&
                attackOnce == -1 && !isDrinking && attackCooldown == 0)
            {
                //playerState = PlayerStates.ATTACKING;
                isAttacking = true;
                SetAnimation("isAttacking", true);
                attackOnce     = 1;
                attackCooldown = attackCooldownMax;

                bool didHit = false;

                foreach (GameObject lep in Global.leprechauns.ToArray())
                {
                    Player p = lep.gameObject.transform.parent.GetComponent <Player>();
                    if (punchCheck.collider2D.bounds.Intersects(p.GetCollisionObject("bodyCheck", lep).collider2D.bounds) && lep != gameObject)
                    {
                        if (p.GetLeprechaunScriptType().GetType() == typeof(Leprechaun))
                        {
                            Leprechaun lepScript = (Leprechaun)p.leprechaunScript;
                            lepScript.GotHit(gameObject.transform.position, damageMultiplayer, gamePadIndex, punchShakeHardness);
                            didHit          = true;
                            lepScript.isHit = true;
                            lepScript.SetAnimation("isHit", true);
                            lepScript.Invoke("NotHit", .2f);
                        }
                        else if (p.GetLeprechaunScriptType().GetType() == typeof(Leprechaun_USA))
                        {
                            Leprechaun_USA lepScript = (Leprechaun_USA)p.leprechaunScript;
                            lepScript.GotHit(gameObject.transform.position, damageMultiplayer, gamePadIndex, punchShakeHardness);
                            didHit          = true;
                            lepScript.isHit = true;
                            lepScript.SetAnimation("isHit", true);
                            lepScript.Invoke("NotHit", .2f);
                        }
                        else if (p.GetLeprechaunScriptType().GetType() == typeof(Cluirichaun))
                        {
                            Cluirichaun lepScript = (Cluirichaun)p.leprechaunScript;
                            lepScript.GotHit(gameObject.transform.position, damageMultiplayer, gamePadIndex, punchShakeHardness);
                            didHit          = true;
                            lepScript.isHit = true;
                            lepScript.SetAnimation("isHit", true);
                            lepScript.Invoke("NotHit", .2f);
                        }
                        else if (p.GetLeprechaunScriptType().GetType() == typeof(FarDarrig))
                        {
                            FarDarrig lepScript = (FarDarrig)p.leprechaunScript;
                            lepScript.GotHit(gameObject.transform.position, damageMultiplayer, gamePadIndex, punchShakeHardness);
                            didHit          = true;
                            lepScript.isHit = true;
                            lepScript.SetAnimation("isHit", true);
                            lepScript.Invoke("NotHit", .2f);
                        }
                        else if (p.GetLeprechaunScriptType().GetType() == typeof(Fairy))
                        {
                            Fairy lepScript = (Fairy)p.leprechaunScript;
                            lepScript.GotHit(gameObject.transform.position, damageMultiplayer, gamePadIndex, punchShakeHardness);
                            didHit          = true;
                            lepScript.isHit = true;
                            lepScript.SetAnimation("isHit", true);
                            lepScript.Invoke("NotHit", .2f);
                        }
                    }
                }

                if (!didHit)
                {
                    int i = UnityEngine.Random.Range(1, 6);
                    gameObject.Stab(Resources.Load("Audio/SFX/Punch_Miss_" + i.ToString()) as AudioClip, 1f, 1f, 0f);
                }
                else
                {
                    int i = UnityEngine.Random.Range(1, 6);
                    gameObject.Stab(Resources.Load("Audio/SFX/Punch_Hit_" + i.ToString()) as AudioClip, 1f, 1f, 0f);
                }
            }

            if (attackOnce >= 1)
            {
                attackOnce -= 1;
            }
            else if (attackOnce == 0)
            {
                attackOnce = -1;
                attackDone = false;

                isAttacking = false;
                SetAnimation("isAttacking", false);
            }

            if (attackCooldown > 0)
            {
                attackCooldown--;
            }
            else if (attackCooldown < 0)
            {
                attackCooldown = 0;
            }

            #endregion

            #region BLOCKING CODE

            //if (GamePad.GetButtonDown(GamePad.Button.B, gamePadIndex) && !isDashing && !isAttacking && !isDrinking)
            //{
            //    isBlocking = true;
            //    SetAnimation("isBlocking", true);
            //}

            //if (GamePad.GetButtonUp(GamePad.Button.B, gamePadIndex))
            //{
            //    isBlocking = false;
            //    SetAnimation("isBlocking", false);
            //}

            #endregion

            #region DASHING CODE
            //if ((GamePad.GetTrigger(GamePad.Trigger.LeftTrigger, gamePadIndex) > 0.1 || GamePad.GetTrigger(GamePad.Trigger.LeftTrigger, gamePadIndex) > 0.1)
            //    && !isDashing && !isDashCooldown)
            //{
            //    isDashing = true;
            //    dashTimer = 0;
            //    //animation.GetAnimation.Start();
            //}

            //if (isDashing)
            //{
            //    if (dashTimer > 10)
            //    {
            //        dashCooldown = 120;
            //        isDashCooldown = true;
            //        isDashing = false;
            //    }

            //    //playerState = PlayerStates.DASHING;
            //    dashTimer++;
            //    Dash();
            //}

            //if (isDashCooldown)
            //{
            //    if (dashCooldown > 0)
            //        dashCooldown--;
            //    else
            //        isDashCooldown = false;
            //}
            #endregion

            #region JUMPING CODE

            if (onGround && useMpu && !isAttacking && !isHit)
            {
                if (mpuController.GetSensor(MPUController.Axis.Y, MPUController.Side.NEGATIVE))
                {
                    SetAnimation("grounded", false);
                    playerObject.rigidbody2D.AddForce(new Vector2(0, maxVelocity.y) / 5);
                }
            }
            else if (onGround && (GamePad.GetButtonDown(GamePad.Button.A, gamePadIndex) || GamePad.GetKeyboardKeyDown(KeyCode.Space)) && !isAttacking && !isHit)
            {
                SetAnimation("grounded", false);
                playerObject.rigidbody2D.AddForce(new Vector2(0, maxVelocity.y));
            }

            if (!onGround && chosenCharacter == Player.Character.FAIRY && canDoubleJump && useMpu && !isAttacking && !isHit)
            {
                if (mpuController.GetSensor(MPUController.Axis.Y, MPUController.Side.NEGATIVE))
                {
                    Vector3 vel = playerObject.rigidbody2D.velocity;
                    vel.y = 0;
                    playerObject.rigidbody2D.velocity = vel;
                    playerObject.rigidbody2D.AddForce(new Vector2(0, maxVelocity.y / 1.2f));
                    canDoubleJump = false;
                }
            }
            else if (!onGround && chosenCharacter == Player.Character.FAIRY && canDoubleJump &&
                     (GamePad.GetButtonDown(GamePad.Button.A, gamePadIndex) || GamePad.GetKeyboardKeyDown(KeyCode.Space)) &&
                     !isAttacking && !isHit)
            {
                Vector3 vel = playerObject.rigidbody2D.velocity;
                vel.y = 0;
                playerObject.rigidbody2D.velocity = vel;
                playerObject.rigidbody2D.AddForce(new Vector2(0, maxVelocity.y / 1.2f));
                canDoubleJump = false;
            }

            #endregion
        }
        else if (isDrinking)
        {
            if (bottom_animator.GetCurrentAnimatorStateInfo(0).IsName("Drink") &&
                bottom_animator.GetCurrentAnimatorStateInfo(0).normalizedTime > 1 &&
                !bottom_animator.IsInTransition(0))
            {
                NotDrinking(1, false);
            }

            if (bottom_animator.GetCurrentAnimatorStateInfo(0).IsName("Drink") &&
                bottom_animator.GetCurrentAnimatorStateInfo(0).normalizedTime > 1 &&
                !bottom_animator.IsInTransition(0))
            {
                NotDrinking(2, true);
            }
        }


        //ManageDrunkness();

        if (IsDead && deathCounter == 0)
        {
            SetAnimation("isDead", true);
            SetAnimation("grounded", true);
            SetAnimation("isHit", false);
            SetAnimation("isAttacking", false);
            SetAnimation("isBlocking", false);
            SetAnimation("isDrinking_1", false);
            SetAnimation("isDrinking_2", false);
            dustOnce = false;
            dustParticle.GetComponent <Animator>().SetBool("triggerOnce", false);
            gameObject.Stab(Resources.Load("Audio/SFX/Knockout") as AudioClip, 1f, 1f, 0f);

            healthHud.SetHealth(0);
            deathCounter++;
        }
        else if (IsDead && deathCounter == 1 &&
                 bottom_animator.GetCurrentAnimatorStateInfo(0).IsName("KnockOut"))
        {
            SetAnimation("deathCounter", deathCounter);
            SetAnimation("isDead", false);
            Global.leprechauns.Remove(gameObject);

            deathCounter++;
        }
        else if (IsDead && deathCounter == 2)
        {
            RespawnButton();
            Camera.main.GetComponent <AdvancedCamera>().ZoomWithDelay(new Vector2(gameObject.transform.position.x, gameObject.transform.position.y), .1f);
            deathCounter++;
        }
        else if (IsDead && deathCounter == 3)
        {
            if (GamePad.GetButtonDown(GamePad.Button.X, gamePadIndex) ||
                (useMpu && mpuController.GetDigitalPressed(9)))
            {
                respawnButton.GetComponent <RespawnButton>().RemoveRespawnButton();
                playerScript.ResetPlayer(gameObject);
            }
        }
    }
Пример #2
0
    public GameObject GetCollisionObject(string collisionName, GameObject leprechaun)
    {
        if (leprechaun.GetComponent <Leprechaun>() != null)
        {
            Leprechaun script = leprechaunScript.GetComponent <Leprechaun>();

            if (collisionName == "groundCheck")
            {
                return(script.groundCheck);
            }
            else if (collisionName == "punchCheck")
            {
                return(script.punchCheck);
            }
            else if (collisionName == "bodyCheck")
            {
                return(script.bodyCheck);
            }
            else if (collisionName == "wallCheck")
            {
                return(script.wallCheck);
            }
        }
        else if (leprechaun.GetComponent <Leprechaun_USA>() != null)
        {
            Leprechaun_USA script = leprechaunScript.GetComponent <Leprechaun_USA>();

            if (collisionName == "groundCheck")
            {
                return(script.groundCheck);
            }
            else if (collisionName == "punchCheck")
            {
                return(script.punchCheck);
            }
            else if (collisionName == "bodyCheck")
            {
                return(script.bodyCheck);
            }
            else if (collisionName == "wallCheck")
            {
                return(script.wallCheck);
            }
        }
        else if (leprechaun.GetComponent <Cluirichaun>() != null)
        {
            Cluirichaun script = leprechaunScript.GetComponent <Cluirichaun>();

            if (collisionName == "groundCheck")
            {
                return(script.groundCheck);
            }
            else if (collisionName == "punchCheck")
            {
                return(script.punchCheck);
            }
            else if (collisionName == "bodyCheck")
            {
                return(script.bodyCheck);
            }
            else if (collisionName == "wallCheck")
            {
                return(script.wallCheck);
            }
        }
        else if (leprechaun.GetComponent <FarDarrig>() != null)
        {
            FarDarrig script = leprechaunScript.GetComponent <FarDarrig>();

            if (collisionName == "groundCheck")
            {
                return(script.groundCheck);
            }
            else if (collisionName == "punchCheck")
            {
                return(script.punchCheck);
            }
            else if (collisionName == "bodyCheck")
            {
                return(script.bodyCheck);
            }
            else if (collisionName == "wallCheck")
            {
                return(script.wallCheck);
            }
        }
        else if (leprechaun.GetComponent <Fairy>() != null)
        {
            Fairy script = leprechaunScript.GetComponent <Fairy>();

            if (collisionName == "groundCheck")
            {
                return(script.groundCheck);
            }
            else if (collisionName == "punchCheck")
            {
                return(script.punchCheck);
            }
            else if (collisionName == "bodyCheck")
            {
                return(script.bodyCheck);
            }
            else if (collisionName == "wallCheck")
            {
                return(script.wallCheck);
            }
        }

        return(gameObject);
    }