new timer + save times to save files (#3)
This commit is contained in:
parent
7ae566720c
commit
ac1f29d111
7 changed files with 269 additions and 37 deletions
42
index.tscn
42
index.tscn
|
@ -1,10 +1,11 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://ccgnnif026wb4"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://ccgnnif026wb4"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://xd3nsiglcdfc" path="res://elements/timer.tscn" id="1_356j3"]
|
||||
|
||||
[sub_resource type="GDScript" id="GDScript_8n212"]
|
||||
script/source = "extends Node
|
||||
|
||||
var playing: bool = false
|
||||
var seconds_spent: float = 0.00
|
||||
var changing_level: bool = false
|
||||
|
||||
var current_level_int: int = 0
|
||||
|
@ -15,6 +16,8 @@ var levels = [
|
|||
]
|
||||
var area_resource = preload(\"res://menus/main/area.tscn\")
|
||||
|
||||
@onready var timer := $GUI/Timer
|
||||
|
||||
func _ready() -> void:
|
||||
var os_name = OS.get_name()
|
||||
if os_name == \"Web\": ## we can't quit the game on web
|
||||
|
@ -58,11 +61,15 @@ func start_level(level_scene: PackedScene) -> void:
|
|||
Vector3.DOWN
|
||||
)
|
||||
changing_level = false
|
||||
timer.seconds_spent_level_attempt = 0.0
|
||||
timer.enabled = true
|
||||
|
||||
func stop_level() -> void:
|
||||
timer.enabled = false
|
||||
PhysicsServer3D.area_set_param(get_viewport().find_world_3d().space, PhysicsServer3D.AREA_PARAM_GRAVITY, 1)
|
||||
playing = false
|
||||
changing_level = true
|
||||
SaveFiles.change_property(\"played_for\", timer.seconds_spent_total, SaveFiles.selected_file)
|
||||
|
||||
var current_levels = get_current_levels()
|
||||
for level in current_levels:
|
||||
|
@ -95,6 +102,7 @@ func restart_level() -> void:
|
|||
start_level(levels[current_level_int])
|
||||
|
||||
func pause_game() -> void:
|
||||
SaveFiles.change_property(\"played_for\", timer.seconds_spent_total, SaveFiles.selected_file)
|
||||
if $Levels.process_mode == PROCESS_MODE_INHERIT:
|
||||
$Levels.process_mode = Node.PROCESS_MODE_DISABLED
|
||||
playing = false
|
||||
|
@ -114,7 +122,6 @@ func fullscreen_game() -> void:
|
|||
DisplayServer.window_set_mode(DisplayServer.WindowMode.WINDOW_MODE_WINDOWED)
|
||||
|
||||
func start_game() -> void:
|
||||
seconds_spent = 0.0
|
||||
current_level_int = 0
|
||||
|
||||
var current_levels = $Levels.get_children(true)
|
||||
|
@ -125,14 +132,7 @@ func start_game() -> void:
|
|||
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
|
||||
start_level(levels[0])
|
||||
|
||||
func update_timer(delta: float) -> void:
|
||||
if playing:
|
||||
seconds_spent += delta
|
||||
var minutes = floor(seconds_spent / 60)
|
||||
$Informations/MarginContainer/Timer.text = (\"%0*d\" % [2, minutes]) + \":\" + (\"%0*.2f\" % [5, seconds_spent - (minutes * 60)])
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
update_timer(delta)
|
||||
func _process(_delta: float) -> void:
|
||||
var current_levels = get_current_levels()
|
||||
if len(current_levels):
|
||||
var current_level = current_levels[0]
|
||||
|
@ -166,6 +166,18 @@ outline_color = Color(0, 0, 0, 1)
|
|||
[node name="Game" type="Node"]
|
||||
script = SubResource("GDScript_8n212")
|
||||
|
||||
[node name="GUI" type="MarginContainer" parent="."]
|
||||
offset_right = 201.0
|
||||
offset_bottom = 104.0
|
||||
rotation = 0.0523599
|
||||
theme_override_constants/margin_left = 15
|
||||
theme_override_constants/margin_top = 15
|
||||
theme_override_constants/margin_right = 15
|
||||
theme_override_constants/margin_bottom = 15
|
||||
|
||||
[node name="Timer" parent="GUI" instance=ExtResource("1_356j3")]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Informations" type="Control" parent="."]
|
||||
visible = false
|
||||
layout_mode = 3
|
||||
|
@ -186,14 +198,6 @@ grow_vertical = 2
|
|||
theme_override_constants/margin_left = 10
|
||||
theme_override_constants/margin_right = 10
|
||||
|
||||
[node name="Timer" type="Label" parent="Informations/MarginContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 0
|
||||
size_flags_vertical = 8
|
||||
text = "00:00.0"
|
||||
label_settings = SubResource("LabelSettings_0s07t")
|
||||
vertical_alignment = 2
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="Informations/MarginContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = -5
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue