Play zones
This commit is contained in:
parent
4826bc4035
commit
7cce797ded
7 changed files with 150 additions and 58 deletions
|
@ -3,36 +3,61 @@ using Godot;
|
|||
|
||||
public partial class GameManager : Node
|
||||
{
|
||||
public struct GameInfo
|
||||
{
|
||||
public ulong GameStart = 0;
|
||||
public ulong GameEnd = 0;
|
||||
public int Attempts = 0;
|
||||
public Node2D Checkpoint;
|
||||
|
||||
public GameInfo(Node2D checkpoint)
|
||||
{
|
||||
Checkpoint = checkpoint;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsPlaying = true;
|
||||
|
||||
public ulong GameStart = 0;
|
||||
public ulong GameEnd = 0;
|
||||
public int Attempts = 0;
|
||||
public Node2D Checkpoint = null;
|
||||
|
||||
[Export] public PlayZone FirstZone;
|
||||
[Export] public Player Player;
|
||||
|
||||
[Signal]
|
||||
public delegate void GameOverEventHandler();
|
||||
|
||||
private static GameInfo _gameInfo;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (!IsPlaying)
|
||||
{
|
||||
IsPlaying = true;
|
||||
_gameInfo = new GameInfo(FirstZone.PlayerSpawnPoint);
|
||||
}
|
||||
|
||||
|
||||
StartGame();
|
||||
}
|
||||
|
||||
public void StartGame() => GameStart = Time.GetTicksMsec();
|
||||
public void StartGame()
|
||||
{
|
||||
_gameInfo.GameStart = Time.GetTicksMsec();
|
||||
Player.Position = _gameInfo.Checkpoint.GlobalPosition;
|
||||
}
|
||||
|
||||
public void EndGame()
|
||||
{
|
||||
GameEnd = Time.GetTicksMsec();
|
||||
_gameInfo.GameEnd = Time.GetTicksMsec();
|
||||
|
||||
EmitSignal(SignalName.GameOver);
|
||||
}
|
||||
|
||||
public string GetFormattedTimeElapsed() => TimeSpan.FromMilliseconds(GameEnd - GameStart).ToString(@"hh\:mm\:ss.fff");
|
||||
public string GetFormattedTimeElapsed() =>
|
||||
TimeSpan.FromMilliseconds(_gameInfo.GameEnd - _gameInfo.GameStart).ToString(@"hh\:mm\:ss.fff");
|
||||
|
||||
public void OnPlayerDied() => Attempts++;
|
||||
public void OnPlayerDied() => _gameInfo.Attempts++;
|
||||
|
||||
public void SetCurrentZone(PlayZone zone)
|
||||
{
|
||||
GD.Print($"New zone {zone}");
|
||||
_gameInfo.Checkpoint = zone.PlayerSpawnPoint;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue