diff --git a/Assets/Scripts/Global/CurrentStateData.cs b/Assets/Scripts/Global/CurrentStateData.cs index 63c906ebc79b966b9904405c688c7949f2d40073..e21aa4e2bad7aa48b2f9b79ad97acec148919939 100644 --- a/Assets/Scripts/Global/CurrentStateData.cs +++ b/Assets/Scripts/Global/CurrentStateData.cs @@ -146,6 +146,30 @@ public class CurrentStateData return true; } + public static int GetCurrentCoin() + { + return _currentGameData.coin; + } + + public static void SetCurrentCoin(int coin) + { + _currentGameData.coin = coin; + } + + public static void AddCoin(int coin) + { + _currentGameData.coin += coin; + } + + public static bool SubtractCoin(int coin) + { + if (_currentGameData.coin < coin) + return false; + + _currentGameData.coin -= coin; + return true; + } + public static float GetCurrentPlayTime() { return _currentGameData.playTime; @@ -226,6 +250,11 @@ public class CurrentStateData _currentGameData.currentWeapon = weapon; } + public static void AddWeapon(int weapon) + { + _currentGameData.weapons[weapon] = true; + } + public static float GetMultiplier() { return _currentGameData.dmgMultiplier; diff --git a/Assets/Scripts/Managers/PauseManager.cs b/Assets/Scripts/Managers/PauseManager.cs index efd5ff0edf1926d5e51bd6e7b0874ef4832eee66..d3a966b080c03314d8b69908e6c63fff33e84be8 100644 --- a/Assets/Scripts/Managers/PauseManager.cs +++ b/Assets/Scripts/Managers/PauseManager.cs @@ -1,59 +1,52 @@ using UnityEngine; -using System.Collections; -using UnityEngine.UI; using UnityEngine.Audio; -#if UNITY_EDITOR -using UnityEditor; -#endif -public class PauseManager : MonoBehaviour { - public AudioMixerSnapshot paused; - public AudioMixerSnapshot unpaused; - public GameObject pauseCanvas; - private bool isOpen = false; +public class PauseManager : MonoBehaviour +{ + private static bool _isPaused; - void Start() - { - pauseCanvas.SetActive(isOpen); - } + public AudioMixerSnapshot paused; + public AudioMixerSnapshot unpaused; - void Update() - { - if (Input.GetKeyDown(KeyCode.Escape)) - { - Pause(); - } - } - - public void Pause() - { - pauseCanvas.SetActive(!isOpen); + private void Start() + { + Time.timeScale = 1; + _isPaused = false; + } + + private void Lowpass() + { + if (Time.timeScale == 0) + { + if (paused != null) + { + paused.TransitionTo(.01f); + } + } + else + { + if (unpaused != null) + { + unpaused?.TransitionTo(.01f); + } + } + } + + public void Pause() + { Time.timeScale = Time.timeScale == 0 ? 1 : 0; - Lowpass (); - - } - - void Lowpass() - { - if (Time.timeScale == 0) - { - isOpen = true; - paused.TransitionTo(.01f); - } - - else - { - isOpen = false; - unpaused.TransitionTo(.01f); - } - } - - public void Quit() - { - #if UNITY_EDITOR - EditorApplication.isPlaying = false; - #else - Application.Quit(); - #endif - } + _isPaused = Time.timeScale == 0; + Lowpass(); + } + + public static void StaticPauseOrUnPause() + { + Time.timeScale = Time.timeScale == 0 ? 1 : 0; + _isPaused = Time.timeScale == 0; + } + + public static bool CheckIfPaused() + { + return _isPaused; + } } diff --git a/Assets/Scripts/Managers/ShopKeeperManager.cs b/Assets/Scripts/Managers/ShopKeeperManager.cs new file mode 100644 index 0000000000000000000000000000000000000000..0fd4d77e24aed32880f81cfc544cd5331d74305a --- /dev/null +++ b/Assets/Scripts/Managers/ShopKeeperManager.cs @@ -0,0 +1,74 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class ShopKeeperManager : MonoBehaviour +{ + private static readonly int BuyClick = Animator.StringToHash("BuyClick"); + private static readonly int BuyErrorClick = Animator.StringToHash("BuyErrorClick"); + + public GameObject shopKeeper; + private Animator _anim; + private ShopKeeperEffect _shopKeeperEffect; + public GameObject shopKeeperCanvas; + private float _startTime; + public float timeLimit; + public float additionalTime = 5f; + public GameObject enemyManager; + + void Start() + { + _anim = GetComponent<Animator>(); + _shopKeeperEffect = shopKeeper.GetComponent<ShopKeeperEffect>(); + shopKeeperCanvas.SetActive(false); + _startTime = Time.time; + PauseManager.StaticPauseOrUnPause(); + UpdateShopKeeperState(CurrentStateData.GetCurrentScene() == "level_01"); + } + + void Update() + { + if (!shopKeeper.activeSelf) return; + + float elapsed = Time.time - _startTime; + if (elapsed > timeLimit + additionalTime) + { + UpdateShopKeeperState(false); + return; + } + + if (elapsed > timeLimit) + { + SetShopKeeperFlight(true, 15, false); + return; + } + + _anim.SetBool("ShopKeeperFlying", _shopKeeperEffect.isShopKeeperFlying); + + if (Input.GetKey(KeyCode.B) && !PauseManager.CheckIfPaused()) + { + if (!_shopKeeperEffect.isShopKeeperFlying) + { + _anim.SetTrigger(BuyErrorClick); + } + else + { + PauseManager.StaticPauseOrUnPause(); + shopKeeperCanvas.SetActive(true); + } + } + } + + private void SetShopKeeperFlight(bool flying, float height, bool alive) + { + _shopKeeperEffect.isShopKeeperFlying = flying; + _shopKeeperEffect.floatHeight = height; + _anim.SetBool("ShopKeeperAlive", alive); + } + + private void UpdateShopKeeperState(bool isActive) + { + shopKeeper.SetActive(isActive); + enemyManager.SetActive(!isActive); + } +} diff --git a/Assets/Scripts/Managers/ShopKeeperManager.cs.meta b/Assets/Scripts/Managers/ShopKeeperManager.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..58eff3508b88f182f0a9d6f5d1fcf287c84c70ac --- /dev/null +++ b/Assets/Scripts/Managers/ShopKeeperManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ae61ffaabdfc3c543bd1b111c78cd222 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Utils/GameData.cs b/Assets/Scripts/Utils/GameData.cs index 03bad9b87bb690278fc6c13fb4b990b7926c96a9..c767a6ab5d6d846ee78db692a19cc1f6db05af05 100644 --- a/Assets/Scripts/Utils/GameData.cs +++ b/Assets/Scripts/Utils/GameData.cs @@ -4,6 +4,7 @@ public struct GameData { public string playerName; public string difficulty; + public int coin; public int star; public float playTime; public string scene;