2022-12-26 03:47:56 +02:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class RunState : GroundParentState
|
|
|
|
|
{
|
|
|
|
|
public override void UpdateLogic(PlayerNetwork player)
|
|
|
|
|
{
|
2022-12-30 14:07:58 +02:00
|
|
|
if (!player.enter)
|
|
|
|
|
{
|
|
|
|
|
player.enter = true;
|
2023-04-04 21:43:30 +03:00
|
|
|
player.animation = "Run";
|
2022-12-30 14:07:58 +02:00
|
|
|
player.animationFrames = 0;
|
2023-04-04 21:43:30 +03:00
|
|
|
return;
|
2022-12-30 14:07:58 +02:00
|
|
|
}
|
2023-07-02 23:17:37 +03:00
|
|
|
player.position = new DemonVector2(player.position.x, DemonicsPhysics.GROUND_POINT);
|
2022-12-26 03:47:56 +02:00
|
|
|
player.animation = "Run";
|
|
|
|
|
player.animationFrames++;
|
2023-07-02 23:17:37 +03:00
|
|
|
player.velocity = new DemonVector2(player.direction.x * player.playerStats.SpeedRun, 0);
|
2022-12-26 03:47:56 +02:00
|
|
|
if (DemonicsWorld.Frame % 5 == 0)
|
|
|
|
|
{
|
|
|
|
|
if (player.flip > 0)
|
|
|
|
|
{
|
2023-07-02 23:17:37 +03:00
|
|
|
DemonVector2 effectPosition = new DemonVector2(player.position.x - 1, player.position.y);
|
2022-12-31 20:46:52 +02:00
|
|
|
player.SetEffect("Ghost", effectPosition, false);
|
2022-12-26 03:47:56 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-07-02 23:17:37 +03:00
|
|
|
DemonVector2 effectPosition = new DemonVector2(player.position.x + 1, player.position.y);
|
2022-12-31 20:46:52 +02:00
|
|
|
player.SetEffect("Ghost", effectPosition, true);
|
2022-12-26 03:47:56 +02:00
|
|
|
}
|
|
|
|
|
}
|
2023-01-07 23:17:55 +02:00
|
|
|
base.UpdateLogic(player);
|
2022-12-26 03:47:56 +02:00
|
|
|
ToIdleState(player);
|
|
|
|
|
ToJumpState(player);
|
|
|
|
|
ToJumpForwardState(player);
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|
2023-03-07 16:42:36 +02:00
|
|
|
|
|
|
|
|
public override void Exit(PlayerNetwork player)
|
|
|
|
|
{
|
|
|
|
|
base.Exit(player);
|
|
|
|
|
player.soundStop = "Run";
|
|
|
|
|
}
|
2022-12-26 03:47:56 +02:00
|
|
|
}
|