Switched to Direction enum
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -59,7 +59,7 @@ namespace Marro.PacManUdon
|
||||
|
||||
networkManager.Initialize();
|
||||
ghostManager.Initialize(maze.ghostStarts, maze.ghostTargets, pacMan, pelletManager, this);
|
||||
pacMan.Initialize(playerInput, maze.pacManStart, this);
|
||||
pacMan.Initialize(playerInput, maze.pacManStart, this, pelletManager);
|
||||
bonusFruit.Initialize();
|
||||
pelletManager.Initialize();
|
||||
statusDisplay.Initialize();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -41,6 +41,7 @@ namespace Marro.PacManUdon
|
||||
|
||||
// External references
|
||||
private GhostManager ghostManager;
|
||||
private PelletManager pelletManager;
|
||||
private Animator animator;
|
||||
private new Renderer renderer;
|
||||
private PacMan pacMan;
|
||||
@@ -88,12 +89,13 @@ namespace Marro.PacManUdon
|
||||
public bool IsScared => isScared;
|
||||
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>();
|
||||
animator = GetComponent<Animator>();
|
||||
renderer = GetComponent<Renderer>();
|
||||
|
||||
this.pelletManager = pelletManager;
|
||||
this.pacMan = pacMan;
|
||||
this.blinky = blinky;
|
||||
this.homePosition = homePosition;
|
||||
@@ -158,7 +160,7 @@ namespace Marro.PacManUdon
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -168,10 +170,11 @@ namespace Marro.PacManUdon
|
||||
private Vector2 ProcessNextPosition(Vector2 position, Vector2 nextPosition)
|
||||
{
|
||||
if (turnAroundSoon && ghostState == PacManGhostState.Normal
|
||||
&& GridMoverTools.CrossesTileBorder(position, nextPosition, direction.x != 0, direction.y != 0))
|
||||
&& CrossesTileBorder(position, nextPosition, direction))
|
||||
{
|
||||
SetDirection(direction * -1);
|
||||
//Debug.Log($"{gameObject} turned around to direction {GetDirection()}");
|
||||
var newDirection = GetInverseDirection(direction);
|
||||
Debug.Log($"{gameObject} turned around from direction {direction} to {newDirection}");
|
||||
SetDirection(newDirection);
|
||||
turnAroundSoon = false;
|
||||
return nextPosition;
|
||||
}
|
||||
@@ -216,21 +219,19 @@ namespace Marro.PacManUdon
|
||||
{
|
||||
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);
|
||||
var newDirection = GetGridDirectionToTargetGreedy(blockedDirections, gridPosition, target);
|
||||
if (newDirection != direction)
|
||||
{
|
||||
target = GetGridTarget(gridPosition);
|
||||
SetDirection(GetGridDirectionToTargetGreedy(availableDirections, gridPosition, target));
|
||||
nextPosition = GridMoverTools.GetNextPosition(gridPosition, direction, speed, networkManager.SyncedDeltaTime);
|
||||
// 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]);
|
||||
nextPosition = GridMoverTools.GetNextPosition(gridPosition, direction, speed, networkManager.SyncedDeltaTime);
|
||||
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}");
|
||||
}
|
||||
@@ -244,9 +245,26 @@ namespace Marro.PacManUdon
|
||||
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)
|
||||
{
|
||||
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
|
||||
int nextValidDirectionIndex = predefinedPathIndex;
|
||||
@@ -254,13 +272,13 @@ namespace Marro.PacManUdon
|
||||
{
|
||||
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 (nextValidDirectionIndex == predefinedPathIndex)
|
||||
{
|
||||
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
|
||||
do
|
||||
@@ -323,15 +341,15 @@ namespace Marro.PacManUdon
|
||||
default:
|
||||
return gridPosition;
|
||||
case PacManGhostType.Blinky:
|
||||
return GridMoverTools.PositionToGrid(pacMan.transform.localPosition);
|
||||
return PositionToGrid(pacMan.transform.localPosition);
|
||||
case PacManGhostType.Pinky:
|
||||
return GridMoverTools.PositionToGrid(pacMan.transform.localPosition) + pacMan.GetDirection() * 4;
|
||||
return PositionToGrid(pacMan.transform.localPosition) + pacMan.GetVector(direction) * 4;
|
||||
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:
|
||||
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
|
||||
{
|
||||
@@ -386,7 +404,7 @@ namespace Marro.PacManUdon
|
||||
case PacManGhostState.Exiting:
|
||||
offGrid = false;
|
||||
SetState(PacManGhostState.Normal);
|
||||
SetDirection(Vector2.left);
|
||||
SetDirection(Direction.Left);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -395,11 +413,11 @@ namespace Marro.PacManUdon
|
||||
{
|
||||
if (startHorizontal)
|
||||
{
|
||||
SetDirection(GetOffGridDirectionToTarget(GetPosition(), newTarget, Vector2.right));
|
||||
SetDirection(GetOffGridDirectionToTarget(GetPosition(), newTarget, Direction.Right));
|
||||
}
|
||||
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}");
|
||||
target = newTarget;
|
||||
@@ -413,69 +431,42 @@ namespace Marro.PacManUdon
|
||||
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;
|
||||
Vector2[] availableDirections;
|
||||
if (horizontalOnly && ghostState == PacManGhostState.Normal)
|
||||
Direction bestDirection = Direction.Zero;
|
||||
float bestDistance = float.MaxValue;
|
||||
for (int i = horizontalOnly ? 2 : 0; i < blockedDirections.Length; i++)
|
||||
{
|
||||
directions = new Vector2[] { new Vector2(1, 0), new Vector2(-1, 0) };
|
||||
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]))
|
||||
if (blockedDirections[i])
|
||||
{
|
||||
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);
|
||||
float distance = Vector2.Distance(gridPosition + direction, targetGridPosition);
|
||||
var direction = cardinalDirections[i];
|
||||
float distance = Vector2.Distance(gridPosition + directionVectors[(int)direction], targetGridPosition);
|
||||
if (distance < bestDistance)
|
||||
{
|
||||
bestDistance = distance;
|
||||
bestDirection = direction;
|
||||
}
|
||||
}
|
||||
// Debug.Log("Closest next tile is in direction " + bestDirection);
|
||||
Debug.Log($"{gameObject.name} Closest next tile is in direction {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}");
|
||||
return new Vector2(target.x - position.x, 0).normalized;
|
||||
return HorizontalToDirection(target.x - position.x);
|
||||
}
|
||||
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}");
|
||||
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("DirY", -1);
|
||||
}
|
||||
else if (specialLook || !direction.Equals(Vector2.zero))
|
||||
else if (specialLook || direction != Direction.Zero)
|
||||
{
|
||||
animator.SetFloat("DirX", direction.x);
|
||||
animator.SetFloat("DirY", direction.y);
|
||||
var vector = GetVector(direction);
|
||||
animator.SetFloat("DirX", vector.x);
|
||||
animator.SetFloat("DirY", vector.y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace Marro.PacManUdon
|
||||
Vector2 idlePosition2 = ghostTargets[2 + 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);
|
||||
|
||||
@@ -3,9 +3,42 @@ namespace Marro.PacManUdon
|
||||
using System;
|
||||
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
|
||||
{
|
||||
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()
|
||||
{
|
||||
@@ -17,43 +50,193 @@ namespace Marro.PacManUdon
|
||||
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;
|
||||
}
|
||||
|
||||
public void SetDirection(Vector2 direction)
|
||||
public void SetDirection(Direction direction)
|
||||
{
|
||||
this.direction = direction;
|
||||
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();
|
||||
|
||||
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
|
||||
{
|
||||
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)
|
||||
{
|
||||
index += 16;
|
||||
index += 9;
|
||||
}
|
||||
|
||||
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
|
||||
{
|
||||
SetPosition(data.ReadVector2(ref index));
|
||||
SetDirection(data.ReadVector2(ref index));
|
||||
SetDirection((Direction)data.ReadByte(ref index));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool ConsumeSyncedData(byte[] data, ref int index, NetworkEventType eventType)
|
||||
{
|
||||
index += 16;
|
||||
index += 9;
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f317309f5509067439e01d1111249555
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -7,8 +7,9 @@ namespace Marro.PacManUdon
|
||||
[RequireComponent(typeof(Renderer))]
|
||||
public class PacMan : GridMover
|
||||
{
|
||||
private GameManager gameController;
|
||||
private GameManager gameManager;
|
||||
private PlayerInput input;
|
||||
private PelletManager pelletManager;
|
||||
private float defaultSpeed;
|
||||
private float powerPelletSpeed;
|
||||
private float speed;
|
||||
@@ -40,9 +41,10 @@ namespace Marro.PacManUdon
|
||||
#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;
|
||||
animator = GetComponent<Animator>();
|
||||
renderer = GetComponent<Renderer>();
|
||||
@@ -57,7 +59,7 @@ namespace Marro.PacManUdon
|
||||
public void Reset()
|
||||
{
|
||||
transform.SetLocalPositionAndRotation(startPosition, startRotation);
|
||||
direction = Vector2.left;
|
||||
direction = Direction.Left;
|
||||
targetDirection = Vector2.left;
|
||||
speed = defaultSpeed;
|
||||
kinematic = false;
|
||||
@@ -104,7 +106,7 @@ namespace Marro.PacManUdon
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -123,34 +125,35 @@ namespace Marro.PacManUdon
|
||||
|
||||
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
|
||||
&& (targetDirection.x == 0 || GridMoverTools.CheckCollisionInDirection(transform, nextPosition, new Vector2(direction.x, 0))))
|
||||
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 || 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
|
||||
nextPosition.x = GridMoverTools.PositionToGrid(nextPosition).x; // Snap pacman to the center of his current tile in this axis
|
||||
SetDirection(new Vector2(0, direction.y));
|
||||
// Debug.Log($"{gameObject} crossed X tile center from {currentPosition}, nextPosition is now {nextPosition} and direction is now {direction}");
|
||||
nextPosition.x = PositionToGrid(nextPosition).x; // Snap pacman to the center of his current tile in this axis
|
||||
SetDirection(VerticalComponent(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
|
||||
&& (targetDirection.y == 0 || GridMoverTools.CheckCollisionInDirection(transform, nextPosition, new Vector2(0, direction.y))))
|
||||
if (CrossesTileCenter(position, nextPosition, Direction.Down) // See comments above but now vertical
|
||||
&& (targetDirection.y == 0 || pelletManager.IsWallUpcoming(nextPosition, directionVectors[(int)VerticalComponent(direction)])))
|
||||
{
|
||||
nextPosition.y = GridMoverTools.PositionToGrid(nextPosition).y;
|
||||
SetDirection(new Vector2(direction.x, 0));
|
||||
// Debug.Log($"{gameObject} crossed Y tile center from {currentPosition} with targetDirection {targetDirection}, nextPosition is now {nextPosition} and direction is now {direction}");
|
||||
nextPosition.y = PositionToGrid(nextPosition).y;
|
||||
SetDirection(HorizontalComponent(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();
|
||||
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
|
||||
&& !GridMoverTools.CheckCollisionInDirection(transform, nextPosition, inputDirection))
|
||||
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) // Target grid position near the edge of a tile may not be correct, ignore inputs near the border
|
||||
&& (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
|
||||
if (inputDirection.x != 0)
|
||||
{ // 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
|
||||
{
|
||||
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
|
||||
|
||||
@@ -165,7 +168,7 @@ namespace Marro.PacManUdon
|
||||
|
||||
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
|
||||
int nextValidDirectionIndex = predefinedPathIndex;
|
||||
@@ -173,14 +176,14 @@ namespace Marro.PacManUdon
|
||||
{
|
||||
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 (nextValidDirectionIndex == predefinedPathIndex)
|
||||
{
|
||||
SetDirection(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
|
||||
do
|
||||
@@ -324,19 +327,19 @@ namespace Marro.PacManUdon
|
||||
{
|
||||
if (pellet.isPowerPellet)
|
||||
{
|
||||
gameController.GotPowerPellet(pellet);
|
||||
gameManager.GotPowerPellet(pellet);
|
||||
freezeSeconds = 0.05f;
|
||||
}
|
||||
else
|
||||
{
|
||||
gameController.GotPellet(pellet);
|
||||
gameManager.GotPellet(pellet);
|
||||
freezeSeconds = 0.0166666666666667f;
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (other.gameObject.GetComponent<BonusFruit>())
|
||||
{
|
||||
gameController.GotFruit();
|
||||
gameManager.GotFruit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
namespace Marro.PacManUdon
|
||||
{
|
||||
using UnityEngine;
|
||||
using VRC.Udon;
|
||||
|
||||
public enum PacManFruitType
|
||||
public enum PacManFruitType
|
||||
{
|
||||
None = -1,
|
||||
Cherries = 0,
|
||||
@@ -15,7 +16,7 @@ namespace Marro.PacManUdon
|
||||
Key = 7
|
||||
}
|
||||
|
||||
public enum PacManGameState
|
||||
public enum PacManGameState
|
||||
{
|
||||
AttractMode,
|
||||
AttractModeDemo,
|
||||
@@ -23,14 +24,14 @@ namespace Marro.PacManUdon
|
||||
InGame,
|
||||
}
|
||||
|
||||
public enum PacManGhostFrozenState
|
||||
public enum PacManGhostFrozenState
|
||||
{
|
||||
Frozen,
|
||||
FrozenIfNotCaught,
|
||||
NotFrozen
|
||||
}
|
||||
|
||||
public enum PacManTimeSequence
|
||||
public enum PacManTimeSequence
|
||||
{
|
||||
AttractScreenIntroduction,
|
||||
AttractScreenDemo,
|
||||
@@ -49,16 +50,77 @@ namespace Marro.PacManUdon
|
||||
Intermission3
|
||||
}
|
||||
|
||||
public static class PacManConstants
|
||||
public enum PacManTileType
|
||||
{
|
||||
Empty = -1,
|
||||
Wall = -2,
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (skipFirstComponent)
|
||||
{
|
||||
GameObject[] gameObjects = new GameObject[components.Length-1];
|
||||
for (int i = 0; i < components.Length-1; i++)
|
||||
GameObject[] gameObjects = new GameObject[components.Length - 1];
|
||||
for (int i = 0; i < components.Length - 1; i++)
|
||||
{
|
||||
gameObjects[i] = components[i+1].gameObject;
|
||||
gameObjects[i] = components[i + 1].gameObject;
|
||||
}
|
||||
return gameObjects;
|
||||
}
|
||||
@@ -71,7 +133,7 @@ namespace Marro.PacManUdon
|
||||
}
|
||||
return gameObjects;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static float GetPowerPelletBlinkToggleInterval()
|
||||
@@ -81,9 +143,9 @@ namespace Marro.PacManUdon
|
||||
|
||||
public static PacManFruitType GetFruitTypeForLevel(int level)
|
||||
{
|
||||
PacManFruitType[] FruitTypePerLevel = new PacManFruitType[]
|
||||
PacManFruitType[] FruitTypePerLevel = new PacManFruitType[]
|
||||
{
|
||||
PacManFruitType.Cherries,
|
||||
PacManFruitType.Cherries,
|
||||
PacManFruitType.Strawberry,
|
||||
PacManFruitType.Peach,
|
||||
PacManFruitType.Peach,
|
||||
@@ -97,15 +159,15 @@ namespace Marro.PacManUdon
|
||||
PacManFruitType.Bell,
|
||||
PacManFruitType.Key
|
||||
};
|
||||
if (level-1 < 0)
|
||||
if (level - 1 < 0)
|
||||
{
|
||||
return PacManFruitType.None;
|
||||
}
|
||||
if (level-1 >= FruitTypePerLevel.Length)
|
||||
if (level - 1 >= FruitTypePerLevel.Length)
|
||||
{
|
||||
return FruitTypePerLevel[FruitTypePerLevel.Length-1];
|
||||
return FruitTypePerLevel[FruitTypePerLevel.Length - 1];
|
||||
}
|
||||
return FruitTypePerLevel[level-1];
|
||||
return FruitTypePerLevel[level - 1];
|
||||
}
|
||||
|
||||
public static float GetGhostHomeSpeed()
|
||||
@@ -113,101 +175,101 @@ namespace Marro.PacManUdon
|
||||
return 3.5f;
|
||||
}
|
||||
|
||||
public static float GetPacManDefaultSpeedForLevel(int level)
|
||||
public static float GetPacManDefaultSpeedForLevel(int level)
|
||||
{
|
||||
if(level <= 1) return 7.576f;
|
||||
if(level <= 4) return 8.523f;
|
||||
if(level <= 20) return 9.470f;
|
||||
return 8.523f;
|
||||
if (level <= 1) return 7.576f;
|
||||
if (level <= 4) return 8.523f;
|
||||
if (level <= 20) return 9.470f;
|
||||
return 8.523f;
|
||||
}
|
||||
|
||||
public static float GetPacManPowerPelletSpeedForLevel(int level)
|
||||
{
|
||||
if(level <= 1) return 8.523f;
|
||||
if(level <= 4) return 8.996f;
|
||||
return 9.470f;
|
||||
if (level <= 1) return 8.523f;
|
||||
if (level <= 4) return 8.996f;
|
||||
return 9.470f;
|
||||
}
|
||||
|
||||
public static float GetGhostDefaultSpeedForLevel(int level)
|
||||
{
|
||||
if(level <= 1) return 7.102f;
|
||||
if(level <= 4) return 8.049f;
|
||||
return 8.996f;
|
||||
if (level <= 1) return 7.102f;
|
||||
if (level <= 4) return 8.049f;
|
||||
return 8.996f;
|
||||
}
|
||||
|
||||
public static float GetGhostTunnelSpeedForLevel(int level)
|
||||
{
|
||||
if(level <= 1) return 3.788f;
|
||||
if(level <= 4) return 4.261f;
|
||||
return 4.735f;
|
||||
if (level <= 1) return 3.788f;
|
||||
if (level <= 4) return 4.261f;
|
||||
return 4.735f;
|
||||
}
|
||||
|
||||
public static float GetBlinkyElroy1SpeedForLevel(int level)
|
||||
public static float GetBlinkyElroy1SpeedForLevel(int level)
|
||||
{
|
||||
if(level <= 1) return 7.576f;
|
||||
if(level <= 4) return 8.523f;
|
||||
return 9.470f;
|
||||
if (level <= 1) return 7.576f;
|
||||
if (level <= 4) return 8.523f;
|
||||
return 9.470f;
|
||||
}
|
||||
|
||||
public static float GetBlinkyElroy2SpeedForLevel(int level)
|
||||
public static float GetBlinkyElroy2SpeedForLevel(int level)
|
||||
{
|
||||
if(level <= 1) return 8.049f;
|
||||
if(level <= 4) return 8.996f;
|
||||
return 9.943f;
|
||||
if (level <= 1) return 8.049f;
|
||||
if (level <= 4) return 8.996f;
|
||||
return 9.943f;
|
||||
}
|
||||
|
||||
public static float GetGhostScaredSpeedForLevel(int level)
|
||||
public static float GetGhostScaredSpeedForLevel(int level)
|
||||
{
|
||||
if(level <= 1) return 4.735f;
|
||||
if(level <= 4) return 5.208f;
|
||||
return 5.682f;
|
||||
if (level <= 1) return 4.735f;
|
||||
if (level <= 4) return 5.208f;
|
||||
return 5.682f;
|
||||
}
|
||||
|
||||
public static int GetElroy1PelletsRemainingForLevel(int level)
|
||||
public static int GetElroy1PelletsRemainingForLevel(int level)
|
||||
{
|
||||
if(level <= 1) return 20;
|
||||
if(level <= 2) return 30;
|
||||
if(level <= 5) return 40;
|
||||
if(level <= 8) return 50;
|
||||
if(level <= 11) return 60;
|
||||
if(level <= 14) return 80;
|
||||
if(level <= 18) return 100;
|
||||
return 120;
|
||||
if (level <= 1) return 20;
|
||||
if (level <= 2) return 30;
|
||||
if (level <= 5) return 40;
|
||||
if (level <= 8) return 50;
|
||||
if (level <= 11) return 60;
|
||||
if (level <= 14) return 80;
|
||||
if (level <= 18) return 100;
|
||||
return 120;
|
||||
}
|
||||
|
||||
public static int GetElroy2PelletsRemainingForLevel(int level)
|
||||
public static int GetElroy2PelletsRemainingForLevel(int level)
|
||||
{
|
||||
if(level <= 1) return 10;
|
||||
if(level <= 2) return 15;
|
||||
if(level <= 5) return 20;
|
||||
if(level <= 8) return 25;
|
||||
if(level <= 11) return 30;
|
||||
if(level <= 14) return 40;
|
||||
if(level <= 18) return 50;
|
||||
return 60;
|
||||
if (level <= 1) return 10;
|
||||
if (level <= 2) return 15;
|
||||
if (level <= 5) return 20;
|
||||
if (level <= 8) return 25;
|
||||
if (level <= 11) return 30;
|
||||
if (level <= 14) return 40;
|
||||
if (level <= 18) return 50;
|
||||
return 60;
|
||||
}
|
||||
|
||||
public static float GetGhostHousePelletTimeoutLimitForLevel(int level)
|
||||
{
|
||||
if(level <= 4) return 4;
|
||||
return 3;
|
||||
if (level <= 4) return 4;
|
||||
return 3;
|
||||
}
|
||||
|
||||
public static int[] GetGhostHousePrivatePelletCounterLimitForLevel(int level)
|
||||
{
|
||||
if(level <= 1) return new int[] { 0, 0, 30, 60};
|
||||
if(level <= 2) return new int[] { 0, 0, 0, 50};
|
||||
return new int[] { 0, 0, 0, 0};
|
||||
if (level <= 1) return new int[] { 0, 0, 30, 60 };
|
||||
if (level <= 2) return new int[] { 0, 0, 0, 50 };
|
||||
return new int[] { 0, 0, 0, 0 };
|
||||
}
|
||||
|
||||
public static float[] GetScatterPatternForLevel(int level)
|
||||
public static float[] GetScatterPatternForLevel(int level)
|
||||
{
|
||||
if(level <= 1) return new float[] { 7, 27, 34, 54, 59, 79, 84 };
|
||||
if(level <= 4) return new float[] { 7, 27, 34, 54, 59, 1092, 1092.0166667f};
|
||||
return new float[] { 5, 25, 30, 50, 55, 1092, 1092.0166667f};
|
||||
if (level <= 1) return new float[] { 7, 27, 34, 54, 59, 79, 84 };
|
||||
if (level <= 4) return new float[] { 7, 27, 34, 54, 59, 1092, 1092.0166667f };
|
||||
return new float[] { 5, 25, 30, 50, 55, 1092, 1092.0166667f };
|
||||
}
|
||||
|
||||
public static float GetScaredDurationForLevel(int level)
|
||||
public static float GetScaredDurationForLevel(int level)
|
||||
{
|
||||
float[] scaredDurationPerLevel =
|
||||
{
|
||||
@@ -231,18 +293,18 @@ namespace Marro.PacManUdon
|
||||
1,
|
||||
0
|
||||
};
|
||||
if (level-1 < 0)
|
||||
if (level - 1 < 0)
|
||||
{
|
||||
return scaredDurationPerLevel[0];
|
||||
}
|
||||
if (level-1 >= scaredDurationPerLevel.Length)
|
||||
if (level - 1 >= scaredDurationPerLevel.Length)
|
||||
{
|
||||
return scaredDurationPerLevel[scaredDurationPerLevel.Length-1];
|
||||
return scaredDurationPerLevel[scaredDurationPerLevel.Length - 1];
|
||||
}
|
||||
return scaredDurationPerLevel[level-1];
|
||||
return scaredDurationPerLevel[level - 1];
|
||||
}
|
||||
|
||||
public static float GetScaredNumberOfFlashesForLevel(int level)
|
||||
public static float GetScaredNumberOfFlashesForLevel(int level)
|
||||
{
|
||||
int[] scaredNumberOfFlashesPerLevel = new int[]
|
||||
{
|
||||
@@ -266,19 +328,20 @@ namespace Marro.PacManUdon
|
||||
3,
|
||||
0
|
||||
};
|
||||
if (level-1 < 0)
|
||||
if (level - 1 < 0)
|
||||
{
|
||||
return scaredNumberOfFlashesPerLevel[0];
|
||||
}
|
||||
if (level-1 >= scaredNumberOfFlashesPerLevel.Length)
|
||||
if (level - 1 >= scaredNumberOfFlashesPerLevel.Length)
|
||||
{
|
||||
return scaredNumberOfFlashesPerLevel[scaredNumberOfFlashesPerLevel.Length-1];
|
||||
return scaredNumberOfFlashesPerLevel[scaredNumberOfFlashesPerLevel.Length - 1];
|
||||
}
|
||||
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
|
||||
switch (fruitType)
|
||||
public static int FruitTypeToValue(PacManFruitType fruitType)
|
||||
{ // I can't get casting from enum to int to work so this is a workaround
|
||||
switch (fruitType)
|
||||
{
|
||||
default:
|
||||
case PacManFruitType.None:
|
||||
|
||||
@@ -43,7 +43,7 @@ MonoBehaviour:
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 12
|
||||
Data: 9
|
||||
Data: 10
|
||||
- Name:
|
||||
Entry: 7
|
||||
Data:
|
||||
@@ -530,6 +530,60 @@ MonoBehaviour:
|
||||
- Name:
|
||||
Entry: 8
|
||||
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:
|
||||
Entry: 13
|
||||
Data:
|
||||
|
||||
@@ -18,6 +18,11 @@ namespace Marro.PacManUdon
|
||||
|
||||
byte[] syncedPelletsCollected;
|
||||
|
||||
int[] tilemap;
|
||||
|
||||
const int mazeWidth = 28;
|
||||
const int mazeHeight = 31;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
@@ -32,6 +37,7 @@ namespace Marro.PacManUdon
|
||||
SubscribeToEvent(NetworkEventType.SyncPellets);
|
||||
}
|
||||
|
||||
#region Power pellet blink
|
||||
public override void SyncedUpdate()
|
||||
{
|
||||
if (!powerPelletBlinkEnabled)
|
||||
@@ -72,7 +78,39 @@ namespace Marro.PacManUdon
|
||||
{
|
||||
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)
|
||||
{
|
||||
pellet.gameObject.SetActive(false);
|
||||
@@ -95,6 +133,8 @@ namespace Marro.PacManUdon
|
||||
syncedPelletsCollected = new byte[pellets.Length/8 + 1];
|
||||
PelletCollectedCount = 0;
|
||||
|
||||
tilemap = PacManConstants.GetMazeDefinition();
|
||||
|
||||
return PelletCount;
|
||||
}
|
||||
|
||||
@@ -131,5 +171,33 @@ namespace Marro.PacManUdon
|
||||
SetPelletsCollectedFromSync();
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -90,7 +90,7 @@ namespace Marro.PacManUdon
|
||||
pacMan.SetKinematic(true);
|
||||
pacMan.SetActive(true);
|
||||
pacMan.SetPosition(attractScreenElements[16].transform.localPosition);
|
||||
pacMan.SetDirection(Vector2.left);
|
||||
pacMan.SetDirection(Direction.Left);
|
||||
|
||||
ghostManager.RestartLevel();
|
||||
ghostManager.SetLevel(2);
|
||||
@@ -100,7 +100,7 @@ namespace Marro.PacManUdon
|
||||
for (int i = 0; i < ghosts.Length; i++)
|
||||
{
|
||||
ghosts[i].SetPosition(attractScreenElements[17 + i].transform.localPosition);
|
||||
ghosts[i].SetDirection(Vector2.left);
|
||||
ghosts[i].SetDirection(Direction.Left);
|
||||
ghosts[i].SetState(PacManGhostState.Normal);
|
||||
}
|
||||
break;
|
||||
@@ -119,7 +119,7 @@ namespace Marro.PacManUdon
|
||||
|
||||
case 18:
|
||||
// Turn PacMan around after eating power pellet
|
||||
pacMan.SetDirection(Vector2.right);
|
||||
pacMan.SetDirection(Direction.Right);
|
||||
pacMan.SetTargetDirection(Vector2.right);
|
||||
break;
|
||||
|
||||
|
||||
@@ -26,14 +26,14 @@ namespace Marro.PacManUdon
|
||||
pacMan.SetKinematic(true);
|
||||
pacMan.SetActive(true);
|
||||
pacMan.SetPosition(intermissionScreenElements[0].transform.localPosition);
|
||||
pacMan.SetDirection(Vector2.left);
|
||||
pacMan.SetDirection(Direction.Left);
|
||||
|
||||
ghostManager.SetLevel(5);
|
||||
ghostManager.SetKinematic(true);
|
||||
ghostManager.gameObject.SetActive(true);
|
||||
blinky.SetElroy(2);
|
||||
blinky.SetPosition(intermissionScreenElements[1].transform.localPosition);
|
||||
blinky.SetDirection(Vector2.left);
|
||||
blinky.SetDirection(Direction.Left);
|
||||
blinky.SetState(PacManGhostState.Normal);
|
||||
|
||||
SetFrozen(false);
|
||||
@@ -46,14 +46,14 @@ namespace Marro.PacManUdon
|
||||
// Reached end, make ghost scared and turn around
|
||||
blinky.BecomeScared();
|
||||
blinky.SetPosition(intermissionScreenElements[3].transform.localPosition);
|
||||
pacMan.SetDirection(Vector2.zero);
|
||||
pacMan.SetDirection(Direction.Zero);
|
||||
pacMan.SetPosition(intermissionScreenElements[2].transform.localPosition);
|
||||
pacMan.SetPowerPellet(true);
|
||||
|
||||
break;
|
||||
case 4:
|
||||
// Pacman starts chasing ghosts
|
||||
pacMan.SetDirection(Vector2.right);
|
||||
pacMan.SetDirection(Direction.Right);
|
||||
pacMan.BecomeBig();
|
||||
break;
|
||||
case 5:
|
||||
|
||||
@@ -34,14 +34,14 @@ namespace Marro.PacManUdon
|
||||
pacMan.SetKinematic(true);
|
||||
pacMan.SetActive(true);
|
||||
pacMan.SetPosition(intermissionScreenElements[0].transform.localPosition);
|
||||
pacMan.SetDirection(Vector2.left);
|
||||
pacMan.SetDirection(Direction.Left);
|
||||
|
||||
ghostManager.SetLevel(5);
|
||||
ghostManager.SetKinematic(true);
|
||||
ghostManager.gameObject.SetActive(true);
|
||||
blinky.SetElroy(2);
|
||||
blinky.SetPosition(intermissionScreenElements[1].transform.localPosition);
|
||||
blinky.SetDirection(Vector2.left);
|
||||
blinky.SetDirection(Direction.Left);
|
||||
blinky.SetState(PacManGhostState.Normal);
|
||||
|
||||
SetFrozen(false);
|
||||
@@ -65,16 +65,16 @@ namespace Marro.PacManUdon
|
||||
case 8:
|
||||
// Blinky sprite updates with broken cover
|
||||
blinky.SetSpecialLook(true);
|
||||
blinky.SetDirection(Vector2.up);
|
||||
blinky.SetDirection(Direction.Up);
|
||||
blinky.SetPosition(blinky.GetPosition() + new Vector2(-0.250f, 0f));
|
||||
break;
|
||||
case 9:
|
||||
// Blinky looks at broken cover
|
||||
blinky.SetDirection(Vector2.down);
|
||||
blinky.SetDirection(Direction.Down);
|
||||
break;
|
||||
case 10:
|
||||
// Cutscene starts to unload
|
||||
blinky.SetDirection(Vector2.zero);
|
||||
blinky.SetDirection(Direction.Zero);
|
||||
break;
|
||||
case 11:
|
||||
// End cutscene
|
||||
|
||||
@@ -26,14 +26,14 @@ namespace Marro.PacManUdon
|
||||
pacMan.SetKinematic(true);
|
||||
pacMan.SetActive(true);
|
||||
pacMan.SetPosition(intermissionScreenElements[0].transform.localPosition);
|
||||
pacMan.SetDirection(Vector2.left);
|
||||
pacMan.SetDirection(Direction.Left);
|
||||
|
||||
ghostManager.SetLevel(5);
|
||||
ghostManager.SetKinematic(true);
|
||||
ghostManager.gameObject.SetActive(true);
|
||||
blinky.SetElroy(2);
|
||||
blinky.SetPosition(intermissionScreenElements[1].transform.localPosition);
|
||||
blinky.SetDirection(Vector2.left);
|
||||
blinky.SetDirection(Direction.Left);
|
||||
blinky.SetState(PacManGhostState.Normal);
|
||||
blinky.SetSpecialLook(true);
|
||||
|
||||
@@ -45,13 +45,13 @@ namespace Marro.PacManUdon
|
||||
break;
|
||||
case 3:
|
||||
// Reached end, freeze
|
||||
pacMan.SetDirection(Vector2.zero);
|
||||
blinky.SetDirection(Vector2.zero);
|
||||
pacMan.SetDirection(Direction.Zero);
|
||||
blinky.SetDirection(Direction.Zero);
|
||||
break;
|
||||
case 4:
|
||||
// Ghost runs back on screen
|
||||
blinky.SetPosition(intermissionScreenElements[3].transform.localPosition);
|
||||
blinky.SetDirection(Vector2.right);
|
||||
blinky.SetDirection(Direction.Right);
|
||||
break;
|
||||
case 5:
|
||||
// End cutscene
|
||||
|
||||
@@ -2,61 +2,21 @@
|
||||
{
|
||||
using UdonSharp;
|
||||
using UnityEngine;
|
||||
using VRC.SDKBase;
|
||||
using VRC.Udon;
|
||||
|
||||
enum Direction
|
||||
{
|
||||
Any,
|
||||
Up,
|
||||
Left,
|
||||
Down,
|
||||
Right
|
||||
}
|
||||
public class Teleporter : UdonSharpBehaviour
|
||||
{
|
||||
[SerializeField] private Direction direction = Direction.Any;
|
||||
[SerializeField] private Direction direction = Direction.Zero;
|
||||
[SerializeField] private Transform target;
|
||||
|
||||
void OnTriggerEnter(Collider other)
|
||||
{
|
||||
GridMover gridMover = other.gameObject.GetComponent<GridMover>();
|
||||
|
||||
if (gridMover == null)
|
||||
if (gridMover == null || gridMover.GetDirection() != direction)
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user