2022-11-17 00:23:38 +08:00
|
|
|
|
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;
|
2022-11-17 00:23:38 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2023-03-21 14:40:30 +08:00
|
|
|
|
using System.Diagnostics.Contracts;
|
2022-11-17 00:23:38 +08:00
|
|
|
|
|
|
|
|
|
public class GameManager : Script
|
|
|
|
|
{
|
2022-11-17 12:54:08 +08:00
|
|
|
|
public enum GameState
|
2023-02-02 22:44:30 +08:00
|
|
|
|
{
|
2022-11-20 16:27:39 +08:00
|
|
|
|
START,
|
2022-11-17 12:54:08 +08:00
|
|
|
|
WIN,
|
2022-11-22 17:28:48 +08:00
|
|
|
|
LOSE
|
2022-11-17 00:23:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-23 16:57:32 +08:00
|
|
|
|
public uint winScene = 92009475;
|
|
|
|
|
public uint loseScene = 91685359;
|
|
|
|
|
|
2022-11-22 17:28:48 +08:00
|
|
|
|
[NonSerialized]
|
|
|
|
|
public GameState currGameState;
|
2022-11-17 12:54:08 +08:00
|
|
|
|
[NonSerialized]
|
2022-11-17 00:23:38 +08:00
|
|
|
|
public int totalItemCount;
|
2022-11-17 12:54:08 +08:00
|
|
|
|
[NonSerialized]
|
2022-11-17 00:23:38 +08:00
|
|
|
|
public int Score;
|
2022-11-17 12:54:08 +08:00
|
|
|
|
[NonSerialized]
|
|
|
|
|
public float timer;
|
|
|
|
|
|
2022-11-23 20:26:53 +08:00
|
|
|
|
public GameObject scoreText;
|
|
|
|
|
public GameObject timeText;
|
2023-03-21 14:40:30 +08:00
|
|
|
|
public GameObject minusTimerText;
|
2022-11-23 20:26:53 +08:00
|
|
|
|
|
2023-02-02 22:44:30 +08:00
|
|
|
|
//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;
|
|
|
|
|
|
2023-01-31 18:13:34 +08:00
|
|
|
|
public static GameManager Instance { get; private set; }
|
2023-02-20 19:53:22 +08:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2023-02-27 00:41:25 +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;
|
|
|
|
|
|
2022-11-17 00:23:38 +08:00
|
|
|
|
totalItemCount = 0;
|
|
|
|
|
Score = 0;
|
2022-11-22 17:28:48 +08:00
|
|
|
|
currGameState = GameState.START;
|
2023-02-02 22:44:30 +08:00
|
|
|
|
itemScored = false;
|
|
|
|
|
currMultiplierCombo = 1;
|
|
|
|
|
currMultiplierDuration = 0;
|
2023-02-27 00:41:25 +08:00
|
|
|
|
itemShatter = false;
|
2023-03-01 00:51:57 +08:00
|
|
|
|
GamePause = false;
|
2023-03-02 17:33:02 +08:00
|
|
|
|
stealFoodPopUpDone = false;
|
|
|
|
|
PreviewLevelDone = false;
|
2023-02-04 00:23:05 +08:00
|
|
|
|
|
2023-03-20 17:34:26 +08:00
|
|
|
|
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;
|
2023-03-01 17:36:02 +08:00
|
|
|
|
|
|
|
|
|
goingToWin = false;
|
|
|
|
|
goingToLose = false;
|
2023-03-02 00:02:18 +08:00
|
|
|
|
|
|
|
|
|
if (scoreText)
|
2023-03-04 03:17:20 +08:00
|
|
|
|
scoreText.GetComponent<TextRenderable>().Text = $"{Score}";
|
2023-03-02 00:02:18 +08:00
|
|
|
|
if (timeText)
|
2023-03-04 03:17:20 +08:00
|
|
|
|
timeText.GetComponent<TextRenderable>().Text = $"{timer.ToString("0")}";
|
2023-03-05 21:23:41 +08:00
|
|
|
|
|
|
|
|
|
Input.SetMouseCentering(true);
|
|
|
|
|
Application.IsCursorVisible = false;
|
|
|
|
|
Application.FixDeltaTime = Time.DefaultFixDeltaTime;
|
2023-03-23 18:20:42 +08:00
|
|
|
|
|
|
|
|
|
AudioHandler.audioClipHandlers["SFXItemScore"] = Audio.CreateAudioClip("event:/Music/stingers/item_scored");
|
2023-03-25 02:38:56 +08:00
|
|
|
|
AudioHandler.audioClipHandlers["RaccoonScored"] = Audio.CreateAudioClip("event:/Raccoon/raccoon_scored");
|
2022-11-17 00:23:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-27 00:41:25 +08:00
|
|
|
|
protected override void start()
|
|
|
|
|
{
|
2023-03-03 18:13:35 +08:00
|
|
|
|
AudioHandler.audioClipHandlers["BGMAdaptive"] = Audio.CreateAudioClip("event:/Music/bgm_adaptive_new");
|
2023-02-27 00:41:25 +08:00
|
|
|
|
AudioHandler.audioClipHandlers["BGMAdaptive"].Play();
|
|
|
|
|
|
2023-03-03 18:13:35 +08:00
|
|
|
|
Audio.SetParameterWithLabel("PlayerDetection", "Undetected");
|
2023-02-27 00:41:25 +08:00
|
|
|
|
|
|
|
|
|
AudioHandler.audioClipHandlers["KitchenAmbience"] = Audio.CreateAudioClip("event:/Ambience/roomtone_kitchen");
|
|
|
|
|
AudioHandler.audioClipHandlers["KitchenAmbience"].Play();
|
|
|
|
|
|
2023-03-03 14:26:36 +08:00
|
|
|
|
if (SceneFadeInOut.Instance != null)
|
|
|
|
|
SceneFadeInOut.Instance.CallFadeOut();
|
2023-03-05 15:35:57 +08:00
|
|
|
|
|
|
|
|
|
GamePause = false;
|
2023-02-27 00:41:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-17 00:23:38 +08:00
|
|
|
|
protected override void update()
|
2022-11-17 12:54:08 +08:00
|
|
|
|
{
|
2023-03-10 19:31:23 +08:00
|
|
|
|
|
|
|
|
|
|
2023-03-02 17:33:02 +08:00
|
|
|
|
if (GamePause || !stealFoodPopUpDone)
|
2023-02-20 19:53:22 +08:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-05 23:48:25 +08:00
|
|
|
|
Cheat();
|
|
|
|
|
|
2022-11-23 20:26:53 +08:00
|
|
|
|
if (currGameState == GameState.START)
|
2023-03-05 21:23:41 +08:00
|
|
|
|
{
|
2022-11-17 12:54:08 +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-04 02:46:56 +08:00
|
|
|
|
timeText.GetComponent<TextRenderable>().Text = $"{timer.ToString("0.00")}";
|
2022-11-23 20:26:53 +08:00
|
|
|
|
|
2023-02-02 22:44:30 +08:00
|
|
|
|
if (itemScored)
|
|
|
|
|
{
|
|
|
|
|
currMultiplierDuration += Time.DeltaTimeF;
|
|
|
|
|
|
|
|
|
|
if (currMultiplierDuration >= maxMultiplierDuration)
|
|
|
|
|
{
|
|
|
|
|
itemScored = false;
|
|
|
|
|
currMultiplierCombo = 1;
|
|
|
|
|
currMultiplierDuration = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-05 23:48:25 +08:00
|
|
|
|
if (!goingToLose && ((timer > 0 && totalItemCount <= 0 && !itemShatter)))
|
2022-11-23 16:57:32 +08:00
|
|
|
|
{
|
2022-11-20 16:27:39 +08:00
|
|
|
|
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;
|
2023-03-03 14:26:36 +08:00
|
|
|
|
if (SceneFadeInOut.Instance != null)
|
|
|
|
|
SceneFadeInOut.Instance.CallFadeIn();
|
2022-11-20 16:27:39 +08:00
|
|
|
|
}
|
2023-03-05 23:48:25 +08:00
|
|
|
|
else if(!goingToWin && (timer < 0))
|
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;
|
2023-03-03 14:26:36 +08:00
|
|
|
|
if (SceneFadeInOut.Instance != null)
|
|
|
|
|
SceneFadeInOut.Instance.CallFadeIn();
|
2023-03-01 17:36:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Handling transitions
|
2023-03-03 14:26:36 +08:00
|
|
|
|
if (SceneFadeInOut.Instance != null)
|
|
|
|
|
{
|
|
|
|
|
if (SceneFadeInOut.Instance.FadeInFinished())
|
|
|
|
|
{
|
|
|
|
|
if (goingToWin)
|
|
|
|
|
{
|
|
|
|
|
SceneManager.ChangeScene(winScene);
|
|
|
|
|
}
|
|
|
|
|
if (goingToLose)
|
|
|
|
|
{
|
|
|
|
|
SceneManager.ChangeScene(loseScene);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2023-03-01 17:36:02 +08:00
|
|
|
|
{
|
|
|
|
|
if (goingToWin)
|
|
|
|
|
{
|
|
|
|
|
SceneManager.ChangeScene(winScene);
|
|
|
|
|
}
|
|
|
|
|
if (goingToLose)
|
|
|
|
|
{
|
2022-11-23 20:26:53 +08:00
|
|
|
|
SceneManager.ChangeScene(loseScene);
|
|
|
|
|
}
|
2022-11-23 16:57:32 +08:00
|
|
|
|
}
|
2022-11-17 00:23:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-21 14:40:30 +08:00
|
|
|
|
public void RacoonCaught()
|
|
|
|
|
{
|
|
|
|
|
timer -= 10.0f;
|
|
|
|
|
if(minusTimerText != GameObject.Null)
|
|
|
|
|
{
|
|
|
|
|
MinusTimerText text =minusTimerText.GetScript<MinusTimerText>();
|
|
|
|
|
if(text)
|
|
|
|
|
{
|
|
|
|
|
text.Reset();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-05 23:48:25 +08:00
|
|
|
|
private void Cheat()
|
|
|
|
|
{
|
|
|
|
|
if (Input.GetKeyUp(Input.KeyCode.F1))
|
|
|
|
|
{
|
|
|
|
|
currGameState = GameState.WIN;
|
2023-03-16 14:54:18 +08:00
|
|
|
|
AudioHandler.audioClipHandlers["BGMWin"].Play();
|
2023-03-05 23:48:25 +08:00
|
|
|
|
AudioHandler.StopAllSounds(false);
|
|
|
|
|
goingToWin = true;
|
|
|
|
|
if (SceneFadeInOut.Instance != null)
|
|
|
|
|
SceneFadeInOut.Instance.CallFadeIn();
|
|
|
|
|
}
|
|
|
|
|
else if (Input.GetKeyUp(Input.KeyCode.F2))
|
|
|
|
|
{
|
|
|
|
|
currGameState = GameState.LOSE;
|
2023-03-16 14:54:18 +08:00
|
|
|
|
AudioHandler.audioClipHandlers["BGMLose"].Play();
|
2023-03-05 23:48:25 +08:00
|
|
|
|
AudioHandler.StopAllSounds(false);
|
|
|
|
|
goingToLose = true;
|
|
|
|
|
if (SceneFadeInOut.Instance != null)
|
|
|
|
|
SceneFadeInOut.Instance.CallFadeIn();
|
|
|
|
|
}
|
2023-03-10 19:31:23 +08:00
|
|
|
|
|
|
|
|
|
if (Input.GetKeyUp(Input.KeyCode.G))
|
|
|
|
|
{
|
|
|
|
|
ItemScored();
|
|
|
|
|
Score += 500;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-05 23:48:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-01-31 18:13:34 +08:00
|
|
|
|
protected override void onDestroy()
|
|
|
|
|
{
|
|
|
|
|
if (Instance == this)
|
|
|
|
|
Instance = null;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-02 22:44:30 +08:00
|
|
|
|
public void ItemScored()
|
|
|
|
|
{
|
|
|
|
|
totalItemCount -= 1;
|
|
|
|
|
itemScored = true;
|
|
|
|
|
currMultiplierDuration = 0;
|
2023-03-02 09:55:41 +08:00
|
|
|
|
|
2023-02-02 22:44:30 +08:00
|
|
|
|
if (currMultiplierCombo < maxMultiplierCombo)
|
|
|
|
|
currMultiplierCombo += 1;
|
2023-03-02 09:55:41 +08:00
|
|
|
|
|
2023-03-23 18:20:42 +08:00
|
|
|
|
Audio.SetParameter("Multiplier", currMultiplierCombo);
|
|
|
|
|
AudioHandler.audioClipHandlers["SFXItemScore"].Play();
|
2023-03-25 02:38:56 +08:00
|
|
|
|
AudioHandler.audioClipHandlers["RaccoonScored"].Play();
|
2023-03-23 18:20:42 +08:00
|
|
|
|
|
2023-03-02 09:55:41 +08:00
|
|
|
|
MultiplierTextFx fx = multiplierText.GetScript<MultiplierTextFx>();
|
|
|
|
|
if (fx)
|
|
|
|
|
{
|
2023-03-04 02:46:56 +08:00
|
|
|
|
fx.ShowMultiplier(currMultiplierCombo, maxMultiplierDuration);
|
2023-03-02 09:55:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 19:31:23 +08:00
|
|
|
|
SingleScaleBounce sb = scoreText.GetScript<SingleScaleBounce>();
|
|
|
|
|
if(sb)
|
|
|
|
|
{
|
|
|
|
|
sb.ScaleBounceOnce();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-03-04 02:46:56 +08:00
|
|
|
|
}
|
2022-11-25 00:54:45 +08:00
|
|
|
|
|
2022-11-17 00:23:38 +08:00
|
|
|
|
}
|