super_space_game/scripts/game_ground.gd

190 lines
4.9 KiB
GDScript3
Raw Permalink Normal View History

extends Node2D
var current_interaction_area = null
2025-12-04 03:30:37 +00:00
signal dialogue_continue
signal choice_made
2025-12-06 19:33:22 +00:00
var dialogue_colors = {
"generic": Color("fff"),
"player": Color("fff"),
"player_woozy": Color("fff"),
"doctor_1": Color("00ffffff"),
"doctor_2": Color("00a2ffff"),
}
var dialogue_speed = {
"generic": 0.037,
"player_slow": 0.06,
"player_woozy": 0.2,
}
2025-12-07 03:06:34 +00:00
func save_game() -> void:
$UI/Control/SaveIndicator.visible = true
global.stats.position = {
"x": $PlayerGround.global_position.x,
"y": $PlayerGround.global_position.y
}
global.save_game()
await get_tree().create_timer(2).timeout
$UI/Control/SaveIndicator.visible = false
func checkpoint() -> void:
var packed_scene = PackedScene.new()
packed_scene.pack(get_tree().get_current_scene())
global.checkpoint = packed_scene
func give_ground_gun(string: String) -> void:
global.stats.equipped_ground_gun = string
2025-12-07 03:06:34 +00:00
func _ready() -> void:
2025-12-04 03:30:37 +00:00
$UI/Control/Dialogue.visible = false
LimboConsole.register_command(give_ground_gun, "give_ground_gun", "Gives a gun for ground mode")
print(global.stats.location)
var location_scene = load("res://scenes/locations/" + global.stats.location + ".tscn").instantiate()
for n in location_scene.get_children():
location_scene.remove_child(n)
add_child(n)
if "game" in n:
n.game = self
# This gets all descendants. Copied it off the forums don't ask me how it works
for o in n.find_children("*", "", true, false):
if "game" in o:
o.game = self
2025-12-06 19:33:22 +00:00
for n in get_children():
if "_ground_ready" in n:
n._ground_ready()
location_scene.free()
2025-12-07 03:06:34 +00:00
if global.stats.position:
print("AAA ", global.stats.position)
2025-12-07 03:06:34 +00:00
$PlayerGround.global_position.x = global.stats.position.x
$PlayerGround.global_position.y = global.stats.position.y
global.stats.position = null
else:
$PlayerGround.global_position = $PlayerSpawn.global_position
if global.stats.loaded:
save_game()
else:
global.stats.loaded = true
func _process(delta: float) -> void:
if current_interaction_area:
$UI/Control/Interact.visible = true
$UI/Control/Interact/End.text = "TO " + (current_interaction_area.interact_text)
if Input.is_action_just_pressed("interact"):
2025-12-04 03:30:37 +00:00
if "_interact" in current_interaction_area.get_parent(): current_interaction_area.get_parent()._interact($PlayerGround)
else:
$UI/Control/Interact.visible = false
2025-12-04 03:30:37 +00:00
2025-12-06 19:33:22 +00:00
func dialogue(text: String, type: String = "generic", allow_input: bool = true) -> void:
2025-12-04 03:30:37 +00:00
$UI/Control/Dialogue/InputIcon.visible = false
$UI/Control/Dialogue.visible = true
2025-12-06 19:33:22 +00:00
var speed = dialogue_speed.generic
if dialogue_speed.has(type): speed = dialogue_speed[type]
$UI/Control/Dialogue/Label.label_settings.font_color = dialogue_colors.generic
if dialogue_colors.has(type): $UI/Control/Dialogue/Label.label_settings.font_color = dialogue_colors[type]
2025-12-04 03:30:37 +00:00
var displayed_text = ""
var i = 0
while i < text.length():
displayed_text = displayed_text + text[i]
$UI/Control/Dialogue/Label.text = displayed_text
$Dialogue.play()
await get_tree().create_timer(speed).timeout
2025-12-04 03:30:37 +00:00
i += 1
2025-12-06 19:33:22 +00:00
if allow_input:
$UI/Control/Dialogue/InputIcon.visible = true
2025-12-04 03:30:37 +00:00
2025-12-06 19:33:22 +00:00
await dialogue_continue
$UI/Control/Dialogue.visible = false
func end_dialogue() -> void:
2025-12-04 03:30:37 +00:00
$UI/Control/Dialogue.visible = false
return
func make_choice(options: Dictionary = {}) -> String:
2025-12-04 03:30:37 +00:00
$UI/Control/DialogueOptions.visible = true
var dialogue_select_button_scene = preload("res://scenes/dialogue_select_button.tscn")
2025-12-06 19:33:22 +00:00
for n in $UI/Control/DialogueOptions.get_children(): if n.is_class("Button"): n.queue_free()
2025-12-04 03:30:37 +00:00
var first_button = null
var last_button = null
for n in options.keys():
var dialogue_select_button = dialogue_select_button_scene.instantiate()
dialogue_select_button.name = n
2025-12-06 19:33:22 +00:00
dialogue_select_button.id = n
2025-12-04 03:30:37 +00:00
dialogue_select_button.text = options[n]
dialogue_select_button.game = self
2025-12-04 03:30:37 +00:00
$UI/Control/DialogueOptions.add_child(dialogue_select_button)
if !first_button: first_button = dialogue_select_button
last_button = dialogue_select_button
first_button.focus_neighbor_top = NodePath(last_button.get_path())
last_button.focus_neighbor_bottom = NodePath(first_button.get_path())
first_button.grab_focus()
2025-12-06 19:33:22 +00:00
var button = await choice_made
var response = button.id
$UI/Control/DialogueOptions.visible = false
return response
2025-12-04 03:30:37 +00:00
2025-12-06 19:33:22 +00:00
func get_vignette_parameter(name: String) -> float:
return $UI/Vignette.material.get_shader_parameter(name)
func set_vignette_parameter(name: String, value: float) -> void:
$UI/Vignette.material.set_shader_parameter(name, value)
2025-12-04 03:30:37 +00:00
func _input(event: InputEvent) -> void:
2025-12-05 21:50:38 +00:00
if event.is_action_released("dialogue_continue"):
2025-12-04 03:30:37 +00:00
dialogue_continue.emit()
if event.is_action_pressed("pause"):
2025-12-07 19:29:07 +00:00
$UiSelect.play()
$UI/Control/PauseMenu.visible = true
$UI/Control/PauseMenu/Panel/Flow/Resume.grab_focus()
get_tree().paused = true
func _exit_tree() -> void:
LimboConsole.unregister_command(give_ground_gun)