Flipped up and down in code
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user