Added the folders for scenes and scripts

This commit is contained in:
JKuijperM 2024-03-23 10:34:51 +01:00
parent ba5f133077
commit 993f8ec6aa
4 changed files with 192 additions and 0 deletions

91
Scenes/TimerHUD.tscn Normal file
View File

@ -0,0 +1,91 @@
[gd_scene load_steps=3 format=3 uid="uid://bsafhva6xh2nf"]
[ext_resource type="Script" path="res://Scripts/TimerHUD.gd" id="1_k2tpr"]
[sub_resource type="LabelSettings" id="LabelSettings_gikwe"]
font_size = 100
[node name="TimerHUD" type="CanvasLayer"]
script = ExtResource("1_k2tpr")
[node name="Timer" type="Timer" parent="."]
[node name="RemainingTime" type="Label" parent="."]
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -240.0
offset_top = -68.5
offset_right = 240.0
offset_bottom = 68.5
grow_horizontal = 2
grow_vertical = 2
text = "x:x"
label_settings = SubResource("LabelSettings_gikwe")
horizontal_alignment = 1
vertical_alignment = 1
[node name="PlayButton" type="Button" parent="."]
anchors_preset = 7
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
offset_left = -50.0
offset_top = -210.0
offset_right = 50.0
offset_bottom = -160.0
grow_horizontal = 2
grow_vertical = 0
size_flags_vertical = 6
text = "PLAY"
[node name="PauseButton" type="Button" parent="."]
anchors_preset = 7
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
offset_left = -153.5
offset_top = -210.0
offset_right = -53.5
offset_bottom = -160.0
grow_horizontal = 2
grow_vertical = 0
text = "Pause
"
[node name="StopButton" type="Button" parent="."]
anchors_preset = 7
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
offset_left = 52.98
offset_top = -210.0
offset_right = 152.98
offset_bottom = -160.0
grow_horizontal = 2
grow_vertical = 0
text = "Stop
"
[node name="SpinBox" type="SpinBox" parent="."]
anchors_preset = 7
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
offset_left = -42.0
offset_top = -31.0
offset_right = 41.0625
grow_horizontal = 2
grow_vertical = 0
editable = false
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]
[connection signal="pressed" from="PlayButton" to="." method="_on_play_button_pressed"]
[connection signal="pressed" from="PauseButton" to="." method="_on_pause_button_pressed"]
[connection signal="pressed" from="StopButton" to="." method="_on_stop_button_pressed"]

20
Scenes/control.tscn Normal file
View File

@ -0,0 +1,20 @@
[gd_scene load_steps=2 format=3 uid="uid://dcr2y4jsyr6d"]
[ext_resource type="Script" path="res://Scripts/Control.gd" id="1_ux8es"]
[node name="Control" type="Control"]
layout_mode = 3
anchors_preset = 0
offset_right = 40.0
offset_bottom = 40.0
script = ExtResource("1_ux8es")
[node name="Timer" type="Timer" parent="."]
autostart = true
[node name="Label" type="Label" parent="."]
layout_mode = 0
offset_right = 86.0
offset_bottom = 31.0
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]

29
Scripts/Control.gd Normal file
View File

@ -0,0 +1,29 @@
extends Control
var seconds
var minutes
var default_seconds = 30
var default_minutes = 1
# Called when the node enters the scene tree for the first time.
func _ready():
reset_timer()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func _on_timer_timeout():
if seconds == 0:
if minutes > 0:
minutes -= 1
seconds == 60
seconds -= 1
$Label.text = str(minutes) + ":" + str(seconds)
func reset_timer():
seconds = default_seconds
minutes = default_minutes

52
Scripts/TimerHUD.gd Normal file
View File

@ -0,0 +1,52 @@
extends CanvasLayer
@export var default_seconds = 30
@export var default_minutes = 1
var seconds
var minutes
var timer_is_playing = false
signal play_timer
# Called when the node enters the scene tree for the first time.
func _ready():
$RemainingTime.text = str(default_minutes) + ":" + str(default_seconds)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func reset_timer():
seconds = default_seconds
minutes = default_minutes
func _on_play_button_pressed():
if $Timer.is_paused():
$Timer.paused = false
else:
if !timer_is_playing:
timer_is_playing = true
reset_timer()
$Timer.start()
func _on_timer_timeout():
if seconds == 0:
if minutes > 0:
minutes -= 1
seconds == 60
seconds -= 1
$RemainingTime.text = str(minutes) + ":" + str(seconds)
func _on_pause_button_pressed():
timer_is_playing = false
$Timer.paused = true
func _on_stop_button_pressed():
timer_is_playing = false
$Timer.paused = false
$Timer.stop()