Fixed ghost caught queue
This commit is contained in:
@@ -38,6 +38,8 @@ namespace Marro.PacManUdon
|
||||
private int[] ghostPositions = new int[4];
|
||||
private int pacManPosition;
|
||||
|
||||
private bool frozen;
|
||||
|
||||
public void Initialize(GameManager gameManager, BonusFruit bonusFruit, Ghost[] ghosts)
|
||||
{
|
||||
this.gameManager = gameManager;
|
||||
@@ -49,13 +51,29 @@ namespace Marro.PacManUdon
|
||||
|
||||
powerPellets = GetComponentsInChildren<Animator>(true);
|
||||
powerPelletBlinkToggleInterval = PacManConstants.GetPowerPelletBlinkToggleInterval();
|
||||
SetPowerPelletsBlink(false);
|
||||
|
||||
collisionMap = PacManConstants.GetMazeCollisionInfo();
|
||||
|
||||
RestoreAllPellets();
|
||||
|
||||
SubscribeToEvent(NetworkEventType.SyncPellets);
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
SetPowerPelletsBlink(false);
|
||||
|
||||
RestoreAllPellets();
|
||||
}
|
||||
|
||||
internal void SetFrozen(bool frozen)
|
||||
{
|
||||
this.frozen = frozen;
|
||||
|
||||
if (!frozen)
|
||||
{
|
||||
SetPowerPelletsBlink(true);
|
||||
}
|
||||
}
|
||||
|
||||
#region Collision
|
||||
@@ -74,7 +92,7 @@ namespace Marro.PacManUdon
|
||||
|
||||
ghostPositions[ghostIndex] = tile;
|
||||
|
||||
if (tile == pacManPosition)
|
||||
if (!frozen && tile == pacManPosition)
|
||||
{
|
||||
Debug.Log("Ghost hit PacMan!");
|
||||
ghosts[ghostIndex].HitPacMan();
|
||||
@@ -90,20 +108,28 @@ namespace Marro.PacManUdon
|
||||
|
||||
pacManPosition = tilemapIndex;
|
||||
|
||||
TryEatGhost(tilemapIndex);
|
||||
if (!frozen)
|
||||
{
|
||||
PacManTryEatGhost();
|
||||
}
|
||||
|
||||
TryCollectFruit(tile, position);
|
||||
return TryCollectPellet(tile, tilemapIndex);
|
||||
}
|
||||
|
||||
private void TryEatGhost(int tilemapIndex)
|
||||
internal void PacManTryEatGhost()
|
||||
{
|
||||
for (int i = 0; i < ghosts.Length; i++)
|
||||
{
|
||||
if (ghostPositions[i] == tilemapIndex)
|
||||
if (ghostPositions[i] != pacManPosition)
|
||||
{
|
||||
Debug.Log("PacMan hit ghost!");
|
||||
ghosts[i].HitPacMan();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ghosts[i].HitPacMan()) // Only one collision may happen at a time
|
||||
{
|
||||
Debug.Log("PacMan hit ghost!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -248,6 +274,8 @@ namespace Marro.PacManUdon
|
||||
|
||||
data.Append((byte)PelletCollectedCount, ref index);
|
||||
data.Append(syncedPelletsCollected, ref index);
|
||||
|
||||
data.Append(frozen, ref index);
|
||||
}
|
||||
|
||||
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
|
||||
@@ -261,6 +289,8 @@ namespace Marro.PacManUdon
|
||||
Array.Copy(data, index, syncedPelletsCollected, 0, syncedPelletsCollected.Length);
|
||||
index += syncedPelletsCollected.Length;
|
||||
SetPelletsCollectedFromSync();
|
||||
|
||||
frozen = data.ReadBool(ref index);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user