Files

62 lines
1.8 KiB
C#
Raw Normal View History

2022-12-26 03:47:56 +02:00
using UnityEngine;
public class WalkState : GroundParentState
{
public override void UpdateLogic(PlayerNetwork player)
{
2022-12-30 14:07:58 +02:00
if (!player.enter)
{
player.animation = "Walk";
2022-12-30 14:07:58 +02:00
player.enter = true;
player.animationFrames = 0;
return;
2022-12-30 14:07:58 +02:00
}
2022-12-26 03:47:56 +02:00
player.canDoubleJump = true;
player.animationFrames++;
2023-04-24 01:19:26 +03:00
bool forwardDash = player.direction.x * player.flip == 1 ? true : false;
2023-07-02 23:17:37 +03:00
DemonFloat walkSpeed = forwardDash ? player.playerStats.SpeedWalk : player.playerStats.SpeedWalkBackwards;
player.velocity = new DemonVector2(player.direction.x * walkSpeed, 0);
2023-02-03 18:03:10 +02:00
bool footstep = player.player.PlayerAnimator.GetFootstep(player.animation, player.animationFrames, out int cel);
if (cel != player.cel && footstep)
2023-01-23 18:31:58 +02:00
{
2023-02-03 18:03:10 +02:00
player.cel = cel;
2023-01-23 18:31:58 +02:00
player.soundGroup = "Footsteps";
}
2023-01-07 23:17:55 +02:00
CheckFlip(player);
base.UpdateLogic(player);
2022-12-26 03:47:56 +02:00
ToIdleState(player);
ToJumpState(player);
ToJumpForwardState(player);
ToCrouchState(player);
}
private void ToCrouchState(PlayerNetwork player)
{
if (player.direction.y < 0)
{
2023-01-23 18:31:58 +02:00
EnterState(player, "Crouch");
2022-12-26 03:47:56 +02:00
}
}
private void ToJumpState(PlayerNetwork player)
{
if (player.direction.y > 0)
{
2023-04-22 03:46:41 +03:00
player.jumpDirection = 0;
EnterState(player, "PreJump");
2022-12-26 03:47:56 +02:00
}
}
private void ToJumpForwardState(PlayerNetwork player)
{
if (player.direction.y > 0 && player.direction.x != 0)
{
2022-12-31 20:46:52 +02:00
player.jumpDirection = (int)player.direction.x;
2023-04-22 03:46:41 +03:00
EnterState(player, "PreJump");
2022-12-26 03:47:56 +02:00
}
}
private void ToIdleState(PlayerNetwork player)
{
if (player.direction.x == 0)
{
2023-01-23 18:31:58 +02:00
EnterState(player, "Idle");
2022-12-26 03:47:56 +02:00
}
}
}