Refactored input
This commit is contained in:
@@ -82,27 +82,7 @@ namespace Marro.PacManUdon
|
||||
return;
|
||||
}
|
||||
|
||||
float speed = this.speed;
|
||||
if (freezeSeconds > 0)
|
||||
{
|
||||
float freezePart = freezeSeconds / networkManager.SyncedDeltaTime;
|
||||
if (freezePart >= 1)
|
||||
{
|
||||
freezeSeconds -= networkManager.SyncedDeltaTime;
|
||||
animator.speed = 0;
|
||||
speed = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
speed *= 1 - freezePart;
|
||||
animator.speed = 1 - freezePart;
|
||||
freezeSeconds = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
animator.speed = 1;
|
||||
}
|
||||
float speed = GetNextSpeed();
|
||||
|
||||
Vector2 position = GetPosition();
|
||||
Vector2 nextPosition = GetNextPosition(position, directionVectors[(int)direction], speed, networkManager.SyncedDeltaTime); // The position pacman will move to, assuming it doens't get changed
|
||||
@@ -127,6 +107,33 @@ namespace Marro.PacManUdon
|
||||
SetPosition(nextPosition);
|
||||
}
|
||||
|
||||
private float GetNextSpeed()
|
||||
{
|
||||
float speed = this.speed;
|
||||
if (freezeSeconds > 0)
|
||||
{
|
||||
float freezePart = freezeSeconds / networkManager.SyncedDeltaTime;
|
||||
if (freezePart >= 1)
|
||||
{
|
||||
freezeSeconds -= networkManager.SyncedDeltaTime;
|
||||
animator.speed = 0;
|
||||
speed = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
speed *= 1 - freezePart;
|
||||
animator.speed = 1 - freezePart;
|
||||
freezeSeconds = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
animator.speed = 1;
|
||||
}
|
||||
|
||||
return speed;
|
||||
}
|
||||
|
||||
private Vector2 ProcessNextPosition(Vector2 position, Vector2 nextPosition)
|
||||
{
|
||||
if (CrossesTileCenter(position, nextPosition, Direction.Left) // If pacman is moving horizontally, check if he may cross the center of a tile in that axis
|
||||
@@ -210,11 +217,11 @@ namespace Marro.PacManUdon
|
||||
|
||||
if (eatResult == EatResult.Pellet)
|
||||
{
|
||||
freezeSeconds = 0.0166666666666667f;
|
||||
freezeSeconds = 0.0165f;
|
||||
}
|
||||
else if (eatResult == EatResult.PowerPellet)
|
||||
{
|
||||
freezeSeconds = 0.05f;
|
||||
freezeSeconds = 0.0495f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user