Ghost turn points baked
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -43,7 +43,7 @@ MonoBehaviour:
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 12
|
||||
Data: 40
|
||||
Data: 41
|
||||
- Name:
|
||||
Entry: 7
|
||||
Data:
|
||||
@@ -2118,6 +2118,55 @@ MonoBehaviour:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 7
|
||||
Data:
|
||||
- Name: $k
|
||||
Entry: 1
|
||||
Data: horizontalDirections
|
||||
- Name: $v
|
||||
Entry: 7
|
||||
Data: 107|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
|
||||
- Name: <Name>k__BackingField
|
||||
Entry: 1
|
||||
Data: horizontalDirections
|
||||
- Name: <UserType>k__BackingField
|
||||
Entry: 9
|
||||
Data: 98
|
||||
- Name: <SystemType>k__BackingField
|
||||
Entry: 9
|
||||
Data: 99
|
||||
- Name: <SyncMode>k__BackingField
|
||||
Entry: 7
|
||||
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
|
||||
- Name:
|
||||
Entry: 6
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name: <IsSerialized>k__BackingField
|
||||
Entry: 5
|
||||
Data: false
|
||||
- Name: _fieldAttributes
|
||||
Entry: 7
|
||||
Data: 108|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
|
||||
mscorlib
|
||||
- Name:
|
||||
Entry: 12
|
||||
Data: 0
|
||||
- Name:
|
||||
Entry: 13
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 13
|
||||
Data:
|
||||
|
||||
@@ -173,7 +173,6 @@ namespace Marro.PacManUdon
|
||||
&& CrossesTileCenter(position, nextPosition, direction))
|
||||
{
|
||||
var newDirection = GetInverseDirection(direction);
|
||||
Debug.Log($"{gameObject} turned around from direction {direction} to {newDirection}");
|
||||
SetDirection(newDirection);
|
||||
turnAroundSoon = false;
|
||||
return nextPosition;
|
||||
@@ -185,6 +184,29 @@ namespace Marro.PacManUdon
|
||||
}
|
||||
|
||||
if (offGrid || ghostState == PacManGhostState.Returning)
|
||||
{
|
||||
PerformOffgridRelatedMovement(position, ref nextPosition);
|
||||
}
|
||||
|
||||
if (!offGrid && followingPredefinedPath)
|
||||
{
|
||||
nextPosition = ProcessPredefinedPath(position, nextPosition);
|
||||
}
|
||||
else if (!offGrid && CrossesTileCenter(position, nextPosition, direction))
|
||||
{
|
||||
TryToTurn(position, ref nextPosition);
|
||||
}
|
||||
|
||||
var distance = Vector2.Distance(position, nextPosition);
|
||||
if (distance > 0.5f)
|
||||
{
|
||||
Debug.LogError($"{gameObject} Just jumped by distance {distance}! position: {position}, nextPosition: {nextPosition}, direction: {direction}, offGrid: {offGrid}, ghostState: {ghostState}");
|
||||
}
|
||||
|
||||
return nextPosition;
|
||||
}
|
||||
|
||||
private Vector2 PerformOffgridRelatedMovement(Vector2 position, ref Vector2 nextPosition)
|
||||
{
|
||||
bool XAxisAlligned = CheckAndAllignToTargetX(position, nextPosition, target);
|
||||
bool YAxisAlligned = CheckAndAllignToTargetY(position, nextPosition, target);
|
||||
@@ -214,51 +236,48 @@ namespace Marro.PacManUdon
|
||||
// Debug.Log($"{gameObject} Alligned X Axis: {XAxisAlligned}, Y Axis: {YAxisAlligned} with position: {position}, new nextPosition: {nextPosition}, new target: {target}, now moving in direction {direction}");
|
||||
// nextPosition = GridMover.GetNextPosition(position, direction, speed);
|
||||
}
|
||||
}
|
||||
if (!offGrid && followingPredefinedPath)
|
||||
{
|
||||
nextPosition = ProcessPredefinedPath(position, nextPosition);
|
||||
}
|
||||
else if (!offGrid && CrossesTileCenter(position, nextPosition, direction))
|
||||
{
|
||||
var gridPosition = PositionToGrid(position);
|
||||
var blockedDirections = pelletManager.GetBlockedDirections(position);
|
||||
blockedDirections[GetIllegalCardinalDirection(direction)] = true; // Not allowed to turn around
|
||||
|
||||
target = GetGridTarget(gridPosition);
|
||||
var newDirection = GetGridDirectionToTargetGreedy(blockedDirections, gridPosition, target);
|
||||
if (newDirection != direction)
|
||||
{
|
||||
Debug.Log($"{gameObject.name} Was moving in direction {direction}, continues with moving in direction {newDirection}");
|
||||
nextPosition = GetNextPosition(gridPosition, directionVectors[(int)newDirection], speed, networkManager.SyncedDeltaTime);
|
||||
SetDirection(newDirection);
|
||||
}
|
||||
// Debug.Log($"{gameObject} crossed tile center {gridPosition}, new target: {target}, new direction: {direction}");
|
||||
}
|
||||
|
||||
var distance = Vector2.Distance(position, nextPosition);
|
||||
if (distance > 0.5f)
|
||||
{
|
||||
Debug.LogError($"{gameObject} Just jumped by distance {distance}! position: {position}, nextPosition: {nextPosition}, direction: {direction}, offGrid: {offGrid}, ghostState: {ghostState}");
|
||||
}
|
||||
|
||||
return nextPosition;
|
||||
}
|
||||
|
||||
private int GetIllegalCardinalDirection(Direction direction)
|
||||
private void TryToTurn(Vector2 position, ref Vector2 nextPosition)
|
||||
{
|
||||
var gridPosition = PositionToGrid(position);
|
||||
var availableDirections = pelletManager.GetAvailableDirections(position);
|
||||
|
||||
if (availableDirections == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
availableDirections &= GetIllegalCardinalDirectionMask(direction); // Not allowed to turn around
|
||||
|
||||
target = GetGridTarget(gridPosition);
|
||||
var newDirection = GetGridDirectionToTargetGreedy(availableDirections, gridPosition, target);
|
||||
if (newDirection == direction)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Log($"{gameObject.name} Turned from direction {direction} to direction {newDirection}");
|
||||
nextPosition = GetNextPosition(gridPosition, directionVectors[(int)newDirection], speed, networkManager.SyncedDeltaTime);
|
||||
SetDirection(newDirection);
|
||||
}
|
||||
|
||||
private int GetIllegalCardinalDirectionMask(Direction direction)
|
||||
{
|
||||
switch (direction)
|
||||
{
|
||||
case Direction.Up:
|
||||
return 1;
|
||||
return 0b1101;
|
||||
case Direction.Down:
|
||||
return 0;
|
||||
return 0b1110;
|
||||
case Direction.Left:
|
||||
return 3;
|
||||
return 0b0111;
|
||||
case Direction.Right:
|
||||
return 2;
|
||||
return 0b1011;
|
||||
default:
|
||||
return 0;
|
||||
return 0b1111;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -431,20 +450,20 @@ namespace Marro.PacManUdon
|
||||
return rngState;
|
||||
}
|
||||
|
||||
private Direction[] cardinalDirections = new Direction[] { Direction.Up, Direction.Down, Direction.Left, Direction.Right };
|
||||
Direction GetGridDirectionToTargetGreedy(bool[] blockedDirections, Vector2 gridPosition, Vector2 targetGridPosition)
|
||||
private readonly Direction[] cardinalDirections = new Direction[] { Direction.Up, Direction.Left, Direction.Down, Direction.Right };
|
||||
private readonly Direction[] horizontalDirections = new Direction[] { Direction.Left, Direction.Right };
|
||||
Direction GetGridDirectionToTargetGreedy(int availableDirections, Vector2 gridPosition, Vector2 targetGridPosition)
|
||||
{
|
||||
Direction bestDirection = Direction.Zero;
|
||||
float bestDistance = float.MaxValue;
|
||||
for (int i = horizontalOnly ? 2 : 0; i < blockedDirections.Length; i++)
|
||||
foreach (var direction in horizontalOnly ? horizontalDirections : cardinalDirections)
|
||||
{
|
||||
if (blockedDirections[i])
|
||||
if (((int)direction & availableDirections) == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Debug.Log("Evaluating direction " + direction);
|
||||
var direction = cardinalDirections[i];
|
||||
float distance = Vector2.Distance(gridPosition + directionVectors[(int)direction], targetGridPosition);
|
||||
if (distance < bestDistance)
|
||||
{
|
||||
|
||||
@@ -59,41 +59,77 @@ namespace Marro.PacManUdon
|
||||
public static class PacManConstants
|
||||
{
|
||||
// Jagged or 2D arrays can't be static so we work with 1D arrays
|
||||
public static int[] GetMazeDefinition() => new int[] {
|
||||
public static int[] GetMazeCollisionInfo() => new int[]
|
||||
{
|
||||
-02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02,
|
||||
-02, 216, 215, 214, 213, 212, 196, 195, 194, 193, 192, 191, 190, -02, -02, 178, 179, 180, 181, 182, 183, 152, 151, 150, 149, 148, 147, -02,
|
||||
-02, 217, -02, -02, -02, -02, 197, -02, -02, -02, -02, -02, 189, -02, -02, 177, -02, -02, -02, -02, -02, 153, -02, -02, -02, -02, 146, -02,
|
||||
-02, 003, -02, -01, -01, -02, 198, -02, -01, -01, -01, -02, 188, -02, -02, 176, -02, -01, -01, -01, -02, 154, -02, -01, -01, -02, 002, -02,
|
||||
-02, 218, -02, -02, -02, -02, 199, -02, -02, -02, -02, -02, 187, -02, -02, 175, -02, -02, -02, -02, -02, 155, -02, -02, -02, -02, 145, -02,
|
||||
-02, 219, 220, 221, 222, 223, 200, 201, 202, 203, 204, 205, 186, 185, 184, 174, 173, 172, 165, 164, 163, 156, 157, 158, 159, 160, 144, -02,
|
||||
-02, 224, -02, -02, -02, -02, 231, -02, -02, 206, -02, -02, -02, -02, -02, -02, -02, -02, 166, -02, -02, 161, -02, -02, -02, -02, 143, -02,
|
||||
-02, 225, -02, -02, -02, -02, 232, -02, -02, 207, -02, -02, -02, -02, -02, -02, -02, -02, 167, -02, -02, 162, -02, -02, -02, -02, 142, -02,
|
||||
-02, 226, 227, 228, 229, 230, 233, -02, -02, 208, 209, 210, 211, -02, -02, 171, 170, 169, 168, -02, -02, 136, 137, 138, 139, 140, 141, -02,
|
||||
-02, -02, -02, -02, -02, -02, 234, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, 134, -02, -02, -02, -02, -02, -02,
|
||||
-01, -01, -01, -01, -01, -02, 235, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, 133, -02, -01, -01, -01, -01, -01,
|
||||
-01, -01, -01, -01, -01, -02, 236, -02, -02, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -02, -02, 132, -02, -01, -01, -01, -01, -01,
|
||||
-01, -01, -01, -01, -01, -02, 237, -02, -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, -02, 131, -02, -01, -01, -01, -01, -01,
|
||||
-02, -02, -02, -02, -02, -02, 238, -02, -02, -01, -02, -01, -01, -01, -01, -01, -01, -02, -01, -02, -02, 130, -02, -02, -02, -02, -02, -02,
|
||||
-01, -01, -01, -01, -01, -01, 239, -01, -01, -01, -02, -01, -01, -01, -01, -01, -01, -02, -01, -01, -01, 129, -01, -01, -01, -01, -01, -01,
|
||||
-02, -02, -02, -02, -02, -02, 240, -02, -02, -01, -02, -01, -01, -01, -01, -01, -01, -02, -01, -02, -02, 128, -02, -02, -02, -02, -02, -02,
|
||||
-01, -01, -01, -01, -01, -02, 241, -02, -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, -02, 127, -02, -01, -01, -01, -01, -01,
|
||||
-01, -01, -01, -01, -01, -02, 242, -02, -02, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -02, -02, 126, -02, -01, -01, -01, -01, -01,
|
||||
-01, -01, -01, -01, -01, -02, 243, -02, -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, -02, 125, -02, -01, -01, -01, -01, -01,
|
||||
-02, -02, -02, -02, -02, -02, 244, -02, -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, -02, 124, -02, -02, -02, -02, -02, -02,
|
||||
-02, 086, 087, 088, 089, 090, 091, 094, 095, 096, 097, 098, 099, -02, -02, 104, 105, 106, 107, 108, 109, 110, 123, 122, 121, 120, 119, -02,
|
||||
-02, 085, -02, -02, -02, -02, 092, -02, -02, -02, -02, -02, 100, -02, -02, 103, -02, -02, -02, -02, -02, 111, -02, -02, -02, -02, 118, -02,
|
||||
-02, 084, -02, -02, -02, -02, 093, -02, -02, -02, -02, -02, 101, -02, -02, 102, -02, -02, -02, -02, -02, 112, -02, -02, -02, -02, 117, -02,
|
||||
-02, 000, 083, 082, -02, -02, 010, 009, 008, 007, 006, 005, 004, -01, -01, 063, 062, 061, 060, 059, 058, 057, -02, -02, 115, 116, 001, -02,
|
||||
-02, -02, -02, 081, -02, -02, 011, -02, -02, 079, -02, -02, -02, -02, -02, -02, -02, -02, 064, -02, -02, 056, -02, -02, 114, -02, -02, -02,
|
||||
-02, -02, -02, 080, -02, -02, 012, -02, -02, 078, -02, -02, -02, -02, -02, -02, -02, -02, 065, -02, -02, 055, -02, -02, 113, -02, -02, -02,
|
||||
-02, 018, 017, 016, 015, 014, 013, -02, -02, 077, 076, 075, 074, -02, -02, 069, 068, 067, 066, -02, -02, 054, 053, 052, 051, 050, 049, -02,
|
||||
-02, 019, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, 073, -02, -02, 070, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, 048, -02,
|
||||
-02, 020, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, 072, -02, -02, 071, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, 047, -02,
|
||||
-02, 021, 022, 023, 024, 025, 026, 027, 028, 029, 030, 031, 032, 033, 034, 035, 036, 037, 038, 039, 040, 041, 042, 043, 044, 045, 046, -02,
|
||||
-02, 009, -01, -01, -01, -01, 013, -01, -01, -01, -01, -01, 005, -02, -02, 009, -01, -01, -01, -01, -01, 013, -01, -01, -01, -01, 005, -02,
|
||||
-02, -01, -02, -02, -02, -02, -01, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -01, -02, -02, -02, -02, -01, -02,
|
||||
-02, -01, -02, -01, -01, -02, -01, -02, -01, -01, -01, -02, -01, -02, -02, -01, -02, -01, -01, -01, -02, -01, -02, -01, -01, -02, -01, -02,
|
||||
-02, -01, -02, -02, -02, -02, -01, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -01, -02, -02, -02, -02, -01, -02,
|
||||
-02, 011, -01, -01, -01, -01, 015, -01, -01, 013, -01, -01, 014, -01, -01, 014, -01, -01, 013, -01, -01, 015, -01, -01, -01, -01, 007, -02,
|
||||
-02, -01, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -01, -02,
|
||||
-02, -01, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -01, -02,
|
||||
-02, 010, -01, -01, -01, -01, 007, -02, -02, 010, -01, -01, 005, -02, -02, 009, -01, -01, 006, -02, -02, 011, -01, -01, -01, -01, 006, -02,
|
||||
-02, -02, -02, -02, -02, -02, -01, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -01, -02, -02, -02, -02, -02, -02,
|
||||
013, 013, 013, 013, 005, -02, -01, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -01, -02, 009, 013, 013, 013, 013,
|
||||
015, 015, 015, 015, 007, -02, -01, -02, -02, 009, -01, -01, 014, -01, -01, 014, -01, -01, 005, -02, -02, -01, -02, 011, 015, 015, 015, 015,
|
||||
014, 014, 014, 014, 006, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, 010, 014, 014, 014, 014,
|
||||
-02, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, 009, 013, 013, 013, 013, 005, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -02,
|
||||
-01, -01, -01, -01, -01, -01, 015, -01, -01, 007, -02, 011, 015, 015, 015, 015, 007, -02, 011, -01, -01, 015, -01, -01, -01, -01, -01, -01,
|
||||
-02, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, 010, 014, 014, 014, 014, 006, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -02,
|
||||
013, 013, 013, 013, 005, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, 009, 013, 013, 013, 013,
|
||||
015, 015, 015, 015, 007, -02, -01, -02, -02, 011, -01, -01, -01, -01, -01, -01, -01, -01, 007, -02, -02, -01, -02, 011, 015, 015, 015, 015,
|
||||
014, 014, 014, 014, 006, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, 010, 014, 014, 014, 014,
|
||||
-02, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -02,
|
||||
-02, 009, -01, -01, -01, -01, 015, -01, -01, 014, -01, -01, 005, -02, -02, 009, -01, -01, 014, -01, -01, 015, -01, -01, -01, -01, 005, -02,
|
||||
-02, -01, -02, -02, -02, -02, -01, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -01, -02, -02, -02, -02, -01, -02,
|
||||
-02, -01, -02, -02, -02, -02, -01, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -01, -02, -02, -02, -02, -01, -02,
|
||||
-02, 010, -01, 005, -02, -02, 011, -01, -01, 013, -01, -01, 014, -01, -01, 014, -01, -01, 013, -01, -01, 007, -02, -02, 009, -01, 006, -02,
|
||||
-02, -02, -02, -01, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -01, -02, -02, -02,
|
||||
-02, -02, -02, -01, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -01, -02, -02, -02,
|
||||
-02, 009, -01, 014, -01, -01, 006, -02, -02, 010, -01, -01, 005, -02, -02, 009, -01, -01, 006, -02, -02, 010, -01, -01, 014, -01, 005, -02,
|
||||
-02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02,
|
||||
-02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02,
|
||||
-02, 010, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 014, -01, -01, 014, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 006, -02,
|
||||
-02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02,
|
||||
};
|
||||
|
||||
public static int[] GetPelletIndices() => new int[]
|
||||
public static int[] GetMazePelletMap() => new int[]
|
||||
{
|
||||
-01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01,
|
||||
-01, 216, 215, 214, 213, 212, 196, 195, 194, 193, 192, 191, 190, -01, -01, 178, 179, 180, 181, 182, 183, 152, 151, 150, 149, 148, 147, -01,
|
||||
-01, 217, -01, -01, -01, -01, 197, -01, -01, -01, -01, -01, 189, -01, -01, 177, -01, -01, -01, -01, -01, 153, -01, -01, -01, -01, 146, -01,
|
||||
-01, 003, -01, -01, -01, -01, 198, -01, -01, -01, -01, -01, 188, -01, -01, 176, -01, -01, -01, -01, -01, 154, -01, -01, -01, -01, 002, -01,
|
||||
-01, 218, -01, -01, -01, -01, 199, -01, -01, -01, -01, -01, 187, -01, -01, 175, -01, -01, -01, -01, -01, 155, -01, -01, -01, -01, 145, -01,
|
||||
-01, 219, 220, 221, 222, 223, 200, 201, 202, 203, 204, 205, 186, 185, 184, 174, 173, 172, 165, 164, 163, 156, 157, 158, 159, 160, 144, -01,
|
||||
-01, 224, -01, -01, -01, -01, 231, -01, -01, 206, -01, -01, -01, -01, -01, -01, -01, -01, 166, -01, -01, 161, -01, -01, -01, -01, 143, -01,
|
||||
-01, 225, -01, -01, -01, -01, 232, -01, -01, 207, -01, -01, -01, -01, -01, -01, -01, -01, 167, -01, -01, 162, -01, -01, -01, -01, 142, -01,
|
||||
-01, 226, 227, 228, 229, 230, 233, -01, -01, 208, 209, 210, 211, -01, -01, 171, 170, 169, 168, -01, -01, 136, 137, 138, 139, 140, 141, -01,
|
||||
-01, -01, -01, -01, -01, -01, 234, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 134, -01, -01, -01, -01, -01, -01,
|
||||
-01, -01, -01, -01, -01, -01, 235, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 133, -01, -01, -01, -01, -01, -01,
|
||||
-01, -01, -01, -01, -01, -01, 236, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 132, -01, -01, -01, -01, -01, -01,
|
||||
-01, -01, -01, -01, -01, -01, 237, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 131, -01, -01, -01, -01, -01, -01,
|
||||
-01, -01, -01, -01, -01, -01, 238, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 130, -01, -01, -01, -01, -01, -01,
|
||||
-01, -01, -01, -01, -01, -01, 239, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 129, -01, -01, -01, -01, -01, -01,
|
||||
-01, -01, -01, -01, -01, -01, 240, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 128, -01, -01, -01, -01, -01, -01,
|
||||
-01, -01, -01, -01, -01, -01, 241, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 127, -01, -01, -01, -01, -01, -01,
|
||||
-01, -01, -01, -01, -01, -01, 242, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 126, -01, -01, -01, -01, -01, -01,
|
||||
-01, -01, -01, -01, -01, -01, 243, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 125, -01, -01, -01, -01, -01, -01,
|
||||
-01, -01, -01, -01, -01, -01, 244, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 124, -01, -01, -01, -01, -01, -01,
|
||||
-01, 086, 087, 088, 089, 090, 091, 094, 095, 096, 097, 098, 099, -01, -01, 104, 105, 106, 107, 108, 109, 110, 123, 122, 121, 120, 119, -01,
|
||||
-01, 085, -01, -01, -01, -01, 092, -01, -01, -01, -01, -01, 100, -01, -01, 103, -01, -01, -01, -01, -01, 111, -01, -01, -01, -01, 118, -01,
|
||||
-01, 084, -01, -01, -01, -01, 093, -01, -01, -01, -01, -01, 101, -01, -01, 102, -01, -01, -01, -01, -01, 112, -01, -01, -01, -01, 117, -01,
|
||||
-01, 000, 083, 082, -01, -01, 010, 009, 008, 007, 006, 005, 004, -01, -01, 063, 062, 061, 060, 059, 058, 057, -01, -01, 115, 116, 001, -01,
|
||||
-01, -01, -01, 081, -01, -01, 011, -01, -01, 079, -01, -01, -01, -01, -01, -01, -01, -01, 064, -01, -01, 056, -01, -01, 114, -01, -01, -01,
|
||||
-01, -01, -01, 080, -01, -01, 012, -01, -01, 078, -01, -01, -01, -01, -01, -01, -01, -01, 065, -01, -01, 055, -01, -01, 113, -01, -01, -01,
|
||||
-01, 018, 017, 016, 015, 014, 013, -01, -01, 077, 076, 075, 074, -01, -01, 069, 068, 067, 066, -01, -01, 054, 053, 052, 051, 050, 049, -01,
|
||||
-01, 019, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 073, -01, -01, 070, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 048, -01,
|
||||
-01, 020, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 072, -01, -01, 071, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, 047, -01,
|
||||
-01, 021, 022, 023, 024, 025, 026, 027, 028, 029, 030, 031, 032, 033, 034, 035, 036, 037, 038, 039, 040, 041, 042, 043, 044, 045, 046, -01,
|
||||
-01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01,
|
||||
};
|
||||
|
||||
public static int[] GetMazePelletIndices() => new int[]
|
||||
{
|
||||
645, 670, 110, 085, 656, 655, 654, 653, 652, 651, 650, 678, 706, 734, 733, 732,
|
||||
731, 730, 729, 757, 785, 813, 814, 815, 816, 817, 818, 819, 820, 821, 822, 823,
|
||||
|
||||
@@ -535,13 +535,13 @@ MonoBehaviour:
|
||||
Data:
|
||||
- Name: $k
|
||||
Entry: 1
|
||||
Data: tilemap
|
||||
Data: collisionMap
|
||||
- Name: $v
|
||||
Entry: 7
|
||||
Data: 29|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
|
||||
- Name: <Name>k__BackingField
|
||||
Entry: 1
|
||||
Data: tilemap
|
||||
Data: collisionMap
|
||||
- Name: <UserType>k__BackingField
|
||||
Entry: 7
|
||||
Data: 30|System.RuntimeType, mscorlib
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Marro.PacManUdon
|
||||
|
||||
byte[] syncedPelletsCollected;
|
||||
|
||||
int[] tilemap;
|
||||
int[] collisionMap;
|
||||
|
||||
const int mazeWidth = 28;
|
||||
const int mazeHeight = 31;
|
||||
@@ -84,23 +84,22 @@ namespace Marro.PacManUdon
|
||||
public bool IsWallUpcoming(Vector2 position, Vector2 directionVector)
|
||||
{
|
||||
var result = GetTileAt(position + directionVector) == (int)PacManTileType.Wall;
|
||||
Debug.Log($"Is wall upcoming {result} at position {position}, direction {directionVector}");
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool[] GetBlockedDirections(Vector2 position)
|
||||
public int GetAvailableDirections(Vector2 position)
|
||||
{
|
||||
var results = new bool[4];
|
||||
var directions = GetTileAt(position);
|
||||
|
||||
results[0] = IsWallUpcoming(position, Vector2.down);
|
||||
results[1] = IsWallUpcoming(position, Vector2.up);
|
||||
results[2] = IsWallUpcoming(position, Vector2.left);
|
||||
results[3] = IsWallUpcoming(position, Vector2.right);
|
||||
|
||||
return results;
|
||||
if (directions <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int GetTileAt(Vector2 position) => tilemap[GetTilemapIndex(position)];
|
||||
return directions;
|
||||
}
|
||||
|
||||
private int GetTileAt(Vector2 position) => collisionMap[GetTilemapIndex(position)];
|
||||
|
||||
private int GetTilemapIndex(Vector2 position)
|
||||
{
|
||||
@@ -133,7 +132,7 @@ namespace Marro.PacManUdon
|
||||
syncedPelletsCollected = new byte[pellets.Length/8 + 1];
|
||||
PelletCollectedCount = 0;
|
||||
|
||||
tilemap = PacManConstants.GetMazeDefinition();
|
||||
collisionMap = PacManConstants.GetMazeCollisionInfo();
|
||||
|
||||
return PelletCount;
|
||||
}
|
||||
|
||||
@@ -9,29 +9,23 @@ 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];
|
||||
var collisionMap = GetCollisionMap();
|
||||
|
||||
for (int i = 0; i < map.Length; i++)
|
||||
{
|
||||
if (collisionMap[i])
|
||||
{
|
||||
map[i] = (int)PacManTileType.Wall;
|
||||
}
|
||||
else
|
||||
{
|
||||
map[i] = (int)PacManTileType.Empty;
|
||||
}
|
||||
map[i] = -1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < pellets.Length; i++)
|
||||
@@ -43,6 +37,104 @@ public class MazeDefinitionGenerator : UdonSharpBehaviour
|
||||
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++)
|
||||
{
|
||||
if (collisionMap[i])
|
||||
{
|
||||
map[i] = (int)PacManTileType.Wall;
|
||||
continue;
|
||||
}
|
||||
|
||||
map[i] = GetGhostTurnInformation(collisionMap, i, width, height);
|
||||
}
|
||||
|
||||
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)])
|
||||
{
|
||||
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