Pull request #4: Jason
Merge in CEGJ/ludumdare50 from jason to dev * commit 'bd5efcb31a1335a9f65b63f37e5ae47b74ee7e0c': Fixed exiting safe zone before game starts Forgot to resolve deltaTime to Time.fixedDeltaTime
This commit is contained in:
commit
64b5704d34
@ -3,6 +3,10 @@ using UnityEngine.InputSystem;
|
|||||||
|
|
||||||
//Could be a singleton
|
//Could be a singleton
|
||||||
public class GameFlowManager : MonoBehaviour {
|
public class GameFlowManager : MonoBehaviour {
|
||||||
|
/// <summary>
|
||||||
|
/// True if time is frozen (Start, Pause Menu, Dead)
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>Could be renamed appropriately</remarks>
|
||||||
[field: SerializeField]
|
[field: SerializeField]
|
||||||
public bool Paused { get; private set; } = true;
|
public bool Paused { get; private set; } = true;
|
||||||
public BaseState CurrentState { get; private set; } = null!;
|
public BaseState CurrentState { get; private set; } = null!;
|
||||||
|
|||||||
@ -51,10 +51,10 @@ public class Entity : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void MoveToTarget(){
|
protected virtual void MoveToTarget(){
|
||||||
|
//Would be nice if we could force this to be in FixedUpdate
|
||||||
direction = Vector3.RotateTowards(direction, (target.position - transform.position), rotSpeed*Time.fixedDeltaTime, 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 * Time.fixedDeltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,8 @@ public class PlayerMovement : MonoBehaviour {
|
|||||||
bool lastJumpButton;
|
bool lastJumpButton;
|
||||||
|
|
||||||
#region Unity Messages
|
#region Unity Messages
|
||||||
void Awake(){
|
|
||||||
|
void Awake() {
|
||||||
rb = GetComponent<Rigidbody2D>();
|
rb = GetComponent<Rigidbody2D>();
|
||||||
currentState = new ImmobileMovementState(this);
|
currentState = new ImmobileMovementState(this);
|
||||||
}
|
}
|
||||||
@ -65,7 +66,7 @@ public class PlayerMovement : MonoBehaviour {
|
|||||||
if (!wasJustPressed)
|
if (!wasJustPressed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (safeZone == null)
|
if (gameFlowManager.Paused || safeZone == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (safeZone.IsInSafeZone) {
|
if (safeZone.IsInSafeZone) {
|
||||||
@ -113,15 +114,14 @@ public class PlayerMovement : MonoBehaviour {
|
|||||||
|
|
||||||
abstract class BaseStatePlayerMovement : BaseState {
|
abstract class BaseStatePlayerMovement : BaseState {
|
||||||
protected PlayerMovement playerMovement;
|
protected PlayerMovement playerMovement;
|
||||||
public BaseStatePlayerMovement(PlayerMovement playerMovement){
|
|
||||||
|
public BaseStatePlayerMovement(PlayerMovement playerMovement) {
|
||||||
this.playerMovement = playerMovement;
|
this.playerMovement = playerMovement;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class NormalMovementState : BaseStatePlayerMovement {
|
class NormalMovementState : BaseStatePlayerMovement {
|
||||||
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;
|
||||||
@ -167,6 +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;
|
||||||
}
|
}
|
||||||
@ -185,6 +186,7 @@ public class PlayerMovement : MonoBehaviour {
|
|||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
@ -200,9 +202,7 @@ public class PlayerMovement : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ImmobileMovementState : BaseStatePlayerMovement {
|
class ImmobileMovementState : BaseStatePlayerMovement {
|
||||||
public ImmobileMovementState(PlayerMovement playerMovement) : base(playerMovement){
|
public ImmobileMovementState(PlayerMovement playerMovement) : base(playerMovement) {}
|
||||||
|
|
||||||
}
|
|
||||||
public override void EnterState() {
|
public override void EnterState() {
|
||||||
base.EnterState();
|
base.EnterState();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user