diff --git a/Assets/Prefabs/Pellet.prefab b/Assets/Prefabs/Pellet.prefab index b0c96c6..32b532d 100644 --- a/Assets/Prefabs/Pellet.prefab +++ b/Assets/Prefabs/Pellet.prefab @@ -11,8 +11,6 @@ GameObject: - component: {fileID: 1315692994360949719} - component: {fileID: 967117457436250906} - component: {fileID: 7512162431685415002} - - component: {fileID: 2135601224056198654} - - component: {fileID: 3963523032509914404} - component: {fileID: 9117212235706742114} m_Layer: 0 m_Name: Pellet @@ -111,54 +109,7 @@ MonoBehaviour: SerializationNodes: [] _udonSharpBackingUdonBehaviour: {fileID: 9117212235706742114} isPowerPellet: 0 ---- !u!65 &2135601224056198654 -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 + pelletRenderer: {fileID: 0} --- !u!114 &9117212235706742114 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 5ccd1af..07f1754 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -61,7 +61,7 @@ namespace Marro.PacManUdon ghostManager.Initialize(maze.ghostStarts, maze.ghostTargets, pacMan, pelletManager, this); pacMan.Initialize(playerInput, maze.pacManStart, this, pelletManager); bonusFruit.Initialize(); - pelletManager.Initialize(); + pelletManager.Initialize(this); statusDisplay.Initialize(); playerInput.Initialize(this); soundManager.Initialize(); @@ -163,25 +163,35 @@ namespace Marro.PacManUdon 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(); + ghostManager.PelletConsumed(pelletsRemainingCount); soundManager.PlayPelletSound(); + soundManager.UpdatePelletCount(pelletsRemainingCount); - var pelletCountRemaining = pelletManager.PelletCount - pelletCollectedCount; - - soundManager.UpdatePelletCount(pelletCountRemaining); - - if (pelletCountRemaining <= 0) + if (pelletsRemainingCount <= 0) { 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(); } @@ -191,16 +201,7 @@ namespace Marro.PacManUdon { //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() @@ -453,4 +454,4 @@ namespace Marro.PacManUdon public int Level => level; } -} \ No newline at end of file +} diff --git a/Assets/Scripts/Ghost.cs b/Assets/Scripts/Ghost.cs index 0e7efd2..606e485 100644 --- a/Assets/Scripts/Ghost.cs +++ b/Assets/Scripts/Ghost.cs @@ -259,7 +259,7 @@ namespace Marro.PacManUdon 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); SetDirection(newDirection); } diff --git a/Assets/Scripts/GhostManager.cs b/Assets/Scripts/GhostManager.cs index f0d49c2..c20cb1b 100644 --- a/Assets/Scripts/GhostManager.cs +++ b/Assets/Scripts/GhostManager.cs @@ -105,7 +105,7 @@ namespace Marro.PacManUdon public void NewLevel() { SetSharedPelletCounterActive(false); - UpdateElroyLevel(); + UpdateElroyLevel(pelletManager.PelletCount); foreach (Ghost ghost in ghosts) { ghost.ResetHousePelletCounter(); @@ -404,11 +404,11 @@ namespace Marro.PacManUdon } } - public void PelletConsumed() + public void PelletConsumed(int pelletsRemainingCount) { pelletTimeout = 0; - UpdateElroyLevel(); + UpdateElroyLevel(pelletsRemainingCount); 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}"); var oldElroyLevel = elroyLevel; - var pelletsRemaining = pelletManager.PelletCount - pelletManager.PelletCollectedCount; - if (pelletsRemaining < elroy2PelletCount) elroyLevel = 2; - else if (pelletsRemaining < elroy1PelletCount) elroyLevel = 1; + if (pelletsRemainingCount < elroy2PelletCount) elroyLevel = 2; + else if (pelletsRemainingCount < elroy1PelletCount) elroyLevel = 1; else elroyLevel = 0; if (elroyLevel != oldElroyLevel) diff --git a/Assets/Scripts/PacMan.cs b/Assets/Scripts/PacMan.cs index 0775616..8187245 100644 --- a/Assets/Scripts/PacMan.cs +++ b/Assets/Scripts/PacMan.cs @@ -120,6 +120,11 @@ namespace Marro.PacManUdon } } + if (CrossesTileBorder(position, nextPosition, direction)) + { + CheckNewTile(nextPosition); + } + SetPosition(nextPosition); } @@ -207,6 +212,20 @@ namespace Marro.PacManUdon 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() { // Debug.Log($"{gameObject} UpdateAnimator with direction {direction}, dead {dead}, frozen {frozen}"); @@ -324,22 +343,7 @@ namespace Marro.PacManUdon void OnTriggerEnter(Collider other) { - Pellet pellet = other.gameObject.GetComponent(); - if (pellet) - { - if (pellet.isPowerPellet) - { - gameManager.GotPowerPellet(pellet); - freezeSeconds = 0.05f; - } - else - { - gameManager.GotPellet(pellet); - freezeSeconds = 0.0166666666666667f; - } - return; - } - else if (other.gameObject.GetComponent()) + if (other.gameObject.GetComponent()) { gameManager.GotFruit(); } diff --git a/Assets/Scripts/PacManConstants.cs b/Assets/Scripts/PacManConstants.cs index 67cfa77..9618101 100644 --- a/Assets/Scripts/PacManConstants.cs +++ b/Assets/Scripts/PacManConstants.cs @@ -97,25 +97,25 @@ namespace Marro.PacManUdon 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, 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, 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, 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, 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, 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, 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, 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, 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, -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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 244, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 124, -01, -01, -01, -01, -01, -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, 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, 197, -01, -01, -01, -01, -01, 187, -01, -01, 175, -01, -01, -01, -01, -01, 153, -01, -01, -01, -01, 002, -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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, @@ -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, 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, + }; 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, 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, - 441, 413, 385, 357, 329, 301, 273, 245, 245, 246, 247, 248, 249, 250, 222, 194, - 166, 138, 082, 054, 053, 052, 051, 050, 049, 077, 105, 133, 161, 162, 163, 164, - 165, 189, 217, 160, 159, 158, 186, 214, 242, 241, 240, 239, 157, 156, 155, 127, - 099, 071, 043, 044, 045, 046, 047, 048, 154, 153, 152, 124, 096, 068, 040, 039, - 038, 037, 036, 035, 034, 062, 090, 118, 146, 147, 148, 149, 150, 151, 177, 205, - 233, 234, 235, 236, 033, 032, 031, 030, 029, 057, 113, 141, 142, 143, 144, 145, - 169, 197, 225, 226, 227, 228, 229, 174, 202, 230, 258, 286, 314, 342, 370, 398, - 426, 454, 482, 510, 538, + 441, 413, 385, 357, 329, 301, 273, 245, 246, 247, 248, 249, 250, 222, 194, 166, + 138, 082, 054, 053, 052, 051, 050, 049, 077, 105, 133, 161, 162, 163, 164, 165, + 189, 217, 160, 159, 158, 186, 214, 242, 241, 240, 239, 157, 156, 155, 127, 099, + 071, 043, 044, 045, 046, 047, 048, 154, 153, 152, 124, 096, 068, 040, 039, 038, + 037, 036, 035, 034, 062, 090, 118, 146, 147, 148, 149, 150, 151, 177, 205, 233, + 234, 235, 236, 033, 032, 031, 030, 029, 057, 113, 141, 142, 143, 144, 145, 169, + 197, 225, 226, 227, 228, 229, 174, 202, 230, 258, 286, 314, 342, 370, 398, 426, + 454, 482, 510, 538, }; public static GameObject[] ComponentsToGameObjects(Component[] components, bool skipFirstComponent = false) diff --git a/Assets/Scripts/PelletManager.asset b/Assets/Scripts/PelletManager.asset index 3984151..b9f50f1 100644 --- a/Assets/Scripts/PelletManager.asset +++ b/Assets/Scripts/PelletManager.asset @@ -43,7 +43,7 @@ MonoBehaviour: Data: - Name: Entry: 12 - Data: 10 + Data: 12 - Name: Entry: 7 Data: @@ -163,31 +163,25 @@ MonoBehaviour: Data: - Name: $k Entry: 1 - Data: pellets + Data: gameManager - Name: $v Entry: 7 Data: 9|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor - Name: k__BackingField Entry: 1 - Data: pellets + Data: gameManager - Name: k__BackingField Entry: 7 Data: 10|System.RuntimeType, mscorlib - Name: Entry: 1 - Data: Marro.PacManUdon.Pellet[], Assembly-CSharp + Data: Marro.PacManUdon.GameManager, Assembly-CSharp - Name: Entry: 8 Data: - Name: k__BackingField - Entry: 7 - Data: 11|System.RuntimeType, mscorlib - - Name: - Entry: 1 - Data: UnityEngine.Component[], UnityEngine.CoreModule - - Name: - Entry: 8 - Data: + Entry: 9 + Data: 4 - Name: k__BackingField Entry: 7 Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib @@ -202,7 +196,7 @@ MonoBehaviour: Data: false - Name: _fieldAttributes 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: Entry: 12 Data: 0 @@ -223,25 +217,31 @@ MonoBehaviour: Data: - Name: $k Entry: 1 - Data: powerPellets + Data: pellets - Name: $v Entry: 7 - Data: 13|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor + Data: 12|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor - Name: k__BackingField Entry: 1 - Data: powerPellets + Data: pellets - Name: k__BackingField Entry: 7 - Data: 14|System.RuntimeType, mscorlib + Data: 13|System.RuntimeType, mscorlib - Name: Entry: 1 - Data: UnityEngine.Animator[], UnityEngine.AnimationModule + Data: Marro.PacManUdon.Pellet[], Assembly-CSharp - Name: Entry: 8 Data: - Name: k__BackingField - Entry: 9 - Data: 14 + Entry: 7 + Data: 14|System.RuntimeType, mscorlib + - Name: + Entry: 1 + Data: UnityEngine.Component[], UnityEngine.CoreModule + - Name: + Entry: 8 + Data: - Name: k__BackingField Entry: 7 Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib @@ -277,19 +277,19 @@ MonoBehaviour: Data: - Name: $k Entry: 1 - Data: powerPelletBlinkEnabled + Data: powerPellets - Name: $v Entry: 7 Data: 16|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor - Name: k__BackingField Entry: 1 - Data: powerPelletBlinkEnabled + Data: powerPellets - Name: k__BackingField Entry: 7 Data: 17|System.RuntimeType, mscorlib - Name: Entry: 1 - Data: System.Boolean, mscorlib + Data: UnityEngine.Animator[], UnityEngine.AnimationModule - Name: Entry: 8 Data: @@ -331,19 +331,19 @@ MonoBehaviour: Data: - Name: $k Entry: 1 - Data: powerPelletBlinkToggleInterval + Data: powerPelletBlinkEnabled - Name: $v Entry: 7 Data: 19|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor - Name: k__BackingField Entry: 1 - Data: powerPelletBlinkToggleInterval + Data: powerPelletBlinkEnabled - Name: k__BackingField Entry: 7 Data: 20|System.RuntimeType, mscorlib - Name: Entry: 1 - Data: System.Single, mscorlib + Data: System.Boolean, mscorlib - Name: Entry: 8 Data: @@ -385,19 +385,73 @@ MonoBehaviour: Data: - Name: $k Entry: 1 - Data: powerPelletBlinkProgress + Data: powerPelletBlinkToggleInterval - Name: $v Entry: 7 Data: 22|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor + - Name: k__BackingField + Entry: 1 + Data: powerPelletBlinkToggleInterval + - Name: k__BackingField + Entry: 7 + Data: 23|System.RuntimeType, mscorlib + - Name: + Entry: 1 + Data: System.Single, mscorlib + - Name: + Entry: 8 + Data: + - Name: k__BackingField + Entry: 9 + Data: 23 + - Name: k__BackingField + Entry: 7 + Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib + - Name: + Entry: 6 + Data: + - Name: + Entry: 8 + Data: + - Name: 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: k__BackingField Entry: 1 Data: powerPelletBlinkProgress - Name: k__BackingField Entry: 9 - Data: 20 + Data: 23 - Name: k__BackingField Entry: 9 - Data: 20 + Data: 23 - Name: k__BackingField Entry: 7 Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib @@ -412,7 +466,7 @@ MonoBehaviour: Data: false - Name: _fieldAttributes 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: Entry: 12 Data: 0 @@ -436,70 +490,16 @@ MonoBehaviour: Data: powerPelletBlinkCurrentlyVisible - Name: $v Entry: 7 - Data: 24|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor + Data: 27|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor - Name: k__BackingField Entry: 1 Data: powerPelletBlinkCurrentlyVisible - Name: k__BackingField Entry: 9 - Data: 17 + Data: 20 - Name: k__BackingField Entry: 9 - Data: 17 - - Name: k__BackingField - Entry: 7 - Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib - - Name: - Entry: 6 - Data: - - Name: - Entry: 8 - Data: - - Name: 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: k__BackingField - Entry: 1 - Data: syncedPelletsCollected - - Name: k__BackingField - Entry: 7 - Data: 27|System.RuntimeType, mscorlib - - Name: - Entry: 1 - Data: System.Byte[], mscorlib - - Name: - Entry: 8 - Data: - - Name: k__BackingField - Entry: 9 - Data: 27 + Data: 20 - Name: k__BackingField Entry: 7 Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib @@ -535,19 +535,19 @@ MonoBehaviour: Data: - Name: $k Entry: 1 - Data: collisionMap + Data: syncedPelletsCollected - Name: $v Entry: 7 Data: 29|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor - Name: k__BackingField Entry: 1 - Data: collisionMap + Data: syncedPelletsCollected - Name: k__BackingField Entry: 7 Data: 30|System.RuntimeType, mscorlib - Name: Entry: 1 - Data: System.Int32[], mscorlib + Data: System.Byte[], mscorlib - Name: Entry: 8 Data: @@ -584,6 +584,108 @@ MonoBehaviour: - Name: Entry: 8 Data: + - Name: + Entry: 7 + Data: + - Name: $k + Entry: 1 + Data: collisionMap + - Name: $v + Entry: 7 + Data: 32|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor + - Name: k__BackingField + Entry: 1 + Data: collisionMap + - Name: k__BackingField + Entry: 7 + Data: 33|System.RuntimeType, mscorlib + - Name: + Entry: 1 + Data: System.Int32[], mscorlib + - Name: + Entry: 8 + Data: + - Name: k__BackingField + Entry: 9 + Data: 33 + - Name: k__BackingField + Entry: 7 + Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib + - Name: + Entry: 6 + Data: + - Name: + Entry: 8 + Data: + - Name: 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: k__BackingField + Entry: 1 + Data: pelletMap + - Name: k__BackingField + Entry: 9 + Data: 33 + - Name: k__BackingField + Entry: 9 + Data: 33 + - Name: k__BackingField + Entry: 7 + Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib + - Name: + Entry: 6 + Data: + - Name: + Entry: 8 + Data: + - Name: 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: Entry: 13 Data: diff --git a/Assets/Scripts/PelletManager.cs b/Assets/Scripts/PelletManager.cs index dcc5721..45f68cc 100644 --- a/Assets/Scripts/PelletManager.cs +++ b/Assets/Scripts/PelletManager.cs @@ -3,11 +3,19 @@ using UnityEngine; namespace Marro.PacManUdon { + enum PelletType + { + None, + Pellet, + PowerPellet + } public class PelletManager : SyncedObject { public int PelletCount => pellets.Length; public int PelletCollectedCount { get; private set; } + private GameManager gameManager; + Pellet[] pellets; Animator[] powerPellets; @@ -19,12 +27,15 @@ namespace Marro.PacManUdon byte[] syncedPelletsCollected; int[] collisionMap; + int[] pelletMap; const int mazeWidth = 28; const int mazeHeight = 31; - public void Initialize() + public void Initialize(GameManager gameManager) { + this.gameManager = gameManager; + gameObject.SetActive(true); pellets = GetComponentsInChildren(includeInactive: true); @@ -32,6 +43,8 @@ namespace Marro.PacManUdon powerPelletBlinkToggleInterval = PacManConstants.GetPowerPelletBlinkToggleInterval(); SetPowerPelletsBlink(false); + collisionMap = PacManConstants.GetMazeCollisionInfo(); + RestoreAllPellets(); SubscribeToEvent(NetworkEventType.SyncPellets); @@ -87,6 +100,36 @@ namespace Marro.PacManUdon 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) { var directions = GetTileAt(position); @@ -110,18 +153,6 @@ namespace Marro.PacManUdon #endregion #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() { foreach (var pellet in pellets) @@ -132,7 +163,7 @@ namespace Marro.PacManUdon syncedPelletsCollected = new byte[pellets.Length/8 + 1]; PelletCollectedCount = 0; - collisionMap = PacManConstants.GetMazeCollisionInfo(); + pelletMap = PacManConstants.GetMazePelletMap(); return PelletCount; } diff --git a/Assets/Scripts/Sequences/AttractScreenIntroduction.cs b/Assets/Scripts/Sequences/AttractScreenIntroduction.cs index 02b98ef..bbb3dcc 100644 --- a/Assets/Scripts/Sequences/AttractScreenIntroduction.cs +++ b/Assets/Scripts/Sequences/AttractScreenIntroduction.cs @@ -16,7 +16,7 @@ namespace Marro.PacManUdon // Initialize soundManager.SuppressSound(true); attractScreen.gameObject.SetActive(true); - attractScreen.Initialize(); + attractScreen.Initialize(this); for (int i = 0; i <= 15; i++) { // Debug.Log($"{gameObject} TimeSequenceAttractScreen deactivating with iteration i");