Skip to content

Commit

Permalink
create timer
Browse files Browse the repository at this point in the history
  • Loading branch information
Hope-Parnell committed Apr 29, 2023
1 parent 70507d5 commit 9542a39
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 2 deletions.
25 changes: 25 additions & 0 deletions Sick_Day_Delivery/HUD.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[gd_scene load_steps=3 format=3 uid="uid://by2kd0e26letn"]

[ext_resource type="Script" path="res://Scripts/TimeAlive.gd" id="1_if4uy"]
[ext_resource type="Script" path="res://Scripts/HUD.gd" id="1_qxxad"]

[node name="HUD" type="CanvasLayer"]
script = ExtResource("1_qxxad")

[node name="TimeAlive" type="Label" parent="."]
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -20.0
offset_right = 20.0
offset_bottom = 26.0
grow_horizontal = 2
theme_override_font_sizes/font_size = 64
text = "0:00"
horizontal_alignment = 1
vertical_alignment = 1
script = ExtResource("1_if4uy")

[node name="Timer" type="Timer" parent="TimeAlive"]

[connection signal="timeout" from="TimeAlive/Timer" to="TimeAlive" method="_on_timer_timeout"]
9 changes: 7 additions & 2 deletions Sick_Day_Delivery/Scenes/main.tscn
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
[gd_scene load_steps=4 format=3 uid="uid://b4xi3mlkhu4ow"]
[gd_scene load_steps=6 format=3 uid="uid://b4xi3mlkhu4ow"]

[ext_resource type="PackedScene" uid="uid://bhh5dmfulsc0f" path="res://Scenes/body_map.tscn" id="1_6xrru"]
[ext_resource type="Script" path="res://Scripts/main.gd" id="1_mnr5t"]
[ext_resource type="PackedScene" uid="uid://cvpq0di0nimsq" path="res://Scenes/player_cell.tscn" id="2_dynj6"]
[ext_resource type="PackedScene" uid="uid://bshn0kdmpqbnj" path="res://Scenes/bacterium.tscn" id="3_vq0pw"]
[ext_resource type="PackedScene" path="res://Scenes/bacterium.tscn" id="3_vq0pw"]
[ext_resource type="PackedScene" uid="uid://by2kd0e26letn" path="res://HUD.tscn" id="5_fiipk"]

[node name="Node2D" type="Node2D"]
script = ExtResource("1_mnr5t")

[node name="Body Map" parent="." instance=ExtResource("1_6xrru")]

[node name="PlayerCell" parent="." instance=ExtResource("2_dynj6")]

[node name="Bacterium" parent="." instance=ExtResource("3_vq0pw")]
position = Vector2(919, 161)

[node name="HUD" parent="." instance=ExtResource("5_fiipk")]
14 changes: 14 additions & 0 deletions Sick_Day_Delivery/Scripts/HUD.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
extends CanvasLayer


# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass

func start_timer():
$TimeAlive/Timer.start()
18 changes: 18 additions & 0 deletions Sick_Day_Delivery/Scripts/TimeAlive.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
extends Label

var time

# Called when the node enters the scene tree for the first time.
func _ready():
time = 0

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass


func _on_timer_timeout():
time += 1
var minutes = time/60
var seconds = time%60
text = "%d:%02d" %[minutes, seconds]
10 changes: 10 additions & 0 deletions Sick_Day_Delivery/Scripts/main.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extends Node2D


# Called when the node enters the scene tree for the first time.
func _ready():
$HUD.start_timer()

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass

0 comments on commit 9542a39

Please sign in to comment.