public void ReceiveHit() { if (invuln.IsInvulnerable() || !movement.CanMove()) { return; } AudioManager.GetInstance().PlayEffect(Sfx.NUN_DAMAGED, 1f); GameState.holyWaters -= GameplayValues.watersPerHit; if (GameState.holyWaters > -1) { invuln.SetInvulnerable(GameplayValues.GetInvulnerableTime()); } }
private void Update() { DebugModeHotkeys(); if (!GameState.isGameLocked) { // Time the character has been idle. lastAction += Time.deltaTime; var downPressed = inputManager.IsActionPressed(GameCommand.DOWN); var upPressed = inputManager.IsActionPressed(GameCommand.UP); var leftPressed = inputManager.IsActionPressed(GameCommand.LEFT); var rightPressed = inputManager.IsActionPressed(GameCommand.RIGHT); // Hit management on overlapping objects if (overlapping != null) { if (overlapping && overlapping.activeSelf && overlapping.CompareTag(Tags.ENEMY_HIT) && !invuln.IsInvulnerable()) { EnemyHit(); } } // Halo management, if active. if (haloActive && !invuln.IsInvulnerable()) { haloActive = false; invulnerableAura.SetActive(false); } // Crouch management. if (crouching && !inputManager.IsActionPressed(GameCommand.DOWN)) { Uncrouch(); } // Looking up management. if (!inputManager.IsActionPressed(GameCommand.UP)) { lookingUp = false; } // Control grounded state and the related animations. if (controller.isGrounded) { AchievementManager.jumpKills = 0; velocity.y = 0; if (crouching) { SetAnimation(Animations.NUN_CROUCHING); } if (lookingUp && !leftPressed && !rightPressed) { SetAnimation(Animations.NUN_LOOKING_UP); } } else { // Clean parent from moving platforms if falling or jumping. if (transform.parent != null) { transform.parent = null; } } // Restore one way platform being detected if not pressing crouch+jump if (controller.ignoringOneWayPlatforms && (!downPressed || !inputManager.IsActionPressed(GameCommand.JUMP))) { controller.ignoringOneWayPlatforms = false; } // Horizontal movement. if (canMove && rightPressed) { shootingDirection = Direction.RIGHT; lastAction = 0; normalizedHorizontalSpeed = 1; if (controller.isGrounded && !crouching) { SetAnimation(Animations.NUN_WALKING); } if (!flipper.lookingRight) { flipper.Flip(); shootingDirection = Direction.RIGHT; } } else if (canMove && leftPressed) { shootingDirection = Direction.LEFT; lastAction = 0; normalizedHorizontalSpeed = -1; if (controller.isGrounded && !crouching) { SetAnimation(Animations.NUN_WALKING); } if (flipper.lookingRight) { flipper.Flip(); shootingDirection = Direction.LEFT; } } else { normalizedHorizontalSpeed = 0; velocity.x = 0; // Set the standing up idle animation if there's no movement. if (canMove && !crouching && !lookingUp && controller.isGrounded && lastAction < 4.99f) { SetAnimation(Animations.NUN_IDLE); } } // Shooting if (canMove && inputManager.IsActionPressed(GameCommand.SHOOT) && Time.time - lastProjectile >= projectileRatio) { AudioManager.GetInstance().PlayEffect(Sfx.SHOOT); lastAction = 0; ShootProjectile(); } // Jump only while grounded. // If you're holding down, jump down a platform. if (canMove && controller.isGrounded && inputManager.IsActionPressedOnce(GameCommand.JUMP)) { if (downPressed) { transform.parent = null; controller.ignoringOneWayPlatforms = true; } else { Jump(false); } } // This controls the variable jump. If the key stops being pressed, the velocity is set to 0. if (!ignoreJumpVariable && velocity.y > 0 && velocity.y < 6f && !inputManager.IsActionPressed(GameCommand.JUMP)) { velocity.y = 0; } // Crouch action. if (canMove && controller.isGrounded && downPressed) { lastAction = 0; Crouch(); } // Look up, only possible while in an idle animation (not moving). if (canMove && controller.isGrounded && upPressed && idleAnims.Contains(currentAnimation)) { lastAction = 0; lookingUp = true; } // Apply horizontal speed. var smoothedMovementFactor = controller.isGrounded ? groundDamping : inAirDamping; var actualRunSpeed = speedBuffed ? runSpeed * 2 : runSpeed; if (crouching) { actualRunSpeed /= 2; } velocity.x = Mathf.Lerp(velocity.x, normalizedHorizontalSpeed * actualRunSpeed, Time.deltaTime * smoothedMovementFactor); // Apply gravity before moving. velocity.y += gravity * Time.deltaTime; velocity.y = Mathf.Clamp(velocity.y, -18f, 18f); // Jumping sprite if (velocity.y > 0.8f || velocity.y < -0.8f) { SetAnimation(Animations.NUN_JUMPING); } controller.move(velocity * Time.deltaTime); // Grab our current velocity to use as a base for all calculations. velocity = controller.velocity; // Speed booooooooost if (speedBuffed && Time.time - speedBuffApplied >= GameplayValues.GetSpeedBuffDuration()) { speedBuffed = false; audioManager.UndoFasterSong(); } // Idle animation when no movement after 5 seconds. if (lastAction > 5f && lastAction <= 7.5f) { SetAnimation(Animations.NUN_WAITING); } if (lastAction > 7.5f && lastAction <= 16f) { SetAnimation(Animations.NUN_BORED); } if (lastAction > 16f) { SetAnimation(Animations.NUN_PRAYING); } } }