Pellet sync

This commit is contained in:
2026-01-18 17:47:07 +01:00
parent eef7084e21
commit c3a19cc53e
12 changed files with 1933 additions and 747 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -7,7 +7,7 @@ namespace Marro.PacManUdon
{
public static void Append(this byte[] target, byte[] value, ref int index)
{
Debug.Log($"ByteUtils Append {nameof(value)}.Length: {value.Length}, {nameof(target)}.Length : {target.Length}, {nameof(index)}: {index}");
//Debug.Log($"ByteUtils Append {nameof(value)}.Length: {value.Length}, {nameof(target)}.Length : {target.Length}, {nameof(index)}: {index}");
Array.Copy(value, 0, target, index, value.Length);
index += value.Length;
}

View File

@@ -43,7 +43,7 @@ MonoBehaviour:
Data:
- Name:
Entry: 12
Data: 37
Data: 34
- Name:
Entry: 7
Data:
@@ -1423,79 +1423,16 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: pelletCountOverride
Data: maze
- Name: $v
Entry: 7
Data: 86|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: pelletCountOverride
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
- Name: <SystemType>k__BackingField
Entry: 9
Data: 15
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: true
- Name: _fieldAttributes
Entry: 7
Data: 87|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 2
- Name:
Entry: 7
Data: 88|UnityEngine.TooltipAttribute, UnityEngine.CoreModule
- Name: tooltip
Entry: 1
Data: Override amount of pellets needed to clear stage, set to -1 to disable.
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: 89|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: maze
- Name: $v
Entry: 7
Data: 90|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: maze
- Name: <UserType>k__BackingField
Entry: 7
Data: 91|System.RuntimeType, mscorlib
Data: 87|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.Maze, Assembly-CSharp
@@ -1519,7 +1456,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 92|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 88|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -1543,13 +1480,13 @@ MonoBehaviour:
Data: intermission2Pole
- Name: $v
Entry: 7
Data: 93|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 89|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: intermission2Pole
- Name: <UserType>k__BackingField
Entry: 7
Data: 94|System.RuntimeType, mscorlib
Data: 90|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.Intermission2Pole, Assembly-CSharp
@@ -1573,7 +1510,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 95|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 91|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -1597,7 +1534,7 @@ MonoBehaviour:
Data: mazeSpriteAnimator
- Name: $v
Entry: 7
Data: 96|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 92|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: mazeSpriteAnimator
@@ -1621,7 +1558,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 97|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 93|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -1642,19 +1579,25 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: pelletCountTotal
Data: attractScreenElements
- Name: $v
Entry: 7
Data: 98|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 94|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: pelletCountTotal
Data: attractScreenElements
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
Entry: 7
Data: 95|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.GameObject[], UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 15
Data: 95
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1669,7 +1612,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 99|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 96|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -1690,16 +1633,70 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: pelletCountRemaining
Data: intermissionScreenElements
- Name: $v
Entry: 7
Data: 100|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 97|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: pelletCountRemaining
Data: intermissionScreenElements
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
Data: 95
- Name: <SystemType>k__BackingField
Entry: 9
Data: 95
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 98|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: gameState
- Name: $v
Entry: 7
Data: 99|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: gameState
- Name: <UserType>k__BackingField
Entry: 7
Data: 100|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.PacManGameState, Assembly-CSharp
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 15
@@ -1739,126 +1736,16 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: attractScreenElements
Data: score
- Name: $v
Entry: 7
Data: 102|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: attractScreenElements
- Name: <UserType>k__BackingField
Entry: 7
Data: 103|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.GameObject[], UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 103
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 104|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: intermissionScreenElements
- Name: $v
Entry: 7
Data: 105|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: intermissionScreenElements
Data: score
- Name: <UserType>k__BackingField
Entry: 9
Data: 103
- Name: <SystemType>k__BackingField
Entry: 9
Data: 103
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 106|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: gameState
- Name: $v
Entry: 7
Data: 107|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: gameState
- Name: <UserType>k__BackingField
Entry: 7
Data: 108|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.PacManGameState, Assembly-CSharp
- Name:
Entry: 8
Data:
Data: 15
- Name: <SystemType>k__BackingField
Entry: 9
Data: 15
@@ -1866,8 +1753,8 @@ MonoBehaviour:
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
Entry: 3
Data: 1
- Name:
Entry: 8
Data:
@@ -1876,11 +1763,23 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 109|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
Data: 103|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib
- Name:
Entry: 12
Data: 0
Data: 2
- Name:
Entry: 7
Data: 104|UdonSharp.UdonSyncedAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: 105|UdonSharp.FieldChangeCallbackAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
@@ -1898,13 +1797,74 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: score
Data: level
- Name: $v
Entry: 7
Data: 106|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: level
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
- Name: <SystemType>k__BackingField
Entry: 9
Data: 15
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 3
Data: 1
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 107|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib
- Name:
Entry: 12
Data: 2
- Name:
Entry: 7
Data: 108|UdonSharp.UdonSyncedAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: 109|UdonSharp.FieldChangeCallbackAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: highScore
- Name: $v
Entry: 7
Data: 110|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: score
Data: highScore
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
@@ -1959,13 +1919,13 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: level
Data: extraLives
- Name: $v
Entry: 7
Data: 114|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: level
Data: extraLives
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
@@ -2015,128 +1975,6 @@ MonoBehaviour:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: highScore
- Name: $v
Entry: 7
Data: 118|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: highScore
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
- Name: <SystemType>k__BackingField
Entry: 9
Data: 15
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 3
Data: 1
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 119|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib
- Name:
Entry: 12
Data: 2
- Name:
Entry: 7
Data: 120|UdonSharp.UdonSyncedAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: 121|UdonSharp.FieldChangeCallbackAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: extraLives
- Name: $v
Entry: 7
Data: 122|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: extraLives
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
- Name: <SystemType>k__BackingField
Entry: 9
Data: 15
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 3
Data: 1
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 123|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib
- Name:
Entry: 12
Data: 2
- Name:
Entry: 7
Data: 124|UdonSharp.UdonSyncedAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: 125|UdonSharp.FieldChangeCallbackAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:

View File

@@ -26,15 +26,11 @@ namespace Marro.PacManUdon
[Header("Game settings")]
[SerializeField] private int startingExtraLives = 3;
[SerializeField] private int scoreToExtraLife = 10000;
[Tooltip("Override amount of pellets needed to clear stage, set to -1 to disable.")]
[SerializeField] private int pelletCountOverride = -1;
private Maze maze;
private Intermission2Pole intermission2Pole;
private Animator mazeSpriteAnimator;
private int pelletCountTotal;
private int pelletCountRemaining;
private GameObject[] attractScreenElements;
private GameObject[] intermissionScreenElements;
@@ -63,7 +59,7 @@ namespace Marro.PacManUdon
intermission2Pole = intermissionScreenElements[4].GetComponent<Intermission2Pole>();
networkManager.Initialize();
ghostManager.Initialize(maze.ghostStarts, maze.ghostTargets, pacMan, this);
ghostManager.Initialize(maze.ghostStarts, maze.ghostTargets, pacMan, pelletManager, this);
pacMan.Initialize(playerInput, maze.pacManStart, this);
bonusFruit.Initialize();
pelletManager.Initialize();
@@ -138,27 +134,20 @@ namespace Marro.PacManUdon
{
Debug.Log($"{gameObject} New level started!");
pelletCountTotal = pelletManager.PelletCount;
pelletCountRemaining = pelletCountTotal;
ghostManager.SetPelletsRemaining(pelletCountRemaining);
ghostManager.NewLevel();
pelletManager.RestoreAllPellets();
if (pelletCountOverride > 0)
{
pelletCountRemaining = pelletCountOverride;
}
ghostManager.NewLevel();
mazeSpriteAnimator.SetBool("Blinking", false);
}
private void RestartLevel()
private void RestartLevel(bool afterLifeLost = false)
{
Debug.Log($"{gameObject} (Re)started level!");
// SetInGameComponentVisibility(true);
ghostManager.Reset();
ghostManager.Reset(afterLifeLost);
pacMan.Reset();
bonusFruit.Despawn();
soundManager.Reset();
@@ -172,29 +161,31 @@ namespace Marro.PacManUdon
SetFrozen(true);
}
public void GotPellet(bool addScore = true)
public void GotPellet(Pellet pellet, bool addScore = true)
{
pelletCountRemaining--;
var pelletCollectedCount = pelletManager.PelletCollected(pellet);
if (addScore) AddScore(10);
ghostManager.PelletConsumed();
soundManager.PlayPelletSound();
var pelletCountRemaining = pelletManager.PelletCount - pelletCollectedCount;
soundManager.UpdatePelletCount(pelletCountRemaining);
int pelletsConsumed = pelletCountTotal - pelletCountRemaining;
if (pelletCountRemaining <= 0)
{
StartTimeSequence(PacManTimeSequence.BoardClear);
}
else if (pelletsConsumed == 70 || pelletsConsumed == 170)
else if (pelletCollectedCount == 70 || pelletCollectedCount == 170)
{
bonusFruit.Spawn();
}
}
public void GotPowerPellet()
public void GotPowerPellet(Pellet pellet)
{
Debug.Log($"{gameObject} GotPowerPellet");
@@ -203,7 +194,7 @@ namespace Marro.PacManUdon
TimeSequenceSkipToNextStep();
return;
}
GotPellet(addScore: false);
GotPellet(pellet, addScore: false);
AddScore(50);
ghostManager.SetPowerPellet(true);
pacMan.SetPowerPellet(true);

View File

@@ -32,6 +32,8 @@ namespace Marro.PacManUdon
TargetingIdlePosition2
}
[RequireComponent(typeof(Renderer))]
[RequireComponent(typeof(Animator))]
public class Ghost : GridMover
{
[SerializeField] private PacManGhostType ghostType;
@@ -73,7 +75,6 @@ namespace Marro.PacManUdon
private bool isScared;
private bool scattering;
private PacManGhostFrozenState frozenState;
private bool hideUntilUnfrozen;
private int housePelletCounter;
private bool housePelletCounterActive;
private bool turnAroundSoon;
@@ -137,12 +138,8 @@ namespace Marro.PacManUdon
public override void SyncedUpdate()
{
if (ghostType == PacManGhostType.Blinky)
{
// ghostManager.gameStateManager.statusDisplay.SetDebugText(2, $"{turnAroundSoon}");
}
if (frozenState == PacManGhostFrozenState.Frozen ||
(frozenState == PacManGhostFrozenState.FrozenIfNotCaught && ((ghostState != PacManGhostState.Returning && ghostState != PacManGhostState.Entering) || hideUntilUnfrozen)))
(frozenState == PacManGhostFrozenState.FrozenIfNotCaught && ghostState != PacManGhostState.Returning && ghostState != PacManGhostState.Entering))
{
return;
}
@@ -642,7 +639,7 @@ namespace Marro.PacManUdon
if (reverseDirection && this.scattering != scattering)
{
if (ghostState == PacManGhostState.Normal || ghostState == PacManGhostState.Home || ghostState == PacManGhostState.Exiting
// This is afaik not normal PacMan behaviour, but is needed to accomidate slight timing differences
// This is afaik not normal PacMan behaviour, but is needed to accomidate slight timing differences during the demo
|| ghostState == PacManGhostState.Entering && ghostManager.gameController.GameState == PacManGameState.AttractModeDemo
)
{

File diff suppressed because it is too large Load Diff

View File

@@ -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);

View File

@@ -15,6 +15,7 @@ namespace Marro.PacManUdon
FullSync = 1,
PacManTurn = 2,
StartGameButtonPressed = 3,
SyncPellets = 4,
}
public class NetworkManager : UdonSharpBehaviour
@@ -624,7 +625,6 @@ namespace Marro.PacManUdon
if (Synced)
{
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)} blaat");
UpdateNextEventTime();
}
}
@@ -657,7 +657,6 @@ namespace Marro.PacManUdon
}
DequeueEventsFromBuffer(1);
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)} damn");
UpdateNextEventTime();
}
}
@@ -964,6 +963,11 @@ namespace Marro.PacManUdon
{
SendEventSoon(NetworkEventType.FullSync);
}
public void DoPelletSync()
{
SendEventSoon(NetworkEventType.SyncPellets);
}
#endregion
}
}

View File

@@ -316,16 +316,14 @@ namespace Marro.PacManUdon
Pellet pellet = other.gameObject.GetComponent<Pellet>();
if (pellet)
{
pellet.gameObject.SetActive(false);
if (pellet.isPowerPellet)
{
gameController.GotPowerPellet();
gameController.GotPowerPellet(pellet);
freezeSeconds = 0.05f;
}
else
{
gameController.GotPellet();
gameController.GotPellet(pellet);
freezeSeconds = 0.0166666666666667f;
}
return;

View File

@@ -43,7 +43,7 @@ MonoBehaviour:
Data:
- Name:
Entry: 12
Data: 8
Data: 9
- Name:
Entry: 7
Data:
@@ -109,31 +109,25 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: pellets
Data: <PelletCollectedCount>k__BackingField
- Name: $v
Entry: 7
Data: 6|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: pellets
Data: <PelletCollectedCount>k__BackingField
- Name: <UserType>k__BackingField
Entry: 7
Data: 7|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.Pellet[], Assembly-CSharp
Data: System.Int32, mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 7
Data: 8|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.Component[], UnityEngine.CoreModule
- Name:
Entry: 8
Data:
Entry: 9
Data: 7
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -148,7 +142,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 9|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 8|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -169,25 +163,31 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: pelletRenderers
Data: pellets
- Name: $v
Entry: 7
Data: 10|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 9|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: pelletRenderers
Data: pellets
- Name: <UserType>k__BackingField
Entry: 7
Data: 11|System.RuntimeType, mscorlib
Data: 10|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.Renderer[], UnityEngine.CoreModule
Data: Marro.PacManUdon.Pellet[], Assembly-CSharp
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 11
Entry: 7
Data: 11|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.Component[], UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -476,6 +476,60 @@ MonoBehaviour:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: syncedPelletsCollected
- Name: $v
Entry: 7
Data: 26|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: syncedPelletsCollected
- Name: <UserType>k__BackingField
Entry: 7
Data: 27|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Byte[], mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 27
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 28|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:

View File

@@ -1,12 +1,14 @@
using UdonSharp;
using System;
using UnityEngine;
namespace Marro.PacManUdon
{
public class PelletManager : SyncedObject
{
public int PelletCount => pellets.Length;
public int PelletCollectedCount { get; private set; }
Pellet[] pellets;
Renderer[] pelletRenderers;
Animator[] powerPellets;
bool powerPelletBlinkEnabled;
@@ -14,20 +16,18 @@ namespace Marro.PacManUdon
float powerPelletBlinkProgress;
bool powerPelletBlinkCurrentlyVisible;
byte[] syncedPelletsCollected;
public void Initialize()
{
gameObject.SetActive(true);
pellets = GetComponentsInChildren<Pellet>(includeInactive: true);
pelletRenderers = new Renderer[pellets.Length];
for (int i = 0; i < pelletRenderers.Length; i++)
{
pelletRenderers[i] = pellets[i].GetComponent<Renderer>();
}
powerPellets = GetComponentsInChildren<Animator>(true);
powerPelletBlinkToggleInterval = PacManConstants.GetPowerPelletBlinkToggleInterval();
SetPowerPelletsBlink(false);
RestoreAllPellets();
}
public override void SyncedUpdate()
@@ -71,29 +71,63 @@ namespace Marro.PacManUdon
powerPelletBlinkEnabled = !frozen;
}
public void RestoreAllPellets()
public int PelletCollected(Pellet pellet)
{
pellet.gameObject.SetActive(false);
var index = pellet.transform.GetSiblingIndex();
syncedPelletsCollected[index/8] |= (byte)(1 << index%8);
PelletCollectedCount++;
return PelletCollectedCount;
}
public int RestoreAllPellets()
{
foreach (var pellet in pellets)
{
pellet.gameObject.SetActive(true);
}
foreach (Renderer pelletRenderer in pelletRenderers)
syncedPelletsCollected = new byte[pellets.Length/8 + 1];
PelletCollectedCount = 0;
return PelletCount;
}
private void SetPelletsCollectedFromSync()
{
for (int i = 0; i < pellets.Length; i++)
{
pelletRenderer.enabled = true;
var active = (syncedPelletsCollected[i/8] & (byte)(1 << i%8)) == 0;
pellets[i].gameObject.SetActive(active);
}
}
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
if (eventType != NetworkEventType.SyncPellets)
{
return;
}
data.Append((byte)PelletCollectedCount, ref index);
data.Append(syncedPelletsCollected, ref index);
}
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
if (eventType != NetworkEventType.SyncPellets)
{
return true;
}
PelletCollectedCount = data.ReadByte(ref index);
Array.Copy(data, index, syncedPelletsCollected, 0, syncedPelletsCollected.Length);
index += syncedPelletsCollected.Length;
SetPelletsCollectedFromSync();
return true;
}
public int PelletCount => pellets.Length;
}
}

View File

@@ -13,8 +13,7 @@ namespace Marro.PacManUdon
break;
case 1:
// Make maze visible
RestartLevel();
ghostManager.RestartAfterLifeLost();
RestartLevel(afterLifeLost: true);
SetMazeVisible(true);
break;
case 2:
@@ -43,7 +42,7 @@ namespace Marro.PacManUdon
SetFrozen(false);
soundManager.SuppressSound(false);
soundManager.StartGhostSound();
soundManager.UpdatePelletCount(pelletCountRemaining);
soundManager.UpdatePelletCount(pelletManager.PelletCount - pelletManager.PelletCollectedCount);
}
}
}