211 lines
5.5 KiB
C#
211 lines
5.5 KiB
C#
using SHADE;
|
|
using SHADE_Scripting.Audio;
|
|
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;
|
|
|
|
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; }
|
|
public bool stealFoodPopUpDone { get; set; }
|
|
public bool PreviewLevelDone { get; set; }
|
|
|
|
public bool itemShatter { get; set; }
|
|
|
|
//For scene transitions
|
|
private bool goingToWin;
|
|
private bool goingToLose;
|
|
|
|
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;
|
|
stealFoodPopUpDone = false;
|
|
PreviewLevelDone = false;
|
|
|
|
AudioHandler.audioClipHandlers["BGMWin"] = Audio.CreateAudioClip("event:/Music/stingers/game_win");
|
|
AudioHandler.audioClipHandlers["BGMLose"] = Audio.CreateAudioClip("event:/Music/stingers/game_lose");
|
|
|
|
goingToWin = false;
|
|
goingToLose = false;
|
|
|
|
if (scoreText)
|
|
scoreText.GetComponent<TextRenderable>().Text = $"{Score}";
|
|
if (timeText)
|
|
timeText.GetComponent<TextRenderable>().Text = $"{timer.ToString("0")}";
|
|
}
|
|
|
|
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();
|
|
|
|
AudioHandler.audioClipHandlers["SFXHumming"] = Audio.CreateAudioClip("event:/Homeowner/homeowner_humming");
|
|
AudioHandler.audioClipHandlers["SFXHumming"].SetVolume(0.15f);
|
|
AudioHandler.audioClipHandlers["SFXHumming"].Play();
|
|
|
|
if (SceneFadeInOut.Instance != null)
|
|
SceneFadeInOut.Instance.CallFadeOut();
|
|
Application.IsCursorVisible = false;
|
|
}
|
|
|
|
protected override void update()
|
|
{
|
|
if (GamePause || !stealFoodPopUpDone)
|
|
{
|
|
Input.SetMouseCentering(false);
|
|
Application.IsCursorVisible = true;
|
|
return;
|
|
}
|
|
|
|
if (currGameState == GameState.START)
|
|
{
|
|
Input.SetMouseCentering(true);
|
|
|
|
timer -= Time.DeltaTimeF;
|
|
if(scoreText)
|
|
scoreText.GetComponent<TextRenderable>().Text = $"{Score}";
|
|
if(timeText)
|
|
timeText.GetComponent<TextRenderable>().Text = $"{timer.ToString("0.00")}";
|
|
|
|
if (itemScored)
|
|
{
|
|
currMultiplierDuration += Time.DeltaTimeF;
|
|
|
|
if (currMultiplierDuration >= maxMultiplierDuration)
|
|
{
|
|
itemScored = false;
|
|
currMultiplierCombo = 1;
|
|
currMultiplierDuration = 0;
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
//multiplierText.GetComponent<Transform>().LocalScale = Vector3.Zero;
|
|
}
|
|
|
|
if (!goingToLose && ((timer > 0 && totalItemCount <= 0 && !itemShatter) || Input.GetKeyDown(Input.KeyCode.F1)))
|
|
{
|
|
currGameState = GameState.WIN;
|
|
AudioHandler.StopAllSounds(false);
|
|
AudioHandler.audioClipHandlers["BGMWin"].Play();
|
|
goingToWin = true;
|
|
if (SceneFadeInOut.Instance != null)
|
|
SceneFadeInOut.Instance.CallFadeIn();
|
|
}
|
|
else if(!goingToWin && (timer < 0 || Input.GetKeyDown(Input.KeyCode.F2)))
|
|
{
|
|
currGameState = GameState.LOSE;
|
|
AudioHandler.StopAllSounds(false);
|
|
AudioHandler.audioClipHandlers["BGMLose"].Play();
|
|
goingToLose = true;
|
|
if (SceneFadeInOut.Instance != null)
|
|
SceneFadeInOut.Instance.CallFadeIn();
|
|
}
|
|
}
|
|
|
|
//Handling transitions
|
|
if (SceneFadeInOut.Instance != null)
|
|
{
|
|
if (SceneFadeInOut.Instance.FadeInFinished())
|
|
{
|
|
if (goingToWin)
|
|
{
|
|
SceneManager.ChangeScene(winScene);
|
|
}
|
|
if (goingToLose)
|
|
{
|
|
SceneManager.ChangeScene(loseScene);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (goingToWin)
|
|
{
|
|
SceneManager.ChangeScene(winScene);
|
|
}
|
|
if (goingToLose)
|
|
{
|
|
SceneManager.ChangeScene(loseScene);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected override void onDestroy()
|
|
{
|
|
if (Instance == this)
|
|
Instance = null;
|
|
}
|
|
|
|
public void ItemScored()
|
|
{
|
|
totalItemCount -= 1;
|
|
itemScored = true;
|
|
currMultiplierDuration = 0;
|
|
|
|
if (currMultiplierCombo < maxMultiplierCombo)
|
|
currMultiplierCombo += 1;
|
|
|
|
MultiplierTextFx fx = multiplierText.GetScript<MultiplierTextFx>();
|
|
if (fx)
|
|
{
|
|
fx.ShowMultiplier(currMultiplierCombo, maxMultiplierDuration);
|
|
}
|
|
|
|
}
|
|
|
|
}
|