diff --git a/Assets/Scripts/GridMover.cs b/Assets/Scripts/GridMover.cs index 410a0f1..4ad4545 100644 --- a/Assets/Scripts/GridMover.cs +++ b/Assets/Scripts/GridMover.cs @@ -190,7 +190,7 @@ namespace Marro.PacManUdon public static Vector2 PositionToGrid(Vector2 position) { - return new Vector2((float)Math.Round(position.x-0.5f)+0.5f, (float)Math.Round(position.y-0.5f)+0.5f); + return new Vector2((int)position.x + 0.5f, (int)position.y + 0.5f); } public static bool CrossesTileBorder(Vector2 currentPosition, Vector2 nextPosition, Direction direction) diff --git a/Assets/Scripts/PacMan.cs b/Assets/Scripts/PacMan.cs index 7124f63..2e1c66b 100644 --- a/Assets/Scripts/PacMan.cs +++ b/Assets/Scripts/PacMan.cs @@ -130,30 +130,29 @@ namespace Marro.PacManUdon private Vector2 ProcessNextPosition(Vector2 position, Vector2 nextPosition) { - if (CrossesTileCenter(position, nextPosition, Direction.Left) // If pacman is moving horizontally, check if he may cross the center of a tile in that axis + if (CrossesTileCenter(position, nextPosition, Direction.Left) // If pacman is moving horizontally, check if he may cross the center of a tile in that axis && (!IsHorizontal(targetDirection) || pelletManager.IsWallUpcoming(nextPosition, directionVectors[(int)HorizontalComponent(direction)]))) { // If the target direction is in the other axis or if we're about to run into a wall - nextPosition.x = PositionToGrid(nextPosition).x; // Snap pacman to the center of his current tile in this axis + nextPosition.x = PositionToGrid(nextPosition).x; // Snap pacman to the center of his current tile in this axis SetDirection(VerticalComponent(direction)); - Debug.Log($"{gameObject} crossed X tile center from {position}, nextPosition is now {nextPosition} and direction is now {direction}"); + //Debug.Log($"{gameObject} crossed X tile center from {position}, nextPosition is now {nextPosition} and direction is now {direction}"); } - if (CrossesTileCenter(position, nextPosition, Direction.Down) // See comments above but now vertical + if (CrossesTileCenter(position, nextPosition, Direction.Down) // See comments above but now vertical && (!IsVertical(targetDirection) || pelletManager.IsWallUpcoming(nextPosition, directionVectors[(int)VerticalComponent(direction)]))) { nextPosition.y = PositionToGrid(nextPosition).y; SetDirection(HorizontalComponent(direction)); - Debug.Log($"{gameObject} crossed Y tile center from {position} with targetDirection {targetDirection}, nextPosition is now {nextPosition} and direction is now {direction}"); + //Debug.Log($"{gameObject} crossed Y tile center from {position} with targetDirection {targetDirection}, nextPosition is now {nextPosition} and direction is now {direction}"); } 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.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 + && !pelletManager.IsWallUpcoming(nextPosition, directionVectors[(int)inputDirection])) // Check if the requested direction does not have a wall + { + // Move in the requested direction, as well as perpundicular to it to get to the center of the tunnel if (IsHorizontal(inputDirection)) - { // Move in the requested direction, as well as perpundicular to it to get to the center of the tunnel + { var directionToCenter = VerticalToDirection(PositionToGrid(nextPosition).y - nextPosition.y); SetDirection((Direction)((int)inputDirection | (int)directionToCenter)); } diff --git a/Assets/Scripts/PacManConstants.cs b/Assets/Scripts/PacManConstants.cs index 976ac56..5c39429 100644 --- a/Assets/Scripts/PacManConstants.cs +++ b/Assets/Scripts/PacManConstants.cs @@ -118,12 +118,12 @@ namespace Marro.PacManUdon 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, 241, 255, 255, 255, 255, 255, 255, 253, 254, 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, 236, 255, 255, 255, 255, 255, 255, 255, 255, 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, diff --git a/Assets/Test stuff/MazeDefinitionGenerator.cs b/Assets/Test stuff/MazeDefinitionGenerator.cs index fa5f970..6c532b9 100644 --- a/Assets/Test stuff/MazeDefinitionGenerator.cs +++ b/Assets/Test stuff/MazeDefinitionGenerator.cs @@ -58,10 +58,10 @@ namespace Marro.PacManUdon.Dev private void WriteBonusFruitTiles(int[] map) { - var position = bonusFruit.transform.localPosition; - var leftTileIndex = PelletManager.GetTilemapIndex(new Vector2(position.x - 0.5f, position.y)); + var position = GridMover.PositionToGrid(new Vector2(bonusFruit.transform.localPosition.x, bonusFruit.transform.localPosition.y)); + var leftTileIndex = PelletManager.GetTilemapIndex(position); map[leftTileIndex] = (int)PacManConsumableType.FruitLeft; - var rightTileIndex = PelletManager.GetTilemapIndex(new Vector2(position.x + 0.5f, position.y)); + var rightTileIndex = leftTileIndex - 1; map[rightTileIndex] = (int)PacManConsumableType.FruitRight; }