Implement game pausing

This commit is contained in:
Mario Martínez 2024-10-09 11:37:37 +02:00
parent 3d558ca28d
commit be045c220b
6 changed files with 96 additions and 1 deletions

View file

@ -8,6 +8,7 @@ signal finished(cutscene_name: String)
@export var cutscene: Cutscene
var is_running = false
@onready var _step = -1
var _current_command: CutsceneCommand: get = get_current_command
var _inner_timer = 0.0
@ -24,8 +25,10 @@ func get_current_command() -> CutsceneCommand:
func step() -> void:
_step += 1
if(_step == 0):
is_running = true
started.emit(cutscene.resource_name)
if(_step >= cutscene.commands.size()):
is_running = false
finished.emit(cutscene.resource_name)
else:
_current_command = cutscene.commands[_step]
@ -34,6 +37,7 @@ func step() -> void:
func load_cutscene(new_cutscene: Cutscene) -> void:
cutscene = new_cutscene
_step = -1
is_running = false
loaded.emit(cutscene.resource_name)
func _on_ui_dialogue_completed():

View file

@ -25,6 +25,7 @@ func _on_ai_defeated():
func _on_cutscene_started(cutscene_name):
$HiroPlayer.can_move = false
$GameState.can_pause = false
if cutscene_name == "prototype_start":
$HiroAI.set_ai_enabled(false)
$ReedAI.set_ai_enabled(false)
@ -32,6 +33,7 @@ func _on_cutscene_started(cutscene_name):
func _on_cutscene_finished(cutscene_name: String):
print("Cutscene " + cutscene_name + " finished")
$HiroPlayer.can_move = true
$GameState.can_pause = true
if cutscene_name == "prototype_start":
$HiroAI.set_ai_enabled(true)
$ReedAI.set_ai_enabled(true)

26
Scripts/UI/pause_menu.gd Normal file
View file

@ -0,0 +1,26 @@
extends CanvasLayer
@export_range(0.1, 10.0) var blinking_interval = 1.0
var blink_time = 0
@onready var label = $Control/Label
signal game_unpaused
func _input(event):
if event.is_action_pressed("pause"):
get_tree().paused = false
visible = false
get_viewport().set_input_as_handled()
game_unpaused.emit()
func _process(delta):
blink_time += delta
if blink_time >= blinking_interval:
blink_time = 0.0
label.visible = !label.visible
func _on_game_paused():
visible = true
label.visible = true
blink_time = 0

10
Scripts/game_state.gd Normal file
View file

@ -0,0 +1,10 @@
extends Node
signal game_paused
var can_pause = true
func _unhandled_input(event):
if event.is_action_pressed("pause") and can_pause:
game_paused.emit()
get_tree().paused = true

View file

@ -94,6 +94,12 @@ melee={
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":true,"script":null)
]
}
pause={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":6,"pressure":0.0,"pressed":false,"script":null)
]
}
[layer_names]

View file

@ -1,8 +1,10 @@
[gd_scene load_steps=24 format=3 uid="uid://bxuxjqxxqy7ce"]
[gd_scene load_steps=28 format=3 uid="uid://bxuxjqxxqy7ce"]
[ext_resource type="PackedScene" uid="uid://di21xheryhp0k" path="res://Hiro/hiro_player.tscn" id="1_c1gpq"]
[ext_resource type="PackedScene" uid="uid://b8sfype1vx5ad" path="res://Nem/nem_npc.tscn" id="1_sqt7d"]
[ext_resource type="Script" path="res://Scripts/Levels/arena_level.gd" id="1_y634h"]
[ext_resource type="FontFile" uid="uid://bgqotudi6bifk" path="res://UI/Gundam 00 font gaufont.ttf" id="2_64thh"]
[ext_resource type="Script" path="res://Scripts/UI/pause_menu.gd" id="2_nw73f"]
[ext_resource type="PackedScene" uid="uid://bcwkugn6v3oy7" path="res://addons/godot_state_charts/utilities/state_chart_debugger.tscn" id="2_o5str"]
[ext_resource type="Texture2D" uid="uid://b40la2vyf4rn6" path="res://world/Fighting Dojo BG.png" id="4_elb6q"]
[ext_resource type="PackedScene" uid="uid://dd2km6qhpdicx" path="res://Hiro/hiro_ai.tscn" id="5_r7nw4"]
@ -21,6 +23,14 @@
[ext_resource type="Script" path="res://Scripts/Cutscenes/manager.gd" id="19_5yvrq"]
[ext_resource type="Resource" uid="uid://bj3rm1r1ouq0r" path="res://Cutscenes/prototype_start.tres" id="20_elypl"]
[ext_resource type="PackedScene" uid="uid://bwrwh5of0jw4a" path="res://Reed/reed_ai.tscn" id="21_dioix"]
[ext_resource type="Script" path="res://Scripts/game_state.gd" id="24_6ypry"]
[sub_resource type="LabelSettings" id="LabelSettings_f2g0a"]
font = ExtResource("2_64thh")
font_size = 32
shadow_size = 10
shadow_color = Color(0, 0, 0, 0.501961)
shadow_offset = Vector2(5, 5)
[sub_resource type="Gradient" id="Gradient_3ox2i"]
colors = PackedColorArray(0, 0, 0, 1, 0, 0, 0, 1)
@ -32,6 +42,37 @@ gradient = SubResource("Gradient_3ox2i")
y_sort_enabled = true
script = ExtResource("1_y634h")
[node name="PauseMenu" type="CanvasLayer" parent="."]
process_mode = 2
layer = 3
visible = false
script = ExtResource("2_nw73f")
blinking_interval = 0.5
[node name="Control" type="Control" parent="PauseMenu"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="Label" type="Label" parent="PauseMenu/Control"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -20.0
offset_top = -11.5
offset_right = 20.0
offset_bottom = 11.5
grow_horizontal = 2
grow_vertical = 2
text = "PAUSED"
label_settings = SubResource("LabelSettings_f2g0a")
[node name="TextboxUI" parent="." instance=ExtResource("12_8pgvx")]
layer = 2
cps = 100.0
@ -192,6 +233,7 @@ script = ExtResource("19_5yvrq")
cutscene = ExtResource("20_elypl")
[node name="ReedAI" parent="." node_paths=PackedStringArray("player_character") instance=ExtResource("21_dioix")]
process_mode = 4
position = Vector2(64, -16)
player_character = NodePath("../HiroPlayer")
KNOCKBACK_REPOSITION_POWER = 90
@ -200,6 +242,10 @@ reduce_recoil_time_threshold = 0.75
health = 400
attack_power = 10
[node name="GameState" type="Node" parent="."]
process_mode = 3
script = ExtResource("24_6ypry")
[connection signal="dialogue_completed" from="TextboxUI" to="CutsceneManager" method="_on_ui_dialogue_completed"]
[connection signal="attack_did_hit" from="HiroPlayer" to="HiroAI" method="_on_player_attack_did_hit"]
[connection signal="defeated" from="HiroPlayer" to="." method="_on_player_defeated"]
@ -218,3 +264,4 @@ attack_power = 10
[connection signal="attack_did_hit" from="ReedAI" to="HiroPlayer" method="_on_enemy_attack_did_hit"]
[connection signal="defeated" from="ReedAI" to="." method="_on_ai_defeated"]
[connection signal="got_hurt" from="ReedAI" to="CanvasLayer/BattleUI" method="_on_enemy_got_hurt"]
[connection signal="game_paused" from="GameState" to="PauseMenu" method="_on_game_paused"]