From 8684f1ecc7d33a4743396e30e4fb2999c8f31398 Mon Sep 17 00:00:00 2001 From: Marro64 Date: Wed, 17 Jun 2026 12:12:17 +0200 Subject: [PATCH] Maze 32x32 --- Assets/Maze/maze collision.bmp | Bin 186 -> 582 bytes Assets/PacManGame.prefab | 1725 +++++++++-------- Assets/Prefabs/Ghost.prefab | 257 ++- Assets/Scenes/PacMan.unity | 294 ++- Assets/Scripts/Ghost.cs | 58 +- Assets/Scripts/GridMover.cs | 8 +- Assets/Scripts/PacMan.cs | 4 +- Assets/Scripts/PacManConstants.cs | 177 +- Assets/Scripts/PelletManager.asset | 22 +- Assets/Scripts/PelletManager.cs | 38 +- .../Test stuff/MazeDefinitionGenerator.asset | 2 +- Assets/Test stuff/MazeDefinitionGenerator.cs | 372 ++-- 12 files changed, 1747 insertions(+), 1210 deletions(-) diff --git a/Assets/Maze/maze collision.bmp b/Assets/Maze/maze collision.bmp index dcd2fdb3cd9424e0743c7bab11168371e246e318..f2cf33641e2322123a347d4698d1f83aad0435a5 100644 GIT binary patch literal 582 zcma)2K@tKX3@gr_9jYJDi{sVd2Ojq3ul?7Ww1oxbU}gzTX}f{vYdwfz1>dnQv63u^ z9PgtD7c-IF2w6Zk*=k+elXl1=$xd=?6Rnz4e2RKBcrlprTPGF#;CccH>oFM27LR_k z*}*Re8@SImYu;R$DK8Goraen0nm@#)ln0yus%HpB{rOzee>dM-;M}p_2O7qQ_u>7l Yk{tIRv|ThP&fENdw6zZJRejC&4;afAfB*mh literal 186 zcmZ?r-NgU_c0fu4h-H9S9*7x%5C)F$F))BI6Howz{{sPt0?F6^|Np>&lR*K5>nfi= z5OPpy0O8{Qe;zn-vM7LX{m=gom>g6XemSUq_*MV(1BhmdU&8SJ{(dkG7w2UCz{JVI Z05ZqPK}7+CLFR+Zh()) - { - horizontalOnly = true; - } - else if (other.gameObject.GetComponent()) - { - SetInTunnel(true); - } - } - - void OnTriggerExit(Collider other) - { - if (other.gameObject.GetComponent()) - { - horizontalOnly = false; - } - else if (other.gameObject.GetComponent()) - { - SetInTunnel(false); - } } } } \ No newline at end of file diff --git a/Assets/Scripts/GridMover.cs b/Assets/Scripts/GridMover.cs index f9bcc19..410a0f1 100644 --- a/Assets/Scripts/GridMover.cs +++ b/Assets/Scripts/GridMover.cs @@ -21,7 +21,7 @@ namespace Marro.PacManUdon // Cannot be static, much to my annoyance public readonly Vector2[] directionVectors = - { + { Vector2.zero, // 0 Vector2.down, // 1 Vector2.up, // 2 @@ -190,10 +190,10 @@ namespace Marro.PacManUdon public static Vector2 PositionToGrid(Vector2 position) { - return new Vector2((float)Math.Round(position.x), (float)Math.Round(position.y)); + return new Vector2((float)Math.Round(position.x-0.5f)+0.5f, (float)Math.Round(position.y-0.5f)+0.5f); } - public static bool CrossesTileCenter(Vector2 currentPosition, Vector2 nextPosition, Direction direction) + public static bool CrossesTileBorder(Vector2 currentPosition, Vector2 nextPosition, Direction direction) { bool result = false; @@ -209,7 +209,7 @@ namespace Marro.PacManUdon return result; } - public static bool CrossesTileBorder(Vector2 currentPosition, Vector2 nextPosition, Direction direction) + public static bool CrossesTileCenter(Vector2 currentPosition, Vector2 nextPosition, Direction direction) { bool result = false; diff --git a/Assets/Scripts/PacMan.cs b/Assets/Scripts/PacMan.cs index 5991bd2..7124f63 100644 --- a/Assets/Scripts/PacMan.cs +++ b/Assets/Scripts/PacMan.cs @@ -148,8 +148,8 @@ namespace Marro.PacManUdon var inputDirection = input.GetDirection(); if (!inputDirection.Equals(Direction.Zero) && !inputDirection.Equals(targetDirection) // Ignore neutral input or input in our current direction - && (!IsHorizontal(inputDirection) || (Math.Round(nextPosition.y, 5) - 0.5) % 1 != 0) // Target grid position near the edge of a tile may not be correct, ignore inputs near the border - && (!IsVertical(inputDirection) || (Math.Round(nextPosition.x, 5) - 0.5) % 1 != 0) + //&& (!IsHorizontal(inputDirection) || (Math.Round(nextPosition.x, 5) - 0.5) % 1 != 0) // Target grid position near the edge of a tile may not be correct, ignore inputs near the border + //&& (!IsVertical(inputDirection) || (Math.Round(nextPosition.y, 5) - 0.5) % 1 != 0) && !pelletManager.IsWallUpcoming(nextPosition, directionVectors[(int)inputDirection])) { // Check if the requested direction does not have a wall if (IsHorizontal(inputDirection)) diff --git a/Assets/Scripts/PacManConstants.cs b/Assets/Scripts/PacManConstants.cs index 9f88814..976ac56 100644 --- a/Assets/Scripts/PacManConstants.cs +++ b/Assets/Scripts/PacManConstants.cs @@ -1,7 +1,6 @@ namespace Marro.PacManUdon { using UnityEngine; - using VRC.Udon; public enum PacManFruitType { @@ -50,110 +49,114 @@ namespace Marro.PacManUdon Intermission3 } - public enum PacManCollisionType + public enum PacManCollisionInfoType { - Empty = -1, - Wall = -2, + Tunnel = 0b00100000, + HorizontalOnly = 0b00010000, // Bit that indicates tiles on which ghosts are only allowed to go horizontal unless they're scared + NoTurn = 0b01000000, + Wall = 0b10000000, } public enum PacManConsumableType { - None = -1, - FruitLeft = -2, - FruitRight = -3, + None = 255, + FruitLeft = 254, + FruitRight = 253, } public static class PacManConstants { // Jagged or 2D arrays can't be static so we work with 1D arrays - public static int[] GetMazeCollisionInfo() => new int[] + public static byte[] GetMazeCollisionInfo() => new byte[] { - -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, - -02, 009, -01, -01, -01, -01, 013, -01, -01, -01, -01, -01, 005, -02, -02, 009, -01, -01, -01, -01, -01, 013, -01, -01, -01, -01, 005, -02, - -02, -01, -02, -02, -02, -02, -01, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -01, -02, -02, -02, -02, -01, -02, - -02, -01, -02, -01, -01, -02, -01, -02, -01, -01, -01, -02, -01, -02, -02, -01, -02, -01, -01, -01, -02, -01, -02, -01, -01, -02, -01, -02, - -02, -01, -02, -02, -02, -02, -01, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -01, -02, -02, -02, -02, -01, -02, - -02, 011, -01, -01, -01, -01, 015, -01, -01, 013, -01, -01, 014, -01, -01, 014, -01, -01, 013, -01, -01, 015, -01, -01, -01, -01, 007, -02, - -02, -01, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -01, -02, - -02, -01, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -01, -02, - -02, 010, -01, -01, -01, -01, 007, -02, -02, 010, -01, -01, 005, -02, -02, 009, -01, -01, 006, -02, -02, 011, -01, -01, -01, -01, 006, -02, - -02, -02, -02, -02, -02, -02, -01, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -01, -02, -02, -02, -02, -02, -02, - 013, 013, 013, 013, 005, -02, -01, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -01, -02, 009, 013, 013, 013, 013, - 015, 015, 015, 015, 007, -02, -01, -02, -02, 009, -01, -01, 014, -01, -01, 014, -01, -01, 005, -02, -02, -01, -02, 011, 015, 015, 015, 015, - 014, 014, 014, 014, 006, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, 010, 014, 014, 014, 014, - -02, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, 009, 013, 013, 013, 013, 005, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -02, - -01, -01, -01, -01, -01, -01, 015, -01, -01, 007, -02, 011, 015, 015, 015, 015, 007, -02, 011, -01, -01, 015, -01, -01, -01, -01, -01, -01, - -02, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, 010, 014, 014, 014, 014, 006, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -02, - 013, 013, 013, 013, 005, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, 009, 013, 013, 013, 013, - 015, 015, 015, 015, 007, -02, -01, -02, -02, 011, -01, -01, -01, -01, -01, -01, -01, -01, 007, -02, -02, -01, -02, 011, 015, 015, 015, 015, - 014, 014, 014, 014, 006, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, 010, 014, 014, 014, 014, - -02, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -02, - -02, 009, -01, -01, -01, -01, 015, -01, -01, 014, -01, -01, 005, -02, -02, 009, -01, -01, 014, -01, -01, 015, -01, -01, -01, -01, 005, -02, - -02, -01, -02, -02, -02, -02, -01, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -01, -02, -02, -02, -02, -01, -02, - -02, -01, -02, -02, -02, -02, -01, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -01, -02, -02, -02, -02, -01, -02, - -02, 010, -01, 005, -02, -02, 011, -01, -01, 013, -01, -01, 014, -01, -01, 014, -01, -01, 013, -01, -01, 007, -02, -02, 009, -01, 006, -02, - -02, -02, -02, -01, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -01, -02, -02, -02, - -02, -02, -02, -01, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -01, -02, -02, -02, - -02, 009, -01, 014, -01, -01, 006, -02, -02, 010, -01, -01, 005, -02, -02, 009, -01, -01, 006, -02, -02, 010, -01, -01, 014, -01, 005, -02, - -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, - -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, - -02, 010, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 014, -01, -01, 014, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 006, -02, - -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, + 192, 192, 192, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 192, 192, 192, + 192, 192, 200, 010, 076, 076, 076, 076, 076, 076, 076, 076, 076, 076, 014, 076, 076, 014, 076, 076, 076, 076, 076, 076, 076, 076, 076, 076, 006, 196, 192, 192, + 192, 192, 200, 067, 133, 193, 193, 193, 193, 193, 193, 193, 193, 137, 067, 133, 137, 067, 133, 193, 193, 193, 193, 193, 193, 193, 193, 137, 067, 196, 192, 192, + 192, 192, 200, 067, 134, 194, 194, 194, 194, 192, 192, 194, 194, 138, 067, 196, 200, 067, 134, 194, 194, 192, 192, 194, 194, 194, 194, 138, 067, 196, 192, 192, + 192, 192, 200, 009, 076, 014, 076, 076, 006, 196, 200, 010, 076, 076, 005, 196, 200, 009, 076, 076, 006, 196, 200, 010, 076, 076, 014, 076, 005, 196, 192, 192, + 192, 192, 192, 193, 137, 067, 133, 137, 067, 196, 200, 067, 133, 193, 193, 192, 192, 193, 193, 137, 067, 196, 200, 067, 133, 137, 067, 133, 193, 192, 192, 192, + 192, 192, 192, 194, 138, 067, 196, 200, 067, 134, 138, 067, 134, 194, 194, 194, 194, 194, 194, 138, 067, 134, 138, 067, 196, 200, 067, 134, 194, 192, 192, 192, + 192, 192, 200, 010, 076, 005, 196, 200, 011, 076, 076, 013, 076, 076, 030, 076, 076, 030, 076, 076, 013, 076, 076, 007, 196, 200, 009, 076, 006, 196, 192, 192, + 192, 192, 200, 067, 133, 193, 192, 200, 067, 133, 193, 193, 193, 137, 067, 133, 137, 067, 133, 193, 193, 193, 137, 067, 196, 192, 193, 137, 067, 196, 192, 192, + 192, 192, 200, 067, 134, 194, 194, 138, 067, 134, 194, 194, 194, 138, 067, 196, 200, 067, 134, 194, 194, 194, 138, 067, 134, 194, 194, 138, 067, 196, 192, 192, + 192, 192, 200, 009, 076, 076, 076, 076, 015, 076, 076, 014, 076, 076, 005, 196, 200, 009, 076, 076, 014, 076, 076, 015, 076, 076, 076, 076, 005, 196, 192, 192, + 192, 192, 192, 193, 193, 193, 193, 137, 067, 133, 137, 067, 133, 193, 193, 192, 192, 193, 193, 137, 067, 133, 137, 067, 133, 193, 193, 193, 193, 192, 192, 192, + 192, 192, 192, 192, 192, 192, 192, 200, 067, 196, 200, 067, 134, 194, 194, 194, 194, 194, 194, 138, 067, 196, 200, 067, 196, 192, 192, 192, 192, 192, 192, 192, + 192, 192, 192, 192, 192, 192, 192, 200, 067, 196, 200, 011, 076, 076, 076, 076, 076, 076, 076, 076, 007, 196, 200, 067, 196, 192, 192, 192, 192, 192, 192, 192, + 192, 192, 192, 192, 192, 192, 192, 200, 067, 196, 200, 067, 133, 193, 193, 193, 193, 193, 193, 137, 067, 196, 200, 067, 196, 192, 192, 192, 192, 192, 192, 192, + 194, 194, 194, 194, 194, 194, 194, 138, 067, 134, 138, 067, 196, 192, 192, 192, 192, 192, 192, 200, 067, 134, 138, 067, 134, 194, 194, 194, 194, 194, 194, 194, + 108, 108, 108, 108, 108, 108, 108, 076, 015, 076, 076, 007, 196, 192, 192, 192, 192, 192, 192, 200, 011, 076, 076, 015, 076, 108, 108, 108, 108, 108, 108, 108, + 193, 193, 193, 193, 193, 193, 193, 137, 067, 133, 137, 067, 196, 192, 192, 192, 192, 192, 192, 200, 067, 133, 137, 067, 133, 193, 193, 193, 193, 193, 193, 193, + 192, 192, 192, 192, 192, 192, 192, 200, 067, 196, 200, 067, 134, 194, 194, 194, 194, 194, 194, 138, 067, 196, 200, 067, 196, 192, 192, 192, 192, 192, 192, 192, + 192, 192, 192, 192, 192, 192, 192, 200, 067, 196, 200, 009, 076, 076, 030, 076, 076, 030, 076, 076, 005, 196, 200, 067, 196, 192, 192, 192, 192, 192, 192, 192, + 192, 192, 192, 192, 192, 192, 192, 200, 067, 196, 192, 193, 193, 137, 067, 133, 137, 067, 133, 193, 193, 192, 200, 067, 196, 192, 192, 192, 192, 192, 192, 192, + 192, 192, 192, 194, 194, 194, 194, 138, 067, 196, 192, 194, 194, 138, 067, 196, 200, 067, 134, 194, 194, 192, 200, 067, 134, 194, 194, 194, 194, 192, 192, 192, + 192, 192, 200, 010, 076, 076, 076, 076, 007, 196, 200, 010, 076, 076, 005, 196, 200, 009, 076, 076, 006, 196, 200, 011, 076, 076, 076, 076, 006, 196, 192, 192, + 192, 192, 200, 067, 133, 193, 193, 137, 067, 196, 200, 067, 133, 193, 193, 192, 192, 193, 193, 137, 067, 196, 200, 067, 133, 193, 193, 137, 067, 196, 192, 192, + 192, 192, 200, 067, 134, 194, 194, 138, 067, 134, 138, 067, 134, 194, 194, 194, 194, 194, 194, 138, 067, 134, 138, 067, 134, 194, 194, 138, 067, 196, 192, 192, + 192, 192, 200, 011, 076, 076, 076, 076, 015, 076, 076, 013, 076, 076, 014, 076, 076, 014, 076, 076, 013, 076, 076, 015, 076, 076, 076, 076, 007, 196, 192, 192, + 192, 192, 200, 067, 133, 193, 193, 137, 067, 133, 193, 193, 193, 137, 067, 133, 137, 067, 133, 193, 193, 193, 137, 067, 133, 193, 193, 137, 067, 196, 192, 192, + 192, 192, 200, 067, 196, 192, 192, 200, 067, 196, 192, 192, 192, 200, 067, 196, 200, 067, 196, 192, 192, 192, 200, 067, 196, 192, 192, 200, 067, 196, 192, 192, + 192, 192, 200, 067, 134, 194, 194, 138, 067, 134, 194, 194, 194, 138, 067, 196, 200, 067, 134, 194, 194, 194, 138, 067, 134, 194, 194, 138, 067, 196, 192, 192, + 192, 192, 200, 009, 076, 076, 076, 076, 013, 076, 076, 076, 076, 076, 005, 196, 200, 009, 076, 076, 076, 076, 076, 013, 076, 076, 076, 076, 005, 196, 192, 192, + 192, 192, 192, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 192, 192, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 192, 192, 192, + 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, }; - public static int[] GetMazePelletMap() => new int[] + public static byte[] GetMazePelletMap() => new byte[] { - -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, 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, -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, - -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, 000, 083, 082, -01, -01, 010, 009, 008, 007, 006, 005, 004, -01, -01, 063, 062, 061, 060, 059, 058, 057, -01, -01, 115, 116, 001, -01, - -01, -01, -01, 081, -01, -01, 011, -01, -01, 079, -01, -01, -01, -01, -01, -01, -01, -01, 064, -01, -01, 056, -01, -01, 114, -01, -01, -01, - -01, -01, -01, 080, -01, -01, 012, -01, -01, 078, -01, -01, -01, -01, -01, -01, -01, -01, 065, -01, -01, 055, -01, -01, 113, -01, -01, -01, - -01, 018, 017, 016, 015, 014, 013, -01, -01, 077, 076, 075, 074, -01, -01, 069, 068, 067, 066, -01, -01, 054, 053, 052, 051, 050, 049, -01, - -01, 019, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 073, -01, -01, 070, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 048, -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, -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, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 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, 255, 255, 255, + 255, 255, 255, 020, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 072, 255, 255, 071, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 047, 255, 255, 255, + 255, 255, 255, 019, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 073, 255, 255, 070, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 048, 255, 255, 255, + 255, 255, 255, 018, 017, 016, 015, 014, 013, 255, 255, 077, 076, 075, 074, 255, 255, 069, 068, 067, 066, 255, 255, 054, 053, 052, 051, 050, 049, 255, 255, 255, + 255, 255, 255, 255, 255, 080, 255, 255, 012, 255, 255, 078, 255, 255, 255, 255, 255, 255, 255, 255, 065, 255, 255, 055, 255, 255, 113, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 081, 255, 255, 011, 255, 255, 079, 255, 255, 255, 255, 255, 255, 255, 255, 064, 255, 255, 056, 255, 255, 114, 255, 255, 255, 255, 255, + 255, 255, 255, 000, 083, 082, 255, 255, 010, 009, 008, 007, 006, 005, 004, 255, 255, 063, 062, 061, 060, 059, 058, 057, 255, 255, 115, 116, 001, 255, 255, 255, + 255, 255, 255, 084, 255, 255, 255, 255, 093, 255, 255, 255, 255, 255, 101, 255, 255, 102, 255, 255, 255, 255, 255, 112, 255, 255, 255, 255, 117, 255, 255, 255, + 255, 255, 255, 085, 255, 255, 255, 255, 092, 255, 255, 255, 255, 255, 100, 255, 255, 103, 255, 255, 255, 255, 255, 111, 255, 255, 255, 255, 118, 255, 255, 255, + 255, 255, 255, 086, 087, 088, 089, 090, 091, 094, 095, 096, 097, 098, 099, 255, 255, 104, 105, 106, 107, 108, 109, 110, 123, 122, 121, 120, 119, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 243, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 124, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 242, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 125, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 241, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 126, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 240, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 127, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 239, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 128, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 238, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 129, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 237, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 130, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 236, 255, 255, 255, 255, 255, 255, 254, 253, 255, 255, 255, 255, 255, 255, 131, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 235, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 132, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 234, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 133, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 233, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 134, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 225, 226, 227, 228, 229, 232, 255, 255, 207, 208, 209, 210, 255, 255, 170, 169, 168, 167, 255, 255, 135, 136, 137, 138, 139, 140, 255, 255, 255, + 255, 255, 255, 224, 255, 255, 255, 255, 231, 255, 255, 206, 255, 255, 255, 255, 255, 255, 255, 255, 166, 255, 255, 161, 255, 255, 255, 255, 141, 255, 255, 255, + 255, 255, 255, 223, 255, 255, 255, 255, 230, 255, 255, 205, 255, 255, 255, 255, 255, 255, 255, 255, 165, 255, 255, 160, 255, 255, 255, 255, 142, 255, 255, 255, + 255, 255, 255, 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, 255, 255, 255, + 255, 255, 255, 217, 255, 255, 255, 255, 198, 255, 255, 255, 255, 255, 186, 255, 255, 174, 255, 255, 255, 255, 255, 154, 255, 255, 255, 255, 144, 255, 255, 255, + 255, 255, 255, 003, 255, 255, 255, 255, 197, 255, 255, 255, 255, 255, 187, 255, 255, 175, 255, 255, 255, 255, 255, 153, 255, 255, 255, 255, 002, 255, 255, 255, + 255, 255, 255, 216, 255, 255, 255, 255, 196, 255, 255, 255, 255, 255, 188, 255, 255, 176, 255, 255, 255, 255, 255, 152, 255, 255, 255, 255, 145, 255, 255, 255, + 255, 255, 255, 215, 214, 213, 212, 211, 195, 194, 193, 192, 191, 190, 189, 255, 255, 177, 178, 179, 180, 181, 182, 151, 150, 149, 148, 147, 146, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, }; public static int[] GetMazePelletIndices() => new int[] { - 645, 670, 110, 085, 656, 655, 654, 653, 652, 651, 650, 678, 706, 734, 733, 732, - 731, 730, 729, 757, 785, 813, 814, 815, 816, 817, 818, 819, 820, 821, 822, 823, - 824, 825, 826, 827, 828, 829, 830, 831, 832, 833, 834, 835, 836, 837, 838, 810, - 782, 754, 753, 752, 751, 750, 749, 721, 693, 665, 664, 663, 662, 661, 660, 659, - 690, 718, 746, 745, 744, 743, 771, 799, 796, 768, 740, 739, 738, 737, 709, 681, - 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, 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, + 227, 252, 892, 867, 238, 237, 236, 235, 234, 233, 232, 200, 168, 136, 135, 134, + 133, 132, 131, 099, 067, 035, 036, 037, 038, 039, 040, 041, 042, 043, 044, 045, + 046, 047, 048, 049, 050, 051, 052, 053, 054, 055, 056, 057, 058, 059, 060, 092, + 124, 156, 155, 154, 153, 152, 151, 183, 215, 247, 246, 245, 244, 243, 242, 241, + 212, 180, 148, 147, 146, 145, 113, 081, 078, 110, 142, 141, 140, 139, 171, 203, + 165, 197, 229, 228, 259, 291, 323, 324, 325, 326, 327, 328, 296, 264, 329, 330, + 331, 332, 333, 334, 302, 270, 273, 305, 337, 338, 339, 340, 341, 342, 343, 311, + 279, 186, 218, 250, 251, 284, 316, 348, 347, 346, 345, 344, 375, 407, 439, 471, + 503, 535, 567, 599, 631, 663, 695, 727, 728, 729, 730, 731, 732, 764, 796, 828, + 860, 924, 956, 955, 954, 953, 952, 951, 919, 887, 855, 823, 824, 825, 826, 827, + 791, 759, 822, 821, 820, 788, 756, 724, 723, 722, 721, 819, 818, 817, 849, 881, + 913, 945, 946, 947, 948, 949, 950, 816, 815, 814, 846, 878, 910, 942, 941, 940, + 939, 938, 937, 936, 904, 872, 840, 808, 809, 810, 811, 812, 813, 779, 747, 715, + 716, 717, 718, 935, 934, 933, 932, 931, 899, 835, 803, 804, 805, 806, 807, 771, + 739, 707, 708, 709, 710, 711, 776, 744, 712, 680, 648, 616, 584, 552, 520, 488, + 456, 424, 392, 360, }; public static GameObject[] ComponentsToGameObjects(Component[] components, bool skipFirstComponent = false) diff --git a/Assets/Scripts/PelletManager.asset b/Assets/Scripts/PelletManager.asset index e420600..3c0e000 100644 --- a/Assets/Scripts/PelletManager.asset +++ b/Assets/Scripts/PelletManager.asset @@ -651,17 +651,11 @@ MonoBehaviour: Entry: 1 Data: collisionMap - Name: k__BackingField - Entry: 7 - Data: 36|System.RuntimeType, mscorlib - - Name: - Entry: 1 - Data: System.Int32[], mscorlib - - Name: - Entry: 8 - Data: + Entry: 9 + Data: 33 - Name: k__BackingField Entry: 9 - Data: 36 + Data: 33 - Name: k__BackingField Entry: 7 Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib @@ -676,7 +670,7 @@ MonoBehaviour: Data: false - Name: _fieldAttributes Entry: 7 - Data: 37|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib + Data: 36|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib - Name: Entry: 12 Data: 0 @@ -700,16 +694,16 @@ MonoBehaviour: Data: pelletMap - Name: $v Entry: 7 - Data: 38|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor + Data: 37|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor - Name: k__BackingField Entry: 1 Data: pelletMap - Name: k__BackingField Entry: 9 - Data: 36 + Data: 33 - Name: k__BackingField Entry: 9 - Data: 36 + Data: 33 - Name: k__BackingField Entry: 7 Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib @@ -724,7 +718,7 @@ MonoBehaviour: Data: false - Name: _fieldAttributes Entry: 7 - Data: 39|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib + Data: 38|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 dfb04fe..305ee27 100644 --- a/Assets/Scripts/PelletManager.cs +++ b/Assets/Scripts/PelletManager.cs @@ -27,11 +27,11 @@ namespace Marro.PacManUdon byte[] syncedPelletsCollected; - int[] collisionMap; - int[] pelletMap; + byte[] collisionMap; + byte[] pelletMap; - const int mazeWidth = 28; - const int mazeHeight = 31; + const int mazeWidth = 32; + const int mazeHeight = 32; public void Initialize(GameManager gameManager, BonusFruit bonusFruit) { @@ -98,7 +98,20 @@ namespace Marro.PacManUdon #region Collision public bool IsWallUpcoming(Vector2 position, Vector2 directionVector) { - var result = GetTileAt(position + directionVector) == (int)PacManCollisionType.Wall; + var index = GetTilemapIndex(position + directionVector); + var tile = collisionMap[index]; + var result = (tile & (int)PacManCollisionInfoType.Wall) != 0; + Debug.Log($"IsWallUpcoming {position}, {directionVector}. index {index}, tile {tile}, result {result}, collisionMap.Length {collisionMap.Length}"); + return result; + } + + public bool IsInTunnel(Vector2 position) + { + var result = (collisionMap[GetTilemapIndex(position)] & (int)PacManCollisionInfoType.Tunnel) != 0; + if (result) + { + Debug.Log($"In tunnel at {position}"); + } return result; } @@ -134,22 +147,15 @@ namespace Marro.PacManUdon public int GetAvailableDirections(Vector2 position) { - var directions = GetTileAt(position); - - if (directions <= 0) - { - return 0; - } + var directions = collisionMap[GetTilemapIndex(position)]; return directions; } - private int GetTileAt(Vector2 position) => collisionMap[GetTilemapIndex(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; + position = Clamp(position, 0, mazeWidth - 1, 0, mazeHeight - 1); + var index = (int)position.x + (int)position.y * mazeWidth; return index; } #endregion @@ -162,7 +168,7 @@ namespace Marro.PacManUdon return PelletType.None; } - pelletMap[tilemapIndex] = -1; + pelletMap[tilemapIndex] = (byte)PacManConsumableType.None; var pellet = pellets[tile]; pellet.gameObject.SetActive(false); diff --git a/Assets/Test stuff/MazeDefinitionGenerator.asset b/Assets/Test stuff/MazeDefinitionGenerator.asset index 5ff1ce7..8ebce24 100644 --- a/Assets/Test stuff/MazeDefinitionGenerator.asset +++ b/Assets/Test stuff/MazeDefinitionGenerator.asset @@ -20,7 +20,7 @@ MonoBehaviour: compiledVersion: 2 behaviourSyncMode: 0 hasInteractEvent: 0 - scriptID: 6724330659013342737 + scriptID: 1069201558343068808 serializationData: SerializedFormat: 2 SerializedBytes: diff --git a/Assets/Test stuff/MazeDefinitionGenerator.cs b/Assets/Test stuff/MazeDefinitionGenerator.cs index 364c1ff..fa5f970 100644 --- a/Assets/Test stuff/MazeDefinitionGenerator.cs +++ b/Assets/Test stuff/MazeDefinitionGenerator.cs @@ -6,202 +6,220 @@ using UnityEngine.UIElements; using VRC.SDKBase; using VRC.Udon; -public class MazeDefinitionGenerator : UdonSharpBehaviour +namespace Marro.PacManUdon.Dev { - public BonusFruit bonusFruit; - public PelletManager pelletManager; - - void Start() + enum CollisionMap { - PrintPelletMap(); - PrintMazeMap(); + Wall = 0x00, + Open = 0xFF, + Tunnel = 0x61, + HorizontalOnly = 0x56, } - - private void PrintPelletMap() + public class MazeDefinitionGenerator : UdonSharpBehaviour { - var width = 28; - var height = 31; + public BonusFruit bonusFruit; + public PelletManager pelletManager; - var pellets = pelletManager.gameObject.GetComponentsInChildren(includeInactive: true); + const int width = 32; + const int height = 32; - int[] map = new int[width * height]; - int[] pelletLocations = new int[pellets.Length]; - - for (int i = 0; i < map.Length; i++) + void Start() { - map[i] = -1; + PrintPelletMap(); + PrintMazeMap(); } - for (int i = 0; i < pellets.Length; i++) + private void PrintPelletMap() { - Pellet pellet = pellets[i]; - var position = GridMover.PositionToGrid(new Vector2(pellet.transform.localPosition.x, -pellet.transform.localPosition.y)); - var index = (int)position.x + (int)position.y * width; - map[index] = i; - pelletLocations[i] = index; - } + var pellets = pelletManager.gameObject.GetComponentsInChildren(includeInactive: true); - WriteBonusFruitTiles(map); + int[] map = new int[width * height]; + int[] pelletLocations = new int[pellets.Length]; - 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; - var height = 31; - - int[] map = new int[width * height]; - var collisionMap = GetCollisionMap(); - - for (int i = 0; i < map.Length; i++) - { - if (collisionMap[i]) + for (int i = 0; i < map.Length; i++) { - map[i] = (int)PacManCollisionType.Wall; - continue; + map[i] = (int)PacManConsumableType.None; } - map[i] = GetGhostTurnInformation(collisionMap, i, width, height); - } - - PrintMap(map, width); - } - - private int GetGhostTurnInformation(bool[] collisionMap, int i, int width, int height) - { - var availableDirections = 0; - var totalAvailableDirections = 0; - if (!collisionMap[GetTilemapIndex(i, Vector2.up, width, height)]) - { - availableDirections |= 0b0001; - totalAvailableDirections += 1; - } - if (!collisionMap[GetTilemapIndex(i, Vector2.down, width, height)]) - { - availableDirections |= 0b0010; - totalAvailableDirections += 1; - } - if (!collisionMap[GetTilemapIndex(i, Vector2.left, width, height)]) - { - availableDirections |= 0b0100; - totalAvailableDirections += 1; - } - if (!collisionMap[GetTilemapIndex(i, Vector2.right, width, height)]) - { - availableDirections |= 0b1000; - totalAvailableDirections += 1; - } - - if (totalAvailableDirections < 2) - { - return (int)PacManCollisionType.Empty; - } - - if (availableDirections == 0b0011 || availableDirections == 0b1100) - { - return (int)PacManCollisionType.Empty; - } - - return availableDirections; - } - - private int GetTilemapIndex(int index, Vector2 direction, int width, int height) - { - var position = new Vector2(index % width, index / width) + direction; - position = Clamp(position, 0, width - 1, 0, height - 1); - var result = (int)position.x + (int)position.y * width; - return result; - } - - private static Vector2 Clamp(Vector2 vector, float xMin, float xMax, float yMin, float yMax) - { - if (vector.x < xMin) - { - vector.x = xMin; - } - - if (vector.x > xMax) - { - vector.x = xMax; - } - - if (vector.y < yMin) - { - vector.y = yMin; - } - - if (vector.y > yMax) - { - vector.y = yMax; - } - - return vector; - } - private void PrintMap(int[] map, int width) - { - var result = ""; - for (int i = 0; i < map.Length; i++) - { - if (map[i] < 0) + for (int i = 0; i < pellets.Length; i++) { - result += $"{map[i]:00}, "; - } - else - { - result += $"{map[i]:000}, "; + Pellet pellet = pellets[i]; + var position = GridMover.PositionToGrid(new Vector2(pellet.transform.localPosition.x, pellet.transform.localPosition.y)); + var index = (int)position.x + (int)position.y * width; + map[index] = i; + pelletLocations[i] = index; } - if (i % width == width - 1) - { - result += "\n"; - } + WriteBonusFruitTiles(map); + + PrintMap(map, width); + PrintMap(pelletLocations, 16); } - Debug.Log(result); - } + 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; + } - public static bool[] GetCollisionMap() => new bool[] { - true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true , - true, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, true , - true, false, true, true, true, true, false, true, true, true, true, true, false, true, true, false, true, true, true, true, true, false, true, true, true, true, false, true , - true, false, true, false, false, true, false, true, false, false, false, true, false, true, true, false, true, false, false, false, true, false, true, false, false, true, false, true , - true, false, true, true, true, true, false, true, true, true, true, true, false, true, true, false, true, true, true, true, true, false, true, true, true, true, false, true , - true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true , - true, false, true, true, true, true, false, true, true, false, true, true, true, true, true, true, true, true, false, true, true, false, true, true, true, true, false, true , - true, false, true, true, true, true, false, true, true, false, true, true, true, true, true, true, true, true, false, true, true, false, true, true, true, true, false, true , - true, false, false, false, false, false, false, true, true, false, false, false, false, true, true, false, false, false, false, true, true, false, false, false, false, false, false, true , - true, true, true, true, true, true, false, true, true, true, true, true, false, true, true, false, true, true, true, true, true, false, true, true, true, true, true, true , - false, false, false, false, false, true, false, true, true, true, true, true, false, true, true, false, true, true, true, true, true, false, true, false, false, false, false, false , - false, false, false, false, false, true, false, true, true, false, false, false, false, false, false, false, false, false, false, true, true, false, true, false, false, false, false, false , - false, false, false, false, false, true, false, true, true, false, true, true, true, true, true, true, true, true, false, true, true, false, true, false, false, false, false, false , - true, true, true, true, true, true, false, true, true, false, true, false, false, false, false, false, false, true, false, true, true, false, true, true, true, true, true, true , - false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false , - true, true, true, true, true, true, false, true, true, false, true, false, false, false, false, false, false, true, false, true, true, false, true, true, true, true, true, true , - false, false, false, false, false, true, false, true, true, false, true, true, true, true, true, true, true, true, false, true, true, false, true, false, false, false, false, false , - false, false, false, false, false, true, false, true, true, false, false, false, false, false, false, false, false, false, false, true, true, false, true, false, false, false, false, false , - false, false, false, false, false, true, false, true, true, false, true, true, true, true, true, true, true, true, false, true, true, false, true, false, false, false, false, false , - true, true, true, true, true, true, false, true, true, false, true, true, true, true, true, true, true, true, false, true, true, false, true, true, true, true, true, true , - true, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, true , - true, false, true, true, true, true, false, true, true, true, true, true, false, true, true, false, true, true, true, true, true, false, true, true, true, true, false, true , - true, false, true, true, true, true, false, true, true, true, true, true, false, true, true, false, true, true, true, true, true, false, true, true, true, true, false, true , - true, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, true , - true, true, true, false, true, true, false, true, true, false, true, true, true, true, true, true, true, true, false, true, true, false, true, true, false, true, true, true , - true, true, true, false, true, true, false, true, true, false, true, true, true, true, true, true, true, true, false, true, true, false, true, true, false, true, true, true , - true, false, false, false, false, false, false, true, true, false, false, false, false, true, true, false, false, false, false, true, true, false, false, false, false, false, false, true , - true, false, true, true, true, true, true, true, true, true, true, true, false, true, true, false, true, true, true, true, true, true, true, true, true, true, false, true , - true, false, true, true, true, true, true, true, true, true, true, true, false, true, true, false, true, true, true, true, true, true, true, true, true, true, false, true , - true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true , - true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true - }; + private void PrintMazeMap() + { + int[] map = new int[width * height]; + var collisionMap = GetCollisionMap(); + + for (int i = 0; i < map.Length; i++) + { + byte result = 0; + var tile = collisionMap[i]; + + if (tile == (byte)CollisionMap.Wall) + { + result |= (byte)PacManCollisionInfoType.Wall; + } + + if (tile == (byte)CollisionMap.Tunnel) + { + result |= (byte)PacManCollisionInfoType.Tunnel; + } + + if (tile == (byte)CollisionMap.HorizontalOnly) + { + result |= (byte)PacManCollisionInfoType.HorizontalOnly; + } + + result |= GetGhostTurnInformation(collisionMap, i, width, height); + + map[(i % width) + (height - i / width - 1) * width] = result; + } + + PrintMap(map, width); + } + + private byte GetGhostTurnInformation(byte[] collisionMap, int i, int width, int height) + { + byte result = 0; + var totalAvailableDirections = 0; + if (collisionMap[GetTilemapIndex(i, Vector2.up, width, height)] != (byte)CollisionMap.Wall) + { + result |= 0b0001; + totalAvailableDirections += 1; + } + if (collisionMap[GetTilemapIndex(i, Vector2.down, width, height)] != (byte)CollisionMap.Wall) + { + result |= 0b0010; + totalAvailableDirections += 1; + } + if (collisionMap[GetTilemapIndex(i, Vector2.left, width, height)] != (byte)CollisionMap.Wall) + { + result |= 0b0100; + totalAvailableDirections += 1; + } + if (collisionMap[GetTilemapIndex(i, Vector2.right, width, height)] != (byte)CollisionMap.Wall) + { + result |= 0b1000; + totalAvailableDirections += 1; + } + + if (totalAvailableDirections < 2 + || result == 0b0011 || result == 0b1100) + { + result |= (byte)PacManCollisionInfoType.NoTurn; + } + + return result; + } + + private int GetTilemapIndex(int index, Vector2 direction, int width, int height) + { + var position = new Vector2(index % width, index / width) + direction; + position = Clamp(position, 0, width - 1, 0, height - 1); + var result = (int)position.x + (int)position.y * width; + return result; + } + + private static Vector2 Clamp(Vector2 vector, float xMin, float xMax, float yMin, float yMax) + { + if (vector.x < xMin) + { + vector.x = xMin; + } + + if (vector.x > xMax) + { + vector.x = xMax; + } + + if (vector.y < yMin) + { + vector.y = yMin; + } + + if (vector.y > yMax) + { + vector.y = yMax; + } + + return vector; + } + private void PrintMap(int[] map, int width) + { + var result = ""; + for (int i = 0; i < map.Length; i++) + { + if (map[i] < 0) + { + result += $"{map[i]:00}, "; + } + else + { + result += $"{map[i]:000}, "; + } + + if (i % width == width - 1) + { + result += "\n"; + } + } + + Debug.Log(result); + } + + public static byte[] GetCollisionMap() => new byte[] { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0x56, 0xff, 0xff, 0x56, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x56, 0xff, 0xff, 0x56, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + } }