now it's actually playable
This commit is contained in:
parent
5496914c2a
commit
b5439da5a0
13 changed files with 84 additions and 26 deletions
|
@ -8,11 +8,17 @@ public partial class GameManager : Node
|
|||
public ulong GameStart = 0;
|
||||
public ulong GameEnd = 0;
|
||||
public int Attempts = 0;
|
||||
public Node2D Checkpoint;
|
||||
public NodePath Checkpoint = new NodePath();
|
||||
|
||||
public GameInfo(Node2D checkpoint)
|
||||
public GameInfo(NodePath path)
|
||||
{
|
||||
Checkpoint = checkpoint;
|
||||
SetCheckpoint(path);
|
||||
}
|
||||
|
||||
public void SetCheckpoint(NodePath path)
|
||||
{
|
||||
GD.Print($"{path}");
|
||||
Checkpoint = path;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,8 +36,9 @@ public partial class GameManager : Node
|
|||
{
|
||||
if (!IsPlaying)
|
||||
{
|
||||
GD.Print("Restart stats");
|
||||
IsPlaying = true;
|
||||
_gameInfo = new GameInfo(FirstZone.PlayerSpawnPoint);
|
||||
_gameInfo = new GameInfo(GetPathTo(FirstZone.PlayerSpawnPoint));
|
||||
}
|
||||
|
||||
StartGame();
|
||||
|
@ -40,18 +47,21 @@ public partial class GameManager : Node
|
|||
public void StartGame()
|
||||
{
|
||||
_gameInfo.GameStart = Time.GetTicksMsec();
|
||||
Player.Position = _gameInfo.Checkpoint.GlobalPosition;
|
||||
Player.GlobalPosition = GetNode<Node2D>(_gameInfo.Checkpoint).GlobalPosition;
|
||||
}
|
||||
|
||||
public void EndGame()
|
||||
{
|
||||
_gameInfo.GameEnd = Time.GetTicksMsec();
|
||||
|
||||
Player.Invincible = true;
|
||||
Player.SetProcess(false);
|
||||
|
||||
EmitSignal(SignalName.GameOver);
|
||||
}
|
||||
|
||||
public string GetFormattedTimeElapsed() =>
|
||||
TimeSpan.FromMilliseconds(_gameInfo.GameEnd - _gameInfo.GameStart).ToString(@"hh\:mm\:ss.fff");
|
||||
TimeSpan.FromMilliseconds(_gameInfo.GameEnd - _gameInfo.GameStart).ToString(@"hh\:mm\:ss\.fff");
|
||||
|
||||
public void OnPlayerDied() => _gameInfo.Attempts++;
|
||||
|
||||
|
@ -60,6 +70,7 @@ public partial class GameManager : Node
|
|||
public void SetCurrentZone(PlayZone zone)
|
||||
{
|
||||
GD.Print($"New zone {zone}");
|
||||
_gameInfo.Checkpoint = zone.PlayerSpawnPoint;
|
||||
var path = GetPathTo(zone.PlayerSpawnPoint);
|
||||
_gameInfo.SetCheckpoint(path);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue