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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,9 +16,12 @@ public partial class PlayZone : Node2D
|
|||
|
||||
private Area2D _area2D;
|
||||
private CollisionShape2D _collisionShape2D;
|
||||
//private GameManager _gameManager;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
//_gameManager = (GameManager)GetTree().Root.FindChild("GameManager");
|
||||
|
||||
_area2D = (Area2D)FindChild("Area2D");
|
||||
_collisionShape2D = (CollisionShape2D)FindChild("CollisionShape2D");
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ public partial class Player : CharacterBody2D
|
|||
public delegate void KilledEventHandler();
|
||||
|
||||
public bool Alive = true;
|
||||
public bool Invincible = false;
|
||||
|
||||
public static Player Instance { get; private set; }
|
||||
|
||||
|
@ -65,7 +66,7 @@ public partial class Player : CharacterBody2D
|
|||
|
||||
public void Kill(Node2D killer)
|
||||
{
|
||||
if (!Alive)
|
||||
if (!Alive || Invincible)
|
||||
return;
|
||||
|
||||
GD.Print($"Killed by {killer.Name}");
|
||||
|
|
|
@ -4,6 +4,7 @@ using System;
|
|||
public partial class WinScreen : TextureRect
|
||||
{
|
||||
[Export] public GameManager Manager;
|
||||
[Export] public Label TextLabel;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
|
@ -14,7 +15,7 @@ public partial class WinScreen : TextureRect
|
|||
{
|
||||
Visible = true;
|
||||
|
||||
((Label)FindChild("Label2")).Text =
|
||||
TextLabel.Text =
|
||||
$"It took you\n{Manager.GetAttempts()} attempts\nand {Manager.GetFormattedTimeElapsed()}\nto finish the game.";
|
||||
}
|
||||
|
||||
|
|
|
@ -15,13 +15,15 @@ public partial class And : Node
|
|||
public void Increment()
|
||||
{
|
||||
_buttons++;
|
||||
GD.Print($"Increment {_buttons}/{CountOfButtons}");
|
||||
if (_buttons == CountOfButtons)
|
||||
EmitSignal(SignalName.ConditionNotMet);
|
||||
EmitSignal(SignalName.ConditionMet);
|
||||
}
|
||||
|
||||
public void Decrement()
|
||||
{
|
||||
_buttons--;
|
||||
GD.Print($"Decrement {_buttons}/{CountOfButtons}");
|
||||
if (_buttons != CountOfButtons)
|
||||
EmitSignal(SignalName.ConditionNotMet);
|
||||
}
|
||||
|
|
|
@ -3,12 +3,18 @@ using Godot;
|
|||
public partial class Door : Node2D
|
||||
{
|
||||
private AnimatedSprite2D _animatedSprite2D;
|
||||
private CollisionShape2D _collisionShape2D;
|
||||
private StaticBody2D _staticBody2D;
|
||||
|
||||
private uint _collisionMask;
|
||||
private uint _collisionLayer;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_animatedSprite2D = (AnimatedSprite2D)FindChild("AnimatedSprite2D");
|
||||
_collisionShape2D = (CollisionShape2D)FindChild("CollisionShape2D");
|
||||
_staticBody2D = (StaticBody2D)FindChild("StaticBody2D");
|
||||
|
||||
_collisionMask = _staticBody2D.CollisionMask;
|
||||
_collisionLayer = _staticBody2D.CollisionLayer;
|
||||
|
||||
Close();
|
||||
}
|
||||
|
@ -16,12 +22,16 @@ public partial class Door : Node2D
|
|||
public void Close()
|
||||
{
|
||||
_animatedSprite2D.Play("close");
|
||||
_collisionShape2D.Disabled = false;
|
||||
|
||||
_staticBody2D.CollisionMask = _collisionMask;
|
||||
_staticBody2D.CollisionLayer = _collisionLayer;
|
||||
}
|
||||
|
||||
public void Open()
|
||||
{
|
||||
_animatedSprite2D.Play("open");
|
||||
_collisionShape2D.Disabled = true;
|
||||
|
||||
_staticBody2D.CollisionMask = 0;
|
||||
_staticBody2D.CollisionLayer = 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue