public void SetEntity(Vector2 pos, bool isPlayer) { health = maxHealth; this.isPlayer = isPlayer; isDead = false; playerScript = playerObject.GetComponent <Player>(); top_animator = Global.getChildGameObject(gameObject, "Animation_top").GetComponent <Animator>(); bottom_animator = Global.getChildGameObject(gameObject, "Animation_bottom").GetComponent <Animator>(); mirrored = false; onGround = false; collidingWithWall = false; skipNextMove = false; fallTroughBar = false; underBar = false; attackDone = false; dustOnce = false; maxDrunk = false; checkDrunkTimer = true; useMpu = playerScript.useMpu; if (chosenCharacter == Player.Character.FAIRY) { canDoubleJump = true; } else { canDoubleJump = false; } isHit = false; isAttacking = false; isBlocking = false; isDashing = false; isDrinking = false; jumpOnce = 0; attackOnce = 0; attackCooldown = 0; drinkAnimCounter = 0; drunkness = 0; drunknessF = 0f; drunkWalkTimer = 0; deathCounter = 0; hitDirection = "filler"; lastVelocity = new Vector2(0, 2); sortOfDrink = Drink.SortOfDrink.NONE; Direction = Facing.RIGHT; groundCheck = Global.getChildGameObject(gameObject, "GroundCheck"); punchCheck = Global.getChildGameObject(gameObject, "PunchCheck"); bodyCheck = Global.getChildGameObject(gameObject, "BodyCheck"); wallCheck = Global.getChildGameObject(gameObject, "WallCheck"); dustParticle = Global.getChildGameObject(gameObject, "Dust particle"); groundLayer = playerObject.GetComponent <LayerMaskPass>().GetLayerMask(); respawnButtonPos = new Vector2(transform.position.x, transform.position.y - 40); healthHud = playerScript.healthHUD.GetComponentInChildren <HealthHUD>(); healthHud.SetHealth(health); advancedCamera = Camera.main.GetComponent <AdvancedCamera>(); this.mpuController = playerScript.mpuController; SetDictionary(); }
public void SetEntity(Vector2 pos, bool isPlayer) { health = maxHealth; this.isPlayer = isPlayer; isDead = false; playerScript = playerObject.GetComponent<Player>(); top_animator = Global.getChildGameObject(gameObject, "Animation_top").GetComponent<Animator>(); bottom_animator = Global.getChildGameObject(gameObject, "Animation_bottom").GetComponent<Animator>(); mirrored = false; onGround = false; collidingWithWall = false; skipNextMove = false; fallTroughBar = false; underBar = false; attackDone = false; dustOnce = false; maxDrunk = false; checkDrunkTimer = true; useMpu = playerScript.useMpu; if (chosenCharacter == Player.Character.FAIRY) canDoubleJump = true; else canDoubleJump = false; isHit = false; isAttacking = false; isBlocking = false; isDashing = false; isDrinking = false; jumpOnce = 0; attackOnce = 0; attackCooldown = 0; drinkAnimCounter = 0; drunkness = 0; drunknessF = 0f; drunkWalkTimer = 0; deathCounter = 0; hitDirection = "filler"; lastVelocity = new Vector2(0, 2); sortOfDrink = Drink.SortOfDrink.NONE; Direction = Facing.RIGHT; groundCheck = Global.getChildGameObject(gameObject, "GroundCheck"); punchCheck = Global.getChildGameObject(gameObject, "PunchCheck"); bodyCheck = Global.getChildGameObject(gameObject, "BodyCheck"); wallCheck = Global.getChildGameObject(gameObject, "WallCheck"); dustParticle = Global.getChildGameObject(gameObject, "Dust particle"); groundLayer = playerObject.GetComponent<LayerMaskPass>().GetLayerMask(); respawnButtonPos = new Vector2(transform.position.x, transform.position.y - 40); healthHud = playerScript.healthHUD.GetComponentInChildren<HealthHUD>(); healthHud.SetHealth(health); advancedCamera = Camera.main.GetComponent<AdvancedCamera>(); this.mpuController = playerScript.mpuController; SetDictionary(); }
// 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); } } }
void UpdateUI() { hphud?.SetHealth(Health / maxHealth); }