Pull request #3: Jason
Merge in CEGJ/ludumdare50 from jason to dev * commit '1112e06d471ef8a67c209a2bfa28b0ef34d5e781': Added Press Start to start (without prompt though) Added rough paused state Added Entity.beingPushed() state without actually using it Added NaughtyAttributes
This commit is contained in:
commit
5c4be70437
91
Assets/GameFlowManager.cs
Normal file
91
Assets/GameFlowManager.cs
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.InputSystem;
|
||||||
|
|
||||||
|
//Could be a singleton
|
||||||
|
public class GameFlowManager : MonoBehaviour {
|
||||||
|
[field: SerializeField]
|
||||||
|
public bool Paused { get; private set; } = true;
|
||||||
|
public BaseState CurrentState { get; private set; } = null!;
|
||||||
|
bool lastStartButton;
|
||||||
|
|
||||||
|
#region Unity Messages
|
||||||
|
void Awake() => CurrentState = new StartFlowState(this);
|
||||||
|
|
||||||
|
void Start() => CurrentState.EnterState();
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
void SetPause(bool value) {
|
||||||
|
Paused = value;
|
||||||
|
Time.timeScale = value ? 0f : 1f;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Inputs
|
||||||
|
public void OnStart(InputAction.CallbackContext ctx) {
|
||||||
|
//feels pretty redundant ^^'
|
||||||
|
bool newValue = ctx.ReadValueAsButton();
|
||||||
|
bool wasJustPressed = !lastStartButton && newValue;
|
||||||
|
lastStartButton = newValue;
|
||||||
|
|
||||||
|
if (!wasJustPressed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (CurrentState is StartFlowState)
|
||||||
|
SwitchState(new GameplayFlowState(this));
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region States
|
||||||
|
void SwitchState(BaseState newState) {
|
||||||
|
CurrentState.LeaveState();
|
||||||
|
CurrentState = newState;
|
||||||
|
newState.EnterState();
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class GameFlowState : BaseState {
|
||||||
|
readonly protected GameFlowManager gameFlowManager;
|
||||||
|
|
||||||
|
protected GameFlowState(GameFlowManager gameFlowManager) {
|
||||||
|
this.gameFlowManager = gameFlowManager;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class StartFlowState : GameFlowState {
|
||||||
|
public StartFlowState(GameFlowManager gameFlowManager) : base(gameFlowManager) {}
|
||||||
|
|
||||||
|
public override void EnterState() {
|
||||||
|
base.EnterState();
|
||||||
|
|
||||||
|
Debug.Log("Press Start to start...!");
|
||||||
|
gameFlowManager.SetPause(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void LeaveState() {
|
||||||
|
Debug.Log("Let the games begin!!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class GameplayFlowState : GameFlowState {
|
||||||
|
public GameplayFlowState(GameFlowManager gameFlowManager) : base(gameFlowManager) {}
|
||||||
|
|
||||||
|
public override void EnterState() {
|
||||||
|
base.EnterState();
|
||||||
|
gameFlowManager.SetPause(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class PauseMenuFlowState : GameFlowState {
|
||||||
|
public PauseMenuFlowState(GameFlowManager gameFlowManager) : base(gameFlowManager) {}
|
||||||
|
|
||||||
|
public override void EnterState() {
|
||||||
|
base.EnterState();
|
||||||
|
gameFlowManager.SetPause(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class DeadFlowState : GameFlowState {
|
||||||
|
public DeadFlowState(GameFlowManager gameFlowManager) : base(gameFlowManager) {}
|
||||||
|
|
||||||
|
public override void EnterState() {
|
||||||
|
base.EnterState();
|
||||||
|
gameFlowManager.SetPause(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
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:
|
||||||
@ -246,7 +246,7 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 63e66d66543b37e419694ac22a2941fd, type: 3}
|
m_Script: {fileID: 11500000, guid: 63e66d66543b37e419694ac22a2941fd, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
stats: {fileID: 11400000, guid: 188711c0b201b1a45ad601ee20233b20, type: 2}
|
<Stats>k__BackingField: {fileID: 11400000, guid: 188711c0b201b1a45ad601ee20233b20, type: 2}
|
||||||
moatCollider: {fileID: 9196727423716235687}
|
moatCollider: {fileID: 9196727423716235687}
|
||||||
--- !u!1 &9196727423754814335
|
--- !u!1 &9196727423754814335
|
||||||
GameObject:
|
GameObject:
|
||||||
@ -1752,6 +1752,7 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 72794012913ccd840a73788b90573212, type: 3}
|
m_Script: {fileID: 11500000, guid: 72794012913ccd840a73788b90573212, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
gameFlowManager: {fileID: 0}
|
||||||
spawners:
|
spawners:
|
||||||
- {x: -10, y: 10, z: 0}
|
- {x: -10, y: 10, z: 0}
|
||||||
- {x: 10, y: 10, z: 0}
|
- {x: 10, y: 10, z: 0}
|
||||||
|
|||||||
@ -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}
|
||||||
@ -386,44 +408,84 @@ PrefabInstance:
|
|||||||
m_Modifications:
|
m_Modifications:
|
||||||
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
propertyPath: m_ActionEvents.Array.size
|
propertyPath: m_ActionEvents.Array.size
|
||||||
value: 14
|
value: 15
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
propertyPath: m_ActionEvents.Array.data[13].m_ActionId
|
propertyPath: m_ActionEvents.Array.data[13].m_ActionId
|
||||||
value: d0405457-c534-4103-a0b6-cf113432b467
|
value: d0405457-c534-4103-a0b6-cf113432b467
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
|
propertyPath: m_ActionEvents.Array.data[14].m_ActionId
|
||||||
|
value: 01a06960-a379-49e3-9d58-9b7c8effcb3d
|
||||||
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
propertyPath: m_ActionEvents.Array.data[13].m_ActionName
|
propertyPath: m_ActionEvents.Array.data[13].m_ActionName
|
||||||
value: Player/SwitchMinion[/Keyboard/q,/Keyboard/e,/XInputControllerWindows/leftShoulder,/XInputControllerWindows/rightShoulder]
|
value: Player/SwitchMinion[/Keyboard/q,/Keyboard/e,/XInputControllerWindows/leftShoulder,/XInputControllerWindows/rightShoulder]
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
|
propertyPath: m_ActionEvents.Array.data[14].m_ActionName
|
||||||
|
value: Player/Start[/XInputControllerWindows/start,/Keyboard/enter]
|
||||||
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
propertyPath: m_ActionEvents.Array.data[13].m_PersistentCalls.m_Calls.Array.size
|
propertyPath: m_ActionEvents.Array.data[13].m_PersistentCalls.m_Calls.Array.size
|
||||||
value: 1
|
value: 1
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
|
propertyPath: m_ActionEvents.Array.data[14].m_PersistentCalls.m_Calls.Array.size
|
||||||
|
value: 1
|
||||||
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
propertyPath: m_ActionEvents.Array.data[13].m_PersistentCalls.m_Calls.Array.data[0].m_Mode
|
propertyPath: m_ActionEvents.Array.data[13].m_PersistentCalls.m_Calls.Array.data[0].m_Mode
|
||||||
value: 0
|
value: 0
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
|
propertyPath: m_ActionEvents.Array.data[14].m_PersistentCalls.m_Calls.Array.data[0].m_Mode
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
propertyPath: m_ActionEvents.Array.data[13].m_PersistentCalls.m_Calls.Array.data[0].m_Target
|
propertyPath: m_ActionEvents.Array.data[13].m_PersistentCalls.m_Calls.Array.data[0].m_Target
|
||||||
value:
|
value:
|
||||||
objectReference: {fileID: 1551362087}
|
objectReference: {fileID: 1551362087}
|
||||||
|
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
|
propertyPath: m_ActionEvents.Array.data[14].m_PersistentCalls.m_Calls.Array.data[0].m_Target
|
||||||
|
value:
|
||||||
|
objectReference: {fileID: 1359990806}
|
||||||
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
propertyPath: m_ActionEvents.Array.data[13].m_PersistentCalls.m_Calls.Array.data[0].m_CallState
|
propertyPath: m_ActionEvents.Array.data[13].m_PersistentCalls.m_Calls.Array.data[0].m_CallState
|
||||||
value: 2
|
value: 2
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
|
propertyPath: m_ActionEvents.Array.data[14].m_PersistentCalls.m_Calls.Array.data[0].m_CallState
|
||||||
|
value: 2
|
||||||
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
propertyPath: m_ActionEvents.Array.data[13].m_PersistentCalls.m_Calls.Array.data[0].m_MethodName
|
propertyPath: m_ActionEvents.Array.data[13].m_PersistentCalls.m_Calls.Array.data[0].m_MethodName
|
||||||
value: ChangeSelectedIcon
|
value: ChangeSelectedIcon
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
|
propertyPath: m_ActionEvents.Array.data[14].m_PersistentCalls.m_Calls.Array.data[0].m_MethodName
|
||||||
|
value: OnStart
|
||||||
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
propertyPath: m_ActionEvents.Array.data[13].m_PersistentCalls.m_Calls.Array.data[0].m_TargetAssemblyTypeName
|
propertyPath: m_ActionEvents.Array.data[13].m_PersistentCalls.m_Calls.Array.data[0].m_TargetAssemblyTypeName
|
||||||
value: MinionBar, Assembly-CSharp
|
value: MinionBar, Assembly-CSharp
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
|
propertyPath: m_ActionEvents.Array.data[14].m_PersistentCalls.m_Calls.Array.data[0].m_TargetAssemblyTypeName
|
||||||
|
value: GameFlowManager, Assembly-CSharp
|
||||||
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
- target: {fileID: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
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: 1214567908930553477, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
|
||||||
|
propertyPath: m_ActionEvents.Array.data[14].m_PersistentCalls.m_Calls.Array.data[0].m_Arguments.m_ObjectArgumentAssemblyTypeName
|
||||||
|
value: UnityEngine.Object, UnityEngine
|
||||||
|
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 +542,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
|
||||||
|
|||||||
@ -1,12 +1,20 @@
|
|||||||
#nullable enable
|
#nullable enable
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using NaughtyAttributes;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class Arena : MonoBehaviour {
|
public class Arena : MonoBehaviour {
|
||||||
|
[SerializeField] [Required]
|
||||||
|
GameFlowManager gameFlowManager = null!;
|
||||||
|
|
||||||
//TODO probably add initial direction too
|
//TODO probably add initial direction too
|
||||||
[SerializeField] Vector3[] spawners = null!;
|
//TODO Add some kind of "MinLength(1)" attribute
|
||||||
[SerializeField] ArenaStats stats = null!;
|
[SerializeField]
|
||||||
[SerializeField] GameObject monsterPrefab = null!;
|
Vector3[] spawners = null!;
|
||||||
|
[SerializeField] [Required]
|
||||||
|
ArenaStats stats = null!;
|
||||||
|
[SerializeField] [Required]
|
||||||
|
GameObject monsterPrefab = null!;
|
||||||
|
|
||||||
SafeZone safeZone = null!;
|
SafeZone safeZone = null!;
|
||||||
|
|
||||||
@ -15,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);
|
||||||
@ -25,11 +36,10 @@ 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);
|
||||||
yield return new WaitForSeconds(stats.secondsBetweenSpawners);
|
yield return new WaitForSeconds(stats.secondsBetweenSpawners);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,17 +1,23 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using NaughtyAttributes;
|
||||||
using UnityEngine;
|
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]
|
||||||
|
protected EntityStats stats { get; private set; }
|
||||||
[field: SerializeField]protected float Health {get; private set; }
|
[field: SerializeField]protected float Health {get; private set; }
|
||||||
bool isAlive = true;
|
bool isAlive = true;
|
||||||
[SerializeField]public float movementSpeed{get; private set; }
|
[field: SerializeField]public float movementSpeed{get; private set; }
|
||||||
[SerializeField]public float rotSpeed {get; private set; }
|
[field: SerializeField]public float rotSpeed {get; private set; }
|
||||||
[SerializeField]private float fov;
|
[SerializeField]private float fov;
|
||||||
[SerializeField]private float attackRange;
|
[SerializeField]private float attackRange;
|
||||||
[SerializeField]public float attackDmg {get; private set; }
|
[field: SerializeField]public float attackDmg {get; private set; }
|
||||||
[SerializeField]protected float attackCooldown;
|
[SerializeField]protected float attackCooldown;
|
||||||
protected float attackTimer;
|
protected float attackTimer;
|
||||||
[SerializeField]private Transform target;
|
[SerializeField]private Transform target;
|
||||||
@ -19,6 +25,7 @@ public class Entity : MonoBehaviour
|
|||||||
private Collider atkCollider;
|
private Collider atkCollider;
|
||||||
public Vector3 direction {get; set; }
|
public Vector3 direction {get; set; }
|
||||||
public Rigidbody2D rb {get; private set;}
|
public Rigidbody2D rb {get; private set;}
|
||||||
|
bool beingPushed;
|
||||||
|
|
||||||
void Awake() => rb = GetComponent<Rigidbody2D>();
|
void Awake() => rb = GetComponent<Rigidbody2D>();
|
||||||
|
|
||||||
@ -27,6 +34,14 @@ public class Entity : MonoBehaviour
|
|||||||
attackTimer = attackCooldown;
|
attackTimer = attackCooldown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual void FixedUpdate() {
|
||||||
|
//TODO sqrMagnitude?
|
||||||
|
if (beingPushed && rb.velocity.magnitude < stats.MinVelocityWhenPushed) {
|
||||||
|
rb.velocity = Vector2.zero;
|
||||||
|
beingPushed = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual void Attack(){
|
protected virtual void Attack(){
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -35,9 +50,9 @@ public class Entity : MonoBehaviour
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void MoveToTarget(float deltaTime){
|
protected virtual void MoveToTarget(){
|
||||||
|
|
||||||
direction = Vector3.RotateTowards(direction, (target.position - transform.position), rotSpeed*deltaTime, 0.0f);
|
direction = Vector3.RotateTowards(direction, (target.position - transform.position), rotSpeed*Time.fixedDeltaTime, 0.0f);
|
||||||
if(!IsInAttackRange()){
|
if(!IsInAttackRange()){
|
||||||
rb.MovePosition(transform.position + direction * movementSpeed * deltaTime);
|
rb.MovePosition(transform.position + direction * movementSpeed * deltaTime);
|
||||||
}
|
}
|
||||||
@ -74,4 +89,9 @@ public class Entity : MonoBehaviour
|
|||||||
public bool IsAlive(){
|
public bool IsAlive(){
|
||||||
return isAlive;
|
return isAlive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void AddImpulse(Vector3 impulse) {
|
||||||
|
beingPushed = true;
|
||||||
|
rb.AddForce(impulse, ForceMode2D.Impulse);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
6
Assets/Scripts/EntityStats.cs
Normal file
6
Assets/Scripts/EntityStats.cs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class EntityStats {
|
||||||
|
[field: SerializeField] [field: Min(0f)]
|
||||||
|
public float MinVelocityWhenPushed { get; private set; } = 5f;
|
||||||
|
}
|
||||||
3
Assets/Scripts/EntityStats.cs.meta
Normal file
3
Assets/Scripts/EntityStats.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f3b49b8d7dbc43dfbd074996aa811570
|
||||||
|
timeCreated: 1648908811
|
||||||
@ -12,7 +12,11 @@ public class Monster : AIEntity
|
|||||||
base.ennemyName = "Gladiator";
|
base.ennemyName = "Gladiator";
|
||||||
}
|
}
|
||||||
|
|
||||||
void FixedUpdate() => MoveToTarget(Time.fixedDeltaTime);
|
protected override void FixedUpdate() {
|
||||||
|
base.FixedUpdate();
|
||||||
|
|
||||||
|
MoveToTarget();
|
||||||
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update()
|
void Update()
|
||||||
|
|||||||
@ -1,18 +1,26 @@
|
|||||||
#nullable enable
|
#nullable enable
|
||||||
|
using NaughtyAttributes;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.InputSystem;
|
using UnityEngine.InputSystem;
|
||||||
|
|
||||||
[RequireComponent(typeof(PlayerInput), typeof(Rigidbody2D))]
|
[RequireComponent(typeof(PlayerInput), typeof(Rigidbody2D))]
|
||||||
public class PlayerMovement : MonoBehaviour {
|
public class PlayerMovement : MonoBehaviour {
|
||||||
[SerializeField] PlayerStats stats = null!;
|
[SerializeField] [Required]
|
||||||
|
GameFlowManager gameFlowManager = null!;
|
||||||
|
|
||||||
|
[SerializeField] [field: Required]
|
||||||
|
PlayerStats stats = null!;
|
||||||
|
|
||||||
|
[field: Required]
|
||||||
Rigidbody2D rb = null!;
|
Rigidbody2D rb = null!;
|
||||||
|
|
||||||
Vector2 moveDirection;
|
Vector2 moveDirection;
|
||||||
BaseState currentState = null!;
|
BaseState currentState = null!;
|
||||||
SafeZone? safeZone;
|
SafeZone? safeZone;
|
||||||
|
|
||||||
bool lastJumpButton;
|
bool lastJumpButton;
|
||||||
|
|
||||||
|
#region Unity Messages
|
||||||
void Awake(){
|
void Awake(){
|
||||||
rb = GetComponent<Rigidbody2D>();
|
rb = GetComponent<Rigidbody2D>();
|
||||||
currentState = new ImmobileMovementState(this);
|
currentState = new ImmobileMovementState(this);
|
||||||
@ -21,17 +29,27 @@ public class PlayerMovement : MonoBehaviour {
|
|||||||
void Start() => currentState.EnterState();
|
void Start() => currentState.EnterState();
|
||||||
|
|
||||||
void Update() {
|
void Update() {
|
||||||
|
if (gameFlowManager.Paused)
|
||||||
|
return;
|
||||||
|
|
||||||
if (currentState.UpdateState() is {} newState)
|
if (currentState.UpdateState() is {} newState)
|
||||||
SwitchState(newState);
|
SwitchState(newState);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FixedUpdate() {
|
void FixedUpdate() {
|
||||||
|
if (gameFlowManager.Paused)
|
||||||
|
return;
|
||||||
|
|
||||||
if (currentState.FixedUpdateState() is {} newState)
|
if (currentState.FixedUpdateState() is {} newState)
|
||||||
SwitchState(newState);
|
SwitchState(newState);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnDrawGizmos() => currentState?.OnDrawGizmos();
|
void OnDrawGizmos() => currentState?.OnDrawGizmos();
|
||||||
|
|
||||||
|
#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)
|
||||||
@ -46,22 +64,20 @@ public class PlayerMovement : MonoBehaviour {
|
|||||||
|
|
||||||
if (!wasJustPressed)
|
if (!wasJustPressed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (safeZone == null)
|
if (safeZone == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (safeZone.IsInSafeZone) {
|
if (safeZone.IsInSafeZone) {
|
||||||
if (moveDirection.magnitude >= safeZone.stats.MinJumpJoystickValue)
|
if (moveDirection.magnitude >= safeZone.Stats.MinJumpJoystickValue)
|
||||||
SwitchState(new ExitSafeZoneMovementState(this, safeZone, moveDirection));
|
SwitchState(new ExitSafeZoneMovementState(this, safeZone, moveDirection));
|
||||||
} else //TODO if (AngleBetween(moveDirection, toSafeZone) < 90)
|
} else //TODO if (AngleBetween(moveDirection, toSafeZone) < 90)
|
||||||
SwitchState(new EnterSafeZoneMovementState(this, safeZone));
|
SwitchState(new EnterSafeZoneMovementState(this, safeZone));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwitchState(BaseState newState) {
|
#endregion
|
||||||
currentState.LeaveState();
|
|
||||||
currentState = newState;
|
#region Rigidbody
|
||||||
newState.EnterState();
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnTriggerEnter2D(Collider2D other) {
|
void OnTriggerEnter2D(Collider2D other) {
|
||||||
if (other.GetComponent<SafeZone>() is {} triggeredSafeZone)
|
if (other.GetComponent<SafeZone>() is {} triggeredSafeZone)
|
||||||
@ -85,7 +101,17 @@ public class PlayerMovement : MonoBehaviour {
|
|||||||
rb.isKinematic = !enabled;
|
rb.isKinematic = !enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class BaseStatePlayerMovement : BaseState{
|
#endregion
|
||||||
|
|
||||||
|
#region States
|
||||||
|
|
||||||
|
void SwitchState(BaseState newState) {
|
||||||
|
currentState.LeaveState();
|
||||||
|
currentState = newState;
|
||||||
|
newState.EnterState();
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class BaseStatePlayerMovement : BaseState {
|
||||||
protected PlayerMovement playerMovement;
|
protected PlayerMovement playerMovement;
|
||||||
public BaseStatePlayerMovement(PlayerMovement playerMovement){
|
public BaseStatePlayerMovement(PlayerMovement playerMovement){
|
||||||
this.playerMovement = playerMovement;
|
this.playerMovement = playerMovement;
|
||||||
@ -96,9 +122,10 @@ public class PlayerMovement : MonoBehaviour {
|
|||||||
public NormalMovementState(PlayerMovement playerMovement) : base(playerMovement){
|
public NormalMovementState(PlayerMovement playerMovement) : base(playerMovement){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override BaseState? FixedUpdateState() {
|
public override BaseState? FixedUpdateState() {
|
||||||
playerMovement.rb.velocity = (Vector3)playerMovement.moveDirection * playerMovement.stats.movementSpeed;
|
playerMovement.rb.velocity = (Vector3)playerMovement.moveDirection * playerMovement.stats.movementSpeed;
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,7 +151,7 @@ public class PlayerMovement : MonoBehaviour {
|
|||||||
float currentTime = Time.time - startTime;
|
float currentTime = Time.time - startTime;
|
||||||
if (currentTime >= duration)
|
if (currentTime >= duration)
|
||||||
return Transition();
|
return Transition();
|
||||||
|
|
||||||
playerMovement.rb.MovePosition(Vector3.Lerp(
|
playerMovement.rb.MovePosition(Vector3.Lerp(
|
||||||
startPosition,
|
startPosition,
|
||||||
target,
|
target,
|
||||||
@ -140,7 +167,7 @@ public class PlayerMovement : MonoBehaviour {
|
|||||||
|
|
||||||
class EnterSafeZoneMovementState : JumpingMovementState {
|
class EnterSafeZoneMovementState : JumpingMovementState {
|
||||||
readonly SafeZone safeZone;
|
readonly SafeZone safeZone;
|
||||||
public EnterSafeZoneMovementState(PlayerMovement playerMovement, SafeZone safeZone) : base(playerMovement, safeZone.stats.JumpDuration, safeZone.transform.position) {
|
public EnterSafeZoneMovementState(PlayerMovement playerMovement, SafeZone safeZone) : base(playerMovement, safeZone.Stats.JumpDuration, safeZone.transform.position) {
|
||||||
this.safeZone = safeZone;
|
this.safeZone = safeZone;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,12 +180,12 @@ public class PlayerMovement : MonoBehaviour {
|
|||||||
|
|
||||||
protected override BaseState Transition() => new ImmobileMovementState(playerMovement);
|
protected override BaseState Transition() => new ImmobileMovementState(playerMovement);
|
||||||
|
|
||||||
protected override float ModifyLerpTime(float t) => safeZone.stats.JumpSpeedCurve.Evaluate(t);
|
protected override float ModifyLerpTime(float t) => safeZone.Stats.JumpSpeedCurve.Evaluate(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
class ExitSafeZoneMovementState : JumpingMovementState {
|
class ExitSafeZoneMovementState : JumpingMovementState {
|
||||||
readonly SafeZone safeZone;
|
readonly SafeZone safeZone;
|
||||||
public ExitSafeZoneMovementState(PlayerMovement playerMovement, SafeZone safeZone, Vector2 direction) : base(playerMovement, safeZone.stats.JumpDuration, safeZone.GetOutsidePosition(direction)) {
|
public ExitSafeZoneMovementState(PlayerMovement playerMovement, SafeZone safeZone, Vector2 direction) : base(playerMovement, safeZone.Stats.JumpDuration, safeZone.GetOutsidePosition(direction)) {
|
||||||
this.safeZone = safeZone;
|
this.safeZone = safeZone;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +196,7 @@ public class PlayerMovement : MonoBehaviour {
|
|||||||
playerMovement.SetRigidbodyEnabled(true);
|
playerMovement.SetRigidbodyEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override float ModifyLerpTime(float t) => safeZone.stats.JumpSpeedCurve.Evaluate(t);
|
protected override float ModifyLerpTime(float t) => safeZone.Stats.JumpSpeedCurve.Evaluate(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
class ImmobileMovementState : BaseStatePlayerMovement {
|
class ImmobileMovementState : BaseStatePlayerMovement {
|
||||||
@ -188,7 +215,7 @@ public class PlayerMovement : MonoBehaviour {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
Vector3 dropPosition = playerMovement.safeZone.GetOutsidePosition(playerMovement.moveDirection);
|
Vector3 dropPosition = playerMovement.safeZone.GetOutsidePosition(playerMovement.moveDirection);
|
||||||
bool canJump = playerMovement.moveDirection.magnitude >= playerMovement.safeZone.stats.MinJumpJoystickValue;
|
bool canJump = playerMovement.moveDirection.magnitude >= playerMovement.safeZone.Stats.MinJumpJoystickValue;
|
||||||
Gizmos.color = canJump ? Color.green : Color.red;
|
Gizmos.color = canJump ? Color.green : Color.red;
|
||||||
Gizmos.DrawLine(playerMovement.transform.position, dropPosition);
|
Gizmos.DrawLine(playerMovement.transform.position, dropPosition);
|
||||||
if (canJump)
|
if (canJump)
|
||||||
@ -198,4 +225,6 @@ public class PlayerMovement : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
@ -1,7 +1,10 @@
|
|||||||
|
using NaughtyAttributes;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class SafeZone : MonoBehaviour {
|
public class SafeZone : MonoBehaviour {
|
||||||
public SafeZoneStats stats;
|
[field: SerializeField] [field: Required]
|
||||||
|
public SafeZoneStats Stats { get; private set; }
|
||||||
|
|
||||||
[SerializeField] CircleCollider2D moatCollider;
|
[SerializeField] CircleCollider2D moatCollider;
|
||||||
public bool IsInSafeZone { get; private set; } = true;
|
public bool IsInSafeZone { get; private set; } = true;
|
||||||
|
|
||||||
@ -14,6 +17,6 @@ public class SafeZone : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Vector3 GetOutsidePosition(Vector2 direction) {
|
public Vector3 GetOutsidePosition(Vector2 direction) {
|
||||||
return transform.position + (moatCollider.radius + stats.JumpOffset) * (Vector3)direction;
|
return transform.position + (moatCollider.radius + Stats.JumpOffset) * (Vector3)direction;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,9 +1,10 @@
|
|||||||
//TODO Replace with Damageable?
|
using NaughtyAttributes;
|
||||||
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class VampireEntity : Entity {
|
public class VampireEntity : Entity {
|
||||||
[SerializeField] HealthBar healthBar;
|
[SerializeField] [Required]
|
||||||
|
HealthBar healthBar;
|
||||||
|
[Min(10f)]
|
||||||
float initialHealth;
|
float initialHealth;
|
||||||
|
|
||||||
protected override void Start() {
|
protected override void Start() {
|
||||||
|
|||||||
@ -40,6 +40,15 @@
|
|||||||
"processors": "",
|
"processors": "",
|
||||||
"interactions": "",
|
"interactions": "",
|
||||||
"initialStateCheck": false
|
"initialStateCheck": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Start",
|
||||||
|
"type": "Button",
|
||||||
|
"id": "01a06960-a379-49e3-9d58-9b7c8effcb3d",
|
||||||
|
"expectedControlType": "Button",
|
||||||
|
"processors": "",
|
||||||
|
"interactions": "",
|
||||||
|
"initialStateCheck": false
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"bindings": [
|
"bindings": [
|
||||||
@ -284,6 +293,28 @@
|
|||||||
"action": "SwitchMinion",
|
"action": "SwitchMinion",
|
||||||
"isComposite": false,
|
"isComposite": false,
|
||||||
"isPartOfComposite": true
|
"isPartOfComposite": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "",
|
||||||
|
"id": "4715f838-717a-4f10-a668-05a6d761a7bc",
|
||||||
|
"path": "<Gamepad>/start",
|
||||||
|
"interactions": "",
|
||||||
|
"processors": "",
|
||||||
|
"groups": "Gamepad",
|
||||||
|
"action": "Start",
|
||||||
|
"isComposite": false,
|
||||||
|
"isPartOfComposite": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "",
|
||||||
|
"id": "025fe243-6da7-4b27-9c02-f353d7a121df",
|
||||||
|
"path": "<Keyboard>/enter",
|
||||||
|
"interactions": "",
|
||||||
|
"processors": "",
|
||||||
|
"groups": "Keyboard&Mouse",
|
||||||
|
"action": "Start",
|
||||||
|
"isComposite": false,
|
||||||
|
"isPartOfComposite": false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"com.dbrizov.naughtyattributes": "https://github.com/dbrizov/NaughtyAttributes.git#upm",
|
||||||
"com.unity.2d.animation": "5.1.1",
|
"com.unity.2d.animation": "5.1.1",
|
||||||
"com.unity.2d.pixel-perfect": "4.0.1",
|
"com.unity.2d.pixel-perfect": "4.0.1",
|
||||||
"com.unity.2d.psdimporter": "4.2.0",
|
"com.unity.2d.psdimporter": "4.2.0",
|
||||||
|
|||||||
@ -1,5 +1,12 @@
|
|||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"com.dbrizov.naughtyattributes": {
|
||||||
|
"version": "https://github.com/dbrizov/NaughtyAttributes.git#upm",
|
||||||
|
"depth": 0,
|
||||||
|
"source": "git",
|
||||||
|
"dependencies": {},
|
||||||
|
"hash": "8a8fa5a9659a6d63f196391c71e06c4286c8acd7"
|
||||||
|
},
|
||||||
"com.unity.2d.animation": {
|
"com.unity.2d.animation": {
|
||||||
"version": "5.1.1",
|
"version": "5.1.1",
|
||||||
"depth": 0,
|
"depth": 0,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user