Added rough paused state
This commit is contained in:
parent
fe334f8d15
commit
7ac89eb72f
11
Assets/GameFlowManager.cs
Normal file
11
Assets/GameFlowManager.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
//Could be a singleton
|
||||||
|
public class GameFlowManager : MonoBehaviour {
|
||||||
|
[field: SerializeField] public bool Paused { get; private set; } = true;
|
||||||
|
|
||||||
|
void SetPause(bool value) {
|
||||||
|
Paused = value;
|
||||||
|
Time.timeScale = value ? 0f : 1f;
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/GameFlowManager.cs.meta
Normal file
11
Assets/GameFlowManager.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e3fecdc4a8b2cb4419ef9d03180d130d
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -200,6 +200,10 @@ PrefabInstance:
|
|||||||
m_Modification:
|
m_Modification:
|
||||||
m_TransformParent: {fileID: 0}
|
m_TransformParent: {fileID: 0}
|
||||||
m_Modifications:
|
m_Modifications:
|
||||||
|
- target: {fileID: -7596782781093632548, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
|
||||||
|
propertyPath: gameFlowManager
|
||||||
|
value:
|
||||||
|
objectReference: {fileID: 1359990806}
|
||||||
- target: {fileID: 9196727425507610130, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
|
- target: {fileID: 9196727425507610130, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
|
||||||
propertyPath: m_RootOrder
|
propertyPath: m_RootOrder
|
||||||
value: 2
|
value: 2
|
||||||
@ -250,6 +254,24 @@ PrefabInstance:
|
|||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
m_RemovedComponents: []
|
m_RemovedComponents: []
|
||||||
m_SourcePrefab: {fileID: 100100000, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
|
m_SourcePrefab: {fileID: 100100000, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
|
||||||
|
--- !u!1 &1359990805 stripped
|
||||||
|
GameObject:
|
||||||
|
m_CorrespondingSourceObject: {fileID: 9196727425507610131, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
|
||||||
|
m_PrefabInstance: {fileID: 1359990804}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
--- !u!114 &1359990806
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1359990805}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: e3fecdc4a8b2cb4419ef9d03180d130d, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
<Paused>k__BackingField: 1
|
||||||
--- !u!114 &1464970062 stripped
|
--- !u!114 &1464970062 stripped
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_CorrespondingSourceObject: {fileID: 1878107874314509256, guid: e1dac4f28fe75a547b919b7aa8240fed, type: 3}
|
m_CorrespondingSourceObject: {fileID: 1878107874314509256, guid: e1dac4f28fe75a547b919b7aa8240fed, type: 3}
|
||||||
@ -424,6 +446,10 @@ PrefabInstance:
|
|||||||
propertyPath: m_ActionEvents.Array.data[13].m_PersistentCalls.m_Calls.Array.data[0].m_Arguments.m_ObjectArgumentAssemblyTypeName
|
propertyPath: m_ActionEvents.Array.data[13].m_PersistentCalls.m_Calls.Array.data[0].m_Arguments.m_ObjectArgumentAssemblyTypeName
|
||||||
value: UnityEngine.Object, UnityEngine
|
value: UnityEngine.Object, UnityEngine
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 1214567908930553592, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
|
propertyPath: gameFlowManager
|
||||||
|
value:
|
||||||
|
objectReference: {fileID: 1359990806}
|
||||||
- target: {fileID: 1214567908930553593, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
- target: {fileID: 1214567908930553593, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
propertyPath: m_Name
|
propertyPath: m_Name
|
||||||
value: Vampire
|
value: Vampire
|
||||||
@ -480,6 +506,10 @@ PrefabInstance:
|
|||||||
propertyPath: healthBar
|
propertyPath: healthBar
|
||||||
value:
|
value:
|
||||||
objectReference: {fileID: 1464970062}
|
objectReference: {fileID: 1464970062}
|
||||||
|
- target: {fileID: 3126145803593047825, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
|
propertyPath: gameFlowManager
|
||||||
|
value:
|
||||||
|
objectReference: {fileID: 1359990806}
|
||||||
- target: {fileID: 3126145803593047825, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
- target: {fileID: 3126145803593047825, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
propertyPath: <Health>k__BackingField
|
propertyPath: <Health>k__BackingField
|
||||||
value: 100
|
value: 100
|
||||||
|
|||||||
@ -4,8 +4,12 @@ using NaughtyAttributes;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class Arena : MonoBehaviour {
|
public class Arena : MonoBehaviour {
|
||||||
//TODO probably add initial direction too
|
|
||||||
[SerializeField] [Required]
|
[SerializeField] [Required]
|
||||||
|
GameFlowManager gameFlowManager = null!;
|
||||||
|
|
||||||
|
//TODO probably add initial direction too
|
||||||
|
//TODO Add some kind of "MinLength(1)" attribute
|
||||||
|
[SerializeField]
|
||||||
Vector3[] spawners = null!;
|
Vector3[] spawners = null!;
|
||||||
[SerializeField] [Required]
|
[SerializeField] [Required]
|
||||||
ArenaStats stats = null!;
|
ArenaStats stats = null!;
|
||||||
@ -19,6 +23,9 @@ public class Arena : MonoBehaviour {
|
|||||||
void Start() => StartCoroutine(SpawnEnemies());
|
void Start() => StartCoroutine(SpawnEnemies());
|
||||||
|
|
||||||
void SpawnEnemy(int spawnerIndex) {
|
void SpawnEnemy(int spawnerIndex) {
|
||||||
|
if (gameFlowManager.Paused)
|
||||||
|
return;
|
||||||
|
|
||||||
var monster = Instantiate(monsterPrefab, spawners[spawnerIndex], Quaternion.identity).GetComponent<Monster>();
|
var monster = Instantiate(monsterPrefab, spawners[spawnerIndex], Quaternion.identity).GetComponent<Monster>();
|
||||||
//TODO Replace hardcoded target with entity discovery
|
//TODO Replace hardcoded target with entity discovery
|
||||||
monster.SetTarget(FindObjectOfType<PlayerMovement>().transform);
|
monster.SetTarget(FindObjectOfType<PlayerMovement>().transform);
|
||||||
@ -29,7 +36,6 @@ public class Arena : MonoBehaviour {
|
|||||||
|
|
||||||
int currentSpawner = 0;
|
int currentSpawner = 0;
|
||||||
|
|
||||||
//TODO Stop when pause/end game
|
|
||||||
while (true) {
|
while (true) {
|
||||||
SpawnEnemy(currentSpawner);
|
SpawnEnemy(currentSpawner);
|
||||||
currentSpawner = Random.Range(0, spawners.Length);
|
currentSpawner = Random.Range(0, spawners.Length);
|
||||||
|
|||||||
@ -6,6 +6,9 @@ using UnityEngine;
|
|||||||
[RequireComponent(typeof(Rigidbody2D))]
|
[RequireComponent(typeof(Rigidbody2D))]
|
||||||
public class Entity : MonoBehaviour
|
public class Entity : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
[SerializeField] [Required]
|
||||||
|
GameFlowManager gameFlowManager = null!;
|
||||||
|
|
||||||
[field: SerializeField] [field: Required]
|
[field: SerializeField] [field: Required]
|
||||||
protected EntityStats stats { get; private set; }
|
protected EntityStats stats { get; private set; }
|
||||||
[field: SerializeField]protected float Health { get; private set; }
|
[field: SerializeField]protected float Health { get; private set; }
|
||||||
|
|||||||
@ -5,8 +5,12 @@ using UnityEngine.InputSystem;
|
|||||||
|
|
||||||
[RequireComponent(typeof(PlayerInput), typeof(Rigidbody2D))]
|
[RequireComponent(typeof(PlayerInput), typeof(Rigidbody2D))]
|
||||||
public class PlayerMovement : MonoBehaviour {
|
public class PlayerMovement : MonoBehaviour {
|
||||||
|
[SerializeField] [Required]
|
||||||
|
GameFlowManager gameFlowManager = null!;
|
||||||
|
|
||||||
[SerializeField] [field: Required]
|
[SerializeField] [field: Required]
|
||||||
PlayerStats stats = null!;
|
PlayerStats stats = null!;
|
||||||
|
|
||||||
[field: Required]
|
[field: Required]
|
||||||
Rigidbody2D rb = null!;
|
Rigidbody2D rb = null!;
|
||||||
|
|
||||||
@ -16,22 +20,33 @@ public class PlayerMovement : MonoBehaviour {
|
|||||||
|
|
||||||
bool lastJumpButton;
|
bool lastJumpButton;
|
||||||
|
|
||||||
|
#region Unity Messages
|
||||||
void Awake() => rb = GetComponent<Rigidbody2D>();
|
void Awake() => rb = GetComponent<Rigidbody2D>();
|
||||||
|
|
||||||
void Start() => currentState.EnterState(this);
|
void Start() => currentState.EnterState(this);
|
||||||
|
|
||||||
void Update() {
|
void Update() {
|
||||||
|
if (gameFlowManager.Paused)
|
||||||
|
return;
|
||||||
|
|
||||||
if (currentState.UpdateState(this) is {} newState)
|
if (currentState.UpdateState(this) is {} newState)
|
||||||
SwitchState(newState);
|
SwitchState(newState);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FixedUpdate() {
|
void FixedUpdate() {
|
||||||
|
if (gameFlowManager.Paused)
|
||||||
|
return;
|
||||||
|
|
||||||
if (currentState.FixedUpdateState(this) is {} newState)
|
if (currentState.FixedUpdateState(this) is {} newState)
|
||||||
SwitchState(newState);
|
SwitchState(newState);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnDrawGizmos() => currentState.OnDrawGizmos(this);
|
void OnDrawGizmos() => currentState.OnDrawGizmos(this);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Inputs
|
||||||
|
|
||||||
public void OnMove(InputAction.CallbackContext ctx) {
|
public void OnMove(InputAction.CallbackContext ctx) {
|
||||||
moveDirection = ctx.ReadValue<Vector2>();
|
moveDirection = ctx.ReadValue<Vector2>();
|
||||||
if (moveDirection.sqrMagnitude > 1.0f)
|
if (moveDirection.sqrMagnitude > 1.0f)
|
||||||
@ -57,11 +72,9 @@ public class PlayerMovement : MonoBehaviour {
|
|||||||
SwitchState(new EnterSafeZoneMovementState(safeZone));
|
SwitchState(new EnterSafeZoneMovementState(safeZone));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwitchState(BaseState newState) {
|
#endregion
|
||||||
currentState.LeaveState(this);
|
|
||||||
currentState = newState;
|
#region Rigidbody
|
||||||
newState.EnterState(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnTriggerEnter2D(Collider2D other) {
|
void OnTriggerEnter2D(Collider2D other) {
|
||||||
if (other.GetComponent<SafeZone>() is {} triggeredSafeZone)
|
if (other.GetComponent<SafeZone>() is {} triggeredSafeZone)
|
||||||
@ -85,6 +98,16 @@ public class PlayerMovement : MonoBehaviour {
|
|||||||
rb.isKinematic = !enabled;
|
rb.isKinematic = !enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region States
|
||||||
|
|
||||||
|
void SwitchState(BaseState newState) {
|
||||||
|
currentState.LeaveState(this);
|
||||||
|
currentState = newState;
|
||||||
|
newState.EnterState(this);
|
||||||
|
}
|
||||||
|
|
||||||
class BaseState {
|
class BaseState {
|
||||||
public virtual void EnterState(PlayerMovement playerMovement) {}
|
public virtual void EnterState(PlayerMovement playerMovement) {}
|
||||||
|
|
||||||
@ -142,6 +165,7 @@ public class PlayerMovement : MonoBehaviour {
|
|||||||
|
|
||||||
class EnterSafeZoneMovementState : JumpingMovementState {
|
class EnterSafeZoneMovementState : JumpingMovementState {
|
||||||
readonly SafeZone safeZone;
|
readonly SafeZone safeZone;
|
||||||
|
|
||||||
public EnterSafeZoneMovementState(SafeZone safeZone) : base(safeZone.Stats.JumpDuration, safeZone.transform.position) {
|
public EnterSafeZoneMovementState(SafeZone safeZone) : base(safeZone.Stats.JumpDuration, safeZone.transform.position) {
|
||||||
this.safeZone = safeZone;
|
this.safeZone = safeZone;
|
||||||
}
|
}
|
||||||
@ -160,6 +184,7 @@ public class PlayerMovement : MonoBehaviour {
|
|||||||
|
|
||||||
class ExitSafeZoneMovementState : JumpingMovementState {
|
class ExitSafeZoneMovementState : JumpingMovementState {
|
||||||
readonly SafeZone safeZone;
|
readonly SafeZone safeZone;
|
||||||
|
|
||||||
public ExitSafeZoneMovementState(SafeZone safeZone, Vector2 direction) : base(safeZone.Stats.JumpDuration, safeZone.GetOutsidePosition(direction)) {
|
public ExitSafeZoneMovementState(SafeZone safeZone, Vector2 direction) : base(safeZone.Stats.JumpDuration, safeZone.GetOutsidePosition(direction)) {
|
||||||
this.safeZone = safeZone;
|
this.safeZone = safeZone;
|
||||||
}
|
}
|
||||||
@ -197,4 +222,6 @@ public class PlayerMovement : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user