1
Fork 0
mirror of https://github.com/RYGhub/the-cold-night.git synced 2024-11-22 04:34:19 +00:00

Create basic user interface with survival timer

This commit is contained in:
Steffo 2022-04-02 23:23:06 +02:00
parent 11b8ae3652
commit f74d0a6749
Signed by: steffo
GPG key ID: 6965406171929D01
5 changed files with 81 additions and 8 deletions

View file

@ -50,10 +50,16 @@ player_move_right={
] ]
} }
[layer_names]
2d_render/layer_1="Game"
2d_render/layer_2="UserInterface"
[physics] [physics]
common/enable_pause_aware_picking=true common/enable_pause_aware_picking=true
[rendering] [rendering]
environment/default_clear_color=Color( 0.301961, 0.301961, 0.301961, 1 )
environment/default_environment="res://src/default_env.tres" environment/default_environment="res://src/default_env.tres"

14
src/levels/Game.gd Normal file
View file

@ -0,0 +1,14 @@
extends Node2D
var survival_seconds: float setget set_survival_seconds
signal survival_seconds_updated(value)
func set_survival_seconds(value):
survival_seconds = value
emit_signal("survival_seconds_updated", value)
func _process(delta):
set_survival_seconds(survival_seconds + delta)

File diff suppressed because one or more lines are too long

15
src/ui/TimeSurvived.gd Normal file
View file

@ -0,0 +1,15 @@
extends Label
func _ready():
var game = get_tree().root.get_node("Game")
game.connect("survival_seconds_updated", self, "_on_survival_seconds_updated")
func _on_survival_seconds_updated(value: float):
# warning-ignore:NARROWING_CONVERSION
var minutes: int = floor(value / 60)
var seconds_and_millis: float = value - minutes * 60
var seconds: int = int(seconds_and_millis)
var millis: int = int((seconds_and_millis - seconds) * 1000)
text = "%02d:%02d.%03d" % ([minutes, seconds, millis])

16
src/ui/TimeSurvived.tscn Normal file
View file

@ -0,0 +1,16 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://src/ui/TimeSurvived.gd" type="Script" id=1]
[node name="TimeSurvived" type="Label"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -32.0
margin_top = -7.0
margin_right = 32.0
margin_bottom = 7.0
text = "00:00.000"
align = 1
script = ExtResource( 1 )