GameFlow.cs
namespace NiuLai;
public enum GameScreen
{
Title,
Playing,
Paused,
Ending
}
public static class GameFlow
{
public static GameScreen Screen { get; private set; } = GameScreen.Title;
public static event Action Changed;
public static bool BlocksWorld => Screen != GameScreen.Playing || FilmCut.Playing;
public static void SetScreen( GameScreen screen )
{
if ( Screen == screen )
return;
Screen = screen;
ApplyMouse();
Changed?.Invoke();
}
public static void StartNewGame()
{
var again = Trophies.EverWon;
GameAudio.StopMusic();
GameAudio.PlayTitleSting();
GameState.Reset();
WorldBuilder.Rebuild();
SetScreen( GameScreen.Playing );
GameState.Talk( "旁白 / Narrator", Lines.Opening );
Trophies.Unlock( "walk_slow" );
if ( again )
Trophies.Unlock( "watch_again" );
}
public static void TogglePause()
{
if ( Screen == GameScreen.Playing )
SetScreen( GameScreen.Paused );
else if ( Screen == GameScreen.Paused )
SetScreen( GameScreen.Playing );
}
public static void BackToTitle()
{
GameAudio.StopMusic();
SetScreen( GameScreen.Title );
GameAudio.PlayTitleSting();
}
public static void Win()
{
if ( Screen == GameScreen.Ending )
return;
GameState.Won = true;
GameState.SongWalk = true;
Trophies.MarkWon();
GameAudio.PlayClip( GameAudio.Rain, 0.8f );
GameAudio.PlaySong();
SetScreen( GameScreen.Ending );
Trophies.Unlock( "after_rain" );
}
public static void ApplyMouse()
{
try
{
Mouse.Visibility = Screen == GameScreen.Playing
? MouseVisibility.Hidden
: MouseVisibility.Visible;
}
catch
{
// Older runtimes hide the cursor a different way.
}
}
}