This commit is contained in:
2026-06-17 12:29:46 +02:00
parent 8684f1ecc7
commit 97a3d90f14
4 changed files with 15 additions and 16 deletions

View File

@@ -190,7 +190,7 @@ namespace Marro.PacManUdon
public static Vector2 PositionToGrid(Vector2 position) 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) public static bool CrossesTileBorder(Vector2 currentPosition, Vector2 nextPosition, Direction direction)

View File

@@ -130,30 +130,29 @@ namespace Marro.PacManUdon
private Vector2 ProcessNextPosition(Vector2 position, Vector2 nextPosition) 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)]))) && (!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 { // 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)); 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)]))) && (!IsVertical(targetDirection) || pelletManager.IsWallUpcoming(nextPosition, directionVectors[(int)VerticalComponent(direction)])))
{ {
nextPosition.y = PositionToGrid(nextPosition).y; nextPosition.y = PositionToGrid(nextPosition).y;
SetDirection(HorizontalComponent(direction)); 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(); var inputDirection = input.GetDirection();
if (!inputDirection.Equals(Direction.Zero) && !inputDirection.Equals(targetDirection) // Ignore neutral input or input in our current direction 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 && !pelletManager.IsWallUpcoming(nextPosition, directionVectors[(int)inputDirection])) // Check if the requested direction does not have a wall
//&& (!IsVertical(inputDirection) || (Math.Round(nextPosition.y, 5) - 0.5) % 1 != 0) {
&& !pelletManager.IsWallUpcoming(nextPosition, directionVectors[(int)inputDirection])) // Move in the requested direction, as well as perpundicular to it to get to the center of the tunnel
{ // Check if the requested direction does not have a wall
if (IsHorizontal(inputDirection)) 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); var directionToCenter = VerticalToDirection(PositionToGrid(nextPosition).y - nextPosition.y);
SetDirection((Direction)((int)inputDirection | (int)directionToCenter)); SetDirection((Direction)((int)inputDirection | (int)directionToCenter));
} }

View File

@@ -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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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,

View File

@@ -58,10 +58,10 @@ namespace Marro.PacManUdon.Dev
private void WriteBonusFruitTiles(int[] map) private void WriteBonusFruitTiles(int[] map)
{ {
var position = bonusFruit.transform.localPosition; var position = GridMover.PositionToGrid(new Vector2(bonusFruit.transform.localPosition.x, bonusFruit.transform.localPosition.y));
var leftTileIndex = PelletManager.GetTilemapIndex(new Vector2(position.x - 0.5f, position.y)); var leftTileIndex = PelletManager.GetTilemapIndex(position);
map[leftTileIndex] = (int)PacManConsumableType.FruitLeft; 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; map[rightTileIndex] = (int)PacManConsumableType.FruitRight;
} }