More use of Direction
This commit is contained in:
@@ -22,10 +22,10 @@ namespace Marro.PacManUdon
|
||||
private bool kinematic;
|
||||
|
||||
private bool followingPredefinedPath;
|
||||
private Vector2[] predefinedPath;
|
||||
private Direction[] predefinedPath;
|
||||
private int predefinedPathIndex;
|
||||
|
||||
private Vector2 targetDirection;
|
||||
private Direction targetDirection;
|
||||
private float freezeSeconds;
|
||||
private bool frozen;
|
||||
|
||||
@@ -35,8 +35,8 @@ namespace Marro.PacManUdon
|
||||
private const float AnimatorDirectionNone = 0f;
|
||||
private const float AnimatorDirectionRight = 0.25f;
|
||||
private const float AnimatorDirectionLeft = 0.50f;
|
||||
private const float AnimatorDirectionUp = 0.75f;
|
||||
private const float AnimatorDirectionDown = 1f;
|
||||
private const float AnimatorDirectionDown = 0.75f;
|
||||
private const float AnimatorDirectionUp = 1f;
|
||||
private const float AnimatorDirectionRightBig = 1.25f;
|
||||
#endregion
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace Marro.PacManUdon
|
||||
{
|
||||
transform.SetLocalPositionAndRotation(startPosition, startRotation);
|
||||
direction = Direction.Left;
|
||||
targetDirection = Vector2.left;
|
||||
targetDirection = Direction.Left;
|
||||
speed = defaultSpeed;
|
||||
kinematic = false;
|
||||
followingPredefinedPath = false;
|
||||
@@ -126,7 +126,7 @@ namespace Marro.PacManUdon
|
||||
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
|
||||
&& (targetDirection.x == 0 || pelletManager.IsWallUpcoming(nextPosition, directionVectors[(int)HorizontalComponent(direction)])))
|
||||
&& (!IsHorizontal(targetDirection) || pelletManager.IsWallUpcoming(nextPosition, directionVectors[(int)HorizontalComponent(direction)])))
|
||||
{ // If the target direction is in the other axis or if we're about to run into a wall
|
||||
nextPosition.x = PositionToGrid(nextPosition).x; // Snap pacman to the center of his current tile in this axis
|
||||
SetDirection(VerticalComponent(direction));
|
||||
@@ -134,7 +134,7 @@ namespace Marro.PacManUdon
|
||||
}
|
||||
|
||||
if (CrossesTileCenter(position, nextPosition, Direction.Down) // See comments above but now vertical
|
||||
&& (targetDirection.y == 0 || pelletManager.IsWallUpcoming(nextPosition, directionVectors[(int)VerticalComponent(direction)])))
|
||||
&& (!IsVertical(targetDirection) || pelletManager.IsWallUpcoming(nextPosition, directionVectors[(int)VerticalComponent(direction)])))
|
||||
{
|
||||
nextPosition.y = PositionToGrid(nextPosition).y;
|
||||
SetDirection(HorizontalComponent(direction));
|
||||
@@ -155,7 +155,7 @@ namespace Marro.PacManUdon
|
||||
{
|
||||
SetDirection(inputDirection + new Vector2(PositionToGrid(nextPosition).x - nextPosition.x, 0).normalized);
|
||||
}
|
||||
SetTargetDirection(inputDirection); // This is the direction most logic should assume pacman is moving, the actual direction may be different due to cornering
|
||||
SetTargetDirection(VectorToDirection(inputDirection)); // This is the direction most logic should assume pacman is moving, the actual direction may be different due to cornering
|
||||
|
||||
if (!followingPredefinedPath)
|
||||
{
|
||||
@@ -172,11 +172,11 @@ namespace Marro.PacManUdon
|
||||
{
|
||||
// Find the next valid direction which isn't Vector2.zero
|
||||
int nextValidDirectionIndex = predefinedPathIndex;
|
||||
while (predefinedPath[nextValidDirectionIndex] == Vector2.zero)
|
||||
while (predefinedPath[nextValidDirectionIndex] == Direction.Zero)
|
||||
{
|
||||
nextValidDirectionIndex += 1;
|
||||
}
|
||||
if (!CheckCollisionInDirection(transform, nextPosition, predefinedPath[nextValidDirectionIndex]))
|
||||
if (!CheckCollisionInDirection(transform, nextPosition, directionVectors[(int)predefinedPath[nextValidDirectionIndex]]))
|
||||
{
|
||||
// If we're at a Vector2.zero, we skip applying the direction and only increment.
|
||||
if (nextValidDirectionIndex == predefinedPathIndex)
|
||||
@@ -194,7 +194,7 @@ namespace Marro.PacManUdon
|
||||
followingPredefinedPath = false;
|
||||
break;
|
||||
}
|
||||
} while (predefinedPath[nextValidDirectionIndex] == Vector2.zero);
|
||||
} while (predefinedPath[nextValidDirectionIndex] == Direction.Zero);
|
||||
}
|
||||
|
||||
// gameStateManager.statusDisplay.SetDebugText(1, predefinedPathIndex.ToString());
|
||||
@@ -226,22 +226,22 @@ namespace Marro.PacManUdon
|
||||
else
|
||||
{
|
||||
animator.speed = 1;
|
||||
if (targetDirection.Equals(Vector2.right))
|
||||
if (targetDirection.Equals(Direction.Right))
|
||||
{
|
||||
animator.SetFloat(AnimatorKeyDirection, AnimatorDirectionRight);
|
||||
}
|
||||
else if (targetDirection.Equals(Vector2.left))
|
||||
else if (targetDirection.Equals(Direction.Left))
|
||||
{
|
||||
animator.SetFloat(AnimatorKeyDirection, AnimatorDirectionLeft);
|
||||
}
|
||||
else if (targetDirection.Equals(Vector2.up))
|
||||
{
|
||||
animator.SetFloat(AnimatorKeyDirection, AnimatorDirectionUp);
|
||||
}
|
||||
else if (targetDirection.Equals(Vector2.down))
|
||||
else if (targetDirection.Equals(Direction.Down))
|
||||
{
|
||||
animator.SetFloat(AnimatorKeyDirection, AnimatorDirectionDown);
|
||||
}
|
||||
else if (targetDirection.Equals(Direction.Up))
|
||||
{
|
||||
animator.SetFloat(AnimatorKeyDirection, AnimatorDirectionUp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,7 +297,7 @@ namespace Marro.PacManUdon
|
||||
this.kinematic = kinematic;
|
||||
}
|
||||
|
||||
public void SetPredefinedPath(Vector2[] predefinedPath)
|
||||
public void SetPredefinedPath(Direction[] predefinedPath)
|
||||
{
|
||||
this.predefinedPath = predefinedPath;
|
||||
followingPredefinedPath = true;
|
||||
@@ -314,7 +314,7 @@ namespace Marro.PacManUdon
|
||||
renderer.enabled = visible;
|
||||
}
|
||||
|
||||
public void SetTargetDirection(Vector2 targetDirection)
|
||||
public void SetTargetDirection(Direction targetDirection)
|
||||
{
|
||||
this.targetDirection = targetDirection;
|
||||
UpdateAnimator();
|
||||
@@ -352,12 +352,12 @@ namespace Marro.PacManUdon
|
||||
|
||||
if (kinematic || frozen || !enabled)
|
||||
{
|
||||
index += 8;
|
||||
index += 1;
|
||||
base.PadSyncedData(data, ref index, eventType);
|
||||
return;
|
||||
}
|
||||
|
||||
data.Append(targetDirection, ref index);
|
||||
data.AppendAsByte((int)targetDirection, ref index);
|
||||
|
||||
base.CollectSyncedData(data, ref index, eventType);
|
||||
}
|
||||
@@ -371,12 +371,12 @@ namespace Marro.PacManUdon
|
||||
|
||||
if (kinematic || frozen || !enabled)
|
||||
{
|
||||
index += 8;
|
||||
index += 1;
|
||||
base.ConsumeSyncedData(data, ref index, eventType);
|
||||
return true;
|
||||
}
|
||||
|
||||
SetTargetDirection(data.ReadVector2(ref index));
|
||||
SetTargetDirection((Direction)data.ReadByte(ref index));
|
||||
|
||||
return base.WriteSyncedData(data, ref index, eventType);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user