Compare commits
2 Commits
65b153f97d
...
d9aac0158d
| Author | SHA1 | Date | |
|---|---|---|---|
| d9aac0158d | |||
| 4922a91a04 |
@@ -1,14 +1,15 @@
|
||||
namespace Marro.PacManUdon
|
||||
{
|
||||
using UdonSharp;
|
||||
using UnityEngine;
|
||||
using VRC.SDK3.Data;
|
||||
using VRC.SDKBase;
|
||||
using VRC.Udon;
|
||||
using UdonSharp;
|
||||
using UnityEngine;
|
||||
using VRC.SDK3.Data;
|
||||
|
||||
namespace Marro.PacManUdon
|
||||
{
|
||||
[RequireComponent(typeof(Animator))]
|
||||
[RequireComponent(typeof(Renderer))]
|
||||
[RequireComponent(typeof(Collider))]
|
||||
public class BonusFruit : UdonSharpBehaviour
|
||||
{
|
||||
[SerializeField, UdonSynced, FieldChangeCallback(nameof(FruitType))] PacManFruitType fruitType;
|
||||
PacManFruitType fruitType;
|
||||
|
||||
Animator animator;
|
||||
new Renderer renderer;
|
||||
@@ -67,7 +68,6 @@
|
||||
this.fruitType = fruitType;
|
||||
value = (int)fruitScoreValue[PacManConstants.FruitTypeToValue(fruitType)];
|
||||
animator.SetFloat("FruitType", PacManConstants.FruitTypeToValue(fruitType));
|
||||
RequestSerialization();
|
||||
}
|
||||
|
||||
public void SetFrozen(bool frozen)
|
||||
@@ -80,7 +80,6 @@
|
||||
renderer.enabled = active;
|
||||
collider.enabled = active;
|
||||
this.active = active;
|
||||
RequestSerialization();
|
||||
}
|
||||
|
||||
public PacManFruitType FruitType
|
||||
@@ -101,18 +100,17 @@
|
||||
get => active;
|
||||
}
|
||||
|
||||
private DataDictionary fruitScoreValue = new DataDictionary()
|
||||
{
|
||||
{(int)PacManFruitType.None , 0},
|
||||
{(int)PacManFruitType.Cherries , 100},
|
||||
{(int)PacManFruitType.Strawberry, 300},
|
||||
{(int)PacManFruitType.Peach , 500},
|
||||
{(int)PacManFruitType.Apple , 700},
|
||||
{(int)PacManFruitType.Grapes , 1000},
|
||||
{(int)PacManFruitType.Galaxian , 2000},
|
||||
{(int)PacManFruitType.Bell , 3000},
|
||||
{(int)PacManFruitType.Key , 5000}
|
||||
};
|
||||
|
||||
private readonly DataDictionary fruitScoreValue = new DataDictionary()
|
||||
{
|
||||
{(int)PacManFruitType.None , 0},
|
||||
{(int)PacManFruitType.Cherries , 100},
|
||||
{(int)PacManFruitType.Strawberry, 300},
|
||||
{(int)PacManFruitType.Peach , 500},
|
||||
{(int)PacManFruitType.Apple , 700},
|
||||
{(int)PacManFruitType.Grapes , 1000},
|
||||
{(int)PacManFruitType.Galaxian , 2000},
|
||||
{(int)PacManFruitType.Bell , 3000},
|
||||
{(int)PacManFruitType.Key , 5000}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,6 @@ namespace Marro.PacManUdon
|
||||
[SerializeField] private int pelletCountOverride = -1;
|
||||
|
||||
private Maze maze;
|
||||
private VRCObjectPool pelletPool;
|
||||
private Intermission2Pole intermission2Pole;
|
||||
|
||||
private Animator mazeSpriteAnimator;
|
||||
@@ -65,14 +64,13 @@ namespace Marro.PacManUdon
|
||||
}
|
||||
|
||||
maze = mazes[0];
|
||||
pelletPool = maze.pelletContainer.GetComponent<VRCObjectPool>();
|
||||
mazeSpriteAnimator = maze.mazeSprite.GetComponent<Animator>();
|
||||
intermission2Pole = intermissionScreenElements[4].GetComponent<Intermission2Pole>();
|
||||
|
||||
ghostManager.Initialize(maze.ghostTargets, pacMan, this);
|
||||
pacMan.Initialize(playerInput, pelletPool, this);
|
||||
pacMan.Initialize(playerInput, this);
|
||||
bonusFruit.Initialize();
|
||||
pelletManager.Initialize(pelletPool);
|
||||
pelletManager.Initialize();
|
||||
statusDisplay.Initialize();
|
||||
playerInput.Initialize(this);
|
||||
soundManager.Initialize();
|
||||
@@ -114,7 +112,6 @@ namespace Marro.PacManUdon
|
||||
public void StartGameButtonPressed()
|
||||
{
|
||||
Debug.Log($"{gameObject} Start Game Button was pressed!");
|
||||
TakeOwnership();
|
||||
StartTimeSequence(PacManTimeSequence.StartNewGame);
|
||||
}
|
||||
|
||||
@@ -142,7 +139,7 @@ namespace Marro.PacManUdon
|
||||
{
|
||||
Debug.Log($"{gameObject} New level started!");
|
||||
|
||||
pelletCountTotal = pelletPool.Pool.Length;
|
||||
pelletCountTotal = pelletManager.PelletCount;
|
||||
pelletCountRemaining = pelletCountTotal;
|
||||
ghostManager.SetPelletsRemaining(pelletCountRemaining);
|
||||
ghostManager.NewLevel();
|
||||
@@ -283,7 +280,7 @@ namespace Marro.PacManUdon
|
||||
|
||||
void SetPelletsActive(bool active)
|
||||
{
|
||||
pelletPool.gameObject.SetActive(active);
|
||||
pelletManager.gameObject.SetActive(active);
|
||||
}
|
||||
|
||||
void SetMazeVisible(bool visible)
|
||||
@@ -315,10 +312,6 @@ namespace Marro.PacManUdon
|
||||
{
|
||||
// Debug.Log($"{gameObject} State transitioning from {gameState} to {newGameState}");
|
||||
gameState = newGameState;
|
||||
if (Networking.IsOwner(gameObject))
|
||||
{
|
||||
RequestSerialization();
|
||||
}
|
||||
}
|
||||
|
||||
private void IncrementLevel()
|
||||
@@ -348,7 +341,6 @@ namespace Marro.PacManUdon
|
||||
}
|
||||
|
||||
SetScore(this.score + score);
|
||||
RequestSerialization();
|
||||
}
|
||||
|
||||
void SetScore(int score)
|
||||
@@ -370,20 +362,12 @@ namespace Marro.PacManUdon
|
||||
|
||||
public void DecrementLives()
|
||||
{
|
||||
if (!Networking.IsOwner(gameObject))
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Debug.Log($"{gameObject} Decremented lives from {extraLives} to {extraLives - 1}");
|
||||
SetExtraLives(extraLives - 1);
|
||||
}
|
||||
|
||||
void IncrementLives()
|
||||
{
|
||||
if (!Networking.IsOwner(gameObject))
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Debug.Log($"{gameObject} Incremented lives from {extraLives} to {extraLives + 1}");
|
||||
SetExtraLives(extraLives + 1);
|
||||
}
|
||||
@@ -414,14 +398,6 @@ namespace Marro.PacManUdon
|
||||
}
|
||||
}
|
||||
|
||||
void TakeOwnership()
|
||||
{
|
||||
Networking.SetOwner(Networking.LocalPlayer, gameObject);
|
||||
Networking.SetOwner(Networking.LocalPlayer, pacMan.gameObject);
|
||||
Networking.SetOwner(Networking.LocalPlayer, pelletPool.gameObject);
|
||||
ghostManager.SetOwner(Networking.LocalPlayer);
|
||||
}
|
||||
|
||||
public override void AppendSyncedData(byte[][] data, ref int offset, NetworkEventType eventType)
|
||||
{
|
||||
data[offset++] = new byte[] { NetworkManager.Int32ToByte((int)gameState) };
|
||||
|
||||
@@ -145,7 +145,6 @@ namespace Marro.PacManUdon
|
||||
|
||||
faceInStartingDirectionUntilUnfrozen = true;
|
||||
UpdateAnimator();
|
||||
RequestSerialization();
|
||||
|
||||
// Debug.Log($"{gameObject} reset with state: {state}, target: {target}, offGrid: {offGrid}");
|
||||
}
|
||||
@@ -666,7 +665,6 @@ namespace Marro.PacManUdon
|
||||
}
|
||||
this.scattering = scattering;
|
||||
UpdateAnimator();
|
||||
RequestSerialization();
|
||||
}
|
||||
|
||||
public void SetFrozen(bool frozen, bool ignoreIfCaught = false, bool keepAnimating = false)
|
||||
@@ -781,7 +779,7 @@ namespace Marro.PacManUdon
|
||||
|
||||
void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (Networking.IsOwner(gameObject) && other.gameObject.GetComponent<PacManGhostCollider>())
|
||||
if (other.gameObject.GetComponent<PacManGhostCollider>())
|
||||
{
|
||||
if (isScared)
|
||||
{
|
||||
|
||||
@@ -92,7 +92,6 @@
|
||||
}
|
||||
|
||||
SetScattering(true, reverseDirection: false);
|
||||
RequestSerialization();
|
||||
}
|
||||
|
||||
public void NewLevel()
|
||||
@@ -333,15 +332,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
public void SetOwner(VRCPlayerApi player)
|
||||
{
|
||||
Networking.SetOwner(player, gameObject);
|
||||
foreach (Ghost ghost in ghosts)
|
||||
{
|
||||
Networking.SetOwner(player, ghost.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public float GetTargetSpeed(Ghost ghost, PacManGhostState ghostState, bool isScared, bool inTunnel)
|
||||
{
|
||||
if (ghostState == PacManGhostState.Returning || ghostState == PacManGhostState.Entering)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
namespace Marro.PacManUdon
|
||||
{
|
||||
using System;
|
||||
using UdonSharp;
|
||||
using UnityEngine;
|
||||
using VRC.SDKBase;
|
||||
using VRC.Udon;
|
||||
using VRC.SDK3.Components;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using VRC.SDK3.Components;
|
||||
using VRC.SDKBase;
|
||||
|
||||
namespace Marro.PacManUdon
|
||||
{
|
||||
[RequireComponent(typeof(Animator))]
|
||||
[RequireComponent(typeof(Renderer))]
|
||||
public class PacMan : GridMover
|
||||
{
|
||||
private GameManager gameController;
|
||||
@@ -19,7 +19,6 @@
|
||||
private Vector3 startScale;
|
||||
private Animator animator;
|
||||
new Renderer renderer;
|
||||
private VRCObjectPool pelletPool;
|
||||
private bool hideUntilUnfrozen;
|
||||
private bool dead;
|
||||
private bool kinematic;
|
||||
@@ -28,12 +27,11 @@
|
||||
private Vector2[] predefinedPath;
|
||||
private int predefinedPathIndex;
|
||||
|
||||
private Vector2 syncedPosition;
|
||||
private Vector2 targetDirection;
|
||||
private float freezeSeconds;
|
||||
private bool frozen;
|
||||
|
||||
#region Animator constants
|
||||
#region Animator constants
|
||||
private const string AnimatorKeyDead = "Dead";
|
||||
private const string AnimatorKeyDirection = "Direction";
|
||||
private const float AnimatorDirectionNone = 0f;
|
||||
@@ -42,14 +40,13 @@
|
||||
private const float AnimatorDirectionUp = 0.75f;
|
||||
private const float AnimatorDirectionDown = 1f;
|
||||
private const float AnimatorDirectionRightBig = 1.25f;
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
|
||||
public void Initialize(PlayerInput input, VRCObjectPool pelletPool, GameManager gameController)
|
||||
public void Initialize(PlayerInput input, GameManager gameController)
|
||||
{
|
||||
this.gameController = gameController;
|
||||
this.input = input;
|
||||
this.pelletPool = pelletPool;
|
||||
animator = GetComponent<Animator>();
|
||||
renderer = GetComponent<Renderer>();
|
||||
frozen = false;
|
||||
@@ -62,8 +59,7 @@
|
||||
public void Reset()
|
||||
{
|
||||
// Debug.Log($"{gameObject} Reset!");
|
||||
transform.localPosition = startPosition;
|
||||
transform.localRotation = startRotation;
|
||||
transform.SetLocalPositionAndRotation(startPosition, startRotation);
|
||||
transform.localScale = startScale;
|
||||
direction = Vector2.left;
|
||||
targetDirection = Vector2.left;
|
||||
@@ -145,23 +141,20 @@
|
||||
// Debug.Log($"{gameObject} crossed Y tile center from {currentPosition} with targetDirection {targetDirection}, nextPosition is now {nextPosition} and direction is now {direction}");
|
||||
}
|
||||
|
||||
if (Networking.IsOwner(gameObject))
|
||||
{
|
||||
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))
|
||||
{ // 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);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetDirection(inputDirection + new Vector2(GridMoverTools.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
|
||||
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))
|
||||
{ // 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);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetDirection(inputDirection + new Vector2(GridMoverTools.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
|
||||
}
|
||||
|
||||
return nextPosition;
|
||||
@@ -326,15 +319,7 @@
|
||||
Pellet pellet = other.gameObject.GetComponent<Pellet>();
|
||||
if (pellet)
|
||||
{
|
||||
if (Networking.IsOwner(gameObject))
|
||||
{
|
||||
pelletPool.Return(pellet.gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
pellet.pelletRenderer.enabled = false;
|
||||
pellet.gameObject.SetActive(false);
|
||||
}
|
||||
pellet.gameObject.SetActive(false);
|
||||
|
||||
if (pellet.isPowerPellet)
|
||||
{
|
||||
@@ -348,7 +333,7 @@
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (Networking.IsOwner(gameObject) && other.gameObject.GetComponent<BonusFruit>())
|
||||
else if (other.gameObject.GetComponent<BonusFruit>())
|
||||
{
|
||||
gameController.GotFruit();
|
||||
}
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
using UdonSharp;
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(Renderer))]
|
||||
public class Pellet : UdonSharpBehaviour
|
||||
{
|
||||
[SerializeField] public bool isPowerPellet = false;
|
||||
public bool isPowerPellet = false;
|
||||
public Renderer pelletRenderer;
|
||||
|
||||
void Start()
|
||||
|
||||
@@ -1,42 +1,24 @@
|
||||
namespace Marro.PacManUdon
|
||||
{
|
||||
using UdonSharp;
|
||||
using UnityEngine;
|
||||
using VRC.SDK3.Components;
|
||||
using VRC.SDKBase;
|
||||
using VRC.Udon;
|
||||
using UdonSharp;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Marro.PacManUdon
|
||||
{
|
||||
public class PelletManager : UdonSharpBehaviour
|
||||
{
|
||||
[SerializeField] Pellet[] pellets;
|
||||
VRCObjectPool pelletPool;
|
||||
Pellet[] pellets;
|
||||
Renderer[] pelletRenderers;
|
||||
Animator[] powerPellets;
|
||||
|
||||
|
||||
bool powerPelletBlinkEnabled;
|
||||
float powerPelletBlinkToggleInterval;
|
||||
float powerPelletBlinkProgress;
|
||||
bool powerPelletBlinkCurrentlyVisible;
|
||||
|
||||
public void Initialize(VRCObjectPool pelletPool)
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
this.pelletPool = pelletPool;
|
||||
pelletRenderers = new Renderer[pelletPool.Pool.Length];
|
||||
for (int i = 0; i < pelletRenderers.Length; i++)
|
||||
{
|
||||
pelletRenderers[i] = pelletPool.Pool[i].GetComponent<Renderer>();
|
||||
}
|
||||
|
||||
powerPellets = GetComponentsInChildren<Animator>(true);
|
||||
// Debug.Log($"{gameObject} Initialized, powerPellets: {powerPellets}");
|
||||
powerPelletBlinkToggleInterval = PacManConstants.GetPowerPelletBlinkToggleInterval();
|
||||
SetPowerPelletsBlink(false);
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
pellets = GetComponentsInChildren<Pellet>(includeInactive: true);
|
||||
|
||||
pelletRenderers = new Renderer[pellets.Length];
|
||||
for (int i = 0; i < pelletRenderers.Length; i++)
|
||||
{
|
||||
@@ -91,12 +73,9 @@
|
||||
|
||||
public void RestoreAllPellets()
|
||||
{
|
||||
foreach (GameObject pellet in pelletPool.Pool)
|
||||
foreach (var pellet in pellets)
|
||||
{
|
||||
if (pelletPool.TryToSpawn() == false)
|
||||
{
|
||||
break;
|
||||
}
|
||||
pellet.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
foreach (Renderer pelletRenderer in pelletRenderers)
|
||||
@@ -104,5 +83,7 @@
|
||||
pelletRenderer.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
public int PelletCount => pellets.Length;
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ namespace Marro.PacManUdon
|
||||
bool waitingForTimeSequenceFinalize;
|
||||
bool jumpingToTimeSequence;
|
||||
PacManTimeSequence currentTimeSequence;
|
||||
[UdonSynced] float timeSequenceSecondsPassed;
|
||||
float timeSequenceSecondsPassed;
|
||||
int timeSequenceProgress;
|
||||
float[] timeSequenceKeyframeTimes;
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace Marro.PacManUdon
|
||||
|
||||
private void TimeSequencePrepareForFinish(PacManTimeSequence timeSequence)
|
||||
{
|
||||
if (Networking.IsOwner(gameObject))
|
||||
if (networkManager.IsOwner)
|
||||
{
|
||||
TimeSequenceExecuteFinalize(timeSequence);
|
||||
if (!jumpingToTimeSequence)
|
||||
|
||||
Reference in New Issue
Block a user