Pellet sync
This commit is contained in:
@@ -7,9 +7,12 @@ namespace Marro.PacManUdon
|
||||
public class GhostManager : SyncedObject
|
||||
{
|
||||
[NonSerialized] public GameManager gameController;
|
||||
|
||||
private Ghost[] ghosts;
|
||||
private Ghost blinky;
|
||||
|
||||
private PelletManager pelletManager;
|
||||
|
||||
// Level constants
|
||||
private float speedDefault;
|
||||
private float speedScared;
|
||||
@@ -42,7 +45,6 @@ namespace Marro.PacManUdon
|
||||
|
||||
// Elroy logic
|
||||
public int elroyLevel;
|
||||
private int pelletsRemaining;
|
||||
|
||||
// Ghost house logic
|
||||
private bool sharedPelletCounterActive;
|
||||
@@ -55,9 +57,11 @@ namespace Marro.PacManUdon
|
||||
private bool kinematic;
|
||||
|
||||
// This should be called once when the game is initialized
|
||||
public void Initialize(Transform[] ghostStarts, Transform[] ghostTargets, PacMan pacMan, GameManager gameController)
|
||||
public void Initialize(Transform[] ghostStarts, Transform[] ghostTargets, PacMan pacMan, PelletManager pelletManager, GameManager gameController)
|
||||
{
|
||||
this.gameController = gameController;
|
||||
this.pelletManager = pelletManager;
|
||||
|
||||
ghosts = transform.GetComponentsInChildren<Ghost>(true);
|
||||
blinky = ghosts[0];
|
||||
for (int ghostIndex = 0; ghostIndex < ghosts.Length; ghostIndex++)
|
||||
@@ -73,7 +77,7 @@ namespace Marro.PacManUdon
|
||||
}
|
||||
|
||||
// This should be called every time the level is reset
|
||||
public void Reset()
|
||||
public void Reset(bool afterLifeLost = false)
|
||||
{
|
||||
ghostScaredQueue = new DataList();
|
||||
powerPelletActive = false;
|
||||
@@ -84,6 +88,11 @@ namespace Marro.PacManUdon
|
||||
elroyLevel = 0;
|
||||
kinematic = false;
|
||||
|
||||
if (afterLifeLost)
|
||||
{
|
||||
SetSharedPelletCounterActive(true);
|
||||
}
|
||||
|
||||
foreach (Ghost ghost in ghosts)
|
||||
{
|
||||
ghost.Reset();
|
||||
@@ -95,20 +104,15 @@ namespace Marro.PacManUdon
|
||||
public void NewLevel()
|
||||
{
|
||||
SetSharedPelletCounterActive(false);
|
||||
UpdateElroyLevel();
|
||||
foreach (Ghost ghost in ghosts)
|
||||
{
|
||||
ghost.ResetHousePelletCounter();
|
||||
}
|
||||
}
|
||||
|
||||
public void RestartAfterLifeLost()
|
||||
{
|
||||
SetSharedPelletCounterActive(true);
|
||||
}
|
||||
|
||||
public override void SyncedUpdate()
|
||||
{
|
||||
// gameStateManager.statusDisplay.SetDebugText(1, this.blinkCountdown.ToString());
|
||||
if (frozen || kinematic)
|
||||
{
|
||||
return;
|
||||
@@ -368,7 +372,7 @@ namespace Marro.PacManUdon
|
||||
Debug.Log($"{gameObject} SetScattering: {scattering}");
|
||||
foreach (Ghost ghost in ghosts)
|
||||
{
|
||||
if (ghost == blinky && pelletsRemaining <= elroy1PelletCount)
|
||||
if (ghost == blinky && elroyLevel > 0) // Once blinky is elroy he no longer scatters
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -376,15 +380,13 @@ namespace Marro.PacManUdon
|
||||
}
|
||||
}
|
||||
|
||||
public void SetPelletsRemaining(int pelletsRemaining)
|
||||
{
|
||||
this.pelletsRemaining = pelletsRemaining;
|
||||
UpdateElroyLevel();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether to use the shared pellet counter for ghost exiting.
|
||||
/// Should be called before ghosts are reset.
|
||||
/// </summary>
|
||||
void SetSharedPelletCounterActive(bool active)
|
||||
{
|
||||
// Debug.Log($"{gameObject} SetSharedPelletCounterActive {active}");
|
||||
Debug.Log($"{gameObject} SetSharedPelletCounterActive {active}");
|
||||
sharedPelletCounterActive = active;
|
||||
foreach (Ghost ghost in ghosts)
|
||||
{
|
||||
@@ -394,10 +396,10 @@ namespace Marro.PacManUdon
|
||||
|
||||
public void PelletConsumed()
|
||||
{
|
||||
SetPelletsRemaining(pelletsRemaining - 1);
|
||||
|
||||
pelletTimeout = 0;
|
||||
|
||||
UpdateElroyLevel();
|
||||
|
||||
if (sharedPelletCounterActive)
|
||||
{
|
||||
IncrementSharedPelletCounter();
|
||||
@@ -411,6 +413,7 @@ namespace Marro.PacManUdon
|
||||
void IncrementSharedPelletCounter()
|
||||
{
|
||||
sharedPelletCounter++;
|
||||
//Debug.Log($"Incremented shared pellet counter to {sharedPelletCounter}");
|
||||
for (int ghostIndex = 0; ghostIndex < sharedPelletCounterReleaseValues.Length; ghostIndex++)
|
||||
{
|
||||
Ghost ghost = ghosts[ghostIndex];
|
||||
@@ -442,10 +445,13 @@ namespace Marro.PacManUdon
|
||||
void UpdateElroyLevel()
|
||||
{
|
||||
// Debug.Log($"{gameObject} Updating Elroy Level with pelletsRemaining {pelletsRemaining} with elroy2PelletCount {elroy2PelletCount} and elroy1PelletCount {elroy1PelletCount}");
|
||||
int oldElroyLevel = elroyLevel;
|
||||
var oldElroyLevel = elroyLevel;
|
||||
|
||||
var pelletsRemaining = pelletManager.PelletCount - pelletManager.PelletCollectedCount;
|
||||
if (pelletsRemaining < elroy2PelletCount) elroyLevel = 2;
|
||||
else if (pelletsRemaining < elroy1PelletCount) elroyLevel = 1;
|
||||
else elroyLevel = 0;
|
||||
|
||||
if (elroyLevel != oldElroyLevel)
|
||||
{
|
||||
blinky.SetElroy(elroyLevel);
|
||||
|
||||
Reference in New Issue
Block a user