Re-add auto pause on AFK
This commit is contained in:
3 files changed
+37
No files matched your search
@@ -52,6 +52,7 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
public readonly List<GameObject> berries = new();
|
||||
private readonly List<EntityId> noGravityBerries = new();
|
||||
private bool hasJumped = false;
|
||||
private float lastMoveTime;
|
||||
|
||||
internal bool IsGrounded() => Physics2D.Distance(bird.GetComponent<CircleCollider2D>(), groundCollider).distance <= 0.1f;
|
||||
|
||||
@@ -109,6 +110,7 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
leftButton.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
lastMoveTime = Time.time;
|
||||
UnityEngine.InputSystem.EnhancedTouch.EnhancedTouchSupport.Enable();
|
||||
Cursor.visible = false;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
@@ -156,17 +158,20 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
if (doMoveLeft && !doMoveRight) {
|
||||
lastMoveTime = Time.time;
|
||||
bird.transform.position += new UnityEngine.Vector3(-(576f * (speedModifier * canvasRect.lossyScale.x) * Time.deltaTime), 0f, 0f);
|
||||
ClampPosition(bird);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(1f, 1f, 1f);
|
||||
}
|
||||
if (doMoveRight && !doMoveLeft) {
|
||||
lastMoveTime = Time.time;
|
||||
bird.transform.position += new UnityEngine.Vector3(576f * (speedModifier * canvasRect.lossyScale.x) * Time.deltaTime, 0f, 0f);
|
||||
ClampPosition(bird);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(-1f, 1f, 1f);
|
||||
}
|
||||
if (doMoveLeft || doMoveRight) groundCollider.transform.position = new(bird.transform.position.x, groundCollider.transform.position.y);
|
||||
if (doJump && IsGrounded() && !hasJumped) {
|
||||
lastMoveTime = Time.time;
|
||||
hasJumped = true;
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Jump"), Camera.main.transform.position, 0.75f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
if (boostLeft > 0f || speedyLeft > 0f) rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 380f);
|
||||
@@ -339,17 +344,20 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
if (doMoveLeft && !doMoveRight) {
|
||||
lastMoveTime = Time.time;
|
||||
bird.transform.position += new UnityEngine.Vector3(-(576f * (speedModifier * canvasRect.lossyScale.x) * Time.deltaTime), 0f, 0f);
|
||||
ClampPosition(bird);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(1f, 1f, 1f);
|
||||
}
|
||||
if (doMoveRight && !doMoveLeft) {
|
||||
lastMoveTime = Time.time;
|
||||
bird.transform.position += new UnityEngine.Vector3(576f * (speedModifier * canvasRect.lossyScale.x) * Time.deltaTime, 0f, 0f);
|
||||
ClampPosition(bird);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(-1f, 1f, 1f);
|
||||
}
|
||||
if (doMoveLeft || doMoveRight) groundCollider.transform.position = new(bird.transform.position.x, groundCollider.transform.position.y);
|
||||
if (doJump && IsGrounded() && !hasJumped) {
|
||||
lastMoveTime = Time.time;
|
||||
hasJumped = true;
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Jump"), Camera.main.transform.position, 0.75f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
if (boostLeft > 0f || speedyLeft > 0f) rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 480f * canvasRect.lossyScale.y);
|
||||
@@ -479,6 +487,12 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
|
||||
SpawnBerries();
|
||||
if (!pausePanel.activeSelf) {
|
||||
if (Time.time - lastMoveTime > 20) {
|
||||
lastMoveTime = float.MaxValue;
|
||||
EnablePause();
|
||||
return;
|
||||
}
|
||||
|
||||
if (useAI) MoveBirdAI();
|
||||
else MoveBird();
|
||||
if (boostLeft > 0f) {
|
||||
@@ -592,6 +606,7 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
CustomGamePlayerPauseMenu.Instance.ToggleEditingUI();
|
||||
return;
|
||||
}
|
||||
lastMoveTime = Time.time;
|
||||
rb.gravityScale = 100f * canvasRect.lossyScale.y;
|
||||
rb.linearVelocity = velocityBeforePause;
|
||||
velocityBeforePause = new();
|
||||
|
||||
@@ -56,6 +56,7 @@ public class GamePlayer : MonoBehaviour {
|
||||
public readonly List<GameObject> berries = new();
|
||||
private readonly List<EntityId> noGravityBerries = new();
|
||||
private bool hasJumped = false;
|
||||
private float lastMoveTime;
|
||||
|
||||
internal bool IsGrounded() => Physics2D.Distance(bird.GetComponent<CircleCollider2D>(), groundCollider).distance <= 0.1f;
|
||||
|
||||
@@ -82,6 +83,7 @@ public class GamePlayer : MonoBehaviour {
|
||||
BazookaManager.Instance.GetAccountID() ?? 0
|
||||
);
|
||||
|
||||
lastMoveTime = Time.time;
|
||||
UnityEngine.InputSystem.EnhancedTouch.EnhancedTouchSupport.Enable();
|
||||
highscore = BazookaManager.Instance.GetGameStoreHighScore();
|
||||
totalNormalBerries = BazookaManager.Instance.GetGameStoreTotalNormalBerries();
|
||||
@@ -142,17 +144,20 @@ public class GamePlayer : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
if (doMoveLeft && !doMoveRight) {
|
||||
lastMoveTime = Time.time;
|
||||
bird.transform.position += new UnityEngine.Vector3(-(576f * (speedModifier * canvasRect.lossyScale.x) * Time.deltaTime), 0f, 0f);
|
||||
ClampPosition(bird);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(1f, 1f, 1f);
|
||||
}
|
||||
if (doMoveRight && !doMoveLeft) {
|
||||
lastMoveTime = Time.time;
|
||||
bird.transform.position += new UnityEngine.Vector3(576f * (speedModifier * canvasRect.lossyScale.x) * Time.deltaTime, 0f, 0f);
|
||||
ClampPosition(bird);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(-1f, 1f, 1f);
|
||||
}
|
||||
if (doMoveLeft || doMoveRight) groundCollider.transform.position = new(bird.transform.position.x, groundCollider.transform.position.y);
|
||||
if (doJump && IsGrounded() && !hasJumped) {
|
||||
lastMoveTime = Time.time;
|
||||
hasJumped = true;
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Jump"), Camera.main.transform.position, 0.75f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
if (boostLeft > 0f || speedyLeft > 0f) rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 480f * canvasRect.lossyScale.y);
|
||||
@@ -258,6 +263,12 @@ public class GamePlayer : MonoBehaviour {
|
||||
|
||||
SpawnBerries();
|
||||
if (!pausePanel.activeSelf) {
|
||||
if (Time.time - lastMoveTime > 20) {
|
||||
lastMoveTime = float.MaxValue;
|
||||
EnablePause();
|
||||
return;
|
||||
}
|
||||
|
||||
MoveBird();
|
||||
if (boostLeft > 0f) {
|
||||
boostLeft -= Time.deltaTime;
|
||||
@@ -402,6 +413,7 @@ public class GamePlayer : MonoBehaviour {
|
||||
GamePlayerPauseMenu.Instance.ToggleEditingUI();
|
||||
return;
|
||||
}
|
||||
lastMoveTime = Time.time;
|
||||
rb.gravityScale = 100f * canvasRect.lossyScale.y;
|
||||
rb.linearVelocity = velocityBeforePause;
|
||||
velocityBeforePause = new();
|
||||
|
||||
@@ -36,6 +36,7 @@ public class MultiplayerGamePlayer : MonoBehaviour {
|
||||
private readonly List<MultiplayerUser> players = new();
|
||||
private float lastMoveSentTime = -1f;
|
||||
private bool hasJumped = false;
|
||||
private float lastMoveTime;
|
||||
|
||||
private Image bird;
|
||||
[SerializeField] private GameObject birdTemplate;
|
||||
@@ -87,6 +88,7 @@ public class MultiplayerGamePlayer : MonoBehaviour {
|
||||
BazookaManager.Instance.GetAccountID() ?? 0
|
||||
);
|
||||
|
||||
lastMoveTime = Time.time;
|
||||
UnityEngine.InputSystem.EnhancedTouch.EnhancedTouchSupport.Enable();
|
||||
|
||||
Cursor.visible = false;
|
||||
@@ -216,17 +218,20 @@ public class MultiplayerGamePlayer : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
if (doMoveLeft && !doMoveRight) {
|
||||
lastMoveTime = Time.time;
|
||||
bird.transform.position += new UnityEngine.Vector3(-(576f * (speedModifier * canvasRect.lossyScale.x) * Time.deltaTime), 0f, 0f);
|
||||
ClampPosition(bird);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(1f, 1f, 1f);
|
||||
}
|
||||
if (doMoveRight && !doMoveLeft) {
|
||||
lastMoveTime = Time.time;
|
||||
bird.transform.position += new UnityEngine.Vector3(576f * (speedModifier * canvasRect.lossyScale.x) * Time.deltaTime, 0f, 0f);
|
||||
ClampPosition(bird);
|
||||
bird.transform.localScale = new UnityEngine.Vector3(-1f, 1f, 1f);
|
||||
}
|
||||
if (doMoveLeft || doMoveRight) groundCollider.transform.position = new(bird.transform.position.x, groundCollider.transform.position.y);
|
||||
if (doJump && IsGrounded() && !hasJumped) {
|
||||
lastMoveTime = Time.time;
|
||||
hasJumped = true;
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Jump"), Camera.main.transform.position, 0.75f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
if (boostLeft > 0f) rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 480f * canvasRect.lossyScale.y);
|
||||
@@ -272,6 +277,10 @@ public class MultiplayerGamePlayer : MonoBehaviour {
|
||||
return;
|
||||
}
|
||||
if (!pausePanel.activeSelf && rb.gravityScale != 100f * canvasRect.lossyScale.y) rb.gravityScale = 100f * canvasRect.lossyScale.y;
|
||||
if (!pausePanel.activeSelf && Time.time - lastMoveTime > 20) {
|
||||
lastMoveTime = float.MaxValue;
|
||||
EnablePause();
|
||||
}
|
||||
if (WebsocketHandler.Instance != null) {
|
||||
var ping = WebsocketHandler.Instance.GetPing();
|
||||
if (ping == -1f) pingText.text = "";
|
||||
@@ -369,6 +378,7 @@ public class MultiplayerGamePlayer : MonoBehaviour {
|
||||
MultiplayerGamePlayerPauseMenu.Instance.ToggleEditingUI();
|
||||
return;
|
||||
}
|
||||
lastMoveTime = Time.time;
|
||||
rb.gravityScale = 100f * canvasRect.lossyScale.y;
|
||||
rb.linearVelocity = velocityBeforePause;
|
||||
velocityBeforePause = new();
|
||||
|
||||
Reference in new issue
Block a user