Refactored pelletCollectedCount

This commit is contained in:
2026-06-22 15:21:48 +02:00
parent 4ba203b1de
commit d739c9d7b5
2 changed files with 196 additions and 143 deletions

View File

@@ -13,28 +13,27 @@ namespace Marro.PacManUdon
public class CollisionManager : SyncedObject
{
public int PelletCount => pellets.Length;
public int PelletCollectedCount { get; private set; }
private GameManager gameManager;
private BonusFruit bonusFruit;
private Pellet[] pellets;
private Animator[] powerPellets;
private Ghost[] ghosts;
Pellet[] pellets;
Animator[] powerPellets;
Ghost[] ghosts;
private byte[] collisionMap;
private int[] pelletIndices;
bool powerPelletBlinkEnabled;
float powerPelletBlinkToggleInterval;
float powerPelletBlinkProgress;
bool powerPelletBlinkCurrentlyVisible;
private const int mazeWidth = 32;
private const int mazeHeight = 32;
byte[] syncedPelletsCollected;
private bool powerPelletBlinkEnabled;
private float powerPelletBlinkToggleInterval;
private float powerPelletBlinkProgress;
private bool powerPelletBlinkCurrentlyVisible;
byte[] collisionMap;
byte[] pelletMap;
int[] pelletIndices;
const int mazeWidth = 32;
const int mazeHeight = 32;
private byte[] pelletMap;
private byte[] syncedPelletsCollected;
private byte pelletCollectedCount;
private int[] ghostPositions = new int[4];
private int pacManPosition;
@@ -188,11 +187,11 @@ namespace Marro.PacManUdon
var index = pellet.transform.GetSiblingIndex();
syncedPelletsCollected[index / 8] |= (byte)(1 << index % 8);
PelletCollectedCount++;
pelletCollectedCount++;
var pelletType = pellet.isPowerPellet ? EatResult.PowerPellet : EatResult.Pellet;
gameManager.GotPellet(pellet, pellet.isPowerPellet, PelletCollectedCount, PelletCount - PelletCollectedCount);
gameManager.GotPellet(pellet, pellet.isPowerPellet, pelletCollectedCount, PelletCount - pelletCollectedCount);
return pelletType;
}
@@ -205,7 +204,7 @@ namespace Marro.PacManUdon
}
syncedPelletsCollected = new byte[pellets.Length/8 + 1];
PelletCollectedCount = 0;
pelletCollectedCount = 0;
pelletMap = PacManConstants.GetMazePelletMap();
@@ -268,7 +267,7 @@ namespace Marro.PacManUdon
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
data.Append((byte)PelletCollectedCount, ref index);
data.Append((byte)pelletCollectedCount, ref index);
data.Append(syncedPelletsCollected, ref index);
data.Append(frozen, ref index);
@@ -276,7 +275,7 @@ namespace Marro.PacManUdon
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
PelletCollectedCount = data.ReadByte(ref index);
pelletCollectedCount = data.ReadByte(ref index);
Array.Copy(data, index, syncedPelletsCollected, 0, syncedPelletsCollected.Length);
index += syncedPelletsCollected.Length;
SetPelletsCollectedFromSync();