diff --git a/Assets/Scripts/Ghost.cs b/Assets/Scripts/Ghost.cs index db9a469..9e8c02a 100644 --- a/Assets/Scripts/Ghost.cs +++ b/Assets/Scripts/Ghost.cs @@ -132,11 +132,11 @@ namespace Marro.PacManUdon if (startState == PacManGhostStartState.TargetingIdlePosition1) { SetOffGridTarget(idlePosition1, false); - SetTargetDirection(Direction.Up); + SetTargetDirection(Direction.Down); } else { - SetTargetDirection(Direction.Down); + SetTargetDirection(Direction.Up); } ghostState = PacManGhostState.Entering; OffGridTargetReached(); diff --git a/Assets/Scripts/GridMover.cs b/Assets/Scripts/GridMover.cs index 7d6e511..42b8340 100644 --- a/Assets/Scripts/GridMover.cs +++ b/Assets/Scripts/GridMover.cs @@ -24,20 +24,20 @@ namespace Marro.PacManUdon public readonly Vector2[] directionVectors = { Vector2.zero, // 0 - Vector2.down, // 1 - Vector2.up, // 2 + Vector2.up, // 1 + Vector2.down, // 2 Vector2.zero, // 3 Vector2.left, // 4 - Vector2.down + Vector2.left, // 5 - Vector2.up + Vector2.left, // 6 + Vector2.up + Vector2.left, // 5 + Vector2.down + Vector2.left, // 6 Vector2.left, // 7 Vector2.right, // 8 - Vector2.down + Vector2.right, // 9 - Vector2.up + Vector2.right, // 10 + Vector2.up + Vector2.right, // 9 + Vector2.down + Vector2.right, // 10 Vector2.right, // 11 Vector2.zero, // 12 - Vector2.down, // 13 - Vector2.up, // 14 + Vector2.up, // 13 + Vector2.down, // 14 Vector2.zero, // 15 }; @@ -122,11 +122,11 @@ namespace Marro.PacManUdon { if (vertical < 0) { - return Direction.Up; + return Direction.Down; } if (vertical > 0) { - return Direction.Down; + return Direction.Up; } return Direction.Zero; } diff --git a/Assets/Scripts/PacMan.cs b/Assets/Scripts/PacMan.cs index 8bdd1ed..cae34e2 100644 --- a/Assets/Scripts/PacMan.cs +++ b/Assets/Scripts/PacMan.cs @@ -9,7 +9,7 @@ namespace Marro.PacManUdon Moving, Stopped, Big, - Dead, + Dead, } [RequireComponent(typeof(Animator))] diff --git a/Assets/Scripts/PacManConstants.cs b/Assets/Scripts/PacManConstants.cs index 5c39429..8c36835 100644 --- a/Assets/Scripts/PacManConstants.cs +++ b/Assets/Scripts/PacManConstants.cs @@ -69,37 +69,37 @@ namespace Marro.PacManUdon // Jagged or 2D arrays can't be static so we work with 1D arrays public static byte[] GetMazeCollisionInfo() => new byte[] { - 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, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 192, 192, 192, + 192, 192, 200, 009, 076, 076, 076, 076, 076, 076, 076, 076, 076, 076, 013, 076, 076, 013, 076, 076, 076, 076, 076, 076, 076, 076, 076, 076, 005, 196, 192, 192, + 192, 192, 200, 067, 134, 194, 194, 194, 194, 194, 194, 194, 194, 138, 067, 134, 138, 067, 134, 194, 194, 194, 194, 194, 194, 194, 194, 138, 067, 196, 192, 192, + 192, 192, 200, 067, 133, 193, 193, 193, 193, 192, 192, 193, 193, 137, 067, 196, 200, 067, 133, 193, 193, 192, 192, 193, 193, 193, 193, 137, 067, 196, 192, 192, + 192, 192, 200, 010, 076, 013, 076, 076, 005, 196, 200, 009, 076, 076, 006, 196, 200, 010, 076, 076, 005, 196, 200, 009, 076, 076, 013, 076, 006, 196, 192, 192, + 192, 192, 192, 194, 138, 067, 134, 138, 067, 196, 200, 067, 134, 194, 194, 192, 192, 194, 194, 138, 067, 196, 200, 067, 134, 138, 067, 134, 194, 192, 192, 192, + 192, 192, 192, 193, 137, 067, 196, 200, 067, 133, 137, 067, 133, 193, 193, 193, 193, 193, 193, 137, 067, 133, 137, 067, 196, 200, 067, 133, 193, 192, 192, 192, + 192, 192, 200, 009, 076, 006, 196, 200, 011, 076, 076, 014, 076, 076, 029, 076, 076, 029, 076, 076, 014, 076, 076, 007, 196, 200, 010, 076, 005, 196, 192, 192, + 192, 192, 200, 067, 134, 194, 192, 200, 067, 134, 194, 194, 194, 138, 067, 134, 138, 067, 134, 194, 194, 194, 138, 067, 196, 192, 194, 138, 067, 196, 192, 192, + 192, 192, 200, 067, 133, 193, 193, 137, 067, 133, 193, 193, 193, 137, 067, 196, 200, 067, 133, 193, 193, 193, 137, 067, 133, 193, 193, 137, 067, 196, 192, 192, + 192, 192, 200, 010, 076, 076, 076, 076, 015, 076, 076, 013, 076, 076, 006, 196, 200, 010, 076, 076, 013, 076, 076, 015, 076, 076, 076, 076, 006, 196, 192, 192, + 192, 192, 192, 194, 194, 194, 194, 138, 067, 134, 138, 067, 134, 194, 194, 192, 192, 194, 194, 138, 067, 134, 138, 067, 134, 194, 194, 194, 194, 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, 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, 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, + 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, + 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, + 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, + 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, + 192, 192, 192, 192, 192, 192, 192, 200, 067, 196, 200, 010, 076, 076, 029, 076, 076, 029, 076, 076, 006, 196, 200, 067, 196, 192, 192, 192, 192, 192, 192, 192, + 192, 192, 192, 192, 192, 192, 192, 200, 067, 196, 192, 194, 194, 138, 067, 134, 138, 067, 134, 194, 194, 192, 200, 067, 196, 192, 192, 192, 192, 192, 192, 192, + 192, 192, 192, 193, 193, 193, 193, 137, 067, 196, 192, 193, 193, 137, 067, 196, 200, 067, 133, 193, 193, 192, 200, 067, 133, 193, 193, 193, 193, 192, 192, 192, + 192, 192, 200, 009, 076, 076, 076, 076, 007, 196, 200, 009, 076, 076, 006, 196, 200, 010, 076, 076, 005, 196, 200, 011, 076, 076, 076, 076, 005, 196, 192, 192, + 192, 192, 200, 067, 134, 194, 194, 138, 067, 196, 200, 067, 134, 194, 194, 192, 192, 194, 194, 138, 067, 196, 200, 067, 134, 194, 194, 138, 067, 196, 192, 192, + 192, 192, 200, 067, 133, 193, 193, 137, 067, 133, 137, 067, 133, 193, 193, 193, 193, 193, 193, 137, 067, 133, 137, 067, 133, 193, 193, 137, 067, 196, 192, 192, + 192, 192, 200, 011, 076, 076, 076, 076, 015, 076, 076, 014, 076, 076, 013, 076, 076, 013, 076, 076, 014, 076, 076, 015, 076, 076, 076, 076, 007, 196, 192, 192, + 192, 192, 200, 067, 134, 194, 194, 138, 067, 134, 194, 194, 194, 138, 067, 134, 138, 067, 134, 194, 194, 194, 138, 067, 134, 194, 194, 138, 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, 200, 067, 133, 193, 193, 137, 067, 133, 193, 193, 193, 137, 067, 196, 200, 067, 133, 193, 193, 193, 137, 067, 133, 193, 193, 137, 067, 196, 192, 192, + 192, 192, 200, 010, 076, 076, 076, 076, 014, 076, 076, 076, 076, 076, 006, 196, 200, 010, 076, 076, 076, 076, 076, 014, 076, 076, 076, 076, 006, 196, 192, 192, + 192, 192, 192, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 192, 192, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 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, }; diff --git a/Assets/Scripts/PlayerInput.cs b/Assets/Scripts/PlayerInput.cs index 1cf10f8..acc7d5a 100644 --- a/Assets/Scripts/PlayerInput.cs +++ b/Assets/Scripts/PlayerInput.cs @@ -100,7 +100,7 @@ return; } verticalValue = Math.Abs(value); - if (value < -0.5) + if (value > 0.5) { inputVertical = Direction.Up; if (verticalValue >= horizontalValue) @@ -108,7 +108,7 @@ SetPriority(false); } } - else if (value > 0.5) + else if (value < -0.5) { inputVertical = Direction.Down; if (verticalValue >= horizontalValue) diff --git a/Assets/Test stuff/MazeDefinitionGenerator.cs b/Assets/Test stuff/MazeDefinitionGenerator.cs index 2a0ff57..9079553 100644 --- a/Assets/Test stuff/MazeDefinitionGenerator.cs +++ b/Assets/Test stuff/MazeDefinitionGenerator.cs @@ -65,7 +65,7 @@ namespace Marro.PacManUdon.Dev map[rightTileIndex] = (int)PacManConsumableType.FruitRight; } - private void PrintMazeMap() + private static void PrintMazeMap() { int[] map = new int[width * height]; var collisionMap = GetCollisionMap(); @@ -73,7 +73,7 @@ namespace Marro.PacManUdon.Dev for (int i = 0; i < map.Length; i++) { byte result = 0; - var tile = collisionMap[i]; + var tile = GetTileAtIndex(collisionMap, i); if (tile == (byte)CollisionMap.Wall) { @@ -92,34 +92,34 @@ namespace Marro.PacManUdon.Dev result |= GetGhostTurnInformation(collisionMap, i, width, height); - map[(i % width) + (height - i / width - 1) * width] = result; + map[i] = result; } PrintMap(map, width); } - private byte GetGhostTurnInformation(byte[] collisionMap, int i, int width, int height) + private static 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) + if (GetTileAtIndex(collisionMap, GetTilemapIndex(i, Vector2.up, width, height)) != (byte)CollisionMap.Wall) { - result |= 0b0001; + result |= (byte)Direction.Up; totalAvailableDirections += 1; } - if (collisionMap[GetTilemapIndex(i, Vector2.down, width, height)] != (byte)CollisionMap.Wall) + if (GetTileAtIndex(collisionMap, GetTilemapIndex(i, Vector2.down, width, height)) != (byte)CollisionMap.Wall) { - result |= 0b0010; + result |= (byte)Direction.Down; totalAvailableDirections += 1; } - if (collisionMap[GetTilemapIndex(i, Vector2.left, width, height)] != (byte)CollisionMap.Wall) + if (GetTileAtIndex(collisionMap, GetTilemapIndex(i, Vector2.left, width, height)) != (byte)CollisionMap.Wall) { - result |= 0b0100; + result |= (byte)Direction.Left; totalAvailableDirections += 1; } - if (collisionMap[GetTilemapIndex(i, Vector2.right, width, height)] != (byte)CollisionMap.Wall) + if (GetTileAtIndex(collisionMap, GetTilemapIndex(i, Vector2.right, width, height)) != (byte)CollisionMap.Wall) { - result |= 0b1000; + result |= (byte)Direction.Right; totalAvailableDirections += 1; } @@ -132,39 +132,14 @@ namespace Marro.PacManUdon.Dev return result; } - private int GetTilemapIndex(int index, Vector2 direction, int width, int height) + private static 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; + var result = ((int)position.x + width) % width + ((int)position.y + height) % height * 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) + private static void PrintMap(int[] map, int width) { var result = ""; for (int i = 0; i < map.Length; i++) @@ -187,6 +162,10 @@ namespace Marro.PacManUdon.Dev Debug.Log(result); } + private static byte GetTileAtIndex(byte[] map, int index) => map[GetUpsideDownIndex(index)]; + + private static int GetUpsideDownIndex(int index) => (index % width) + (height - index / width - 1) * width; + 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,