Skip to content

Commit

Permalink
😵 Add game over screen
Browse files Browse the repository at this point in the history
  • Loading branch information
tomrijnbeek committed Oct 7, 2024
1 parent e789a82 commit c676981
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/export_presets.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ codesign/digest_algorithm=1
codesign/description=""
codesign/custom_options=PoolStringArray( )
application/modify_resources=true
application/icon="res://assets/images/icon.ico"
application/icon="res://icon.ico"
application/file_version=""
application/product_version=""
application/company_name=""
Expand Down
14 changes: 12 additions & 2 deletions src/nodes/Chronometer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace HalfNibbleGame;
public sealed class Chronometer : Label
{
private TimeSpan elapsedTime = TimeSpan.Zero;
private bool isStopped;

public override void _Ready()
{
Expand All @@ -18,13 +19,22 @@ public override void _Ready()
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(float delta)
{
elapsedTime += TimeSpan.FromSeconds(delta);

if (!isStopped)
{
elapsedTime += TimeSpan.FromSeconds(delta);
}

Text = $"{(elapsedTime.Hours > 0 ? $"{elapsedTime.Hours}:" : "")}{elapsedTime.Minutes:00}:{elapsedTime.Seconds:00}";
}

public void Stop()
{
isStopped = true;
}

public void ResetTime()
{
elapsedTime = TimeSpan.Zero;
isStopped = false;
}
}
17 changes: 16 additions & 1 deletion src/nodes/Systems/GameLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,12 @@ public override void _Process(float delta)
startGame();
break;
case GameLoopState.YouAreWinner:
// TODO: a thing
var chronometer = Global.Services.Get<Chronometer>();
chronometer.Stop();
var gameOver = chronometer.GetNode<Control>("../GameOver");
gameOver.Visible = true;
chronometer.GetNode<Control>("../../../Them").Visible = false;
chronometer.GetNode<Control>("../../../Them2").Visible = false;
break;
default:
throw new ArgumentOutOfRangeException();
Expand Down Expand Up @@ -329,6 +334,12 @@ void consumeChoice(Choice choice)
}
}

public void OnRestartButtonPressed()
{
end = GameEnd.Loss;
endGame();
}

private void resetProgress()
{
currentLevel = 0;
Expand All @@ -342,6 +353,10 @@ private void resetProgress()
if (Global.Services.TryGet<Chronometer>(out var chronometer))
{
chronometer.ResetTime();
var gameOver = chronometer.GetNode<Control>("../GameOver");
gameOver.Visible = false;
chronometer.GetNode<Control>("../../../Them").Visible = true;
chronometer.GetNode<Control>("../../../Them2").Visible = true;
}
}

Expand Down
49 changes: 49 additions & 0 deletions src/scenes/Game.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,53 @@ custom_fonts/font = ExtResource( 2 )
text = "or"
align = 1

[node name="GameOver" type="Control" parent="ViewportContainer/UI"]
visible = false
anchor_right = 1.0
anchor_bottom = 1.0
margin_top = 0.25
margin_bottom = 0.25

[node name="YouWon" type="Label" parent="ViewportContainer/UI/GameOver"]
margin_left = 96.5
margin_top = 26.5
margin_right = 223.5
margin_bottom = 34.5
rect_pivot_offset = Vector2( 33.75, 14 )
custom_colors/font_color = Color( 0.764706, 0.784314, 0.698039, 1 )
custom_colors/font_color_shadow = Color( 0.776471, 0.239216, 0.478431, 1 )
custom_fonts/font = ExtResource( 2 )
text = "You won!"
align = 1
autowrap = true

[node name="TimeLabel" type="Label" parent="ViewportContainer/UI/GameOver"]
margin_left = 100.0
margin_top = 44.5
margin_right = 222.0
margin_bottom = 129.5
custom_colors/font_color = Color( 0.764706, 0.784314, 0.698039, 1 )
custom_fonts/font = ExtResource( 2 )
text = "You kept the queen
safe. She can now
continue to send
her minions out to
find flowers and
lemonade.
Thanks for playing!"

[node name="Button" type="Button" parent="ViewportContainer/UI/GameOver"]
margin_left = 120.25
margin_top = 138.75
margin_right = 199.25
margin_bottom = 152.75
custom_colors/font_color = Color( 0.427451, 0.521569, 0.427451, 1 )
custom_colors/font_color_hover = Color( 0.776471, 0.239216, 0.478431, 1 )
custom_fonts/font = ExtResource( 2 )
text = "Play again"
flat = true

[node name="HelpedItemDescription" type="RichTextLabel" parent="."]
margin_left = 945.0
margin_top = 382.0
Expand Down Expand Up @@ -333,3 +380,5 @@ custom_fonts/font = ExtResource( 18 )
text = "Allies"
align = 2
valign = 1

[connection signal="pressed" from="ViewportContainer/UI/GameOver/Button" to="ViewportContainer/Viewport/World" method="OnRestartButtonPressed"]

0 comments on commit c676981

Please sign in to comment.