Updated wait for start logic
This commit is contained in:
@@ -22,7 +22,8 @@ namespace Marro.PacManUdon
|
||||
Returning,
|
||||
Entering,
|
||||
Home,
|
||||
Exiting
|
||||
Exiting,
|
||||
WaitingForStart,
|
||||
}
|
||||
|
||||
public enum PacManGhostStartState
|
||||
@@ -122,37 +123,31 @@ namespace Marro.PacManUdon
|
||||
// Debug.Log($"{gameObject} Reset!");
|
||||
transform.SetLocalPositionAndRotation(startPosition, startRotation);
|
||||
|
||||
if (startState == PacManGhostStartState.Outside)
|
||||
{
|
||||
ghostState = PacManGhostState.Exiting;
|
||||
OffGridTargetReached();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (startState == PacManGhostStartState.TargetingIdlePosition1)
|
||||
{
|
||||
SetOffGridTarget(idlePosition1, false);
|
||||
SetTargetDirection(Direction.Down);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetTargetDirection(Direction.Up);
|
||||
}
|
||||
ghostState = PacManGhostState.Entering;
|
||||
OffGridTargetReached();
|
||||
}
|
||||
|
||||
offGrid = true;
|
||||
isScared = false;
|
||||
inTunnel = false;
|
||||
kinematic = false;
|
||||
followingPredefinedPath = false;
|
||||
turnAroundSoon = false;
|
||||
specialLook = false;
|
||||
|
||||
rngState = 1;
|
||||
UpdateSpeed();
|
||||
|
||||
UpdateAnimator();
|
||||
ghostState = PacManGhostState.WaitingForStart;
|
||||
|
||||
switch (startState)
|
||||
{
|
||||
case PacManGhostStartState.TargetingIdlePosition1:
|
||||
SetTargetDirection(Direction.Up);
|
||||
break;
|
||||
case PacManGhostStartState.TargetingIdlePosition2:
|
||||
SetTargetDirection(Direction.Down);
|
||||
break;
|
||||
default:
|
||||
SetTargetDirection(Direction.Left);
|
||||
break;
|
||||
}
|
||||
|
||||
UpdateSpeed();
|
||||
|
||||
// Debug.Log($"{gameObject} reset with state: {state}, target: {target}, offGrid: {offGrid}");
|
||||
}
|
||||
@@ -160,7 +155,7 @@ namespace Marro.PacManUdon
|
||||
public override void SyncedUpdate()
|
||||
{
|
||||
if (frozenState == PacManGhostFrozenState.Frozen ||
|
||||
(frozenState == PacManGhostFrozenState.FrozenIfNotCaught && ghostState != PacManGhostState.Returning && ghostState != PacManGhostState.Entering))
|
||||
(frozenState == PacManGhostFrozenState.FrozenIfNotCaught && ghostState != PacManGhostState.Returning && ghostState != PacManGhostState.Entering))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -189,6 +184,25 @@ namespace Marro.PacManUdon
|
||||
return nextPosition;
|
||||
}
|
||||
|
||||
if (ghostState == PacManGhostState.WaitingForStart)
|
||||
{
|
||||
switch (startState)
|
||||
{
|
||||
case PacManGhostStartState.TargetingIdlePosition1:
|
||||
SetOffGridTarget(idlePosition1, false);
|
||||
ghostState = PacManGhostState.Entering;
|
||||
break;
|
||||
case PacManGhostStartState.TargetingIdlePosition2:
|
||||
SetOffGridTarget(idlePosition2, false);
|
||||
ghostState = PacManGhostState.Entering;
|
||||
break;
|
||||
default:
|
||||
ghostState = PacManGhostState.Exiting;
|
||||
break;
|
||||
}
|
||||
OffGridTargetReached();
|
||||
}
|
||||
|
||||
if (offGrid || ghostState == PacManGhostState.Returning)
|
||||
{
|
||||
PerformOffgridRelatedMovement(position, ref nextPosition);
|
||||
@@ -499,33 +513,33 @@ namespace Marro.PacManUdon
|
||||
if (!gameObject.activeInHierarchy)
|
||||
return;
|
||||
|
||||
// Debug.Log($"{gameObject} UpdateAnimator with state: {ghostState}, isScared: {isScared}, direction: {direction}");
|
||||
if (specialLook)
|
||||
if (frozenState == PacManGhostFrozenState.FrozenIfNotCaught) // Looks like a bug but matches the original game
|
||||
{
|
||||
SetAnimatorGhostType((int)PacManGhostType.Special);
|
||||
}
|
||||
else if (!isScared) // Note: Don't update ghost type while scared as this interrupts the white/blue blinking
|
||||
{
|
||||
switch (ghostState)
|
||||
{
|
||||
default:
|
||||
case PacManGhostState.Normal:
|
||||
case PacManGhostState.Home:
|
||||
case PacManGhostState.Exiting:
|
||||
// Debug.Log($"{gameObject} Set GhostType in animator to: {GhostTypeToAnimationValue(ghostType)}");
|
||||
SetAnimatorGhostType((int)ghostType);
|
||||
break;
|
||||
case PacManGhostState.Returning:
|
||||
case PacManGhostState.Entering:
|
||||
SetAnimatorGhostType((int)PacManGhostType.Caught);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (specialLook || targetDirection != Direction.Zero)
|
||||
{
|
||||
SetAnimatorDirection((int)targetDirection);
|
||||
}
|
||||
|
||||
if (isScared) // Don't update ghost type while scared as this interrupts the white/blue blinking
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PacManGhostType ghostType = this.ghostType;
|
||||
|
||||
if (specialLook)
|
||||
{
|
||||
ghostType = PacManGhostType.Special;
|
||||
}
|
||||
else if (ghostState == PacManGhostState.Returning || ghostState == PacManGhostState.Entering)
|
||||
{
|
||||
ghostType = PacManGhostType.Caught;
|
||||
}
|
||||
|
||||
SetAnimatorGhostType((int)ghostType);
|
||||
}
|
||||
|
||||
// A Udon bug means converting an enum to a float causes an exception unless the conversion from int to float is in a separate method
|
||||
@@ -672,7 +686,13 @@ namespace Marro.PacManUdon
|
||||
}
|
||||
else
|
||||
{
|
||||
var oldFrozenState = frozenState;
|
||||
frozenState = PacManGhostFrozenState.NotFrozen;
|
||||
|
||||
if (oldFrozenState == PacManGhostFrozenState.FrozenIfNotCaught) // Catch animator up after not updating during FrozenIfNotCaught
|
||||
{
|
||||
UpdateAnimator();
|
||||
}
|
||||
}
|
||||
animator.speed = frozen && !keepAnimating ? 0 : 1; // This would cause issues if the returning sprite was animated, luckily it isn't :)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user