SHADE_Y3/Assets/Scripts/Gameplay/SC_GameManager.cs

262 lines
6.5 KiB
C#

using SHADE;
using SHADE_Scripting.Audio;
using SHADE_Scripting.UI;
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
public class GameManager : Script
{
public enum GameState
{
START,
OVER
}
public uint winScene = 92009475;
[NonSerialized]
public GameState currGameState;
[NonSerialized]
public int totalItemCount;
[NonSerialized]
public int Score;
[NonSerialized]
public float timer;
public GameObject scoreText;
public GameObject scoreTextBG;
public GameObject timeText;
public GameObject minusTimerText;
public GameObject Results;
public int MaxComboAccquired { get; set; }
public int finalTime { get; set; }
public int finalScore { get; set; }
//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;
public static GameManager Instance { get; private set; }
public bool GamePause { get; set; }
public bool stealFoodPopUpDone { get; set; }
public bool PreviewLevelDone { get; set; }
public bool itemShatter { get; set; }
//For scene transitions
private bool waitForTransition;
private bool playSpeedUp = false;
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;
itemShatter = false;
GamePause = false;
stealFoodPopUpDone = false;
PreviewLevelDone = false;
var winAudio = Audio.CreateAudioClip("event:/Music/stingers/game_win");
winAudio.DestroyOnSceneExit = false;
AudioHandler.audioClipHandlers["BGMWin"] = winAudio;
var loseAudio = Audio.CreateAudioClip("event:/Music/stingers/game_lose");
loseAudio.DestroyOnSceneExit = false;
AudioHandler.audioClipHandlers["BGMLose"] = loseAudio;
waitForTransition = false;
if (scoreText)
scoreText.GetComponent<TextRenderable>().Text = $"{Score}";
if (timeText)
timeText.GetComponent<TextRenderable>().Text = $"{timer.ToString("0")}";
Input.SetMouseCentering(true);
Application.IsCursorVisible = false;
Application.FixDeltaTime = Time.DefaultFixDeltaTime;
AudioHandler.audioClipHandlers["SFXItemScore"] = Audio.CreateAudioClip("event:/Music/stingers/item_scored");
AudioHandler.audioClipHandlers["RaccoonScored"] = Audio.CreateAudioClip("event:/Raccoon/raccoon_scored");
Audio.SetParameterWithLabel("PlaybackSpeed", "Normal");
}
protected override void start()
{
AudioHandler.audioClipHandlers["BGMAdaptive"] = Audio.CreateAudioClip("event:/Music/bgm_adaptive_new");
AudioHandler.audioClipHandlers["BGMAdaptive"].Play();
Audio.SetParameterWithLabel("PlayerDetection", "Undetected");
AudioHandler.audioClipHandlers["KitchenAmbience"] = Audio.CreateAudioClip("event:/Ambience/roomtone_kitchen");
AudioHandler.audioClipHandlers["KitchenAmbience"].Play();
if (SceneFadeInOut.Instance != null)
SceneFadeInOut.Instance.CallFadeOut();
GamePause = false;
}
protected override void update()
{
if (GamePause || !stealFoodPopUpDone)
{
return;
}
Cheat();
if (currGameState == GameState.START)
{
timer -= Time.DeltaTimeF;
if (timer < 30.0f && !playSpeedUp)
{
Audio.SetParameterWithLabel("PlaybackSpeed", "ToTransition");
playSpeedUp = true;
}
if (scoreText)
scoreText.GetComponent<TextRenderable>().Text = $"{Score}";
if (timeText)
timeText.GetComponent<TextRenderable>().Text = $"{timer.ToString("0")}";
if (itemScored)
{
currMultiplierDuration += Time.DeltaTimeF;
if (currMultiplierDuration >= maxMultiplierDuration)
{
itemScored = false;
currMultiplierCombo = 1;
currMultiplierDuration = 0;
}
}
if (timer <= 0 || (totalItemCount <= 0 && !itemShatter))
{
AudioHandler.StopAllSounds(false);
if (timer <= 0)
AudioHandler.audioClipHandlers["BGMLose"].Play();
else if (totalItemCount <= 0)
AudioHandler.audioClipHandlers["BGMWin"].Play();
currGameState = GameState.OVER;
finalTime = (int)timer;
Results.SetActive(true);
Input.SetMouseCentering(false);
Application.IsCursorVisible = true;
GamePause = true;
Application.FixDeltaTime = 0;
AnimationSystem.TimeScale = 0;
}
}
if (SceneFadeInOut.Instance && SceneFadeInOut.Instance.FadeInFinished() && waitForTransition)
SceneManager.ChangeScene(winScene);
}
public void RacoonCaught()
{
timer -= 10.0f;
if (minusTimerText != GameObject.Null)
{
MinusTimerText text = minusTimerText.GetScript<MinusTimerText>();
if (text)
{
text.Reset();
}
}
}
private void Cheat()
{
if (Input.GetKeyUp(Input.KeyCode.F1))
{
currGameState = GameState.OVER;
AudioHandler.audioClipHandlers["BGMWin"].Play();
AudioHandler.StopAllSounds(false);
waitForTransition = true;
if (SceneFadeInOut.Instance != null)
SceneFadeInOut.Instance.CallFadeIn();
}
if (Input.GetKeyUp(Input.KeyCode.G))
{
ItemScored();
Score += 500;
}
}
protected override void onDestroy()
{
if (Instance == this)
Instance = null;
}
public void ItemScored()
{
totalItemCount -= 1;
itemScored = true;
currMultiplierDuration = 0;
if (currMultiplierCombo < maxMultiplierCombo)
{
currMultiplierCombo += 1;
if (currMultiplierCombo > MaxComboAccquired)
MaxComboAccquired = currMultiplierCombo;
}
Audio.SetParameter("Multiplier", currMultiplierCombo);
AudioHandler.audioClipHandlers["SFXItemScore"].Play();
AudioHandler.audioClipHandlers["RaccoonScored"].Play();
SingleScaleBounce textBounce = scoreText.GetScript<SingleScaleBounce>();
SingleScaleBounce textBGBounce = scoreTextBG.GetScript<SingleScaleBounce>();
//if (textBounce)
// textBounce.ScaleBounceOnce();
if (textBGBounce)
textBGBounce.ScaleBounceOnce();
MultiplierTextFx fx = multiplierText.GetScript<MultiplierTextFx>();
if (fx)
{
fx.ShowMultiplier(currMultiplierCombo, maxMultiplierDuration);
}
}
}