SHADE_Y3/Assets/Scripts/Gameplay/SC_GameManager.cs

197 lines
5.4 KiB
C#
Raw Normal View History

using SHADE;
2023-02-03 00:40:22 +08:00
using SHADE_Scripting.Audio;
2023-03-01 17:36:02 +08:00
using SHADE_Scripting.UI;
using System;
using System.Collections.Generic;
public class GameManager : Script
{
public enum GameState
{
START,
WIN,
LOSE
}
public uint winScene = 92009475;
public uint loseScene = 91685359;
[NonSerialized]
public GameState currGameState;
[NonSerialized]
public int totalItemCount;
[NonSerialized]
public int Score;
[NonSerialized]
public float timer;
2022-11-23 20:26:53 +08:00
public GameObject scoreText;
public GameObject timeText;
//mulitpler info
public GameObject multiplierText;
public float maxMultiplierDuration = 5.0f;
public float currMultiplierDuration { get; set; }
public int maxMultiplierCombo = 10;
public bool itemScored {get;set;}
public int currMultiplierCombo { get; set;}
public float multiplierFont = 60.0f;
private Vector3 fontScalar;
public static GameManager Instance { get; private set; }
public bool GamePause { get; set; }
2023-03-02 17:33:02 +08:00
public bool stealFoodPopUpDone { get; set; }
public bool PreviewLevelDone { get; set; }
2022-11-23 20:26:53 +08:00
public bool itemShatter { get; set; }
2023-02-04 01:44:00 +08:00
2023-03-01 17:36:02 +08:00
//For scene transitions
private bool goingToWin;
private bool goingToLose;
2023-02-04 01:44:00 +08:00
protected override void awake()
{
if (Instance != null && Instance != this)
RemoveScript<GameManager>();
else
Instance = this;
totalItemCount = 0;
Score = 0;
currGameState = GameState.START;
itemScored = false;
currMultiplierCombo = 1;
currMultiplierDuration = 0;
fontScalar = new Vector3(multiplierFont / maxMultiplierDuration, multiplierFont / maxMultiplierDuration , multiplierFont / maxMultiplierDuration);
itemShatter = false;
GamePause = false;
2023-03-02 17:33:02 +08:00
stealFoodPopUpDone = false;
PreviewLevelDone = false;
2023-02-04 00:23:05 +08:00
AudioHandler.audioClipHandlers["BGMWin"] = Audio.CreateAudioClip("event:/Music/stingers/game_win");
AudioHandler.audioClipHandlers["BGMLose"] = Audio.CreateAudioClip("event:/Music/stingers/game_lose");
2023-03-01 17:36:02 +08:00
goingToWin = false;
goingToLose = false;
2023-03-02 00:02:18 +08:00
if (scoreText)
scoreText.GetComponent<TextRenderable>().Text = $"Score: {Score}";
if (timeText)
timeText.GetComponent<TextRenderable>().Text = $"Time Left: {timer.ToString("0")}";
}
protected override void start()
{
AudioHandler.audioClipHandlers["BGMAdaptive"] = Audio.CreateAudioClip("event:/Music/bgm_adaptive");
AudioHandler.audioClipHandlers["BGMAdaptive"].Play();
Audio.SetParameter("Detected", 0.0f);
AudioHandler.audioClipHandlers["KitchenAmbience"] = Audio.CreateAudioClip("event:/Ambience/roomtone_kitchen");
AudioHandler.audioClipHandlers["KitchenAmbience"].Play();
AudioHandler.audioClipHandlers["SFXHumming"] = Audio.CreateAudioClip("event:/Homeowner/homeowner_humming");
AudioHandler.audioClipHandlers["SFXHumming"].SetVolume(0.15f);
AudioHandler.audioClipHandlers["SFXHumming"].Play();
2023-03-02 11:33:21 +08:00
SceneFadeInOut.Instance.CallFadeOut();
2023-03-02 10:01:52 +08:00
Application.IsCursorVisible = false;
}
protected override void update()
{
2023-03-02 17:33:02 +08:00
if (GamePause || !stealFoodPopUpDone)
{
Input.SetMouseCentering(false);
2023-03-02 10:01:52 +08:00
//Application.IsCursorVisible = true;
return;
}
2022-11-23 20:26:53 +08:00
if (currGameState == GameState.START)
{
Input.SetMouseCentering(true);
2023-03-02 10:01:52 +08:00
timer -= Time.DeltaTimeF;
2022-11-23 20:26:53 +08:00
if(scoreText)
2023-03-02 09:55:41 +08:00
scoreText.GetComponent<TextRenderable>().Text = $"{Score}";
2022-11-23 20:26:53 +08:00
if(timeText)
2023-03-02 00:02:18 +08:00
timeText.GetComponent<TextRenderable>().Text = $"Time Left: {timer.ToString("0")}";
2022-11-23 20:26:53 +08:00
if (itemScored)
{
2023-03-02 09:55:41 +08:00
//multiplierText.GetComponent<TextRenderable>().Text = $"X {currMultiplierCombo}";
2023-02-27 16:39:31 +08:00
//multiplierText.GetComponent<Transform>().LocalScale -= fontScalar * Time.DeltaTimeF;
currMultiplierDuration += Time.DeltaTimeF;
if (currMultiplierDuration >= maxMultiplierDuration)
{
itemScored = false;
currMultiplierCombo = 1;
currMultiplierDuration = 0;
}
}
else
{
2023-02-27 16:39:31 +08:00
//multiplierText.GetComponent<Transform>().LocalScale = Vector3.Zero;
}
2023-03-01 17:36:02 +08:00
if (!goingToLose && ((timer > 0 && totalItemCount <= 0 && !itemShatter) || Input.GetKeyDown(Input.KeyCode.F1)))
{
currGameState = GameState.WIN;
2023-03-01 17:36:02 +08:00
AudioHandler.StopAllSounds(false);
2023-02-04 01:44:00 +08:00
AudioHandler.audioClipHandlers["BGMWin"].Play();
2023-03-01 17:36:02 +08:00
goingToWin = true;
SceneFadeInOut.Instance.CallFadeIn();
}
2023-03-01 17:36:02 +08:00
else if(!goingToWin && (timer < 0 || Input.GetKeyDown(Input.KeyCode.F2)))
2022-11-23 20:26:53 +08:00
{
currGameState = GameState.LOSE;
2023-03-01 17:36:02 +08:00
AudioHandler.StopAllSounds(false);
2023-02-04 01:44:00 +08:00
AudioHandler.audioClipHandlers["BGMLose"].Play();
2023-03-01 17:36:02 +08:00
goingToLose = true;
SceneFadeInOut.Instance.CallFadeIn();
}
}
//Handling transitions
if (SceneFadeInOut.Instance.FadeInFinished())
{
if (goingToWin)
{
SceneManager.ChangeScene(winScene);
}
if (goingToLose)
{
2022-11-23 20:26:53 +08:00
SceneManager.ChangeScene(loseScene);
}
}
}
protected override void onDestroy()
{
if (Instance == this)
Instance = null;
}
public void ItemScored()
{
totalItemCount -= 1;
itemScored = true;
currMultiplierDuration = 0;
2023-03-02 09:55:41 +08:00
//multiplierText.GetComponent<Transform>().LocalScale = new Vector3(multiplierFont, multiplierFont, multiplierFont);
if (currMultiplierCombo < maxMultiplierCombo)
currMultiplierCombo += 1;
2023-03-02 09:55:41 +08:00
MultiplierTextFx fx = multiplierText.GetScript<MultiplierTextFx>();
if (fx)
{
fx.ShowMultiplier(currMultiplierCombo, maxMultiplierDuration);
}
}
}