merge dev

This commit is contained in:
Yann Dupont 01 2022-04-02 19:34:26 -04:00
commit c259b3f4b6
7 changed files with 53 additions and 43 deletions

View File

@ -55,6 +55,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
gameFlowManager: {fileID: 0} gameFlowManager: {fileID: 0}
stats: {fileID: 11400000, guid: 12a626b5a296d934ba078d222ad6ba98, type: 2} stats: {fileID: 11400000, guid: 12a626b5a296d934ba078d222ad6ba98, type: 2}
globalCamera: {fileID: 0}
safeZonePrompt: {fileID: 0} safeZonePrompt: {fileID: 0}
--- !u!114 &3126145803593047825 --- !u!114 &3126145803593047825
MonoBehaviour: MonoBehaviour:
@ -95,6 +96,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 56c3e06ea5db48a40a7f55e72291cb0d, type: 3} m_Script: {fileID: 11500000, guid: 56c3e06ea5db48a40a7f55e72291cb0d, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
gameFlowManager: {fileID: 0}
minionPrefabs: minionPrefabs:
- {fileID: 2399377275812995974, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3} - {fileID: 2399377275812995974, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
aimArrow: {fileID: 5124059627794595469} aimArrow: {fileID: 5124059627794595469}
@ -339,7 +341,7 @@ Rigidbody2D:
m_LinearDrag: 0 m_LinearDrag: 0
m_AngularDrag: 0.05 m_AngularDrag: 0.05
m_GravityScale: 0 m_GravityScale: 0
m_Material: {fileID: 0} m_Material: {fileID: 6200000, guid: 72c8b57001d325c418a78771641a077f, type: 2}
m_Interpolate: 0 m_Interpolate: 0
m_SleepingMode: 1 m_SleepingMode: 1
m_CollisionDetection: 0 m_CollisionDetection: 0

View File

@ -31,7 +31,7 @@ public class Arena : MonoBehaviour {
void Start() => StartCoroutine(SpawnEnemies()); void Start() => StartCoroutine(SpawnEnemies());
void SpawnEnemy(int spawnerIndex) { void SpawnEnemy(int spawnerIndex) {
if (gameFlowManager.Paused) if (!gameFlowManager.CanDoAction)
return; return;
var entity = Instantiate(entityPrefab, spawners[spawnerIndex].position, Quaternion.identity).GetComponent<Entity>(); var entity = Instantiate(entityPrefab, spawners[spawnerIndex].position, Quaternion.identity).GetComponent<Entity>();

View File

@ -8,12 +8,16 @@ public class GameFlowManager : MonoBehaviour {
[SerializeField] [Required] [SerializeField] [Required]
GameTimer gameTimer = null!; GameTimer gameTimer = null!;
/// <summary> public enum PauseLevel {
/// True if time is frozen (Start, Pause Menu, Dead) NotPaused,
/// </summary> PreventActions,
/// <remarks>Could be renamed appropriately</remarks> WorldFreeze,
}
[field: SerializeField] [field: SerializeField]
public bool Paused { get; private set; } = true; public PauseLevel pauseLevel { get; private set; } = PauseLevel.PreventActions;
public bool CanDoAction => pauseLevel <= PauseLevel.NotPaused;
public BaseState CurrentState { get; private set; } = null!; public BaseState CurrentState { get; private set; } = null!;
bool lastStartButton; bool lastStartButton;
@ -33,10 +37,9 @@ public class GameFlowManager : MonoBehaviour {
#endregion #endregion
void SetPause(bool value) { void SetPauseLevel(PauseLevel value) {
Debug.Log($"Setting pause to {value}"); pauseLevel = value;
Paused = value; Time.timeScale = value >= PauseLevel.WorldFreeze ? 0f : 1f;
Time.timeScale = value ? 0f : 1f;
} }
public void GameOver() => SwitchState(new DeadFlowState(this)); public void GameOver() => SwitchState(new DeadFlowState(this));
@ -85,8 +88,7 @@ public class GameFlowManager : MonoBehaviour {
public override void EnterState() { public override void EnterState() {
base.EnterState(); base.EnterState();
Debug.Log("Press Start to start...!"); gameFlowManager.SetPauseLevel(PauseLevel.PreventActions);
gameFlowManager.SetPause(true);
} }
public override void LeaveState() { public override void LeaveState() {
@ -101,7 +103,7 @@ public class GameFlowManager : MonoBehaviour {
base.EnterState(); base.EnterState();
gameFlowManager.gameTimer.StartTimer(); gameFlowManager.gameTimer.StartTimer();
gameFlowManager.SetPause(false); gameFlowManager.SetPauseLevel(PauseLevel.NotPaused);
} }
public override void LeaveState() { public override void LeaveState() {
@ -116,7 +118,7 @@ public class GameFlowManager : MonoBehaviour {
public override void EnterState() { public override void EnterState() {
base.EnterState(); base.EnterState();
gameFlowManager.SetPause(true); gameFlowManager.SetPauseLevel(PauseLevel.NotPaused);
} }
} }
@ -127,7 +129,7 @@ public class GameFlowManager : MonoBehaviour {
base.EnterState(); base.EnterState();
Debug.Log("You died!\nPress Accept to restart!"); Debug.Log("You died!\nPress Accept to restart!");
gameFlowManager.SetPause(true); gameFlowManager.SetPauseLevel(PauseLevel.PreventActions);
} }
public void ReloadGame() { public void ReloadGame() {

View File

@ -6,7 +6,8 @@ using UnityEngine;
using UnityEngine.InputSystem; using UnityEngine.InputSystem;
public class MinionThrower : MonoBehaviour { public class MinionThrower : MonoBehaviour {
[SerializeField] [Required] [SerializeField]
[Required]
GameFlowManager gameFlowManager = null!; GameFlowManager gameFlowManager = null!;
public Entity[] minionPrefabs; public Entity[] minionPrefabs;
@ -34,14 +35,14 @@ public class MinionThrower : MonoBehaviour {
} }
void FixedUpdate() { void FixedUpdate() {
if(currentCooldownTimer > 0f) { if (currentCooldownTimer > 0f) {
currentCooldownTimer -= Time.fixedDeltaTime; currentCooldownTimer -= Time.fixedDeltaTime;
minionBar.UpdateReload(currentCooldownTimer / currentInitialCooldown); minionBar.UpdateReload(currentCooldownTimer / currentInitialCooldown);
} }
} }
public void ToggleThrowMode(InputAction.CallbackContext context) { public void ToggleThrowMode(InputAction.CallbackContext context) {
if (gameFlowManager.Paused) if (!gameFlowManager.CanDoAction)
return; return;
if (context.performed) { if (context.performed) {
@ -56,7 +57,11 @@ public class MinionThrower : MonoBehaviour {
public void AimThrow(InputAction.CallbackContext context) { public void AimThrow(InputAction.CallbackContext context) {
throwDirection = context.ReadValue<Vector2>().normalized; throwDirection = context.ReadValue<Vector2>().normalized;
aimArrow.transform.rotation = Quaternion.FromToRotation(transform.right, throwDirection); if (vampireEntity.playerMovement.facingRight) {
aimArrow.transform.rotation = Quaternion.FromToRotation(Vector2.right, throwDirection);
} else {
aimArrow.transform.rotation = Quaternion.FromToRotation(Vector2.left, throwDirection);
}
} }
void PerformThrow() { void PerformThrow() {
@ -65,7 +70,7 @@ public class MinionThrower : MonoBehaviour {
} }
float minionHealthCost = 10f; // TODO float minionHealthCost = 10f; // TODO
if(minionHealthCost >= vampireEntity.Health) { if (minionHealthCost >= vampireEntity.Health) {
return; return;
} }
vampireEntity.TakeDamage(minionHealthCost, vampireEntity); vampireEntity.TakeDamage(minionHealthCost, vampireEntity);
@ -76,7 +81,7 @@ public class MinionThrower : MonoBehaviour {
var newMinion = Instantiate(minionBar.GetCurrentMinion().gameObject, transform.position + new Vector3(throwDirection.x, throwDirection.y, 0f) * 1f, Quaternion.identity) var newMinion = Instantiate(minionBar.GetCurrentMinion().gameObject, transform.position + new Vector3(throwDirection.x, throwDirection.y, 0f) * 1f, Quaternion.identity)
.GetComponent<Monster>(); .GetComponent<Monster>();
if (movement.GetSafeZoneIfImmobile() is {} safeZone) { if (movement.GetSafeZoneIfImmobile() is { } safeZone) {
newMinion.thrownFromSafeZone = true; newMinion.thrownFromSafeZone = true;
newMinion.thrownTargetPosition = safeZone.GetOutsidePosition(throwDirection); newMinion.thrownTargetPosition = safeZone.GetOutsidePosition(throwDirection);
} }

View File

@ -21,7 +21,7 @@ public class PlayerMovement : MonoBehaviour {
SafeZone? safeZone; SafeZone? safeZone;
VampireEntity vampireEntity; VampireEntity vampireEntity;
Animator animator; Animator animator;
bool facingRight = true; public bool facingRight { get; private set; } = true;
bool lastJumpButton; bool lastJumpButton;
@ -43,7 +43,7 @@ public class PlayerMovement : MonoBehaviour {
} }
void Update() { void Update() {
if (gameFlowManager.Paused) if (gameFlowManager.pauseLevel >= GameFlowManager.PauseLevel.WorldFreeze)
return; return;
if (currentState.UpdateState() is {} newState) if (currentState.UpdateState() is {} newState)
@ -51,7 +51,7 @@ public class PlayerMovement : MonoBehaviour {
} }
void FixedUpdate() { void FixedUpdate() {
if (gameFlowManager.Paused) if (gameFlowManager.pauseLevel >= GameFlowManager.PauseLevel.WorldFreeze)
return; return;
if (safeZone != null && IsInSafeZone) { if (safeZone != null && IsInSafeZone) {
@ -92,17 +92,20 @@ public class PlayerMovement : MonoBehaviour {
#region Inputs #region Inputs
public void OnMove(InputAction.CallbackContext ctx) { public void OnMove(InputAction.CallbackContext ctx) {
if (gameFlowManager.CanDoAction) {
moveDirection = ctx.ReadValue<Vector2>(); moveDirection = ctx.ReadValue<Vector2>();
if (moveDirection.sqrMagnitude > 1.0f) if (moveDirection.sqrMagnitude > 1.0f)
moveDirection.Normalize(); moveDirection.Normalize();
FlipAccordingToInput(); FlipAccordingToInput();
}else //TODO Should set to zero via event or callback
moveDirection = Vector2.zero;
} }
public void OnJump(InputAction.CallbackContext ctx) { public void OnJump(InputAction.CallbackContext ctx) {
if (!ctx.WasPressedThisFrame(ref lastJumpButton)) if (!ctx.WasPressedThisFrame(ref lastJumpButton))
return; return;
if (gameFlowManager.Paused || safeZone == null) if (!gameFlowManager.CanDoAction || safeZone == null)
return; return;
if (IsInSafeZone) { if (IsInSafeZone) {

View File

@ -7,7 +7,7 @@ public class VampireEntity : Entity {
// [SerializeField] [Required] // [SerializeField] [Required]
// HealthBar healthBar; // HealthBar healthBar;
PlayerMovement playerMovement; [HideInInspector] public PlayerMovement playerMovement;
protected override void Start() { protected override void Start() {
base.Start(); base.Start();
@ -18,9 +18,7 @@ public class VampireEntity : Entity {
protected override void Update() { protected override void Update() {
base.Update(); base.Update();
if (gameFlowManager.Paused) if (gameFlowManager.CanDoAction)
return;
TakeDamage(playerStats.bloodLossRate * Time.deltaTime, this); TakeDamage(playerStats.bloodLossRate * Time.deltaTime, this);
} }

View File

@ -76,7 +76,7 @@ PlayerSettings:
androidFullscreenMode: 1 androidFullscreenMode: 1
defaultIsNativeResolution: 1 defaultIsNativeResolution: 1
macRetinaSupport: 1 macRetinaSupport: 1
runInBackground: 0 runInBackground: 1
captureSingleScreen: 0 captureSingleScreen: 0
muteOtherAudioSources: 0 muteOtherAudioSources: 0
Prepare IOS For Recording: 0 Prepare IOS For Recording: 0