Skip to content

Commit 35a675d

Browse files
committed
play/pause working
1 parent bda208b commit 35a675d

File tree

6 files changed

+55
-10
lines changed

6 files changed

+55
-10
lines changed

project.godot

+5
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ move_right={
8787
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null)
8888
]
8989
}
90+
pause_game={
91+
"deadzone": 0.5,
92+
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":80,"unicode":0,"echo":false,"script":null)
93+
]
94+
}
9095

9196
[rendering]
9297

scenes/Pause.tscn

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[gd_scene load_steps=4 format=2]
2+
3+
[ext_resource path="res://scripts/Pause.gd" type="Script" id=1]
4+
[ext_resource path="res://assets/fonts/Bangers-Regular.ttf" type="DynamicFontData" id=2]
5+
6+
[sub_resource type="DynamicFont" id=1]
7+
size = 64
8+
font_data = ExtResource( 2 )
9+
10+
[node name="Pause" type="Control"]
11+
pause_mode = 2
12+
anchor_right = 1.0
13+
anchor_bottom = 1.0
14+
script = ExtResource( 1 )
15+
16+
[node name="ColorRect" type="ColorRect" parent="."]
17+
margin_right = 1920.0
18+
margin_bottom = 1080.0
19+
color = Color( 0, 0, 0, 0.498039 )
20+
21+
[node name="Message" type="Label" parent="."]
22+
margin_left = 610.0
23+
margin_top = 415.0
24+
margin_right = 1310.0
25+
margin_bottom = 665.0
26+
custom_fonts/font = SubResource( 1 )
27+
text = "Game Paused
28+
29+
Press P to continue playing"
30+
align = 1
31+
valign = 1
32+

scenes/UI.tscn

+6-6
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ margin_right = 1920.0
116116
margin_bottom = 640.0
117117
script = ExtResource( 3 )
118118

119+
[node name="ColorRect" type="ColorRect" parent="Message"]
120+
visible = false
121+
margin_right = 1920.0
122+
margin_bottom = 200.0
123+
color = Color( 0, 0, 0, 0.25098 )
124+
119125
[node name="Value" type="Label" parent="Message"]
120126
margin_right = 1920.0
121127
margin_bottom = 200.0
@@ -125,12 +131,6 @@ custom_colors/font_color = Color( 0, 0, 0, 1 )
125131
align = 1
126132
valign = 1
127133

128-
[node name="ColorRect" type="ColorRect" parent="Message"]
129-
visible = false
130-
margin_right = 1920.0
131-
margin_bottom = 200.0
132-
color = Color( 0, 0, 0, 0.25098 )
133-
134134
[node name="Facts" type="Label" parent="."]
135135
margin_top = 880.0
136136
margin_right = 1920.0

scenes/World.tscn

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
[gd_scene load_steps=5 format=2]
1+
[gd_scene load_steps=6 format=2]
22

33
[ext_resource path="res://scripts/World.gd" type="Script" id=1]
44
[ext_resource path="res://scenes/Player.tscn" type="PackedScene" id=2]
55
[ext_resource path="res://scenes/Shop.tscn" type="PackedScene" id=3]
66
[ext_resource path="res://scenes/ShopMenu.tscn" type="PackedScene" id=4]
7+
[ext_resource path="res://scenes/Pause.tscn" type="PackedScene" id=5]
78

89
[node name="World" type="Spatial"]
910
script = ExtResource( 1 )
@@ -29,3 +30,6 @@ wait_time = 600.0
2930
one_shot = true
3031
autostart = true
3132

33+
[node name="Pause" parent="." instance=ExtResource( 5 )]
34+
visible = false
35+

scripts/Pause.gd

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extends Control
2+
3+
func _input(event):
4+
if Input.is_action_pressed("pause_game"):
5+
print("p pressed")
6+
get_tree().paused = !get_tree().paused
7+
visible = !visible

scripts/Player.gd

-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ func _input(event):
3333
PlayerVariables.is_popup_open = true
3434
emit_signal("show_shop")
3535

36-
if Input.is_action_just_pressed("ui_cancel"):
37-
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
38-
3936
if Input.is_key_pressed(KEY_C):
4037
cam1_active = !cam1_active
4138
$Camera.current = cam1_active

0 commit comments

Comments
 (0)