DreamBall/index.tscn

222 lines
7.3 KiB
Text

[gd_scene load_steps=8 format=3 uid="uid://ccgnnif026wb4"]
[ext_resource type="PackedScene" uid="uid://xd3nsiglcdfc" path="res://gui/timer.tscn" id="1_356j3"]
[ext_resource type="PackedScene" uid="uid://dw0xl8644x166" path="res://gui/gravity.tscn" id="1_ir7so"]
[ext_resource type="PackedScene" uid="uid://cckeamgkt8bqo" path="res://gui/speed.tscn" id="2_2gn6w"]
[ext_resource type="PackedScene" uid="uid://bcxbw6wd54ksv" path="res://gui/map.tscn" id="2_d1yoc"]
[ext_resource type="PackedScene" uid="uid://cn55m5dqo3m6u" path="res://gui/rings.tscn" id="3_mbj17"]
[ext_resource type="PackedScene" uid="uid://dkxtwpcy4moyo" path="res://menus/pause_menu.tscn" id="4_3bfj3"]
[sub_resource type="GDScript" id="GDScript_8n212"]
script/source = "extends Node
var playing := false
var changing_level := false
var main_menu: Node
var current_level: Level
var current_level_scene: PackedScene
const res_main_menu = preload(\"res://menus/main/main_menu.tscn\")
@onready var gui_gravity := $GUI/Gravity
@onready var gui_map := $GUI/Map
@onready var gui_timer := $GUI/TopLeft/Timer
@onready var gui_speed := $GUI/TopRight/Speed
@onready var gui_rings := $GUI/BottomRight/Rings
@onready var pause_menu := $PauseMenu
func _ready() -> void:
## Add the version of the game and the name of the OS to the footer of the start menu
if OS.has_feature(\"editor\"):
$DevInfos.text = \"dev \"
$DevInfos.text += \"build \" + ProjectSettings.get_setting(\"application/config/version\") + \" (\" + OS.get_name() + \")\"
## Hide UI stuff that shouldn't be visible until later in the game
pause_menu.hide()
## Connect to necessary signals
pause_menu.connect(\"request_pause\", pause_game)
pause_menu.connect(\"request_fullscreen\", fullscreen_game)
pause_menu.connect(\"request_restart\", restart_level)
set_main_menu()
func set_main_menu() -> void:
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
$GUI.hide()
## If no main menu exists yet, create one
if !is_instance_valid(main_menu):
main_menu = res_main_menu.instantiate()
main_menu.connect(\"request_play_level\", start_level)
add_child(main_menu)
func start_level(level: Level, scene: PackedScene) -> void:
if is_instance_valid(current_level):
current_level.queue_free()
if is_instance_valid(main_menu) and self.is_ancestor_of(main_menu):
self.remove_child(main_menu)
current_level = level
current_level_scene = scene
add_child(current_level)
current_level.connect(\"started_playing\", func(): gui_timer.enabled = true)
current_level.connect(\"gravity_change\", gui_gravity.react_to_gravity_change)
current_level.connect(\"completed\", finish_current_level)
current_level.connect(\"ring_collected\", func():
gui_rings.remaining_rings = len(current_level.rings) - current_level.finished_rings_count
)
gui_rings.remaining_rings = len(current_level.rings) - current_level.finished_rings_count
$GUI.show()
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
pause_game(false)
playing = true
changing_level = false
gui_timer.seconds_spent_level_attempt = 0.0
func finish_current_level() -> void:
gui_timer.enabled = false
PhysicsServer3D.area_set_param(get_viewport().find_world_3d().space, PhysicsServer3D.AREA_PARAM_GRAVITY, 0.5)
playing = false
changing_level = true
SaveFiles.change_property(\"played_for\", gui_timer.seconds_spent_total, SaveFiles.selected_file)
var save_file_data = SaveFiles.read(SaveFiles.selected_file)
var property_name := current_level.id + \"_best_time\"
if !save_file_data.has(property_name) or save_file_data[property_name] is not float or save_file_data[property_name] > gui_timer.seconds_spent_level_attempt:
SaveFiles.change_property(property_name, gui_timer.seconds_spent_level_attempt, SaveFiles.selected_file)
current_level.music.fadeOut(2)
await get_tree().create_timer(2).timeout
current_level.queue_free()
set_main_menu()
func restart_level() -> void:
gui_timer.enabled = false
if !current_level or changing_level:
return
if current_level_scene is not PackedScene:
print(\"Tried to restart the level despite not having the level scene\")
return
SaveFiles.change_property(\"played_for\", gui_timer.seconds_spent_total, SaveFiles.selected_file)
start_level(current_level_scene.instantiate(), current_level_scene)
func pause_game(to_pause: bool) -> void:
if !is_instance_valid(current_level) or changing_level:
return
if to_pause:
SaveFiles.change_property(\"played_for\", gui_timer.seconds_spent_total, SaveFiles.selected_file)
current_level.process_mode = Node.PROCESS_MODE_DISABLED
playing = false
pause_menu.show()
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
else:
current_level.process_mode = Node.PROCESS_MODE_INHERIT
playing = true
pause_menu.hide()
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
func fullscreen_game() -> void:
var fs = DisplayServer.window_get_mode()
if fs != DisplayServer.WindowMode.WINDOW_MODE_FULLSCREEN:
DisplayServer.window_set_mode(DisplayServer.WindowMode.WINDOW_MODE_FULLSCREEN)
else:
DisplayServer.window_set_mode(DisplayServer.WindowMode.WINDOW_MODE_WINDOWED)
func _process(_delta: float) -> void:
if is_instance_valid(current_level):
gui_speed.ball_velocity = current_level.velocity
if Input.is_action_pressed(\"display_map\"):
gui_map.display_rings(current_level.player, current_level.rings)
func _input(_event: InputEvent) -> void:
if Input.is_action_just_released(\"display_map\"):
gui_map.hide()
if Input.is_action_just_pressed(\"display_map\"):
gui_map.show()
if Input.is_action_just_pressed(\"restart_level\"):
restart_level()
func _on_btn_quit_pressed() -> void:
get_tree().quit()
"
[node name="Game" type="Node"]
script = SubResource("GDScript_8n212")
[node name="GUI" type="Control" parent="."]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
[node name="Gravity" parent="GUI" instance=ExtResource("1_ir7so")]
layout_mode = 1
[node name="Map" parent="GUI" instance=ExtResource("2_d1yoc")]
visible = false
layout_mode = 1
[node name="TopLeft" type="MarginContainer" parent="GUI"]
layout_mode = 1
offset_right = 160.0
offset_bottom = 85.0
rotation = 0.0523599
theme_override_constants/margin_left = 15
[node name="Timer" parent="GUI/TopLeft" instance=ExtResource("1_356j3")]
layout_mode = 2
[node name="TopRight" type="MarginContainer" parent="GUI"]
layout_mode = 1
anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
offset_left = -106.0
offset_bottom = 51.0
grow_horizontal = 0
rotation = -0.0523599
theme_override_constants/margin_top = 5
theme_override_constants/margin_right = 15
[node name="Speed" parent="GUI/TopRight" instance=ExtResource("2_2gn6w")]
layout_mode = 2
[node name="BottomRight" type="MarginContainer" parent="GUI"]
layout_mode = 1
anchors_preset = 3
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -222.0
offset_top = -51.0
grow_horizontal = 0
grow_vertical = 0
rotation = 0.0523599
theme_override_constants/margin_right = 15
theme_override_constants/margin_bottom = 15
[node name="Rings" parent="GUI/BottomRight" instance=ExtResource("3_mbj17")]
layout_mode = 2
[node name="DevInfos" type="Label" parent="."]
anchors_preset = 12
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_top = -23.0
grow_horizontal = 2
grow_vertical = 0
horizontal_alignment = 1
[node name="PauseMenu" parent="." instance=ExtResource("4_3bfj3")]