implement pause system
This commit is contained in:
parent
c1ba98a91b
commit
ef5e8268c5
24 changed files with 213 additions and 25 deletions
13
Main.tscn
13
Main.tscn
|
@ -1,13 +0,0 @@
|
|||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://Main.gd" type="Script" id=1]
|
||||
[ext_resource path="res://UI.tscn" type="PackedScene" id=3]
|
||||
[ext_resource path="res://mini-game/MiniGame.tscn" type="PackedScene" id=4]
|
||||
|
||||
[node name="Main" type="Node"]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="MiniGame" parent="." instance=ExtResource( 4 )]
|
||||
|
||||
[node name="UI" parent="." instance=ExtResource( 3 )]
|
||||
[connection signal="game_over" from="MiniGame" to="." method="_on_MiniGame_game_over"]
|
7
fonts/ButtonFont.tres
Normal file
7
fonts/ButtonFont.tres
Normal file
|
@ -0,0 +1,7 @@
|
|||
[gd_resource type="DynamicFont" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://fonts/open-sans/OpenSans-Regular.ttf" type="DynamicFontData" id=1]
|
||||
|
||||
[resource]
|
||||
size = 30
|
||||
font_data = ExtResource( 1 )
|
BIN
images/pause.png
BIN
images/pause.png
Binary file not shown.
Before Width: | Height: | Size: 314 B After Width: | Height: | Size: 457 B |
|
@ -15,8 +15,8 @@
|
|||
inkscape:version="1.0.2 (1.0.2+r75+1)"
|
||||
sodipodi:docname="pause.svg"
|
||||
inkscape:export-filename="/home/vergnet/Godot/pir-serious-game-ethics/images/pause.png"
|
||||
inkscape:export-xdpi="4.0640001"
|
||||
inkscape:export-ydpi="4.0640001">
|
||||
inkscape:export-xdpi="8.1280003"
|
||||
inkscape:export-ydpi="8.1280003">
|
||||
<defs
|
||||
id="defs2">
|
||||
<inkscape:path-effect
|
||||
|
@ -94,8 +94,8 @@
|
|||
showgrid="false"
|
||||
inkscape:pagecheckerboard="true"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1043"
|
||||
inkscape:window-x="1920"
|
||||
inkscape:window-height="993"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="1" />
|
||||
<metadata
|
||||
|
@ -106,7 +106,7 @@
|
|||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
<dc:title />
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
|
@ -122,7 +122,7 @@
|
|||
x="30.616072"
|
||||
y="7.5595241"
|
||||
inkscape:path-effect="#path-effect12"
|
||||
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"
|
||||
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"
|
||||
sodipodi:type="rect"
|
||||
transform="matrix(0.97264845,0,0,1,95.144941,5.8839269)" />
|
||||
</g>
|
||||
|
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
|
@ -2,8 +2,18 @@ extends Node2D
|
|||
|
||||
onready var texture : TextureRect = $TextureRect
|
||||
|
||||
var moving = false
|
||||
|
||||
func stop():
|
||||
moving = false
|
||||
texture.material.set_shader_param("scroll_speed", 0)
|
||||
|
||||
func start():
|
||||
moving = true
|
||||
texture.material.set_shader_param("scroll_speed", 0.2)
|
||||
|
||||
func _process(delta):
|
||||
if get_tree().paused and moving:
|
||||
stop()
|
||||
elif not get_tree().paused and not moving:
|
||||
start()
|
||||
|
|
|
@ -24,6 +24,7 @@ shader_param/scroll_speed = 0.0
|
|||
extents = Vector2( 958.398, 78.6175 )
|
||||
|
||||
[node name="foreground" type="Node2D"]
|
||||
pause_mode = 2
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="."]
|
||||
|
|
|
@ -45,7 +45,7 @@ _global_script_class_icons={
|
|||
[application]
|
||||
|
||||
config/name="Pir-serious-game-ethics"
|
||||
run/main_scene="res://Main.tscn"
|
||||
run/main_scene="res://scenes/Main.tscn"
|
||||
config/icon="res://icon.png"
|
||||
|
||||
[autoload]
|
||||
|
|
13
scenes/Main.tscn
Normal file
13
scenes/Main.tscn
Normal file
|
@ -0,0 +1,13 @@
|
|||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://scenes/Main.gd" type="Script" id=1]
|
||||
[ext_resource path="res://scenes/UI.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://mini-game/MiniGame.tscn" type="PackedScene" id=3]
|
||||
|
||||
[node name="Main" type="Node"]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="MiniGame" parent="." instance=ExtResource( 3 )]
|
||||
|
||||
[node name="UI" parent="." instance=ExtResource( 2 )]
|
||||
[connection signal="game_over" from="MiniGame" to="." method="_on_MiniGame_game_over"]
|
31
scenes/PauseMenu.gd
Normal file
31
scenes/PauseMenu.gd
Normal file
|
@ -0,0 +1,31 @@
|
|||
extends Control
|
||||
|
||||
func pause():
|
||||
get_tree().paused = true
|
||||
show()
|
||||
|
||||
|
||||
func unpause():
|
||||
get_tree().paused = false
|
||||
hide()
|
||||
|
||||
|
||||
func _ready():
|
||||
connect("gui_input", self, '_on_gui_input')
|
||||
|
||||
func _input(event: InputEvent):
|
||||
if event.is_action_pressed("ui_cancel") and visible:
|
||||
unpause()
|
||||
get_tree().set_input_as_handled()
|
||||
|
||||
|
||||
func _on_BackgroundButton_pressed():
|
||||
unpause()
|
||||
|
||||
|
||||
func _on_ContinueButton_pressed():
|
||||
unpause()
|
||||
|
||||
|
||||
func _on_ExitButton_pressed():
|
||||
get_tree().quit(0)
|
118
scenes/PauseMenu.tscn
Normal file
118
scenes/PauseMenu.tscn
Normal file
|
@ -0,0 +1,118 @@
|
|||
[gd_scene load_steps=6 format=2]
|
||||
|
||||
[ext_resource path="res://scenes/PauseMenu.gd" type="Script" id=1]
|
||||
[ext_resource path="res://images/pause.png" type="Texture" id=2]
|
||||
[ext_resource path="res://fonts/ButtonFont.tres" type="DynamicFont" id=3]
|
||||
[ext_resource path="res://fonts/open-sans/OpenSans-Light.ttf" type="DynamicFontData" id=4]
|
||||
|
||||
[sub_resource type="DynamicFont" id=1]
|
||||
size = 50
|
||||
font_data = ExtResource( 4 )
|
||||
|
||||
[node name="PauseMenu" type="Control"]
|
||||
pause_mode = 2
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Background" type="ColorRect" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
color = Color( 0, 0, 0, 0.196078 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="BackgroundButton" type="TextureButton" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
expand = true
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
mouse_filter = 2
|
||||
custom_constants/margin_right = 400
|
||||
custom_constants/margin_top = 100
|
||||
custom_constants/margin_left = 400
|
||||
custom_constants/margin_bottom = 100
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="MarginContainer"]
|
||||
margin_left = 400.0
|
||||
margin_top = 100.0
|
||||
margin_right = 1520.0
|
||||
margin_bottom = 980.0
|
||||
color = Color( 0.164706, 0.180392, 0.196078, 1 )
|
||||
|
||||
[node name="MarginContainer2" type="MarginContainer" parent="MarginContainer/ColorRect"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
custom_constants/margin_right = 50
|
||||
custom_constants/margin_top = 50
|
||||
custom_constants/margin_left = 50
|
||||
custom_constants/margin_bottom = 50
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/ColorRect/MarginContainer2"]
|
||||
margin_left = 50.0
|
||||
margin_top = 50.0
|
||||
margin_right = 1070.0
|
||||
margin_bottom = 830.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="CenterContainer" type="CenterContainer" parent="MarginContainer/ColorRect/MarginContainer2/VBoxContainer"]
|
||||
margin_right = 1020.0
|
||||
margin_bottom = 64.0
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="MarginContainer/ColorRect/MarginContainer2/VBoxContainer/CenterContainer"]
|
||||
margin_left = 478.0
|
||||
margin_right = 542.0
|
||||
margin_bottom = 64.0
|
||||
texture = ExtResource( 2 )
|
||||
|
||||
[node name="Text" type="Label" parent="MarginContainer/ColorRect/MarginContainer2/VBoxContainer"]
|
||||
margin_top = 68.0
|
||||
margin_right = 1020.0
|
||||
margin_bottom = 728.0
|
||||
size_flags_vertical = 3
|
||||
custom_fonts/font = SubResource( 1 )
|
||||
text = "Le jeu est en pause"
|
||||
align = 1
|
||||
valign = 1
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/ColorRect/MarginContainer2/VBoxContainer"]
|
||||
margin_top = 732.0
|
||||
margin_right = 1020.0
|
||||
margin_bottom = 780.0
|
||||
custom_constants/separation = 50
|
||||
alignment = 1
|
||||
|
||||
[node name="ExitButton" type="Button" parent="MarginContainer/ColorRect/MarginContainer2/VBoxContainer/HBoxContainer"]
|
||||
margin_left = 353.0
|
||||
margin_right = 465.0
|
||||
margin_bottom = 48.0
|
||||
custom_fonts/font = ExtResource( 3 )
|
||||
text = "Quitter"
|
||||
|
||||
[node name="ContinueButton" type="Button" parent="MarginContainer/ColorRect/MarginContainer2/VBoxContainer/HBoxContainer"]
|
||||
margin_left = 515.0
|
||||
margin_right = 666.0
|
||||
margin_bottom = 48.0
|
||||
custom_fonts/font = ExtResource( 3 )
|
||||
text = "Continuer"
|
||||
[connection signal="pressed" from="BackgroundButton" to="." method="_on_BackgroundButton_pressed"]
|
||||
[connection signal="pressed" from="MarginContainer/ColorRect/MarginContainer2/VBoxContainer/HBoxContainer/ExitButton" to="." method="_on_ExitButton_pressed"]
|
||||
[connection signal="pressed" from="MarginContainer/ColorRect/MarginContainer2/VBoxContainer/HBoxContainer/ContinueButton" to="." method="_on_ContinueButton_pressed"]
|
5
scenes/UI.gd
Normal file
5
scenes/UI.gd
Normal file
|
@ -0,0 +1,5 @@
|
|||
extends Control
|
||||
|
||||
|
||||
func _on_TextureButton_pressed():
|
||||
$PauseMenu.pause()
|
|
@ -1,6 +1,8 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://images/pause.png" type="Texture" id=1]
|
||||
[ext_resource path="res://scenes/PauseMenu.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://scenes/UI.gd" type="Script" id=3]
|
||||
|
||||
[node name="UI" type="Control"]
|
||||
anchor_right = 1.0
|
||||
|
@ -8,6 +10,7 @@ anchor_bottom = 1.0
|
|||
margin_top = -0.471939
|
||||
margin_bottom = -0.471924
|
||||
mouse_filter = 2
|
||||
script = ExtResource( 3 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
@ -27,7 +30,7 @@ __meta__ = {
|
|||
margin_left = 10.0
|
||||
margin_top = 10.0
|
||||
margin_right = 1910.0
|
||||
margin_bottom = 42.0
|
||||
margin_bottom = 74.0
|
||||
hint_tooltip = "Mettre en pause"
|
||||
size_flags_horizontal = 3
|
||||
__meta__ = {
|
||||
|
@ -35,7 +38,7 @@ __meta__ = {
|
|||
}
|
||||
|
||||
[node name="Label" type="Label" parent="MarginContainer/HBoxContainer"]
|
||||
margin_right = 1864.0
|
||||
margin_right = 1832.0
|
||||
margin_bottom = 14.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 0
|
||||
|
@ -45,7 +48,20 @@ __meta__ = {
|
|||
}
|
||||
|
||||
[node name="TextureButton" type="TextureButton" parent="MarginContainer/HBoxContainer"]
|
||||
margin_left = 1868.0
|
||||
margin_left = 1836.0
|
||||
margin_right = 1900.0
|
||||
margin_bottom = 32.0
|
||||
margin_bottom = 64.0
|
||||
texture_normal = ExtResource( 1 )
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="MarginContainer/HBoxContainer/TextureButton"]
|
||||
show_behind_parent = true
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
mouse_filter = 2
|
||||
color = Color( 0, 0, 0, 0.231373 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="PauseMenu" parent="." instance=ExtResource( 2 )]
|
||||
[connection signal="pressed" from="MarginContainer/HBoxContainer/TextureButton" to="." method="_on_TextureButton_pressed"]
|
Loading…
Reference in a new issue