diff --git a/Assets/Scripts/BonusFruit.cs b/Assets/Scripts/BonusFruit.cs index f907f2e..9593dae 100644 --- a/Assets/Scripts/BonusFruit.cs +++ b/Assets/Scripts/BonusFruit.cs @@ -6,14 +6,12 @@ namespace Marro.PacManUdon { [RequireComponent(typeof(Animator))] [RequireComponent(typeof(Renderer))] - [RequireComponent(typeof(Collider))] public class BonusFruit : SyncedObject { PacManFruitType fruitType; Animator animator; new Renderer renderer; - new Collider collider; ScoreBonusDisplay scoreBonusDisplay; [UdonSynced] bool active; @@ -25,7 +23,6 @@ namespace Marro.PacManUdon { animator = GetComponent(); renderer = GetComponent(); - collider = GetComponent(); scoreBonusDisplay = transform.Find("ScoreBonusDisplay").gameObject.GetComponent(); scoreBonusDisplay.Initialize(); SetActive(false); @@ -78,7 +75,6 @@ namespace Marro.PacManUdon void SetActive(bool active) { // This replaces GameObject.active, as attempting to update an animator while a gameobject is inactive seems to result in a silent failure renderer.enabled = active; - collider.enabled = active; this.active = active; } diff --git a/Assets/Scripts/Fruit.asset b/Assets/Scripts/Fruit.asset index bba853e..6b85324 100644 --- a/Assets/Scripts/Fruit.asset +++ b/Assets/Scripts/Fruit.asset @@ -43,7 +43,7 @@ MonoBehaviour: Data: - Name: Entry: 12 - Data: 11 + Data: 10 - Name: Entry: 7 Data: @@ -277,25 +277,25 @@ MonoBehaviour: Data: - Name: $k Entry: 1 - Data: collider + Data: scoreBonusDisplay - Name: $v Entry: 7 Data: 16|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor - Name: k__BackingField Entry: 1 - Data: collider + Data: scoreBonusDisplay - Name: k__BackingField Entry: 7 Data: 17|System.RuntimeType, mscorlib - Name: Entry: 1 - Data: UnityEngine.Collider, UnityEngine.PhysicsModule + Data: Marro.PacManUdon.ScoreBonusDisplay, Assembly-CSharp - Name: Entry: 8 Data: - Name: k__BackingField Entry: 9 - Data: 17 + Data: 4 - Name: k__BackingField Entry: 7 Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib @@ -331,25 +331,79 @@ MonoBehaviour: Data: - Name: $k Entry: 1 - Data: scoreBonusDisplay + Data: active - Name: $v Entry: 7 Data: 19|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor - Name: k__BackingField Entry: 1 - Data: scoreBonusDisplay + Data: active - Name: k__BackingField Entry: 7 Data: 20|System.RuntimeType, mscorlib - Name: Entry: 1 - Data: Marro.PacManUdon.ScoreBonusDisplay, Assembly-CSharp + Data: System.Boolean, mscorlib - Name: Entry: 8 Data: - Name: k__BackingField Entry: 9 - Data: 4 + Data: 20 + - Name: k__BackingField + Entry: 7 + Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib + - Name: + Entry: 3 + Data: 1 + - Name: + Entry: 8 + Data: + - Name: k__BackingField + Entry: 5 + Data: false + - Name: _fieldAttributes + Entry: 7 + Data: 21|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib + - Name: + Entry: 12 + Data: 1 + - Name: + Entry: 7 + Data: 22|UdonSharp.UdonSyncedAttribute, 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: value + - Name: $v + Entry: 7 + Data: 23|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor + - Name: k__BackingField + Entry: 1 + Data: value + - Name: k__BackingField + Entry: 9 + Data: 8 + - Name: k__BackingField + Entry: 9 + Data: 8 - Name: k__BackingField Entry: 7 Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib @@ -364,7 +418,7 @@ MonoBehaviour: Data: false - Name: _fieldAttributes Entry: 7 - Data: 21|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib + Data: 24|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib - Name: Entry: 12 Data: 0 @@ -385,79 +439,25 @@ MonoBehaviour: Data: - Name: $k Entry: 1 - Data: active + Data: activeCountdown - Name: $v Entry: 7 - Data: 22|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor + Data: 25|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor - Name: k__BackingField Entry: 1 - Data: active + Data: activeCountdown - Name: k__BackingField Entry: 7 - Data: 23|System.RuntimeType, mscorlib + Data: 26|System.RuntimeType, mscorlib - Name: Entry: 1 - Data: System.Boolean, mscorlib + 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: 3 - Data: 1 - - 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: 1 - - Name: - Entry: 7 - Data: 25|UdonSharp.UdonSyncedAttribute, 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: value - - Name: $v - Entry: 7 - Data: 26|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor - - Name: k__BackingField - Entry: 1 - Data: value - - Name: k__BackingField - Entry: 9 - Data: 8 - - Name: k__BackingField - Entry: 9 - Data: 8 + Data: 26 - Name: k__BackingField Entry: 7 Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib @@ -493,25 +493,19 @@ MonoBehaviour: Data: - Name: $k Entry: 1 - Data: activeCountdown + Data: frozen - Name: $v Entry: 7 Data: 28|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor - Name: k__BackingField Entry: 1 - Data: activeCountdown + Data: frozen - Name: k__BackingField - Entry: 7 - Data: 29|System.RuntimeType, mscorlib - - Name: - Entry: 1 - Data: System.Single, mscorlib - - Name: - Entry: 8 - Data: + Entry: 9 + Data: 20 - Name: k__BackingField Entry: 9 - Data: 29 + Data: 20 - Name: k__BackingField Entry: 7 Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib @@ -526,7 +520,7 @@ MonoBehaviour: Data: false - Name: _fieldAttributes Entry: 7 - Data: 30|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib + Data: 29|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib - Name: Entry: 12 Data: 0 @@ -547,19 +541,25 @@ MonoBehaviour: Data: - Name: $k Entry: 1 - Data: frozen + Data: fruitScoreValue - Name: $v Entry: 7 - Data: 31|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor + Data: 30|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor - Name: k__BackingField Entry: 1 - Data: frozen + Data: fruitScoreValue - Name: k__BackingField - Entry: 9 - Data: 23 + Entry: 7 + Data: 31|System.RuntimeType, mscorlib + - Name: + Entry: 1 + Data: VRC.SDK3.Data.DataDictionary, VRCSDK3 + - Name: + Entry: 8 + Data: - Name: k__BackingField Entry: 9 - Data: 23 + Data: 31 - Name: k__BackingField Entry: 7 Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib @@ -590,60 +590,6 @@ MonoBehaviour: - Name: Entry: 8 Data: - - Name: - Entry: 7 - Data: - - Name: $k - Entry: 1 - Data: fruitScoreValue - - Name: $v - Entry: 7 - Data: 33|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor - - Name: k__BackingField - Entry: 1 - Data: fruitScoreValue - - Name: k__BackingField - Entry: 7 - Data: 34|System.RuntimeType, mscorlib - - Name: - Entry: 1 - Data: VRC.SDK3.Data.DataDictionary, VRCSDK3 - - Name: - Entry: 8 - Data: - - Name: k__BackingField - Entry: 9 - Data: 34 - - 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: 35|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/GameManager.cs b/Assets/Scripts/GameManager.cs index 07f1754..b09126c 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(this); + pelletManager.Initialize(this, bonusFruit); statusDisplay.Initialize(); playerInput.Initialize(this); soundManager.Initialize(); diff --git a/Assets/Scripts/GridMover.cs b/Assets/Scripts/GridMover.cs index 15a0338..f9bcc19 100644 --- a/Assets/Scripts/GridMover.cs +++ b/Assets/Scripts/GridMover.cs @@ -199,11 +199,11 @@ namespace Marro.PacManUdon if (IsHorizontal(direction)) { - result = result || Math.Floor(currentPosition.x) != Math.Floor(nextPosition.x); + result = Math.Floor(currentPosition.x) != Math.Floor(nextPosition.x); } - if (IsVertical(direction)) + if (!result && IsVertical(direction)) { - result = result || Math.Floor(currentPosition.y) != Math.Floor(nextPosition.y); + result = Math.Floor(currentPosition.y) != Math.Floor(nextPosition.y); } return result; @@ -215,15 +215,11 @@ namespace Marro.PacManUdon if (IsHorizontal(direction)) { - result = result || nextPosition.x != currentPosition.x - && ((Math.Floor(currentPosition.x) != Math.Floor(nextPosition.x) && nextPosition.x % 1 != 0) - || currentPosition.x % 1 == 0); + result = Math.Round(currentPosition.x) != Math.Round(nextPosition.x); } - if (IsVertical(direction)) + if (!result && IsVertical(direction)) { - result = result || nextPosition.y != currentPosition.y - && ((Math.Floor(currentPosition.y) != Math.Floor(nextPosition.y) && nextPosition.y % 1 != 0) - || currentPosition.y % 1 == 0); + result = Math.Round(currentPosition.y) != Math.Round(nextPosition.y); } return result; } diff --git a/Assets/Scripts/PacMan.cs b/Assets/Scripts/PacMan.cs index 8187245..5991bd2 100644 --- a/Assets/Scripts/PacMan.cs +++ b/Assets/Scripts/PacMan.cs @@ -122,7 +122,7 @@ namespace Marro.PacManUdon if (CrossesTileBorder(position, nextPosition, direction)) { - CheckNewTile(nextPosition); + CheckNewTile(position, nextPosition); } SetPosition(nextPosition); @@ -212,9 +212,9 @@ namespace Marro.PacManUdon return nextPosition; } - private void CheckNewTile(Vector2 position) + private void CheckNewTile(Vector2 position, Vector2 nextPosition) { - var pellet = pelletManager.CollectPelletAt(position); + var pellet = pelletManager.EatAtTile(position, nextPosition); if (pellet == PelletType.Pellet) { @@ -341,14 +341,6 @@ namespace Marro.PacManUdon UpdateAnimator(); } - void OnTriggerEnter(Collider other) - { - if (other.gameObject.GetComponent()) - { - gameManager.GotFruit(); - } - } - public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType) { if (eventType != NetworkEventType.PacManTurn) diff --git a/Assets/Scripts/PacManConstants.cs b/Assets/Scripts/PacManConstants.cs index 9618101..9f88814 100644 --- a/Assets/Scripts/PacManConstants.cs +++ b/Assets/Scripts/PacManConstants.cs @@ -50,12 +50,19 @@ namespace Marro.PacManUdon Intermission3 } - public enum PacManTileType + public enum PacManCollisionType { Empty = -1, Wall = -2, } + public enum PacManConsumableType + { + None = -1, + FruitLeft = -2, + FruitRight = -3, + } + public static class PacManConstants { // Jagged or 2D arrays can't be static so we work with 1D arrays @@ -113,7 +120,7 @@ namespace Marro.PacManUdon -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, 241, -01, -01, -01, -01, -01, -01, -02, -03, -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, @@ -127,7 +134,6 @@ 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[] diff --git a/Assets/Scripts/PelletManager.asset b/Assets/Scripts/PelletManager.asset index b9f50f1..e420600 100644 --- a/Assets/Scripts/PelletManager.asset +++ b/Assets/Scripts/PelletManager.asset @@ -43,7 +43,7 @@ MonoBehaviour: Data: - Name: Entry: 12 - Data: 12 + Data: 13 - Name: Entry: 7 Data: @@ -217,31 +217,25 @@ MonoBehaviour: Data: - Name: $k Entry: 1 - Data: pellets + Data: bonusFruit - Name: $v Entry: 7 Data: 12|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor - Name: k__BackingField Entry: 1 - Data: pellets + Data: bonusFruit - Name: k__BackingField Entry: 7 Data: 13|System.RuntimeType, mscorlib - Name: Entry: 1 - Data: Marro.PacManUdon.Pellet[], Assembly-CSharp + Data: Marro.PacManUdon.BonusFruit, Assembly-CSharp - Name: Entry: 8 Data: - Name: k__BackingField - Entry: 7 - Data: 14|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 @@ -256,7 +250,7 @@ MonoBehaviour: Data: false - Name: _fieldAttributes Entry: 7 - Data: 15|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib + Data: 14|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib - Name: Entry: 12 Data: 0 @@ -277,25 +271,31 @@ MonoBehaviour: Data: - Name: $k Entry: 1 - Data: powerPellets + Data: pellets - Name: $v Entry: 7 - Data: 16|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor + Data: 15|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor - Name: k__BackingField Entry: 1 - Data: powerPellets + Data: pellets - Name: k__BackingField Entry: 7 - Data: 17|System.RuntimeType, mscorlib + Data: 16|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: 17 + Entry: 7 + Data: 17|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 @@ -331,19 +331,19 @@ MonoBehaviour: Data: - Name: $k Entry: 1 - Data: powerPelletBlinkEnabled + Data: powerPellets - Name: $v Entry: 7 Data: 19|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor - Name: k__BackingField Entry: 1 - Data: powerPelletBlinkEnabled + Data: powerPellets - Name: k__BackingField Entry: 7 Data: 20|System.RuntimeType, mscorlib - Name: Entry: 1 - Data: System.Boolean, mscorlib + Data: UnityEngine.Animator[], UnityEngine.AnimationModule - Name: Entry: 8 Data: @@ -385,19 +385,19 @@ MonoBehaviour: Data: - Name: $k Entry: 1 - Data: powerPelletBlinkToggleInterval + Data: powerPelletBlinkEnabled - Name: $v Entry: 7 Data: 22|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor - Name: k__BackingField Entry: 1 - Data: powerPelletBlinkToggleInterval + Data: powerPelletBlinkEnabled - Name: k__BackingField Entry: 7 Data: 23|System.RuntimeType, mscorlib - Name: Entry: 1 - Data: System.Single, mscorlib + Data: System.Boolean, mscorlib - Name: Entry: 8 Data: @@ -439,19 +439,73 @@ MonoBehaviour: Data: - Name: $k Entry: 1 - Data: powerPelletBlinkProgress + Data: powerPelletBlinkToggleInterval - Name: $v Entry: 7 Data: 25|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor + - Name: k__BackingField + Entry: 1 + Data: powerPelletBlinkToggleInterval + - Name: k__BackingField + Entry: 7 + Data: 26|System.RuntimeType, mscorlib + - Name: + Entry: 1 + Data: System.Single, mscorlib + - Name: + Entry: 8 + Data: + - Name: k__BackingField + Entry: 9 + Data: 26 + - 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: 27|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: 28|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor - Name: k__BackingField Entry: 1 Data: powerPelletBlinkProgress - Name: k__BackingField Entry: 9 - Data: 23 + Data: 26 - Name: k__BackingField Entry: 9 - Data: 23 + Data: 26 - Name: k__BackingField Entry: 7 Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib @@ -466,7 +520,7 @@ MonoBehaviour: Data: false - Name: _fieldAttributes Entry: 7 - Data: 26|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib + Data: 29|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib - Name: Entry: 12 Data: 0 @@ -490,70 +544,16 @@ MonoBehaviour: Data: powerPelletBlinkCurrentlyVisible - Name: $v Entry: 7 - Data: 27|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor + Data: 30|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor - Name: k__BackingField Entry: 1 Data: powerPelletBlinkCurrentlyVisible - Name: k__BackingField Entry: 9 - Data: 20 + Data: 23 - Name: k__BackingField Entry: 9 - Data: 20 - - 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: 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: 7 - Data: - - Name: $k - Entry: 1 - Data: syncedPelletsCollected - - Name: $v - Entry: 7 - Data: 29|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor - - Name: k__BackingField - Entry: 1 - Data: syncedPelletsCollected - - Name: k__BackingField - Entry: 7 - Data: 30|System.RuntimeType, mscorlib - - Name: - Entry: 1 - Data: System.Byte[], mscorlib - - Name: - Entry: 8 - Data: - - Name: k__BackingField - Entry: 9 - Data: 30 + Data: 23 - Name: k__BackingField Entry: 7 Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib @@ -589,19 +589,19 @@ MonoBehaviour: Data: - Name: $k Entry: 1 - Data: collisionMap + Data: syncedPelletsCollected - Name: $v Entry: 7 Data: 32|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor - Name: k__BackingField Entry: 1 - Data: collisionMap + Data: syncedPelletsCollected - Name: k__BackingField Entry: 7 Data: 33|System.RuntimeType, mscorlib - Name: Entry: 1 - Data: System.Int32[], mscorlib + Data: System.Byte[], mscorlib - Name: Entry: 8 Data: @@ -643,19 +643,25 @@ MonoBehaviour: Data: - Name: $k Entry: 1 - Data: pelletMap + Data: collisionMap - Name: $v Entry: 7 Data: 35|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor - Name: k__BackingField Entry: 1 - Data: pelletMap + Data: collisionMap - Name: k__BackingField - Entry: 9 - Data: 33 + Entry: 7 + Data: 36|System.RuntimeType, mscorlib + - Name: + Entry: 1 + Data: System.Int32[], mscorlib + - Name: + Entry: 8 + Data: - Name: k__BackingField Entry: 9 - Data: 33 + Data: 36 - Name: k__BackingField Entry: 7 Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib @@ -670,7 +676,55 @@ MonoBehaviour: Data: false - Name: _fieldAttributes Entry: 7 - Data: 36|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib + Data: 37|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: 38|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor + - Name: k__BackingField + Entry: 1 + Data: pelletMap + - Name: k__BackingField + Entry: 9 + Data: 36 + - Name: k__BackingField + Entry: 9 + Data: 36 + - 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: 39|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib - Name: Entry: 12 Data: 0 diff --git a/Assets/Scripts/PelletManager.cs b/Assets/Scripts/PelletManager.cs index 45f68cc..dfb04fe 100644 --- a/Assets/Scripts/PelletManager.cs +++ b/Assets/Scripts/PelletManager.cs @@ -15,6 +15,7 @@ namespace Marro.PacManUdon public int PelletCollectedCount { get; private set; } private GameManager gameManager; + private BonusFruit bonusFruit; Pellet[] pellets; Animator[] powerPellets; @@ -32,9 +33,10 @@ namespace Marro.PacManUdon const int mazeWidth = 28; const int mazeHeight = 31; - public void Initialize(GameManager gameManager) + public void Initialize(GameManager gameManager, BonusFruit bonusFruit) { this.gameManager = gameManager; + this.bonusFruit = bonusFruit; gameObject.SetActive(true); pellets = GetComponentsInChildren(includeInactive: true); @@ -96,38 +98,38 @@ namespace Marro.PacManUdon #region Collision public bool IsWallUpcoming(Vector2 position, Vector2 directionVector) { - var result = GetTileAt(position + directionVector) == (int)PacManTileType.Wall; + var result = GetTileAt(position + directionVector) == (int)PacManCollisionType.Wall; return result; } - internal PelletType CollectPelletAt(Vector2 position) + internal PelletType EatAtTile(Vector2 position, Vector2 nextPosition) { - var tilemapIndex = GetTilemapIndex(position); - + var tilemapIndex = GetTilemapIndex(nextPosition); var tile = pelletMap[tilemapIndex]; - if (tile < 0 || tile >= pellets.Length) + TryCollectFruit(tile, position, nextPosition); + return TryCollectPellet(tile, tilemapIndex); + } + + private void TryCollectFruit(int tile, Vector2 position, Vector2 nextPosition) + { + if (tile != (int)PacManConsumableType.FruitLeft && tile != (int)PacManConsumableType.FruitRight + || !bonusFruit.Active) { - return PelletType.None; + return; } - pelletMap[tilemapIndex] = -1; + var previousTile = pelletMap[GetTilemapIndex(position)]; - var pellet = pellets[tile]; - pellet.gameObject.SetActive(false); + Debug.Log($"On fruit tile {tile}, previous tile was {previousTile}. Position {position}, nextPosition {nextPosition}"); - Debug.Log($"Collecting pellet {tile} ({pellet.name})"); + if (tile == (int)PacManConsumableType.FruitLeft && previousTile == (int)PacManConsumableType.FruitRight + || tile == (int)PacManConsumableType.FruitRight && previousTile == (int)PacManConsumableType.FruitLeft) + { + Debug.Log("Collecting fruit"); - 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; + gameManager.GotFruit(); + } } public int GetAvailableDirections(Vector2 position) @@ -144,7 +146,7 @@ namespace Marro.PacManUdon private int GetTileAt(Vector2 position) => collisionMap[GetTilemapIndex(position)]; - private int GetTilemapIndex(Vector2 position) + internal static int GetTilemapIndex(Vector2 position) { position = Clamp(position, 0, mazeWidth - 1, 1 - mazeHeight, 0); var index = (int)(position.x + 0.5) - (int)(position.y - 0.5) * mazeWidth; @@ -153,6 +155,30 @@ namespace Marro.PacManUdon #endregion #region Pellet collecting + private PelletType TryCollectPellet(int tile, int tilemapIndex) + { + if (tile < 0 || tile >= pellets.Length) + { + return PelletType.None; + } + + pelletMap[tilemapIndex] = -1; + + var pellet = pellets[tile]; + pellet.gameObject.SetActive(false); + + 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 RestoreAllPellets() { foreach (var pellet in pellets) diff --git a/Assets/Scripts/Sequences/AttractScreenIntroduction.cs b/Assets/Scripts/Sequences/AttractScreenIntroduction.cs index bbb3dcc..8b1fb8b 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(this); + attractScreen.Initialize(this, bonusFruit); for (int i = 0; i <= 15; i++) { // Debug.Log($"{gameObject} TimeSequenceAttractScreen deactivating with iteration i"); diff --git a/Assets/Test stuff/MazeDefinitionGenerator.asset b/Assets/Test stuff/MazeDefinitionGenerator.asset index ba06c41..5ff1ce7 100644 --- a/Assets/Test stuff/MazeDefinitionGenerator.asset +++ b/Assets/Test stuff/MazeDefinitionGenerator.asset @@ -41,6 +41,54 @@ MonoBehaviour: - Name: Entry: 8 Data: + - Name: + Entry: 12 + Data: 2 + - Name: + Entry: 7 + Data: + - Name: $k + Entry: 1 + Data: bonusFruit + - Name: $v + Entry: 7 + Data: 2|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor + - Name: k__BackingField + Entry: 1 + Data: bonusFruit + - Name: k__BackingField + Entry: 7 + Data: 3|System.RuntimeType, mscorlib + - Name: + Entry: 1 + Data: Marro.PacManUdon.BonusFruit, Assembly-CSharp + - Name: + Entry: 8 + Data: + - Name: k__BackingField + Entry: 7 + Data: 4|System.RuntimeType, mscorlib + - Name: + Entry: 1 + Data: VRC.Udon.UdonBehaviour, VRC.Udon + - Name: + Entry: 8 + Data: + - 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: true + - Name: _fieldAttributes + Entry: 7 + Data: 5|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib - Name: Entry: 12 Data: 0 @@ -50,3 +98,69 @@ MonoBehaviour: - Name: Entry: 8 Data: + - Name: + Entry: 8 + Data: + - Name: + Entry: 8 + Data: + - Name: + Entry: 7 + Data: + - Name: $k + Entry: 1 + Data: pelletManager + - Name: $v + Entry: 7 + Data: 6|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor + - Name: k__BackingField + Entry: 1 + Data: pelletManager + - Name: k__BackingField + Entry: 7 + Data: 7|System.RuntimeType, mscorlib + - Name: + Entry: 1 + Data: Marro.PacManUdon.PelletManager, Assembly-CSharp + - Name: + Entry: 8 + Data: + - Name: k__BackingField + Entry: 9 + Data: 4 + - 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: true + - Name: _fieldAttributes + Entry: 7 + Data: 8|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: + - Name: + Entry: 8 + Data: diff --git a/Assets/Test stuff/MazeDefinitionGenerator.cs b/Assets/Test stuff/MazeDefinitionGenerator.cs index f245b14..364c1ff 100644 --- a/Assets/Test stuff/MazeDefinitionGenerator.cs +++ b/Assets/Test stuff/MazeDefinitionGenerator.cs @@ -2,11 +2,15 @@ using Marro.PacManUdon; using UdonSharp; using UnityEngine; +using UnityEngine.UIElements; using VRC.SDKBase; using VRC.Udon; public class MazeDefinitionGenerator : UdonSharpBehaviour { + public BonusFruit bonusFruit; + public PelletManager pelletManager; + void Start() { PrintPelletMap(); @@ -18,7 +22,7 @@ public class MazeDefinitionGenerator : UdonSharpBehaviour var width = 28; var height = 31; - var pellets = GetComponentsInChildren(includeInactive: true); + var pellets = pelletManager.gameObject.GetComponentsInChildren(includeInactive: true); int[] map = new int[width * height]; int[] pelletLocations = new int[pellets.Length]; @@ -37,10 +41,21 @@ public class MazeDefinitionGenerator : UdonSharpBehaviour pelletLocations[i] = index; } + WriteBonusFruitTiles(map); + PrintMap(map, width); PrintMap(pelletLocations, 16); } + private void WriteBonusFruitTiles(int[] map) + { + var position = bonusFruit.transform.localPosition; + var leftTileIndex = PelletManager.GetTilemapIndex(new Vector2(position.x - 0.5f, position.y)); + map[leftTileIndex] = (int)PacManConsumableType.FruitLeft; + var rightTileIndex = PelletManager.GetTilemapIndex(new Vector2(position.x + 0.5f, position.y)); + map[rightTileIndex] = (int)PacManConsumableType.FruitRight; + } + private void PrintMazeMap() { var width = 28; @@ -53,7 +68,7 @@ public class MazeDefinitionGenerator : UdonSharpBehaviour { if (collisionMap[i]) { - map[i] = (int)PacManTileType.Wall; + map[i] = (int)PacManCollisionType.Wall; continue; } @@ -90,12 +105,12 @@ public class MazeDefinitionGenerator : UdonSharpBehaviour if (totalAvailableDirections < 2) { - return (int)PacManTileType.Empty; + return (int)PacManCollisionType.Empty; } if (availableDirections == 0b0011 || availableDirections == 0b1100) { - return (int)PacManTileType.Empty; + return (int)PacManCollisionType.Empty; } return availableDirections;