Maze 32x32
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user