Ghost turn points baked
This commit is contained in:
@@ -9,17 +9,44 @@ public class MazeDefinitionGenerator : UdonSharpBehaviour
|
||||
{
|
||||
void Start()
|
||||
{
|
||||
GetMazeMap();
|
||||
PrintPelletMap();
|
||||
PrintMazeMap();
|
||||
}
|
||||
|
||||
private void GetMazeMap()
|
||||
private void PrintPelletMap()
|
||||
{
|
||||
var pellets = GetComponentsInChildren<Pellet>(includeInactive: true);
|
||||
|
||||
var width = 28;
|
||||
var height = 31;
|
||||
|
||||
var pellets = GetComponentsInChildren<Pellet>(includeInactive: true);
|
||||
|
||||
int[] map = new int[width * height];
|
||||
int[] pelletLocations = new int[pellets.Length];
|
||||
|
||||
for (int i = 0; i < map.Length; i++)
|
||||
{
|
||||
map[i] = -1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < pellets.Length; i++)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
PrintMap(map, width);
|
||||
PrintMap(pelletLocations, 16);
|
||||
}
|
||||
|
||||
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++)
|
||||
@@ -27,22 +54,87 @@ public class MazeDefinitionGenerator : UdonSharpBehaviour
|
||||
if (collisionMap[i])
|
||||
{
|
||||
map[i] = (int)PacManTileType.Wall;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
map[i] = (int)PacManTileType.Empty;
|
||||
}
|
||||
|
||||
map[i] = GetGhostTurnInformation(collisionMap, i, width, height);
|
||||
}
|
||||
|
||||
for (int i = 0; i < pellets.Length; i++)
|
||||
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)])
|
||||
{
|
||||
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;
|
||||
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)PacManTileType.Empty;
|
||||
}
|
||||
|
||||
if (availableDirections == 0b0011 || availableDirections == 0b1100)
|
||||
{
|
||||
return (int)PacManTileType.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++)
|
||||
{
|
||||
@@ -62,19 +154,6 @@ public class MazeDefinitionGenerator : UdonSharpBehaviour
|
||||
}
|
||||
|
||||
Debug.Log(result);
|
||||
|
||||
result = "";
|
||||
for (int i = 0; i < pelletLocations.Length; i++)
|
||||
{
|
||||
result += $"{pelletLocations[i]:000}, ";
|
||||
|
||||
if (i % 16 == 15)
|
||||
{
|
||||
result += "\n";
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Log(result);
|
||||
}
|
||||
|
||||
public static bool[] GetCollisionMap() => new bool[] {
|
||||
|
||||
Reference in New Issue
Block a user