Switched to Direction enum

This commit is contained in:
2026-06-15 10:29:36 +02:00
parent 2ccf77c0eb
commit 73b3194c51
25 changed files with 2874 additions and 1987 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 B

View File

@@ -0,0 +1,114 @@
fileFormatVersion: 2
guid: 433bc126202e0994fa11758168105efa
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 12
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -3955,7 +3955,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 0
--- !u!4 &805005471 --- !u!4 &805005471
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -6266,6 +6266,10 @@ PrefabInstance:
propertyPath: serializationData.Prefab propertyPath: serializationData.Prefab
value: value:
objectReference: {fileID: 626384261962381809, guid: 15ac0ed4c56c7784ea3ae9000fc2af1f, type: 3} objectReference: {fileID: 626384261962381809, guid: 15ac0ed4c56c7784ea3ae9000fc2af1f, type: 3}
- target: {fileID: 642653665749402579, guid: 15ac0ed4c56c7784ea3ae9000fc2af1f, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 2541243872366204002, guid: 7168d13094fcae94b81e672d1f4ab73f, type: 2}
- target: {fileID: 690094551578429092, guid: 15ac0ed4c56c7784ea3ae9000fc2af1f, type: 3} - target: {fileID: 690094551578429092, guid: 15ac0ed4c56c7784ea3ae9000fc2af1f, type: 3}
propertyPath: serializationData.Prefab propertyPath: serializationData.Prefab
value: value:
@@ -10831,10 +10835,6 @@ MonoBehaviour:
ID: 308 ID: 308
SerializedTypeNames: SerializedTypeNames:
- VRC.Udon.UdonBehaviour - VRC.Udon.UdonBehaviour
- gameObject: {fileID: 1777057122}
ID: 39
SerializedTypeNames:
- VRC.Udon.UdonBehaviour
- gameObject: {fileID: 2121595711} - gameObject: {fileID: 2121595711}
ID: 310 ID: 310
SerializedTypeNames: SerializedTypeNames:
@@ -11980,6 +11980,11 @@ MonoBehaviour:
SerializedTypeNames: SerializedTypeNames:
- VRC.Udon.UdonBehaviour - VRC.Udon.UdonBehaviour
- VRC.Udon.UdonBehaviour - VRC.Udon.UdonBehaviour
- gameObject: {fileID: 1777057122}
ID: 39
SerializedTypeNames:
- VRC.Udon.UdonBehaviour
- VRC.Udon.UdonBehaviour
portraitCameraPositionOffset: {x: 0, y: 0, z: 0} portraitCameraPositionOffset: {x: 0, y: 0, z: 0}
portraitCameraRotationOffset: {x: 0, y: 1, z: 0, w: -0.00000004371139} portraitCameraRotationOffset: {x: 0, y: 1, z: 0, w: -0.00000004371139}
PlayerPersistence: [] PlayerPersistence: []
@@ -12129,6 +12134,53 @@ GameObject:
m_CorrespondingSourceObject: {fileID: 8569251470677094682, guid: 15ac0ed4c56c7784ea3ae9000fc2af1f, type: 3} m_CorrespondingSourceObject: {fileID: 8569251470677094682, guid: 15ac0ed4c56c7784ea3ae9000fc2af1f, type: 3}
m_PrefabInstance: {fileID: 7528894854307259292} m_PrefabInstance: {fileID: 7528894854307259292}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!114 &1777057126
MonoBehaviour:
m_ObjectHideFlags: 2
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1777057122}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 45115577ef41a5b4ca741ed302693907, type: 3}
m_Name:
m_EditorClassIdentifier:
interactTextPlacement: {fileID: 0}
interactText: Use
interactTextGO: {fileID: 0}
proximity: 2
SynchronizePosition: 0
AllowCollisionOwnershipTransfer: 0
Reliable: 0
_syncMethod: 2
serializedProgramAsset: {fileID: 11400000, guid: ea99e044f80fed446bb669640608f521, type: 2}
programSource: {fileID: 11400000, guid: 909752e684c57f24093795e3ba5e2c80, type: 2}
serializedPublicVariablesBytesString: Ai8AAAAAATIAAABWAFIAQwAuAFUAZABvAG4ALgBDAG8AbQBtAG8AbgAuAFUAZABvAG4AVgBhAHIAaQBhAGIAbABlAFQAYQBiAGwAZQAsACAAVgBSAEMALgBVAGQAbwBuAC4AQwBvAG0AbQBvAG4AAAAAAAYBAAAAAAAAACcBBAAAAHQAeQBwAGUAAWgAAABTAHkAcwB0AGUAbQAuAEMAbwBsAGwAZQBjAHQAaQBvAG4AcwAuAEcAZQBuAGUAcgBpAGMALgBMAGkAcwB0AGAAMQBbAFsAVgBSAEMALgBVAGQAbwBuAC4AQwBvAG0AbQBvAG4ALgBJAG4AdABlAHIAZgBhAGMAZQBzAC4ASQBVAGQAbwBuAFYAYQByAGkAYQBiAGwAZQAsACAAVgBSAEMALgBVAGQAbwBuAC4AQwBvAG0AbQBvAG4AXQBdACwAIABtAHMAYwBvAHIAbABpAGIAAQEJAAAAVgBhAHIAaQBhAGIAbABlAHMALwEAAAABaAAAAFMAeQBzAHQAZQBtAC4AQwBvAGwAbABlAGMAdABpAG8AbgBzAC4ARwBlAG4AZQByAGkAYwAuAEwAaQBzAHQAYAAxAFsAWwBWAFIAQwAuAFUAZABvAG4ALgBDAG8AbQBtAG8AbgAuAEkAbgB0AGUAcgBmAGEAYwBlAHMALgBJAFUAZABvAG4AVgBhAHIAaQBhAGIAbABlACwAIABWAFIAQwAuAFUAZABvAG4ALgBDAG8AbQBtAG8AbgBdAF0ALAAgAG0AcwBjAG8AcgBsAGkAYgABAAAABgEAAAAAAAAAAi8CAAAAAUkAAABWAFIAQwAuAFUAZABvAG4ALgBDAG8AbQBtAG8AbgAuAFUAZABvAG4AVgBhAHIAaQBhAGIAbABlAGAAMQBbAFsAUwB5AHMAdABlAG0ALgBJAG4AdAAzADIALAAgAG0AcwBjAG8AcgBsAGkAYgBdAF0ALAAgAFYAUgBDAC4AVQBkAG8AbgAuAEMAbwBtAG0AbwBuAAIAAAAGAgAAAAAAAAAnAQQAAAB0AHkAcABlAAEXAAAAUwB5AHMAdABlAG0ALgBTAHQAcgBpAG4AZwAsACAAbQBzAGMAbwByAGwAaQBiACcBCgAAAFMAeQBtAGIAbwBsAE4AYQBtAGUAAR8AAABfAF8AXwBVAGQAbwBuAFMAaABhAHIAcABCAGUAaABhAHYAaQBvAHUAcgBWAGUAcgBzAGkAbwBuAF8AXwBfACcBBAAAAHQAeQBwAGUAARYAAABTAHkAcwB0AGUAbQAuAEkAbgB0ADMAMgAsACAAbQBzAGMAbwByAGwAaQBiABcBBQAAAFYAYQBsAHUAZQACAAAABwUHBQcF
publicVariablesUnityEngineObjects: []
publicVariablesSerializationDataFormat: 0
--- !u!114 &1777057127
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1777057122}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 30a9bec71a4b36a41a9b6ee899bef38c, type: 3}
m_Name:
m_EditorClassIdentifier:
serializationData:
SerializedFormat: 2
SerializedBytes:
ReferencedUnityObjects: []
SerializedBytesString:
Prefab: {fileID: 0}
PrefabModificationsReferencedUnityObjects: []
PrefabModifications: []
SerializationNodes: []
_udonSharpBackingUdonBehaviour: {fileID: 1777057126}
--- !u!1 &1785134014 stripped --- !u!1 &1785134014 stripped
GameObject: GameObject:
m_CorrespondingSourceObject: {fileID: 7466015648019123541, guid: 15ac0ed4c56c7784ea3ae9000fc2af1f, type: 3} m_CorrespondingSourceObject: {fileID: 7466015648019123541, guid: 15ac0ed4c56c7784ea3ae9000fc2af1f, type: 3}
@@ -14886,6 +14938,10 @@ PrefabInstance:
propertyPath: serializationData.Prefab propertyPath: serializationData.Prefab
value: value:
objectReference: {fileID: 6074801139074197290, guid: 15ac0ed4c56c7784ea3ae9000fc2af1f, type: 3} objectReference: {fileID: 6074801139074197290, guid: 15ac0ed4c56c7784ea3ae9000fc2af1f, type: 3}
- target: {fileID: 6124172593973027271, guid: 15ac0ed4c56c7784ea3ae9000fc2af1f, type: 3}
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6155378856640629001, guid: 15ac0ed4c56c7784ea3ae9000fc2af1f, type: 3} - target: {fileID: 6155378856640629001, guid: 15ac0ed4c56c7784ea3ae9000fc2af1f, type: 3}
propertyPath: serializationData.Prefab propertyPath: serializationData.Prefab
value: value:
@@ -15312,6 +15368,12 @@ PrefabInstance:
- targetCorrespondingSourceObject: {fileID: 7219308242589081280, guid: 15ac0ed4c56c7784ea3ae9000fc2af1f, type: 3} - targetCorrespondingSourceObject: {fileID: 7219308242589081280, guid: 15ac0ed4c56c7784ea3ae9000fc2af1f, type: 3}
insertIndex: -1 insertIndex: -1
addedObject: {fileID: 0} addedObject: {fileID: 0}
- targetCorrespondingSourceObject: {fileID: 8569251470677094682, guid: 15ac0ed4c56c7784ea3ae9000fc2af1f, type: 3}
insertIndex: -1
addedObject: {fileID: 1777057127}
- targetCorrespondingSourceObject: {fileID: 8569251470677094682, guid: 15ac0ed4c56c7784ea3ae9000fc2af1f, type: 3}
insertIndex: -1
addedObject: {fileID: 1777057126}
- targetCorrespondingSourceObject: {fileID: 5818876718058315162, guid: 15ac0ed4c56c7784ea3ae9000fc2af1f, type: 3} - targetCorrespondingSourceObject: {fileID: 5818876718058315162, guid: 15ac0ed4c56c7784ea3ae9000fc2af1f, type: 3}
insertIndex: -1 insertIndex: -1
addedObject: {fileID: 0} addedObject: {fileID: 0}

File diff suppressed because it is too large Load Diff

View File

@@ -59,7 +59,7 @@ namespace Marro.PacManUdon
networkManager.Initialize(); networkManager.Initialize();
ghostManager.Initialize(maze.ghostStarts, maze.ghostTargets, pacMan, pelletManager, this); ghostManager.Initialize(maze.ghostStarts, maze.ghostTargets, pacMan, pelletManager, this);
pacMan.Initialize(playerInput, maze.pacManStart, this); pacMan.Initialize(playerInput, maze.pacManStart, this, pelletManager);
bonusFruit.Initialize(); bonusFruit.Initialize();
pelletManager.Initialize(); pelletManager.Initialize();
statusDisplay.Initialize(); statusDisplay.Initialize();

File diff suppressed because it is too large Load Diff

View File

@@ -41,6 +41,7 @@ namespace Marro.PacManUdon
// External references // External references
private GhostManager ghostManager; private GhostManager ghostManager;
private PelletManager pelletManager;
private Animator animator; private Animator animator;
private new Renderer renderer; private new Renderer renderer;
private PacMan pacMan; private PacMan pacMan;
@@ -88,12 +89,13 @@ namespace Marro.PacManUdon
public bool IsScared => isScared; public bool IsScared => isScared;
public int Index { get; private set; } public int Index { get; private set; }
public void Initialize(PacMan pacMan, Ghost blinky, Transform startTransform, Vector2 homePosition, Vector2 idlePosition1, Vector2 idlePosition2, Vector2 cornerPosition, int index) public void Initialize(PelletManager pelletManager, PacMan pacMan, Ghost blinky, Transform startTransform, Vector2 homePosition, Vector2 idlePosition1, Vector2 idlePosition2, Vector2 cornerPosition, int index)
{ {
ghostManager = transform.parent.GetComponent<GhostManager>(); ghostManager = transform.parent.GetComponent<GhostManager>();
animator = GetComponent<Animator>(); animator = GetComponent<Animator>();
renderer = GetComponent<Renderer>(); renderer = GetComponent<Renderer>();
this.pelletManager = pelletManager;
this.pacMan = pacMan; this.pacMan = pacMan;
this.blinky = blinky; this.blinky = blinky;
this.homePosition = homePosition; this.homePosition = homePosition;
@@ -158,7 +160,7 @@ namespace Marro.PacManUdon
} }
Vector2 position = GetPosition(); Vector2 position = GetPosition();
Vector2 nextPosition = GridMoverTools.GetNextPosition(position, direction, speed, networkManager.SyncedDeltaTime); Vector2 nextPosition = GetNextPosition(position, directionVectors[(int)direction], speed, networkManager.SyncedDeltaTime);
nextPosition = ProcessNextPosition(position, nextPosition); nextPosition = ProcessNextPosition(position, nextPosition);
@@ -168,10 +170,11 @@ namespace Marro.PacManUdon
private Vector2 ProcessNextPosition(Vector2 position, Vector2 nextPosition) private Vector2 ProcessNextPosition(Vector2 position, Vector2 nextPosition)
{ {
if (turnAroundSoon && ghostState == PacManGhostState.Normal if (turnAroundSoon && ghostState == PacManGhostState.Normal
&& GridMoverTools.CrossesTileBorder(position, nextPosition, direction.x != 0, direction.y != 0)) && CrossesTileBorder(position, nextPosition, direction))
{ {
SetDirection(direction * -1); var newDirection = GetInverseDirection(direction);
//Debug.Log($"{gameObject} turned around to direction {GetDirection()}"); Debug.Log($"{gameObject} turned around from direction {direction} to {newDirection}");
SetDirection(newDirection);
turnAroundSoon = false; turnAroundSoon = false;
return nextPosition; return nextPosition;
} }
@@ -216,21 +219,19 @@ namespace Marro.PacManUdon
{ {
nextPosition = ProcessPredefinedPath(position, nextPosition); nextPosition = ProcessPredefinedPath(position, nextPosition);
} }
else if (!offGrid && GridMoverTools.CrossesTileCenter(position, nextPosition, direction.x != 0, direction.y != 0)) else if (!offGrid && CrossesTileCenter(position, nextPosition, direction))
{
Vector2 gridPosition = GridMoverTools.PositionToGrid(position);
Vector2[] availableDirections = GetAvailableDirections(gridPosition, direction * -1);
if (availableDirections.Length > 1)
{ {
var gridPosition = PositionToGrid(position);
var blockedDirections = pelletManager.GetBlockedDirections(position);
blockedDirections[GetIllegalCardinalDirection(direction)] = true; // Not allowed to turn around
target = GetGridTarget(gridPosition); target = GetGridTarget(gridPosition);
SetDirection(GetGridDirectionToTargetGreedy(availableDirections, gridPosition, target)); var newDirection = GetGridDirectionToTargetGreedy(blockedDirections, gridPosition, target);
nextPosition = GridMoverTools.GetNextPosition(gridPosition, direction, speed, networkManager.SyncedDeltaTime); if (newDirection != direction)
// Debug.Log($"GetNextPosition at gridPosition {gridPosition} with direction {direction} and speed {speed} gives nextPosition {nextPosition}");
}
else if (availableDirections.Length == 1 && availableDirections[0] != direction)
{ {
SetDirection(availableDirections[0]); Debug.Log($"{gameObject.name} Was moving in direction {direction}, continues with moving in direction {newDirection}");
nextPosition = GridMoverTools.GetNextPosition(gridPosition, direction, speed, networkManager.SyncedDeltaTime); nextPosition = GetNextPosition(gridPosition, directionVectors[(int)newDirection], speed, networkManager.SyncedDeltaTime);
SetDirection(newDirection);
} }
// Debug.Log($"{gameObject} crossed tile center {gridPosition}, new target: {target}, new direction: {direction}"); // Debug.Log($"{gameObject} crossed tile center {gridPosition}, new target: {target}, new direction: {direction}");
} }
@@ -244,9 +245,26 @@ namespace Marro.PacManUdon
return nextPosition; return nextPosition;
} }
private int GetIllegalCardinalDirection(Direction direction)
{
switch (direction)
{
case Direction.Up:
return 1;
case Direction.Down:
return 0;
case Direction.Left:
return 3;
case Direction.Right:
return 2;
default:
return 0;
}
}
private Vector2 ProcessPredefinedPath(Vector2 position, Vector2 nextPosition) private Vector2 ProcessPredefinedPath(Vector2 position, Vector2 nextPosition)
{ {
if (GridMoverTools.CrossesTileCenter(position, nextPosition, direction.x != 0, direction.y != 0)) if (CrossesTileCenter(position, nextPosition, direction))
{ {
// Find the next valid direction which isn't Vector2.zero // Find the next valid direction which isn't Vector2.zero
int nextValidDirectionIndex = predefinedPathIndex; int nextValidDirectionIndex = predefinedPathIndex;
@@ -254,13 +272,13 @@ namespace Marro.PacManUdon
{ {
nextValidDirectionIndex += 1; nextValidDirectionIndex += 1;
} }
if (!GridMoverTools.CheckCollisionInDirection(transform, nextPosition, predefinedPath[nextValidDirectionIndex])) if (!CheckCollisionInDirection(transform, nextPosition, predefinedPath[nextValidDirectionIndex]))
{ {
// If we're at a Vector2.zero, we skip applying the direction and only increment. // If we're at a Vector2.zero, we skip applying the direction and only increment.
if (nextValidDirectionIndex == predefinedPathIndex) if (nextValidDirectionIndex == predefinedPathIndex)
{ {
SetDirection(predefinedPath[nextValidDirectionIndex]); SetDirection(predefinedPath[nextValidDirectionIndex]);
nextPosition = GridMoverTools.PositionToGrid(nextPosition) + direction.normalized * 0.01f; nextPosition = PositionToGrid(nextPosition) + GetVector(direction) * 0.01f;
// Check if we've reached the end of the path, which includes making sure the path doesn't end on Vector2.zero // Check if we've reached the end of the path, which includes making sure the path doesn't end on Vector2.zero
do do
@@ -323,15 +341,15 @@ namespace Marro.PacManUdon
default: default:
return gridPosition; return gridPosition;
case PacManGhostType.Blinky: case PacManGhostType.Blinky:
return GridMoverTools.PositionToGrid(pacMan.transform.localPosition); return PositionToGrid(pacMan.transform.localPosition);
case PacManGhostType.Pinky: case PacManGhostType.Pinky:
return GridMoverTools.PositionToGrid(pacMan.transform.localPosition) + pacMan.GetDirection() * 4; return PositionToGrid(pacMan.transform.localPosition) + pacMan.GetVector(direction) * 4;
case PacManGhostType.Inky: case PacManGhostType.Inky:
return 2 * GridMoverTools.PositionToGrid(pacMan.transform.localPosition) + 4 * pacMan.GetDirection() - GridMoverTools.PositionToGrid(blinky.transform.localPosition); return 2 * PositionToGrid(pacMan.transform.localPosition) + 4 * pacMan.GetVector(direction) - PositionToGrid(blinky.transform.localPosition);
case PacManGhostType.Clyde: case PacManGhostType.Clyde:
if (Vector2.Distance(gridPosition, GridMoverTools.PositionToGrid(pacMan.transform.localPosition)) >= 8) if (Vector2.Distance(gridPosition, PositionToGrid(pacMan.transform.localPosition)) >= 8)
{ {
return GridMoverTools.PositionToGrid(pacMan.transform.localPosition); return PositionToGrid(pacMan.transform.localPosition);
} }
else else
{ {
@@ -386,7 +404,7 @@ namespace Marro.PacManUdon
case PacManGhostState.Exiting: case PacManGhostState.Exiting:
offGrid = false; offGrid = false;
SetState(PacManGhostState.Normal); SetState(PacManGhostState.Normal);
SetDirection(Vector2.left); SetDirection(Direction.Left);
break; break;
} }
} }
@@ -395,11 +413,11 @@ namespace Marro.PacManUdon
{ {
if (startHorizontal) if (startHorizontal)
{ {
SetDirection(GetOffGridDirectionToTarget(GetPosition(), newTarget, Vector2.right)); SetDirection(GetOffGridDirectionToTarget(GetPosition(), newTarget, Direction.Right));
} }
else else
{ {
SetDirection(GetOffGridDirectionToTarget(GetPosition(), newTarget, Vector2.down)); SetDirection(GetOffGridDirectionToTarget(GetPosition(), newTarget, Direction.Down));
} }
// Debug.Log($"{gameObject} SetOffGridTarget with position {GetPosition()}, newTarget {newTarget}, startHorizontal {startHorizontal} resulted in direction {direction}"); // Debug.Log($"{gameObject} SetOffGridTarget with position {GetPosition()}, newTarget {newTarget}, startHorizontal {startHorizontal} resulted in direction {direction}");
target = newTarget; target = newTarget;
@@ -413,69 +431,42 @@ namespace Marro.PacManUdon
return rngState; return rngState;
} }
Vector2[] GetAvailableDirections(Vector2 gridPosition, Vector2 discardDirection) private Direction[] cardinalDirections = new Direction[] { Direction.Up, Direction.Down, Direction.Left, Direction.Right };
Direction GetGridDirectionToTargetGreedy(bool[] blockedDirections, Vector2 gridPosition, Vector2 targetGridPosition)
{ {
Vector2[] directions; Direction bestDirection = Direction.Zero;
Vector2[] availableDirections; float bestDistance = float.MaxValue;
if (horizontalOnly && ghostState == PacManGhostState.Normal) for (int i = horizontalOnly ? 2 : 0; i < blockedDirections.Length; i++)
{ {
directions = new Vector2[] { new Vector2(1, 0), new Vector2(-1, 0) }; if (blockedDirections[i])
availableDirections = new Vector2[2];
}
else
{
directions = new Vector2[] { new Vector2(0, 1), new Vector2(1, 0), new Vector2(0, -1), new Vector2(-1, 0) };
availableDirections = new Vector2[4];
}
int availableDirectionsNum = 0;
for (int i = 0; i < directions.Length; i++)
{
if (directions[i].Equals(discardDirection) || GridMoverTools.CheckCollisionInDirection(transform, gridPosition, directions[i]))
{ {
continue; continue;
} }
availableDirections[availableDirectionsNum] = directions[i];
availableDirectionsNum++;
}
Vector2[] availableDirectionsTrimmed = new Vector2[availableDirectionsNum];
// Debug.Log($"{gameObject} Number of available directions: {availableDirectionsTrimmed.Length}");
Array.Copy(availableDirections, 0, availableDirectionsTrimmed, 0, availableDirectionsNum);
return availableDirectionsTrimmed;
}
Vector2 GetGridDirectionToTargetGreedy(Vector2[] availableDirections, Vector2 gridPosition, Vector2 targetGridPosition)
{
Vector2 bestDirection = Vector2.zero;
float bestDistance = float.MaxValue;
for (int i = 0; i < availableDirections.Length; i++)
{
Vector2 direction = availableDirections[i];
// Debug.Log("Evaluating direction " + direction); // Debug.Log("Evaluating direction " + direction);
float distance = Vector2.Distance(gridPosition + direction, targetGridPosition); var direction = cardinalDirections[i];
float distance = Vector2.Distance(gridPosition + directionVectors[(int)direction], targetGridPosition);
if (distance < bestDistance) if (distance < bestDistance)
{ {
bestDistance = distance; bestDistance = distance;
bestDirection = direction; bestDirection = direction;
} }
} }
// Debug.Log("Closest next tile is in direction " + bestDirection); Debug.Log($"{gameObject.name} Closest next tile is in direction {bestDirection}");
return bestDirection; return bestDirection;
} }
Vector2 GetOffGridDirectionToTarget(Vector2 position, Vector2 target, Vector2 direction) private Direction GetOffGridDirectionToTarget(Vector2 position, Vector2 target, Direction direction)
{ {
if ((direction.x != 0 && position.x != target.x) || position.y == target.y) if ((IsHorizontal(direction) && position.x != target.x) || position.y == target.y)
{ {
// Debug.Log($"{gameObject} getOffGridDirectionToTarget with position {position}, target {target} and direction {direction} gives movement on the X axis in direction {new Vector2(target.x-position.x, 0).normalized}"); // Debug.Log($"{gameObject} getOffGridDirectionToTarget with position {position}, target {target} and direction {direction} gives movement on the X axis in direction {new Vector2(target.x-position.x, 0).normalized}");
return new Vector2(target.x - position.x, 0).normalized; return HorizontalToDirection(target.x - position.x);
} }
else else
{ {
// Debug.Log($"{gameObject} getOffGridDirectionToTarget with position {position}, target {target} and direction {direction} gives movement on the Y axis in direction {new Vector2(0, target.y-position.y).normalized}"); // Debug.Log($"{gameObject} getOffGridDirectionToTarget with position {position}, target {target} and direction {direction} gives movement on the Y axis in direction {new Vector2(0, target.y-position.y).normalized}");
return new Vector2(0, target.y - position.y).normalized; return VerticalToDirection(target.y - position.y);
} }
} }
@@ -526,10 +517,11 @@ namespace Marro.PacManUdon
animator.SetFloat("DirX", 0); animator.SetFloat("DirX", 0);
animator.SetFloat("DirY", -1); animator.SetFloat("DirY", -1);
} }
else if (specialLook || !direction.Equals(Vector2.zero)) else if (specialLook || direction != Direction.Zero)
{ {
animator.SetFloat("DirX", direction.x); var vector = GetVector(direction);
animator.SetFloat("DirY", direction.y); animator.SetFloat("DirX", vector.x);
animator.SetFloat("DirY", vector.y);
} }
} }

View File

@@ -72,7 +72,7 @@ namespace Marro.PacManUdon
Vector2 idlePosition2 = ghostTargets[2 + ghostIndex * 3].localPosition; Vector2 idlePosition2 = ghostTargets[2 + ghostIndex * 3].localPosition;
Vector2 cornerPosition = ghostTargets[3 + ghostIndex * 3].localPosition; Vector2 cornerPosition = ghostTargets[3 + ghostIndex * 3].localPosition;
ghosts[ghostIndex].Initialize(pacMan, blinky, startTransform, homePosition, idlePosition1, idlePosition2, cornerPosition, ghostIndex); ghosts[ghostIndex].Initialize(pelletManager, pacMan, blinky, startTransform, homePosition, idlePosition1, idlePosition2, cornerPosition, ghostIndex);
} }
SubscribeToEvent(NetworkEventType.GhostUpdate); SubscribeToEvent(NetworkEventType.GhostUpdate);

View File

@@ -3,9 +3,42 @@ namespace Marro.PacManUdon
using System; using System;
using UnityEngine; using UnityEngine;
public enum Direction
{
Zero = 0, Up = 1, Down = 2, Left = 4, Right = 8, UpLeft = 5, UpRight = 9, DownLeft = 6, DownRight = 10
}
public enum DirectionAxis
{
Horizontal = 0,
Vertical = 1,
Both = 2
}
public abstract class GridMover : SyncedObject public abstract class GridMover : SyncedObject
{ {
protected Vector2 direction; protected Direction direction;
// Cannot be static, much to my annoyance
public readonly Vector2[] directionVectors =
{
Vector2.zero, // 0
Vector2.down, // 1
Vector2.up, // 2
Vector2.zero, // 3
Vector2.left, // 4
Vector2.down + Vector2.left, // 5
Vector2.up + Vector2.left, // 6
Vector2.left, // 7
Vector2.right, // 8
Vector2.down + Vector2.right, // 9
Vector2.up + Vector2.right, // 10
Vector2.right, // 11
Vector2.zero, // 12
Vector2.down, // 13
Vector2.up, // 14
Vector2.zero, // 15
};
public virtual Vector2 GetPosition() public virtual Vector2 GetPosition()
{ {
@@ -17,43 +50,193 @@ namespace Marro.PacManUdon
transform.localPosition = new Vector3(position.x, position.y, transform.localPosition.z); transform.localPosition = new Vector3(position.x, position.y, transform.localPosition.z);
} }
public virtual Vector2 GetDirection() public Vector2 GetVector(Direction direction)
{
return directionVectors[(int)direction];
}
public Direction GetDirection()
{ {
return direction; return direction;
} }
public void SetDirection(Vector2 direction) public void SetDirection(Direction direction)
{ {
this.direction = direction; this.direction = direction;
UpdateAnimator(); UpdateAnimator();
} }
public void SetDirection(Vector2 vector)
{
direction = VectorToDirection(vector);
UpdateAnimator();
}
protected static Direction VectorToDirection(Vector2 vector)
{
var directionId = 0;
if (vector.x < 0)
{
directionId = 4;
}
else if (vector.x > 0)
{
directionId = 8;
}
if (vector.y < 0)
{
directionId += 1;
}
else if (vector.y > 0)
{
directionId += 2;
}
return (Direction)directionId;
}
protected static Direction HorizontalToDirection(float horizontal)
{
if (horizontal < 0)
{
return Direction.Left;
}
if (horizontal > 0)
{
return Direction.Right;
}
return Direction.Zero;
}
protected static Direction VerticalToDirection(float vertical)
{
if (vertical < 0)
{
return Direction.Up;
}
if (vertical > 0)
{
return Direction.Down;
}
return Direction.Zero;
}
protected abstract void UpdateAnimator(); protected abstract void UpdateAnimator();
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType) public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{ {
data.Append(GetPosition(), ref index); data.Append(GetPosition(), ref index);
data.Append(GetDirection(), ref index); data.AppendAsByte((int)direction, ref index);
} }
public void PadSyncedData(byte[] data, ref int index, NetworkEventType eventType) public void PadSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{ {
index += 16; index += 9;
} }
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType) public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{ {
SetPosition(data.ReadVector2(ref index)); SetPosition(data.ReadVector2(ref index));
SetDirection(data.ReadVector2(ref index)); SetDirection((Direction)data.ReadByte(ref index));
return true; return true;
} }
public bool ConsumeSyncedData(byte[] data, ref int index, NetworkEventType eventType) public bool ConsumeSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{ {
index += 16; index += 9;
return true; return true;
} }
#region Utils
public static Direction GetInverseDirection(Direction direction)
{
switch (direction)
{
case Direction.Up:
return Direction.Down;
case Direction.Down:
return Direction.Up;
case Direction.Left:
return Direction.Right;
case Direction.Right:
return Direction.Left;
case Direction.UpLeft:
return Direction.DownRight;
case Direction.UpRight:
return Direction.DownLeft;
case Direction.DownLeft:
return Direction.UpRight;
case Direction.DownRight:
return Direction.UpLeft;
default:
return Direction.Zero;
}
}
public static bool IsVertical(Direction direction) => ((int)direction & 0b0011) != 0;
public static bool IsHorizontal(Direction direction) => ((int)direction & 0b1100) != 0;
public static Direction VerticalComponent(Direction direction) => (Direction)((int)direction & 0b0011);
public static Direction HorizontalComponent(Direction direction) => (Direction)((int)direction & 0b1100);
public static Vector2 GetNextPosition(Vector2 currentPosition, Vector2 directionVector, float speed, float deltaTime)
{
return currentPosition + deltaTime * speed * directionVector;
}
public static Vector2 PositionToGrid(Vector2 position)
{
return new Vector2((float)Math.Round(position.x), (float)Math.Round(position.y));
}
public static bool CrossesTileCenter(Vector2 currentPosition, Vector2 nextPosition, Direction direction)
{
bool result = false;
if (IsHorizontal(direction))
{
result = result || Math.Floor(currentPosition.x) != Math.Floor(nextPosition.x);
}
if (IsVertical(direction))
{
result = result || Math.Floor(currentPosition.y) != Math.Floor(nextPosition.y);
}
return result;
}
public static bool CrossesTileBorder(Vector2 currentPosition, Vector2 nextPosition, Direction direction)
{
bool result = false;
if (IsHorizontal(direction))
{
result = result || nextPosition.x != currentPosition.x
&& ((Math.Floor(currentPosition.x) != Math.Floor(nextPosition.x) && nextPosition.x % 1 != 0)
|| currentPosition.x % 1 == 0);
}
if (IsVertical(direction))
{
result = result || nextPosition.y != currentPosition.y
&& ((Math.Floor(currentPosition.y) != Math.Floor(nextPosition.y) && nextPosition.y % 1 != 0)
|| currentPosition.y % 1 == 0);
}
return result;
}
public static bool CheckCollisionInDirection(Transform transform, Vector2 position, Vector2 direction)
{
// Debug.Log("Collision check");
bool result = Physics.Linecast(transform.parent.TransformPoint(position), transform.parent.TransformPoint(position + direction.normalized), 1 << 22, QueryTriggerInteraction.Ignore);
// Debug.DrawLine(transform.parent.TransformPoint(position), transform.parent.TransformPoint(position + direction.normalized), Color.red, 1);
// Debug.Log($"{gameObject} Collision; Position {position} became {transform.parent.TransformPoint(position)}, direction {direction.normalized} became {transform.parent.TransformDirection(direction.normalized)}");
// Debug.Log("collision check for " + position + " in direction " + direction + " returned " + result);
return result;
}
#endregion
} }
} }

View File

@@ -1,64 +0,0 @@
namespace Marro.PacManUdon
{
using System;
using UnityEngine;
public static class GridMoverTools
{
public static Vector2 GetNextPosition(Vector2 currentPosition, Vector2 direction, float speed, float deltaTime)
{
return currentPosition + direction * speed * deltaTime;
}
public static Vector2 PositionToGrid(Vector2 position)
{
return new Vector2((float)Math.Round(position.x), (float)Math.Round(position.y));
}
public static bool CrossesTileCenter(Vector2 currentPosition, Vector2 nextPosition, bool horizontal, bool vertical)
{
bool result = false;
if (horizontal)
{
result = result || Math.Floor(currentPosition.x) != Math.Floor(nextPosition.x);
}
if (vertical)
{
result = result || Math.Floor(currentPosition.y) != Math.Floor(nextPosition.y);
}
// Debug.Log($"CrossesTileCenter at currentPosition {currentPosition} with nextPosition {nextPosition}, horizontal {horizontal} and vertical {vertical} gives {result}");
return result;
}
public static bool CrossesTileBorder(Vector2 currentPosition, Vector2 nextPosition, bool horizontal, bool vertical)
{
bool result = false;
if (horizontal)
{
result = result || nextPosition.x != currentPosition.x
&& ((Math.Floor(currentPosition.x) != Math.Floor(nextPosition.x) && nextPosition.x % 1 != 0)
|| currentPosition.x % 1 == 0);
}
if (vertical)
{
result = result || nextPosition.y != currentPosition.y
&& ((Math.Floor(currentPosition.y) != Math.Floor(nextPosition.y) && nextPosition.y % 1 != 0)
|| currentPosition.y % 1 == 0);
}
return result;
}
public static bool CheckCollisionInDirection(Transform transform, Vector2 position, Vector2 direction)
{
// Debug.Log("Collision check");
bool result = Physics.Linecast(transform.parent.TransformPoint(position), transform.parent.TransformPoint(position + direction.normalized), 1 << 22, QueryTriggerInteraction.Ignore);
// Debug.DrawLine(transform.parent.TransformPoint(position), transform.parent.TransformPoint(position + direction.normalized), Color.red, 1);
// Debug.Log($"{gameObject} Collision; Position {position} became {transform.parent.TransformPoint(position)}, direction {direction.normalized} became {transform.parent.TransformDirection(direction.normalized)}");
// Debug.Log("collision check for " + position + " in direction " + direction + " returned " + result);
return result;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -7,8 +7,9 @@ namespace Marro.PacManUdon
[RequireComponent(typeof(Renderer))] [RequireComponent(typeof(Renderer))]
public class PacMan : GridMover public class PacMan : GridMover
{ {
private GameManager gameController; private GameManager gameManager;
private PlayerInput input; private PlayerInput input;
private PelletManager pelletManager;
private float defaultSpeed; private float defaultSpeed;
private float powerPelletSpeed; private float powerPelletSpeed;
private float speed; private float speed;
@@ -40,9 +41,10 @@ namespace Marro.PacManUdon
#endregion #endregion
public void Initialize(PlayerInput input, Transform startTransform, GameManager gameController) public void Initialize(PlayerInput input, Transform startTransform, GameManager gameManager, PelletManager pelletManager)
{ {
this.gameController = gameController; this.gameManager = gameManager;
this.pelletManager = pelletManager;
this.input = input; this.input = input;
animator = GetComponent<Animator>(); animator = GetComponent<Animator>();
renderer = GetComponent<Renderer>(); renderer = GetComponent<Renderer>();
@@ -57,7 +59,7 @@ namespace Marro.PacManUdon
public void Reset() public void Reset()
{ {
transform.SetLocalPositionAndRotation(startPosition, startRotation); transform.SetLocalPositionAndRotation(startPosition, startRotation);
direction = Vector2.left; direction = Direction.Left;
targetDirection = Vector2.left; targetDirection = Vector2.left;
speed = defaultSpeed; speed = defaultSpeed;
kinematic = false; kinematic = false;
@@ -104,7 +106,7 @@ namespace Marro.PacManUdon
} }
Vector2 position = GetPosition(); Vector2 position = GetPosition();
Vector2 nextPosition = GridMoverTools.GetNextPosition(position, direction, speed, networkManager.SyncedDeltaTime); // The position pacman will move to, assuming it doens't get changed Vector2 nextPosition = GetNextPosition(position, directionVectors[(int)direction], speed, networkManager.SyncedDeltaTime); // The position pacman will move to, assuming it doens't get changed
if (!kinematic) if (!kinematic)
{ {
@@ -123,34 +125,35 @@ namespace Marro.PacManUdon
private Vector2 ProcessNextPosition(Vector2 position, Vector2 nextPosition) private Vector2 ProcessNextPosition(Vector2 position, Vector2 nextPosition)
{ {
if (GridMoverTools.CrossesTileCenter(position, nextPosition, direction.x != 0, false) // 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
&& (targetDirection.x == 0 || GridMoverTools.CheckCollisionInDirection(transform, nextPosition, new Vector2(direction.x, 0)))) && (targetDirection.x == 0 || 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 = GridMoverTools.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(new Vector2(0, direction.y)); SetDirection(VerticalComponent(direction));
// Debug.Log($"{gameObject} crossed X tile center from {currentPosition}, 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 (GridMoverTools.CrossesTileCenter(position, nextPosition, false, direction.y != 0) // See comments above but now vertical if (CrossesTileCenter(position, nextPosition, Direction.Down) // See comments above but now vertical
&& (targetDirection.y == 0 || GridMoverTools.CheckCollisionInDirection(transform, nextPosition, new Vector2(0, direction.y)))) && (targetDirection.y == 0 || pelletManager.IsWallUpcoming(nextPosition, directionVectors[(int)VerticalComponent(direction)])))
{ {
nextPosition.y = GridMoverTools.PositionToGrid(nextPosition).y; nextPosition.y = PositionToGrid(nextPosition).y;
SetDirection(new Vector2(direction.x, 0)); SetDirection(HorizontalComponent(direction));
// Debug.Log($"{gameObject} crossed Y tile center from {currentPosition} 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}");
} }
Vector2 inputDirection = input.GetDirection(); Vector2 inputDirection = input.GetDirection();
if (!inputDirection.Equals(Vector2.zero) && !inputDirection.Equals(targetDirection) // Ignore neutral input or input in our current direction if (!inputDirection.Equals(Vector2.zero) && !inputDirection.Equals(targetDirection) // Ignore neutral input or input in our current direction
&& (inputDirection.x == 0 || (Math.Round(nextPosition.y, 5) - 0.5) % 1 != 0) && (inputDirection.y == 0 || (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 && (inputDirection.x == 0 || (Math.Round(nextPosition.y, 5) - 0.5) % 1 != 0) // Target grid position near the edge of a tile may not be correct, ignore inputs near the border
&& !GridMoverTools.CheckCollisionInDirection(transform, nextPosition, inputDirection)) && (inputDirection.y == 0 || (Math.Round(nextPosition.x, 5) - 0.5) % 1 != 0)
&& !CheckCollisionInDirection(transform, nextPosition, inputDirection))
{ // Check if the requested direction does not have a wall { // Check if the requested direction does not have a wall
if (inputDirection.x != 0) if (inputDirection.x != 0)
{ // Move in the requested direction, as well as perpundicular to it to get to the center of the tunnel { // Move in the requested direction, as well as perpundicular to it to get to the center of the tunnel
SetDirection(inputDirection + new Vector2(0, GridMoverTools.PositionToGrid(nextPosition).y - nextPosition.y).normalized); SetDirection(inputDirection + new Vector2(0, PositionToGrid(nextPosition).y - nextPosition.y).normalized);
} }
else else
{ {
SetDirection(inputDirection + new Vector2(GridMoverTools.PositionToGrid(nextPosition).x - nextPosition.x, 0).normalized); SetDirection(inputDirection + new Vector2(PositionToGrid(nextPosition).x - nextPosition.x, 0).normalized);
} }
SetTargetDirection(inputDirection); // This is the direction most logic should assume pacman is moving, the actual direction may be different due to cornering SetTargetDirection(inputDirection); // This is the direction most logic should assume pacman is moving, the actual direction may be different due to cornering
@@ -165,7 +168,7 @@ namespace Marro.PacManUdon
private Vector2 ProcessPredefinedPath(Vector2 position, Vector2 nextPosition) private Vector2 ProcessPredefinedPath(Vector2 position, Vector2 nextPosition)
{ {
if (GridMoverTools.CrossesTileCenter(position, nextPosition, direction.x != 0, direction.y != 0)) if (CrossesTileCenter(position, nextPosition, direction))
{ {
// Find the next valid direction which isn't Vector2.zero // Find the next valid direction which isn't Vector2.zero
int nextValidDirectionIndex = predefinedPathIndex; int nextValidDirectionIndex = predefinedPathIndex;
@@ -173,14 +176,14 @@ namespace Marro.PacManUdon
{ {
nextValidDirectionIndex += 1; nextValidDirectionIndex += 1;
} }
if (!GridMoverTools.CheckCollisionInDirection(transform, nextPosition, predefinedPath[nextValidDirectionIndex])) if (!CheckCollisionInDirection(transform, nextPosition, predefinedPath[nextValidDirectionIndex]))
{ {
// If we're at a Vector2.zero, we skip applying the direction and only increment. // If we're at a Vector2.zero, we skip applying the direction and only increment.
if (nextValidDirectionIndex == predefinedPathIndex) if (nextValidDirectionIndex == predefinedPathIndex)
{ {
SetDirection(predefinedPath[nextValidDirectionIndex]); SetDirection(predefinedPath[nextValidDirectionIndex]);
SetTargetDirection(predefinedPath[nextValidDirectionIndex]); SetTargetDirection(predefinedPath[nextValidDirectionIndex]);
nextPosition = GridMoverTools.PositionToGrid(nextPosition) + direction.normalized * 0.01f; nextPosition = PositionToGrid(nextPosition) + directionVectors[(int)direction] * 0.01f;
// Check if we've reached the end of the path, which includes making sure the path doesn't end on Vector2.zero // Check if we've reached the end of the path, which includes making sure the path doesn't end on Vector2.zero
do do
@@ -324,19 +327,19 @@ namespace Marro.PacManUdon
{ {
if (pellet.isPowerPellet) if (pellet.isPowerPellet)
{ {
gameController.GotPowerPellet(pellet); gameManager.GotPowerPellet(pellet);
freezeSeconds = 0.05f; freezeSeconds = 0.05f;
} }
else else
{ {
gameController.GotPellet(pellet); gameManager.GotPellet(pellet);
freezeSeconds = 0.0166666666666667f; freezeSeconds = 0.0166666666666667f;
} }
return; return;
} }
else if (other.gameObject.GetComponent<BonusFruit>()) else if (other.gameObject.GetComponent<BonusFruit>())
{ {
gameController.GotFruit(); gameManager.GotFruit();
} }
} }

View File

@@ -1,6 +1,7 @@
namespace Marro.PacManUdon namespace Marro.PacManUdon
{ {
using UnityEngine; using UnityEngine;
using VRC.Udon;
public enum PacManFruitType public enum PacManFruitType
{ {
@@ -49,8 +50,69 @@ namespace Marro.PacManUdon
Intermission3 Intermission3
} }
public enum PacManTileType
{
Empty = -1,
Wall = -2,
}
public static class PacManConstants public static class PacManConstants
{ {
// Jagged or 2D arrays can't be static so we work with 1D arrays
public static int[] GetMazeDefinition() => 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, -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[]
{
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,
824, 825, 826, 827, 828, 829, 830, 831, 832, 833, 834, 835, 836, 837, 838, 810,
782, 754, 753, 752, 751, 750, 749, 721, 693, 665, 664, 663, 662, 661, 660, 659,
690, 718, 746, 745, 744, 743, 771, 799, 796, 768, 740, 739, 738, 737, 709, 681,
703, 675, 647, 646, 617, 589, 561, 562, 563, 564, 565, 566, 594, 622, 567, 568,
569, 570, 571, 572, 600, 628, 631, 603, 575, 576, 577, 578, 579, 580, 581, 609,
637, 724, 696, 668, 669, 642, 614, 586, 585, 584, 583, 582, 553, 525, 497, 469,
441, 413, 385, 357, 329, 301, 273, 245, 245, 246, 247, 248, 249, 250, 222, 194,
166, 138, 082, 054, 053, 052, 051, 050, 049, 077, 105, 133, 161, 162, 163, 164,
165, 189, 217, 160, 159, 158, 186, 214, 242, 241, 240, 239, 157, 156, 155, 127,
099, 071, 043, 044, 045, 046, 047, 048, 154, 153, 152, 124, 096, 068, 040, 039,
038, 037, 036, 035, 034, 062, 090, 118, 146, 147, 148, 149, 150, 151, 177, 205,
233, 234, 235, 236, 033, 032, 031, 030, 029, 057, 113, 141, 142, 143, 144, 145,
169, 197, 225, 226, 227, 228, 229, 174, 202, 230, 258, 286, 314, 342, 370, 398,
426, 454, 482, 510, 538,
};
public static GameObject[] ComponentsToGameObjects(Component[] components, bool skipFirstComponent = false) public static GameObject[] ComponentsToGameObjects(Component[] components, bool skipFirstComponent = false)
{ {
if (skipFirstComponent) if (skipFirstComponent)
@@ -277,7 +339,8 @@ namespace Marro.PacManUdon
return scaredNumberOfFlashesPerLevel[level - 1]; return scaredNumberOfFlashesPerLevel[level - 1];
} }
public static int FruitTypeToValue(PacManFruitType fruitType) { // I can't get casting from enum to int to work so this is a workaround public static int FruitTypeToValue(PacManFruitType fruitType)
{ // I can't get casting from enum to int to work so this is a workaround
switch (fruitType) switch (fruitType)
{ {
default: default:

View File

@@ -43,7 +43,7 @@ MonoBehaviour:
Data: Data:
- Name: - Name:
Entry: 12 Entry: 12
Data: 9 Data: 10
- Name: - Name:
Entry: 7 Entry: 7
Data: Data:
@@ -530,6 +530,60 @@ MonoBehaviour:
- Name: - Name:
Entry: 8 Entry: 8
Data: Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: tilemap
- Name: $v
Entry: 7
Data: 29|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: tilemap
- Name: <UserType>k__BackingField
Entry: 7
Data: 30|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Int32[], mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 30
- 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: 31|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: - Name:
Entry: 13 Entry: 13
Data: Data:

View File

@@ -18,6 +18,11 @@ namespace Marro.PacManUdon
byte[] syncedPelletsCollected; byte[] syncedPelletsCollected;
int[] tilemap;
const int mazeWidth = 28;
const int mazeHeight = 31;
public void Initialize() public void Initialize()
{ {
gameObject.SetActive(true); gameObject.SetActive(true);
@@ -32,6 +37,7 @@ namespace Marro.PacManUdon
SubscribeToEvent(NetworkEventType.SyncPellets); SubscribeToEvent(NetworkEventType.SyncPellets);
} }
#region Power pellet blink
public override void SyncedUpdate() public override void SyncedUpdate()
{ {
if (!powerPelletBlinkEnabled) if (!powerPelletBlinkEnabled)
@@ -72,7 +78,39 @@ namespace Marro.PacManUdon
{ {
powerPelletBlinkEnabled = !frozen; powerPelletBlinkEnabled = !frozen;
} }
#endregion
#region Collision
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)
{
var results = new bool[4];
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;
}
private int GetTileAt(Vector2 position) => tilemap[GetTilemapIndex(position)];
private 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;
return index;
}
#endregion
#region Pellet collecting
public int PelletCollected(Pellet pellet) public int PelletCollected(Pellet pellet)
{ {
pellet.gameObject.SetActive(false); pellet.gameObject.SetActive(false);
@@ -95,6 +133,8 @@ namespace Marro.PacManUdon
syncedPelletsCollected = new byte[pellets.Length/8 + 1]; syncedPelletsCollected = new byte[pellets.Length/8 + 1];
PelletCollectedCount = 0; PelletCollectedCount = 0;
tilemap = PacManConstants.GetMazeDefinition();
return PelletCount; return PelletCount;
} }
@@ -131,5 +171,33 @@ namespace Marro.PacManUdon
SetPelletsCollectedFromSync(); SetPelletsCollectedFromSync();
return true; return true;
} }
#endregion
#region Utils
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;
}
#endregion
} }
} }

View File

@@ -90,7 +90,7 @@ namespace Marro.PacManUdon
pacMan.SetKinematic(true); pacMan.SetKinematic(true);
pacMan.SetActive(true); pacMan.SetActive(true);
pacMan.SetPosition(attractScreenElements[16].transform.localPosition); pacMan.SetPosition(attractScreenElements[16].transform.localPosition);
pacMan.SetDirection(Vector2.left); pacMan.SetDirection(Direction.Left);
ghostManager.RestartLevel(); ghostManager.RestartLevel();
ghostManager.SetLevel(2); ghostManager.SetLevel(2);
@@ -100,7 +100,7 @@ namespace Marro.PacManUdon
for (int i = 0; i < ghosts.Length; i++) for (int i = 0; i < ghosts.Length; i++)
{ {
ghosts[i].SetPosition(attractScreenElements[17 + i].transform.localPosition); ghosts[i].SetPosition(attractScreenElements[17 + i].transform.localPosition);
ghosts[i].SetDirection(Vector2.left); ghosts[i].SetDirection(Direction.Left);
ghosts[i].SetState(PacManGhostState.Normal); ghosts[i].SetState(PacManGhostState.Normal);
} }
break; break;
@@ -119,7 +119,7 @@ namespace Marro.PacManUdon
case 18: case 18:
// Turn PacMan around after eating power pellet // Turn PacMan around after eating power pellet
pacMan.SetDirection(Vector2.right); pacMan.SetDirection(Direction.Right);
pacMan.SetTargetDirection(Vector2.right); pacMan.SetTargetDirection(Vector2.right);
break; break;

View File

@@ -26,14 +26,14 @@ namespace Marro.PacManUdon
pacMan.SetKinematic(true); pacMan.SetKinematic(true);
pacMan.SetActive(true); pacMan.SetActive(true);
pacMan.SetPosition(intermissionScreenElements[0].transform.localPosition); pacMan.SetPosition(intermissionScreenElements[0].transform.localPosition);
pacMan.SetDirection(Vector2.left); pacMan.SetDirection(Direction.Left);
ghostManager.SetLevel(5); ghostManager.SetLevel(5);
ghostManager.SetKinematic(true); ghostManager.SetKinematic(true);
ghostManager.gameObject.SetActive(true); ghostManager.gameObject.SetActive(true);
blinky.SetElroy(2); blinky.SetElroy(2);
blinky.SetPosition(intermissionScreenElements[1].transform.localPosition); blinky.SetPosition(intermissionScreenElements[1].transform.localPosition);
blinky.SetDirection(Vector2.left); blinky.SetDirection(Direction.Left);
blinky.SetState(PacManGhostState.Normal); blinky.SetState(PacManGhostState.Normal);
SetFrozen(false); SetFrozen(false);
@@ -46,14 +46,14 @@ namespace Marro.PacManUdon
// Reached end, make ghost scared and turn around // Reached end, make ghost scared and turn around
blinky.BecomeScared(); blinky.BecomeScared();
blinky.SetPosition(intermissionScreenElements[3].transform.localPosition); blinky.SetPosition(intermissionScreenElements[3].transform.localPosition);
pacMan.SetDirection(Vector2.zero); pacMan.SetDirection(Direction.Zero);
pacMan.SetPosition(intermissionScreenElements[2].transform.localPosition); pacMan.SetPosition(intermissionScreenElements[2].transform.localPosition);
pacMan.SetPowerPellet(true); pacMan.SetPowerPellet(true);
break; break;
case 4: case 4:
// Pacman starts chasing ghosts // Pacman starts chasing ghosts
pacMan.SetDirection(Vector2.right); pacMan.SetDirection(Direction.Right);
pacMan.BecomeBig(); pacMan.BecomeBig();
break; break;
case 5: case 5:

View File

@@ -34,14 +34,14 @@ namespace Marro.PacManUdon
pacMan.SetKinematic(true); pacMan.SetKinematic(true);
pacMan.SetActive(true); pacMan.SetActive(true);
pacMan.SetPosition(intermissionScreenElements[0].transform.localPosition); pacMan.SetPosition(intermissionScreenElements[0].transform.localPosition);
pacMan.SetDirection(Vector2.left); pacMan.SetDirection(Direction.Left);
ghostManager.SetLevel(5); ghostManager.SetLevel(5);
ghostManager.SetKinematic(true); ghostManager.SetKinematic(true);
ghostManager.gameObject.SetActive(true); ghostManager.gameObject.SetActive(true);
blinky.SetElroy(2); blinky.SetElroy(2);
blinky.SetPosition(intermissionScreenElements[1].transform.localPosition); blinky.SetPosition(intermissionScreenElements[1].transform.localPosition);
blinky.SetDirection(Vector2.left); blinky.SetDirection(Direction.Left);
blinky.SetState(PacManGhostState.Normal); blinky.SetState(PacManGhostState.Normal);
SetFrozen(false); SetFrozen(false);
@@ -65,16 +65,16 @@ namespace Marro.PacManUdon
case 8: case 8:
// Blinky sprite updates with broken cover // Blinky sprite updates with broken cover
blinky.SetSpecialLook(true); blinky.SetSpecialLook(true);
blinky.SetDirection(Vector2.up); blinky.SetDirection(Direction.Up);
blinky.SetPosition(blinky.GetPosition() + new Vector2(-0.250f, 0f)); blinky.SetPosition(blinky.GetPosition() + new Vector2(-0.250f, 0f));
break; break;
case 9: case 9:
// Blinky looks at broken cover // Blinky looks at broken cover
blinky.SetDirection(Vector2.down); blinky.SetDirection(Direction.Down);
break; break;
case 10: case 10:
// Cutscene starts to unload // Cutscene starts to unload
blinky.SetDirection(Vector2.zero); blinky.SetDirection(Direction.Zero);
break; break;
case 11: case 11:
// End cutscene // End cutscene

View File

@@ -26,14 +26,14 @@ namespace Marro.PacManUdon
pacMan.SetKinematic(true); pacMan.SetKinematic(true);
pacMan.SetActive(true); pacMan.SetActive(true);
pacMan.SetPosition(intermissionScreenElements[0].transform.localPosition); pacMan.SetPosition(intermissionScreenElements[0].transform.localPosition);
pacMan.SetDirection(Vector2.left); pacMan.SetDirection(Direction.Left);
ghostManager.SetLevel(5); ghostManager.SetLevel(5);
ghostManager.SetKinematic(true); ghostManager.SetKinematic(true);
ghostManager.gameObject.SetActive(true); ghostManager.gameObject.SetActive(true);
blinky.SetElroy(2); blinky.SetElroy(2);
blinky.SetPosition(intermissionScreenElements[1].transform.localPosition); blinky.SetPosition(intermissionScreenElements[1].transform.localPosition);
blinky.SetDirection(Vector2.left); blinky.SetDirection(Direction.Left);
blinky.SetState(PacManGhostState.Normal); blinky.SetState(PacManGhostState.Normal);
blinky.SetSpecialLook(true); blinky.SetSpecialLook(true);
@@ -45,13 +45,13 @@ namespace Marro.PacManUdon
break; break;
case 3: case 3:
// Reached end, freeze // Reached end, freeze
pacMan.SetDirection(Vector2.zero); pacMan.SetDirection(Direction.Zero);
blinky.SetDirection(Vector2.zero); blinky.SetDirection(Direction.Zero);
break; break;
case 4: case 4:
// Ghost runs back on screen // Ghost runs back on screen
blinky.SetPosition(intermissionScreenElements[3].transform.localPosition); blinky.SetPosition(intermissionScreenElements[3].transform.localPosition);
blinky.SetDirection(Vector2.right); blinky.SetDirection(Direction.Right);
break; break;
case 5: case 5:
// End cutscene // End cutscene

View File

@@ -2,61 +2,21 @@
{ {
using UdonSharp; using UdonSharp;
using UnityEngine; using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
enum Direction
{
Any,
Up,
Left,
Down,
Right
}
public class Teleporter : UdonSharpBehaviour public class Teleporter : UdonSharpBehaviour
{ {
[SerializeField] private Direction direction = Direction.Any; [SerializeField] private Direction direction = Direction.Zero;
[SerializeField] private Transform target; [SerializeField] private Transform target;
void OnTriggerEnter(Collider other) void OnTriggerEnter(Collider other)
{ {
GridMover gridMover = other.gameObject.GetComponent<GridMover>(); GridMover gridMover = other.gameObject.GetComponent<GridMover>();
if (gridMover == null) if (gridMover == null || gridMover.GetDirection() != direction)
{ {
return; return;
} }
switch (direction)
{
case Direction.Up:
if (gridMover.GetDirection().y < 0)
{
return;
}
break;
case Direction.Down:
if (gridMover.GetDirection().y > 0)
{
return;
}
break;
case Direction.Left:
if (gridMover.GetDirection().x > 0)
{
return;
}
break;
case Direction.Right:
if (gridMover.GetDirection().x < 0)
{
return;
}
break;
default:
break;
}
gridMover.SetPosition(gridMover.GetPosition() + (Vector2)(target.localPosition - transform.localPosition)); gridMover.SetPosition(gridMover.GetPosition() + (Vector2)(target.localPosition - transform.localPosition));
} }
} }

View File

@@ -0,0 +1,52 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3}
m_Name: MazeDefinitionGenerator
m_EditorClassIdentifier:
serializedUdonProgramAsset: {fileID: 11400000, guid: ea99e044f80fed446bb669640608f521, type: 2}
udonAssembly:
assemblyError:
sourceCsScript: {fileID: 11500000, guid: 30a9bec71a4b36a41a9b6ee899bef38c, type: 3}
scriptVersion: 2
compiledVersion: 2
behaviourSyncMode: 0
hasInteractEvent: 0
scriptID: 6724330659013342737
serializationData:
SerializedFormat: 2
SerializedBytes:
ReferencedUnityObjects: []
SerializedBytesString:
Prefab: {fileID: 0}
PrefabModificationsReferencedUnityObjects: []
PrefabModifications: []
SerializationNodes:
- Name: fieldDefinitions
Entry: 7
Data: 0|System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[UdonSharp.Compiler.FieldDefinition,
UdonSharp.Editor]], mscorlib
- Name: comparer
Entry: 7
Data: 1|System.Collections.Generic.GenericEqualityComparer`1[[System.String,
mscorlib]], mscorlib
- Name:
Entry: 8
Data:
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 909752e684c57f24093795e3ba5e2c80
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,113 @@
using Marro.PacManUdon;
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
public class MazeDefinitionGenerator : UdonSharpBehaviour
{
void Start()
{
GetMazeMap();
}
private void GetMazeMap()
{
var pellets = GetComponentsInChildren<Pellet>(includeInactive: true);
var width = 28;
var height = 31;
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;
}
}
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;
}
var result = "";
for (int i = 0; i < map.Length; i++)
{
if (map[i] < 0)
{
result += $"{map[i]:00}, ";
}
else
{
result += $"{map[i]:000}, ";
}
if (i % width == width - 1)
{
result += "\n";
}
}
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[] {
true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true ,
true, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, true ,
true, false, true, true, true, true, false, true, true, true, true, true, false, true, true, false, true, true, true, true, true, false, true, true, true, true, false, true ,
true, false, true, false, false, true, false, true, false, false, false, true, false, true, true, false, true, false, false, false, true, false, true, false, false, true, false, true ,
true, false, true, true, true, true, false, true, true, true, true, true, false, true, true, false, true, true, true, true, true, false, true, true, true, true, false, true ,
true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true ,
true, false, true, true, true, true, false, true, true, false, true, true, true, true, true, true, true, true, false, true, true, false, true, true, true, true, false, true ,
true, false, true, true, true, true, false, true, true, false, true, true, true, true, true, true, true, true, false, true, true, false, true, true, true, true, false, true ,
true, false, false, false, false, false, false, true, true, false, false, false, false, true, true, false, false, false, false, true, true, false, false, false, false, false, false, true ,
true, true, true, true, true, true, false, true, true, true, true, true, false, true, true, false, true, true, true, true, true, false, true, true, true, true, true, true ,
false, false, false, false, false, true, false, true, true, true, true, true, false, true, true, false, true, true, true, true, true, false, true, false, false, false, false, false ,
false, false, false, false, false, true, false, true, true, false, false, false, false, false, false, false, false, false, false, true, true, false, true, false, false, false, false, false ,
false, false, false, false, false, true, false, true, true, false, true, true, true, true, true, true, true, true, false, true, true, false, true, false, false, false, false, false ,
true, true, true, true, true, true, false, true, true, false, true, false, false, false, false, false, false, true, false, true, true, false, true, true, true, true, true, true ,
false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false ,
true, true, true, true, true, true, false, true, true, false, true, false, false, false, false, false, false, true, false, true, true, false, true, true, true, true, true, true ,
false, false, false, false, false, true, false, true, true, false, true, true, true, true, true, true, true, true, false, true, true, false, true, false, false, false, false, false ,
false, false, false, false, false, true, false, true, true, false, false, false, false, false, false, false, false, false, false, true, true, false, true, false, false, false, false, false ,
false, false, false, false, false, true, false, true, true, false, true, true, true, true, true, true, true, true, false, true, true, false, true, false, false, false, false, false ,
true, true, true, true, true, true, false, true, true, false, true, true, true, true, true, true, true, true, false, true, true, false, true, true, true, true, true, true ,
true, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, true ,
true, false, true, true, true, true, false, true, true, true, true, true, false, true, true, false, true, true, true, true, true, false, true, true, true, true, false, true ,
true, false, true, true, true, true, false, true, true, true, true, true, false, true, true, false, true, true, true, true, true, false, true, true, true, true, false, true ,
true, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, true ,
true, true, true, false, true, true, false, true, true, false, true, true, true, true, true, true, true, true, false, true, true, false, true, true, false, true, true, true ,
true, true, true, false, true, true, false, true, true, false, true, true, true, true, true, true, true, true, false, true, true, false, true, true, false, true, true, true ,
true, false, false, false, false, false, false, true, true, false, false, false, false, true, true, false, false, false, false, true, true, false, false, false, false, false, false, true ,
true, false, true, true, true, true, true, true, true, true, true, true, false, true, true, false, true, true, true, true, true, true, true, true, true, true, false, true ,
true, false, true, true, true, true, true, true, true, true, true, true, false, true, true, false, true, true, true, true, true, true, true, true, true, true, false, true ,
true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true ,
true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true
};
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: f317309f5509067439e01d1111249555 guid: 30a9bec71a4b36a41a9b6ee899bef38c
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@@ -6,6 +6,7 @@ using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using VRC.SDKBase; using VRC.SDKBase;
using VRC.Udon; using VRC.Udon;
using UnityEngine.Tilemaps;
public class TestBallManager : UdonSharpBehaviour public class TestBallManager : UdonSharpBehaviour
{ {