Browse Source

implement pause system

Arnaud Vergnet 6 months ago
parent
commit
ef5e8268c5

+ 0
- 13
Main.tscn View File

@@ -1,13 +0,0 @@
1
-[gd_scene load_steps=4 format=2]
2
-
3
-[ext_resource path="res://Main.gd" type="Script" id=1]
4
-[ext_resource path="res://UI.tscn" type="PackedScene" id=3]
5
-[ext_resource path="res://mini-game/MiniGame.tscn" type="PackedScene" id=4]
6
-
7
-[node name="Main" type="Node"]
8
-script = ExtResource( 1 )
9
-
10
-[node name="MiniGame" parent="." instance=ExtResource( 4 )]
11
-
12
-[node name="UI" parent="." instance=ExtResource( 3 )]
13
-[connection signal="game_over" from="MiniGame" to="." method="_on_MiniGame_game_over"]

+ 7
- 0
fonts/ButtonFont.tres View File

@@ -0,0 +1,7 @@
1
+[gd_resource type="DynamicFont" load_steps=2 format=2]
2
+
3
+[ext_resource path="res://fonts/open-sans/OpenSans-Regular.ttf" type="DynamicFontData" id=1]
4
+
5
+[resource]
6
+size = 30
7
+font_data = ExtResource( 1 )

mini-game/ressources/font/open-sans/LICENSE.txt → fonts/open-sans/LICENSE.txt View File


mini-game/ressources/font/open-sans/OpenSans-Bold.ttf → fonts/open-sans/OpenSans-Bold.ttf View File


mini-game/ressources/font/open-sans/OpenSans-BoldItalic.ttf → fonts/open-sans/OpenSans-BoldItalic.ttf View File


mini-game/ressources/font/open-sans/OpenSans-ExtraBold.ttf → fonts/open-sans/OpenSans-ExtraBold.ttf View File


mini-game/ressources/font/open-sans/OpenSans-ExtraBoldItalic.ttf → fonts/open-sans/OpenSans-ExtraBoldItalic.ttf View File


mini-game/ressources/font/open-sans/OpenSans-Italic.ttf → fonts/open-sans/OpenSans-Italic.ttf View File


mini-game/ressources/font/open-sans/OpenSans-Light.ttf → fonts/open-sans/OpenSans-Light.ttf View File


mini-game/ressources/font/open-sans/OpenSans-LightItalic.ttf → fonts/open-sans/OpenSans-LightItalic.ttf View File


mini-game/ressources/font/open-sans/OpenSans-Regular.ttf → fonts/open-sans/OpenSans-Regular.ttf View File


mini-game/ressources/font/open-sans/OpenSans-Semibold.ttf → fonts/open-sans/OpenSans-Semibold.ttf View File


mini-game/ressources/font/open-sans/OpenSans-SemiboldItalic.ttf → fonts/open-sans/OpenSans-SemiboldItalic.ttf View File


BIN
images/pause.png View File


+ 6
- 6
images/pause.svg View File

@@ -15,8 +15,8 @@
15 15
    inkscape:version="1.0.2 (1.0.2+r75+1)"
16 16
    sodipodi:docname="pause.svg"
17 17
    inkscape:export-filename="/home/vergnet/Godot/pir-serious-game-ethics/images/pause.png"
18
-   inkscape:export-xdpi="4.0640001"
19
-   inkscape:export-ydpi="4.0640001">
18
+   inkscape:export-xdpi="8.1280003"
19
+   inkscape:export-ydpi="8.1280003">
20 20
   <defs
21 21
      id="defs2">
22 22
     <inkscape:path-effect
@@ -94,8 +94,8 @@
94 94
      showgrid="false"
95 95
      inkscape:pagecheckerboard="true"
96 96
      inkscape:window-width="1920"
97
-     inkscape:window-height="1043"
98
-     inkscape:window-x="1920"
97
+     inkscape:window-height="993"
98
+     inkscape:window-x="0"
99 99
      inkscape:window-y="0"
100 100
      inkscape:window-maximized="1" />
101 101
   <metadata
@@ -106,7 +106,7 @@
106 106
         <dc:format>image/svg+xml</dc:format>
107 107
         <dc:type
108 108
            rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
109
-        <dc:title></dc:title>
109
+        <dc:title />
110 110
       </cc:Work>
111 111
     </rdf:RDF>
112 112
   </metadata>
@@ -122,7 +122,7 @@
122 122
        x="30.616072"
123 123
        y="7.5595241"
124 124
        inkscape:path-effect="#path-effect12"
125
-       d="M 30.616072,7.5595241 H 81.642859 V 180.67262 H 30.616072 Z m -28.8955677,0 H -49.306282 V 180.67262 H 1.7205043 Z"
125
+       d="M 30.616072,7.5595241 H 81.642859 V 180.67262 H 30.616072 Z m -51.24897,0 H -71.659685 V 180.67262 h 51.026787 z"
126 126
        sodipodi:type="rect"
127 127
        transform="matrix(0.97264845,0,0,1,95.144941,5.8839269)" />
128 128
   </g>

+ 10
- 0
mini-game/scenes/decor/foreground.gd View File

@@ -2,8 +2,18 @@ extends Node2D
2 2
 
3 3
 onready var texture : TextureRect = $TextureRect
4 4
 
5
+var moving = false
6
+
5 7
 func stop():
8
+	moving = false
6 9
 	texture.material.set_shader_param("scroll_speed", 0)
7 10
 
8 11
 func start():
12
+	moving = true
9 13
 	texture.material.set_shader_param("scroll_speed", 0.2)
14
+
15
+func _process(delta):
16
+	if get_tree().paused and moving:
17
+		stop()
18
+	elif not get_tree().paused and not moving:
19
+		start()

+ 1
- 0
mini-game/scenes/decor/foreground.tscn View File

@@ -24,6 +24,7 @@ shader_param/scroll_speed = 0.0
24 24
 extents = Vector2( 958.398, 78.6175 )
25 25
 
26 26
 [node name="foreground" type="Node2D"]
27
+pause_mode = 2
27 28
 script = ExtResource( 1 )
28 29
 
29 30
 [node name="TextureRect" type="TextureRect" parent="."]

+ 1
- 1
project.godot View File

@@ -45,7 +45,7 @@ _global_script_class_icons={
45 45
 [application]
46 46
 
47 47
 config/name="Pir-serious-game-ethics"
48
-run/main_scene="res://Main.tscn"
48
+run/main_scene="res://scenes/Main.tscn"
49 49
 config/icon="res://icon.png"
50 50
 
51 51
 [autoload]

Main.gd → scenes/Main.gd View File


+ 13
- 0
scenes/Main.tscn View File

@@ -0,0 +1,13 @@
1
+[gd_scene load_steps=4 format=2]
2
+
3
+[ext_resource path="res://scenes/Main.gd" type="Script" id=1]
4
+[ext_resource path="res://scenes/UI.tscn" type="PackedScene" id=2]
5
+[ext_resource path="res://mini-game/MiniGame.tscn" type="PackedScene" id=3]
6
+
7
+[node name="Main" type="Node"]
8
+script = ExtResource( 1 )
9
+
10
+[node name="MiniGame" parent="." instance=ExtResource( 3 )]
11
+
12
+[node name="UI" parent="." instance=ExtResource( 2 )]
13
+[connection signal="game_over" from="MiniGame" to="." method="_on_MiniGame_game_over"]

+ 31
- 0
scenes/PauseMenu.gd View File

@@ -0,0 +1,31 @@
1
+extends Control
2
+
3
+func pause():
4
+	get_tree().paused = true
5
+	show()
6
+
7
+
8
+func unpause():
9
+	get_tree().paused = false
10
+	hide()
11
+
12
+
13
+func _ready():
14
+	connect("gui_input", self, '_on_gui_input')
15
+
16
+func _input(event: InputEvent):
17
+	if event.is_action_pressed("ui_cancel") and visible:
18
+		unpause()
19
+		get_tree().set_input_as_handled()
20
+
21
+
22
+func _on_BackgroundButton_pressed():
23
+	unpause()
24
+
25
+
26
+func _on_ContinueButton_pressed():
27
+	unpause()
28
+
29
+
30
+func _on_ExitButton_pressed():
31
+	get_tree().quit(0)

+ 118
- 0
scenes/PauseMenu.tscn View File

@@ -0,0 +1,118 @@
1
+[gd_scene load_steps=6 format=2]
2
+
3
+[ext_resource path="res://scenes/PauseMenu.gd" type="Script" id=1]
4
+[ext_resource path="res://images/pause.png" type="Texture" id=2]
5
+[ext_resource path="res://fonts/ButtonFont.tres" type="DynamicFont" id=3]
6
+[ext_resource path="res://fonts/open-sans/OpenSans-Light.ttf" type="DynamicFontData" id=4]
7
+
8
+[sub_resource type="DynamicFont" id=1]
9
+size = 50
10
+font_data = ExtResource( 4 )
11
+
12
+[node name="PauseMenu" type="Control"]
13
+pause_mode = 2
14
+anchor_right = 1.0
15
+anchor_bottom = 1.0
16
+script = ExtResource( 1 )
17
+__meta__ = {
18
+"_edit_use_anchors_": false
19
+}
20
+
21
+[node name="Background" type="ColorRect" parent="."]
22
+anchor_right = 1.0
23
+anchor_bottom = 1.0
24
+color = Color( 0, 0, 0, 0.196078 )
25
+__meta__ = {
26
+"_edit_use_anchors_": false
27
+}
28
+
29
+[node name="BackgroundButton" type="TextureButton" parent="."]
30
+anchor_right = 1.0
31
+anchor_bottom = 1.0
32
+expand = true
33
+__meta__ = {
34
+"_edit_use_anchors_": false
35
+}
36
+
37
+[node name="MarginContainer" type="MarginContainer" parent="."]
38
+anchor_right = 1.0
39
+anchor_bottom = 1.0
40
+mouse_filter = 2
41
+custom_constants/margin_right = 400
42
+custom_constants/margin_top = 100
43
+custom_constants/margin_left = 400
44
+custom_constants/margin_bottom = 100
45
+__meta__ = {
46
+"_edit_use_anchors_": false
47
+}
48
+
49
+[node name="ColorRect" type="ColorRect" parent="MarginContainer"]
50
+margin_left = 400.0
51
+margin_top = 100.0
52
+margin_right = 1520.0
53
+margin_bottom = 980.0
54
+color = Color( 0.164706, 0.180392, 0.196078, 1 )
55
+
56
+[node name="MarginContainer2" type="MarginContainer" parent="MarginContainer/ColorRect"]
57
+anchor_right = 1.0
58
+anchor_bottom = 1.0
59
+custom_constants/margin_right = 50
60
+custom_constants/margin_top = 50
61
+custom_constants/margin_left = 50
62
+custom_constants/margin_bottom = 50
63
+__meta__ = {
64
+"_edit_use_anchors_": false
65
+}
66
+
67
+[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/ColorRect/MarginContainer2"]
68
+margin_left = 50.0
69
+margin_top = 50.0
70
+margin_right = 1070.0
71
+margin_bottom = 830.0
72
+__meta__ = {
73
+"_edit_use_anchors_": false
74
+}
75
+
76
+[node name="CenterContainer" type="CenterContainer" parent="MarginContainer/ColorRect/MarginContainer2/VBoxContainer"]
77
+margin_right = 1020.0
78
+margin_bottom = 64.0
79
+
80
+[node name="TextureRect" type="TextureRect" parent="MarginContainer/ColorRect/MarginContainer2/VBoxContainer/CenterContainer"]
81
+margin_left = 478.0
82
+margin_right = 542.0
83
+margin_bottom = 64.0
84
+texture = ExtResource( 2 )
85
+
86
+[node name="Text" type="Label" parent="MarginContainer/ColorRect/MarginContainer2/VBoxContainer"]
87
+margin_top = 68.0
88
+margin_right = 1020.0
89
+margin_bottom = 728.0
90
+size_flags_vertical = 3
91
+custom_fonts/font = SubResource( 1 )
92
+text = "Le jeu est en pause"
93
+align = 1
94
+valign = 1
95
+
96
+[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/ColorRect/MarginContainer2/VBoxContainer"]
97
+margin_top = 732.0
98
+margin_right = 1020.0
99
+margin_bottom = 780.0
100
+custom_constants/separation = 50
101
+alignment = 1
102
+
103
+[node name="ExitButton" type="Button" parent="MarginContainer/ColorRect/MarginContainer2/VBoxContainer/HBoxContainer"]
104
+margin_left = 353.0
105
+margin_right = 465.0
106
+margin_bottom = 48.0
107
+custom_fonts/font = ExtResource( 3 )
108
+text = "Quitter"
109
+
110
+[node name="ContinueButton" type="Button" parent="MarginContainer/ColorRect/MarginContainer2/VBoxContainer/HBoxContainer"]
111
+margin_left = 515.0
112
+margin_right = 666.0
113
+margin_bottom = 48.0
114
+custom_fonts/font = ExtResource( 3 )
115
+text = "Continuer"
116
+[connection signal="pressed" from="BackgroundButton" to="." method="_on_BackgroundButton_pressed"]
117
+[connection signal="pressed" from="MarginContainer/ColorRect/MarginContainer2/VBoxContainer/HBoxContainer/ExitButton" to="." method="_on_ExitButton_pressed"]
118
+[connection signal="pressed" from="MarginContainer/ColorRect/MarginContainer2/VBoxContainer/HBoxContainer/ContinueButton" to="." method="_on_ContinueButton_pressed"]

+ 5
- 0
scenes/UI.gd View File

@@ -0,0 +1,5 @@
1
+extends Control
2
+
3
+
4
+func _on_TextureButton_pressed():
5
+	$PauseMenu.pause()

UI.tscn → scenes/UI.tscn View File

@@ -1,6 +1,8 @@
1
-[gd_scene load_steps=2 format=2]
1
+[gd_scene load_steps=4 format=2]
2 2
 
3 3
 [ext_resource path="res://images/pause.png" type="Texture" id=1]
4
+[ext_resource path="res://scenes/PauseMenu.tscn" type="PackedScene" id=2]
5
+[ext_resource path="res://scenes/UI.gd" type="Script" id=3]
4 6
 
5 7
 [node name="UI" type="Control"]
6 8
 anchor_right = 1.0
@@ -8,6 +10,7 @@ anchor_bottom = 1.0
8 10
 margin_top = -0.471939
9 11
 margin_bottom = -0.471924
10 12
 mouse_filter = 2
13
+script = ExtResource( 3 )
11 14
 __meta__ = {
12 15
 "_edit_use_anchors_": false
13 16
 }
@@ -27,7 +30,7 @@ __meta__ = {
27 30
 margin_left = 10.0
28 31
 margin_top = 10.0
29 32
 margin_right = 1910.0
30
-margin_bottom = 42.0
33
+margin_bottom = 74.0
31 34
 hint_tooltip = "Mettre en pause"
32 35
 size_flags_horizontal = 3
33 36
 __meta__ = {
@@ -35,7 +38,7 @@ __meta__ = {
35 38
 }
36 39
 
37 40
 [node name="Label" type="Label" parent="MarginContainer/HBoxContainer"]
38
-margin_right = 1864.0
41
+margin_right = 1832.0
39 42
 margin_bottom = 14.0
40 43
 size_flags_horizontal = 3
41 44
 size_flags_vertical = 0
@@ -45,7 +48,20 @@ __meta__ = {
45 48
 }
46 49
 
47 50
 [node name="TextureButton" type="TextureButton" parent="MarginContainer/HBoxContainer"]
48
-margin_left = 1868.0
51
+margin_left = 1836.0
49 52
 margin_right = 1900.0
50
-margin_bottom = 32.0
53
+margin_bottom = 64.0
51 54
 texture_normal = ExtResource( 1 )
55
+
56
+[node name="ColorRect" type="ColorRect" parent="MarginContainer/HBoxContainer/TextureButton"]
57
+show_behind_parent = true
58
+anchor_right = 1.0
59
+anchor_bottom = 1.0
60
+mouse_filter = 2
61
+color = Color( 0, 0, 0, 0.231373 )
62
+__meta__ = {
63
+"_edit_use_anchors_": false
64
+}
65
+
66
+[node name="PauseMenu" parent="." instance=ExtResource( 2 )]
67
+[connection signal="pressed" from="MarginContainer/HBoxContainer/TextureButton" to="." method="_on_TextureButton_pressed"]

Loading…
Cancel
Save