Pellet collision

This commit is contained in:
2026-06-15 14:36:07 +02:00
parent 246718f1bd
commit c601dda10a
9 changed files with 318 additions and 229 deletions

View File

@@ -11,8 +11,6 @@ GameObject:
- component: {fileID: 1315692994360949719} - component: {fileID: 1315692994360949719}
- component: {fileID: 967117457436250906} - component: {fileID: 967117457436250906}
- component: {fileID: 7512162431685415002} - component: {fileID: 7512162431685415002}
- component: {fileID: 2135601224056198654}
- component: {fileID: 3963523032509914404}
- component: {fileID: 9117212235706742114} - component: {fileID: 9117212235706742114}
m_Layer: 0 m_Layer: 0
m_Name: Pellet m_Name: Pellet
@@ -111,54 +109,7 @@ MonoBehaviour:
SerializationNodes: [] SerializationNodes: []
_udonSharpBackingUdonBehaviour: {fileID: 9117212235706742114} _udonSharpBackingUdonBehaviour: {fileID: 9117212235706742114}
isPowerPellet: 0 isPowerPellet: 0
--- !u!65 &2135601224056198654 pelletRenderer: {fileID: 0}
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4099390335584803315}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 1
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Size: {x: 0.5, y: 0.5, z: 0.5}
m_Center: {x: 0, y: 0, z: 0}
--- !u!54 &3963523032509914404
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4099390335584803315}
serializedVersion: 4
m_Mass: 1
m_Drag: 0
m_AngularDrag: 0.05
m_CenterOfMass: {x: 0, y: 0, z: 0}
m_InertiaTensor: {x: 1, y: 1, z: 1}
m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_ImplicitCom: 1
m_ImplicitTensor: 1
m_UseGravity: 1
m_IsKinematic: 1
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!114 &9117212235706742114 --- !u!114 &9117212235706742114
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@@ -61,7 +61,7 @@ namespace Marro.PacManUdon
ghostManager.Initialize(maze.ghostStarts, maze.ghostTargets, pacMan, pelletManager, this); ghostManager.Initialize(maze.ghostStarts, maze.ghostTargets, pacMan, pelletManager, this);
pacMan.Initialize(playerInput, maze.pacManStart, this, pelletManager); pacMan.Initialize(playerInput, maze.pacManStart, this, pelletManager);
bonusFruit.Initialize(); bonusFruit.Initialize();
pelletManager.Initialize(); pelletManager.Initialize(this);
statusDisplay.Initialize(); statusDisplay.Initialize();
playerInput.Initialize(this); playerInput.Initialize(this);
soundManager.Initialize(); soundManager.Initialize();
@@ -163,25 +163,35 @@ namespace Marro.PacManUdon
SetFrozen(true); SetFrozen(true);
} }
public void GotPellet(Pellet pellet, bool addScore = true) internal void GotPellet(Pellet pellet, PelletType pelletType, int pelletsCollectedCount, int pelletsRemainingCount)
{ {
var pelletCollectedCount = pelletManager.PelletCollected(pellet); AddScore(pelletType == PelletType.PowerPellet ? 50 : 10);
if (addScore) AddScore(10); ghostManager.PelletConsumed(pelletsRemainingCount);
ghostManager.PelletConsumed();
soundManager.PlayPelletSound(); soundManager.PlayPelletSound();
soundManager.UpdatePelletCount(pelletsRemainingCount);
var pelletCountRemaining = pelletManager.PelletCount - pelletCollectedCount; if (pelletsRemainingCount <= 0)
soundManager.UpdatePelletCount(pelletCountRemaining);
if (pelletCountRemaining <= 0)
{ {
StartTimeSequence(PacManTimeSequence.BoardClear); StartTimeSequence(PacManTimeSequence.BoardClear);
return;
} }
else if (pelletCollectedCount == 70 || pelletCollectedCount == 170)
if (pelletType == PelletType.PowerPellet)
{
if (gameState == PacManGameState.AttractMode)
{
TimeSequenceSkipToNextStep();
return;
}
ghostManager.SetPowerPellet(true);
pacMan.SetPowerPellet(true);
soundManager.SetGhostBlue(true);
}
if (pelletsCollectedCount == 70 || pelletsCollectedCount == 170)
{ {
bonusFruit.Spawn(); bonusFruit.Spawn();
} }
@@ -191,16 +201,7 @@ namespace Marro.PacManUdon
{ {
//Debug.Log($"{gameObject} GotPowerPellet"); //Debug.Log($"{gameObject} GotPowerPellet");
if (gameState == PacManGameState.AttractMode)
{
TimeSequenceSkipToNextStep();
return;
}
GotPellet(pellet, addScore: false);
AddScore(50);
ghostManager.SetPowerPellet(true);
pacMan.SetPowerPellet(true);
soundManager.SetGhostBlue(true);
} }
public void EndPowerPellet() public void EndPowerPellet()

View File

@@ -259,7 +259,7 @@ namespace Marro.PacManUdon
return; return;
} }
Debug.Log($"{gameObject.name} Turned from direction {direction} to direction {newDirection}"); //Debug.Log($"{gameObject.name} Turned from direction {direction} to direction {newDirection}");
nextPosition = GetNextPosition(gridPosition, directionVectors[(int)newDirection], speed, networkManager.SyncedDeltaTime); nextPosition = GetNextPosition(gridPosition, directionVectors[(int)newDirection], speed, networkManager.SyncedDeltaTime);
SetDirection(newDirection); SetDirection(newDirection);
} }

View File

@@ -105,7 +105,7 @@ namespace Marro.PacManUdon
public void NewLevel() public void NewLevel()
{ {
SetSharedPelletCounterActive(false); SetSharedPelletCounterActive(false);
UpdateElroyLevel(); UpdateElroyLevel(pelletManager.PelletCount);
foreach (Ghost ghost in ghosts) foreach (Ghost ghost in ghosts)
{ {
ghost.ResetHousePelletCounter(); ghost.ResetHousePelletCounter();
@@ -404,11 +404,11 @@ namespace Marro.PacManUdon
} }
} }
public void PelletConsumed() public void PelletConsumed(int pelletsRemainingCount)
{ {
pelletTimeout = 0; pelletTimeout = 0;
UpdateElroyLevel(); UpdateElroyLevel(pelletsRemainingCount);
if (sharedPelletCounterActive) if (sharedPelletCounterActive)
{ {
@@ -452,14 +452,13 @@ namespace Marro.PacManUdon
} }
} }
void UpdateElroyLevel() void UpdateElroyLevel(int pelletsRemainingCount)
{ {
// Debug.Log($"{gameObject} Updating Elroy Level with pelletsRemaining {pelletsRemaining} with elroy2PelletCount {elroy2PelletCount} and elroy1PelletCount {elroy1PelletCount}"); // Debug.Log($"{gameObject} Updating Elroy Level with pelletsRemaining {pelletsRemaining} with elroy2PelletCount {elroy2PelletCount} and elroy1PelletCount {elroy1PelletCount}");
var oldElroyLevel = elroyLevel; var oldElroyLevel = elroyLevel;
var pelletsRemaining = pelletManager.PelletCount - pelletManager.PelletCollectedCount; if (pelletsRemainingCount < elroy2PelletCount) elroyLevel = 2;
if (pelletsRemaining < elroy2PelletCount) elroyLevel = 2; else if (pelletsRemainingCount < elroy1PelletCount) elroyLevel = 1;
else if (pelletsRemaining < elroy1PelletCount) elroyLevel = 1;
else elroyLevel = 0; else elroyLevel = 0;
if (elroyLevel != oldElroyLevel) if (elroyLevel != oldElroyLevel)

View File

@@ -120,6 +120,11 @@ namespace Marro.PacManUdon
} }
} }
if (CrossesTileBorder(position, nextPosition, direction))
{
CheckNewTile(nextPosition);
}
SetPosition(nextPosition); SetPosition(nextPosition);
} }
@@ -207,6 +212,20 @@ namespace Marro.PacManUdon
return nextPosition; return nextPosition;
} }
private void CheckNewTile(Vector2 position)
{
var pellet = pelletManager.CollectPelletAt(position);
if (pellet == PelletType.Pellet)
{
freezeSeconds = 0.0166666666666667f;
}
else if (pellet == PelletType.PowerPellet)
{
freezeSeconds = freezeSeconds = 0.05f;
}
}
protected override void UpdateAnimator() protected override void UpdateAnimator()
{ {
// Debug.Log($"{gameObject} UpdateAnimator with direction {direction}, dead {dead}, frozen {frozen}"); // Debug.Log($"{gameObject} UpdateAnimator with direction {direction}, dead {dead}, frozen {frozen}");
@@ -324,22 +343,7 @@ namespace Marro.PacManUdon
void OnTriggerEnter(Collider other) void OnTriggerEnter(Collider other)
{ {
Pellet pellet = other.gameObject.GetComponent<Pellet>(); if (other.gameObject.GetComponent<BonusFruit>())
if (pellet)
{
if (pellet.isPowerPellet)
{
gameManager.GotPowerPellet(pellet);
freezeSeconds = 0.05f;
}
else
{
gameManager.GotPellet(pellet);
freezeSeconds = 0.0166666666666667f;
}
return;
}
else if (other.gameObject.GetComponent<BonusFruit>())
{ {
gameManager.GotFruit(); gameManager.GotFruit();
} }

View File

@@ -97,25 +97,25 @@ namespace Marro.PacManUdon
public static int[] GetMazePelletMap() => new int[] public static int[] GetMazePelletMap() => new int[]
{ {
-01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01,
-01, 216, 215, 214, 213, 212, 196, 195, 194, 193, 192, 191, 190, -01, -01, 178, 179, 180, 181, 182, 183, 152, 151, 150, 149, 148, 147, -01, -01, 215, 214, 213, 212, 211, 195, 194, 193, 192, 191, 190, 189, -01, -01, 177, 178, 179, 180, 181, 182, 151, 150, 149, 148, 147, 146, -01,
-01, 217, -01, -01, -01, -01, 197, -01, -01, -01, -01, -01, 189, -01, -01, 177, -01, -01, -01, -01, -01, 153, -01, -01, -01, -01, 146, -01, -01, 216, -01, -01, -01, -01, 196, -01, -01, -01, -01, -01, 188, -01, -01, 176, -01, -01, -01, -01, -01, 152, -01, -01, -01, -01, 145, -01,
-01, 003, -01, -01, -01, -01, 198, -01, -01, -01, -01, -01, 188, -01, -01, 176, -01, -01, -01, -01, -01, 154, -01, -01, -01, -01, 002, -01, -01, 003, -01, -01, -01, -01, 197, -01, -01, -01, -01, -01, 187, -01, -01, 175, -01, -01, -01, -01, -01, 153, -01, -01, -01, -01, 002, -01,
-01, 218, -01, -01, -01, -01, 199, -01, -01, -01, -01, -01, 187, -01, -01, 175, -01, -01, -01, -01, -01, 155, -01, -01, -01, -01, 145, -01, -01, 217, -01, -01, -01, -01, 198, -01, -01, -01, -01, -01, 186, -01, -01, 174, -01, -01, -01, -01, -01, 154, -01, -01, -01, -01, 144, -01,
-01, 219, 220, 221, 222, 223, 200, 201, 202, 203, 204, 205, 186, 185, 184, 174, 173, 172, 165, 164, 163, 156, 157, 158, 159, 160, 144, -01, -01, 218, 219, 220, 221, 222, 199, 200, 201, 202, 203, 204, 185, 184, 183, 173, 172, 171, 164, 163, 162, 155, 156, 157, 158, 159, 143, -01,
-01, 224, -01, -01, -01, -01, 231, -01, -01, 206, -01, -01, -01, -01, -01, -01, -01, -01, 166, -01, -01, 161, -01, -01, -01, -01, 143, -01, -01, 223, -01, -01, -01, -01, 230, -01, -01, 205, -01, -01, -01, -01, -01, -01, -01, -01, 165, -01, -01, 160, -01, -01, -01, -01, 142, -01,
-01, 225, -01, -01, -01, -01, 232, -01, -01, 207, -01, -01, -01, -01, -01, -01, -01, -01, 167, -01, -01, 162, -01, -01, -01, -01, 142, -01, -01, 224, -01, -01, -01, -01, 231, -01, -01, 206, -01, -01, -01, -01, -01, -01, -01, -01, 166, -01, -01, 161, -01, -01, -01, -01, 141, -01,
-01, 226, 227, 228, 229, 230, 233, -01, -01, 208, 209, 210, 211, -01, -01, 171, 170, 169, 168, -01, -01, 136, 137, 138, 139, 140, 141, -01, -01, 225, 226, 227, 228, 229, 232, -01, -01, 207, 208, 209, 210, -01, -01, 170, 169, 168, 167, -01, -01, 135, 136, 137, 138, 139, 140, -01,
-01, -01, -01, -01, -01, -01, 234, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 134, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 233, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 134, -01, -01, -01, -01, -01, -01,
-01, -01, -01, -01, -01, -01, 235, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 133, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 234, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 133, -01, -01, -01, -01, -01, -01,
-01, -01, -01, -01, -01, -01, 236, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 132, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 235, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 132, -01, -01, -01, -01, -01, -01,
-01, -01, -01, -01, -01, -01, 237, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 131, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 236, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 131, -01, -01, -01, -01, -01, -01,
-01, -01, -01, -01, -01, -01, 238, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 130, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 237, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 130, -01, -01, -01, -01, -01, -01,
-01, -01, -01, -01, -01, -01, 239, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 129, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 238, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 129, -01, -01, -01, -01, -01, -01,
-01, -01, -01, -01, -01, -01, 240, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 128, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 239, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 128, -01, -01, -01, -01, -01, -01,
-01, -01, -01, -01, -01, -01, 241, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 127, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 240, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 127, -01, -01, -01, -01, -01, -01,
-01, -01, -01, -01, -01, -01, 242, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 126, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 241, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 126, -01, -01, -01, -01, -01, -01,
-01, -01, -01, -01, -01, -01, 243, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 125, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 242, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 125, -01, -01, -01, -01, -01, -01,
-01, -01, -01, -01, -01, -01, 244, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 124, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 243, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 124, -01, -01, -01, -01, -01, -01,
-01, 086, 087, 088, 089, 090, 091, 094, 095, 096, 097, 098, 099, -01, -01, 104, 105, 106, 107, 108, 109, 110, 123, 122, 121, 120, 119, -01, -01, 086, 087, 088, 089, 090, 091, 094, 095, 096, 097, 098, 099, -01, -01, 104, 105, 106, 107, 108, 109, 110, 123, 122, 121, 120, 119, -01,
-01, 085, -01, -01, -01, -01, 092, -01, -01, -01, -01, -01, 100, -01, -01, 103, -01, -01, -01, -01, -01, 111, -01, -01, -01, -01, 118, -01, -01, 085, -01, -01, -01, -01, 092, -01, -01, -01, -01, -01, 100, -01, -01, 103, -01, -01, -01, -01, -01, 111, -01, -01, -01, -01, 118, -01,
-01, 084, -01, -01, -01, -01, 093, -01, -01, -01, -01, -01, 101, -01, -01, 102, -01, -01, -01, -01, -01, 112, -01, -01, -01, -01, 117, -01, -01, 084, -01, -01, -01, -01, 093, -01, -01, -01, -01, -01, 101, -01, -01, 102, -01, -01, -01, -01, -01, 112, -01, -01, -01, -01, 117, -01,
@@ -127,6 +127,7 @@ namespace Marro.PacManUdon
-01, 020, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 072, -01, -01, 071, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 047, -01, -01, 020, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 072, -01, -01, 071, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 047, -01,
-01, 021, 022, 023, 024, 025, 026, 027, 028, 029, 030, 031, 032, 033, 034, 035, 036, 037, 038, 039, 040, 041, 042, 043, 044, 045, 046, -01, -01, 021, 022, 023, 024, 025, 026, 027, 028, 029, 030, 031, 032, 033, 034, 035, 036, 037, 038, 039, 040, 041, 042, 043, 044, 045, 046, -01,
-01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01,
}; };
public static int[] GetMazePelletIndices() => new int[] public static int[] GetMazePelletIndices() => new int[]
@@ -139,14 +140,14 @@ namespace Marro.PacManUdon
703, 675, 647, 646, 617, 589, 561, 562, 563, 564, 565, 566, 594, 622, 567, 568, 703, 675, 647, 646, 617, 589, 561, 562, 563, 564, 565, 566, 594, 622, 567, 568,
569, 570, 571, 572, 600, 628, 631, 603, 575, 576, 577, 578, 579, 580, 581, 609, 569, 570, 571, 572, 600, 628, 631, 603, 575, 576, 577, 578, 579, 580, 581, 609,
637, 724, 696, 668, 669, 642, 614, 586, 585, 584, 583, 582, 553, 525, 497, 469, 637, 724, 696, 668, 669, 642, 614, 586, 585, 584, 583, 582, 553, 525, 497, 469,
441, 413, 385, 357, 329, 301, 273, 245, 245, 246, 247, 248, 249, 250, 222, 194, 441, 413, 385, 357, 329, 301, 273, 245, 246, 247, 248, 249, 250, 222, 194, 166,
166, 138, 082, 054, 053, 052, 051, 050, 049, 077, 105, 133, 161, 162, 163, 164, 138, 082, 054, 053, 052, 051, 050, 049, 077, 105, 133, 161, 162, 163, 164, 165,
165, 189, 217, 160, 159, 158, 186, 214, 242, 241, 240, 239, 157, 156, 155, 127, 189, 217, 160, 159, 158, 186, 214, 242, 241, 240, 239, 157, 156, 155, 127, 099,
099, 071, 043, 044, 045, 046, 047, 048, 154, 153, 152, 124, 096, 068, 040, 039, 071, 043, 044, 045, 046, 047, 048, 154, 153, 152, 124, 096, 068, 040, 039, 038,
038, 037, 036, 035, 034, 062, 090, 118, 146, 147, 148, 149, 150, 151, 177, 205, 037, 036, 035, 034, 062, 090, 118, 146, 147, 148, 149, 150, 151, 177, 205, 233,
233, 234, 235, 236, 033, 032, 031, 030, 029, 057, 113, 141, 142, 143, 144, 145, 234, 235, 236, 033, 032, 031, 030, 029, 057, 113, 141, 142, 143, 144, 145, 169,
169, 197, 225, 226, 227, 228, 229, 174, 202, 230, 258, 286, 314, 342, 370, 398, 197, 225, 226, 227, 228, 229, 174, 202, 230, 258, 286, 314, 342, 370, 398, 426,
426, 454, 482, 510, 538, 454, 482, 510, 538,
}; };
public static GameObject[] ComponentsToGameObjects(Component[] components, bool skipFirstComponent = false) public static GameObject[] ComponentsToGameObjects(Component[] components, bool skipFirstComponent = false)

View File

@@ -43,7 +43,7 @@ MonoBehaviour:
Data: Data:
- Name: - Name:
Entry: 12 Entry: 12
Data: 10 Data: 12
- Name: - Name:
Entry: 7 Entry: 7
Data: Data:
@@ -163,31 +163,25 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: pellets Data: gameManager
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 9|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 9|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: pellets Data: gameManager
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 7
Data: 10|System.RuntimeType, mscorlib Data: 10|System.RuntimeType, mscorlib
- Name: - Name:
Entry: 1 Entry: 1
Data: Marro.PacManUdon.Pellet[], Assembly-CSharp Data: Marro.PacManUdon.GameManager, Assembly-CSharp
- Name: - Name:
Entry: 8 Entry: 8
Data: Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 7 Entry: 9
Data: 11|System.RuntimeType, mscorlib Data: 4
- Name:
Entry: 1
Data: UnityEngine.Component[], UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -202,7 +196,7 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 12|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 11|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 0
@@ -223,25 +217,31 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: powerPellets Data: pellets
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 13|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 12|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: powerPellets Data: pellets
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 7
Data: 14|System.RuntimeType, mscorlib Data: 13|System.RuntimeType, mscorlib
- Name: - Name:
Entry: 1 Entry: 1
Data: UnityEngine.Animator[], UnityEngine.AnimationModule Data: Marro.PacManUdon.Pellet[], Assembly-CSharp
- Name: - Name:
Entry: 8 Entry: 8
Data: Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 7
Data: 14 Data: 14|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.Component[], UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -277,19 +277,19 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: powerPelletBlinkEnabled Data: powerPellets
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 16|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 16|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: powerPelletBlinkEnabled Data: powerPellets
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 7
Data: 17|System.RuntimeType, mscorlib Data: 17|System.RuntimeType, mscorlib
- Name: - Name:
Entry: 1 Entry: 1
Data: System.Boolean, mscorlib Data: UnityEngine.Animator[], UnityEngine.AnimationModule
- Name: - Name:
Entry: 8 Entry: 8
Data: Data:
@@ -331,19 +331,19 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: powerPelletBlinkToggleInterval Data: powerPelletBlinkEnabled
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 19|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 19|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: powerPelletBlinkToggleInterval Data: powerPelletBlinkEnabled
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 7
Data: 20|System.RuntimeType, mscorlib Data: 20|System.RuntimeType, mscorlib
- Name: - Name:
Entry: 1 Entry: 1
Data: System.Single, mscorlib Data: System.Boolean, mscorlib
- Name: - Name:
Entry: 8 Entry: 8
Data: Data:
@@ -385,19 +385,73 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: powerPelletBlinkProgress Data: powerPelletBlinkToggleInterval
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 22|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 22|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: powerPelletBlinkToggleInterval
- Name: <UserType>k__BackingField
Entry: 7
Data: 23|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Single, mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 23
- 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: 24|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: powerPelletBlinkProgress
- Name: $v
Entry: 7
Data: 25|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: powerPelletBlinkProgress Data: powerPelletBlinkProgress
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 20 Data: 23
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 20 Data: 23
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -412,7 +466,7 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 23|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 26|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 0
@@ -436,70 +490,16 @@ MonoBehaviour:
Data: powerPelletBlinkCurrentlyVisible Data: powerPelletBlinkCurrentlyVisible
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 24|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 27|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: powerPelletBlinkCurrentlyVisible Data: powerPelletBlinkCurrentlyVisible
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 17 Data: 20
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 17 Data: 20
- 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: 25|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: 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 - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -535,19 +535,19 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: collisionMap Data: syncedPelletsCollected
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 29|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 29|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: collisionMap Data: syncedPelletsCollected
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 7
Data: 30|System.RuntimeType, mscorlib Data: 30|System.RuntimeType, mscorlib
- Name: - Name:
Entry: 1 Entry: 1
Data: System.Int32[], mscorlib Data: System.Byte[], mscorlib
- Name: - Name:
Entry: 8 Entry: 8
Data: Data:
@@ -584,6 +584,108 @@ MonoBehaviour:
- Name: - Name:
Entry: 8 Entry: 8
Data: Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: collisionMap
- Name: $v
Entry: 7
Data: 32|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: collisionMap
- Name: <UserType>k__BackingField
Entry: 7
Data: 33|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Int32[], mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 33
- 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: 34|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: pelletMap
- Name: $v
Entry: 7
Data: 35|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: pelletMap
- Name: <UserType>k__BackingField
Entry: 9
Data: 33
- Name: <SystemType>k__BackingField
Entry: 9
Data: 33
- 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: 36|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: - Name:
Entry: 13 Entry: 13
Data: Data:

View File

@@ -3,11 +3,19 @@ using UnityEngine;
namespace Marro.PacManUdon namespace Marro.PacManUdon
{ {
enum PelletType
{
None,
Pellet,
PowerPellet
}
public class PelletManager : SyncedObject public class PelletManager : SyncedObject
{ {
public int PelletCount => pellets.Length; public int PelletCount => pellets.Length;
public int PelletCollectedCount { get; private set; } public int PelletCollectedCount { get; private set; }
private GameManager gameManager;
Pellet[] pellets; Pellet[] pellets;
Animator[] powerPellets; Animator[] powerPellets;
@@ -19,12 +27,15 @@ namespace Marro.PacManUdon
byte[] syncedPelletsCollected; byte[] syncedPelletsCollected;
int[] collisionMap; int[] collisionMap;
int[] pelletMap;
const int mazeWidth = 28; const int mazeWidth = 28;
const int mazeHeight = 31; const int mazeHeight = 31;
public void Initialize() public void Initialize(GameManager gameManager)
{ {
this.gameManager = gameManager;
gameObject.SetActive(true); gameObject.SetActive(true);
pellets = GetComponentsInChildren<Pellet>(includeInactive: true); pellets = GetComponentsInChildren<Pellet>(includeInactive: true);
@@ -32,6 +43,8 @@ namespace Marro.PacManUdon
powerPelletBlinkToggleInterval = PacManConstants.GetPowerPelletBlinkToggleInterval(); powerPelletBlinkToggleInterval = PacManConstants.GetPowerPelletBlinkToggleInterval();
SetPowerPelletsBlink(false); SetPowerPelletsBlink(false);
collisionMap = PacManConstants.GetMazeCollisionInfo();
RestoreAllPellets(); RestoreAllPellets();
SubscribeToEvent(NetworkEventType.SyncPellets); SubscribeToEvent(NetworkEventType.SyncPellets);
@@ -87,6 +100,36 @@ namespace Marro.PacManUdon
return result; return result;
} }
internal PelletType CollectPelletAt(Vector2 position)
{
var tilemapIndex = GetTilemapIndex(position);
var tile = pelletMap[tilemapIndex];
if (tile < 0 || tile >= pellets.Length)
{
return PelletType.None;
}
pelletMap[tilemapIndex] = -1;
var pellet = pellets[tile];
pellet.gameObject.SetActive(false);
Debug.Log($"Collecting pellet {tile} ({pellet.name})");
var index = pellet.transform.GetSiblingIndex();
syncedPelletsCollected[index / 8] |= (byte)(1 << index % 8);
PelletCollectedCount++;
var pelletType = pellet.isPowerPellet ? PelletType.PowerPellet : PelletType.Pellet;
gameManager.GotPellet(pellet, pelletType, PelletCollectedCount, PelletCount - PelletCollectedCount);
return pelletType;
}
public int GetAvailableDirections(Vector2 position) public int GetAvailableDirections(Vector2 position)
{ {
var directions = GetTileAt(position); var directions = GetTileAt(position);
@@ -110,18 +153,6 @@ namespace Marro.PacManUdon
#endregion #endregion
#region Pellet collecting #region Pellet collecting
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() public int RestoreAllPellets()
{ {
foreach (var pellet in pellets) foreach (var pellet in pellets)
@@ -132,7 +163,7 @@ namespace Marro.PacManUdon
syncedPelletsCollected = new byte[pellets.Length/8 + 1]; syncedPelletsCollected = new byte[pellets.Length/8 + 1];
PelletCollectedCount = 0; PelletCollectedCount = 0;
collisionMap = PacManConstants.GetMazeCollisionInfo(); pelletMap = PacManConstants.GetMazePelletMap();
return PelletCount; return PelletCount;
} }

View File

@@ -16,7 +16,7 @@ namespace Marro.PacManUdon
// Initialize // Initialize
soundManager.SuppressSound(true); soundManager.SuppressSound(true);
attractScreen.gameObject.SetActive(true); attractScreen.gameObject.SetActive(true);
attractScreen.Initialize(); attractScreen.Initialize(this);
for (int i = 0; i <= 15; i++) for (int i = 0; i <= 15; i++)
{ {
// Debug.Log($"{gameObject} TimeSequenceAttractScreen deactivating with iteration i"); // Debug.Log($"{gameObject} TimeSequenceAttractScreen deactivating with iteration i");