From 352c043eba36cb1ab4ec4408ae3a5ef05e06359d Mon Sep 17 00:00:00 2001 From: Mylloon Date: Thu, 8 Apr 2021 02:31:29 +0200 Subject: [PATCH] ajout menu --- assets/images/buttonExit.png | 3 ++ assets/images/buttonExitSelected.png | 3 ++ assets/images/buttonPlay.png | 3 ++ assets/images/buttonPlaySelected.png | 3 ++ assets/images/fondMenu.png | 3 ++ assets/images/titreMenu.png | 3 ++ project.godot | 2 +- scenes/Menu.tscn | 64 ++++++++++++++++++++++++++++ scripts/PortailDeFin.gd | 3 +- scripts/menuPrincipal.gd | 17 ++++++++ 10 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 assets/images/buttonExit.png create mode 100644 assets/images/buttonExitSelected.png create mode 100644 assets/images/buttonPlay.png create mode 100644 assets/images/buttonPlaySelected.png create mode 100644 assets/images/fondMenu.png create mode 100644 assets/images/titreMenu.png create mode 100644 scenes/Menu.tscn create mode 100644 scripts/menuPrincipal.gd diff --git a/assets/images/buttonExit.png b/assets/images/buttonExit.png new file mode 100644 index 0000000..19908d3 --- /dev/null +++ b/assets/images/buttonExit.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b9c93e8957067c6c026a16cb421dfbcaed6f34efb561d6bcb92f519023edba80 +size 1719 diff --git a/assets/images/buttonExitSelected.png b/assets/images/buttonExitSelected.png new file mode 100644 index 0000000..5fcf6ed --- /dev/null +++ b/assets/images/buttonExitSelected.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c6e1320bcefa8aa2a853183ff4c1eb714f408e60d49d50975fbc34fea88147af +size 2797 diff --git a/assets/images/buttonPlay.png b/assets/images/buttonPlay.png new file mode 100644 index 0000000..4a5a416 --- /dev/null +++ b/assets/images/buttonPlay.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9c061843d97225f4a26ebfa7dfa3072b6d46c90c4e0ec59e18d56dbd1c2a0327 +size 1789 diff --git a/assets/images/buttonPlaySelected.png b/assets/images/buttonPlaySelected.png new file mode 100644 index 0000000..262826e --- /dev/null +++ b/assets/images/buttonPlaySelected.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5010ef1bbafe34fd0a4acc057f45984953aff55d6d2a03c606da7549f2cf5595 +size 2849 diff --git a/assets/images/fondMenu.png b/assets/images/fondMenu.png new file mode 100644 index 0000000..ecfebb0 --- /dev/null +++ b/assets/images/fondMenu.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cdd13fd32dea9f6b97d603e131c91b14f755b86e16ee3ac8ffe3f716f3eb1a2d +size 3179 diff --git a/assets/images/titreMenu.png b/assets/images/titreMenu.png new file mode 100644 index 0000000..502fc76 --- /dev/null +++ b/assets/images/titreMenu.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:95d76cb8df2766d04410499f209a85159435599ebc9abd463431ed5e73fa3a78 +size 4092 diff --git a/project.godot b/project.godot index 55940ac..44f33ff 100644 --- a/project.godot +++ b/project.godot @@ -17,7 +17,7 @@ _global_script_class_icons={ config/name="Tyra" config/description="Tyra est un jeu 2D." -run/main_scene="res://scenes/Monde.tscn" +run/main_scene="res://scenes/Menu.tscn" config/icon="res://assets/images/sortie.png" config/windows_native_icon="res://assets/images/icon.ico" diff --git a/scenes/Menu.tscn b/scenes/Menu.tscn new file mode 100644 index 0000000..c9b2c8f --- /dev/null +++ b/scenes/Menu.tscn @@ -0,0 +1,64 @@ +[gd_scene load_steps=8 format=2] + +[ext_resource path="res://assets/images/fondMenu.png" type="Texture" id=1] +[ext_resource path="res://assets/images/titreMenu.png" type="Texture" id=2] +[ext_resource path="res://assets/images/buttonPlay.png" type="Texture" id=3] +[ext_resource path="res://assets/images/buttonPlaySelected.png" type="Texture" id=4] +[ext_resource path="res://assets/images/buttonExitSelected.png" type="Texture" id=5] +[ext_resource path="res://assets/images/buttonExit.png" type="Texture" id=6] +[ext_resource path="res://scripts/menuPrincipal.gd" type="Script" id=7] + +[node name="Menu" type="Node2D"] + +[node name="Principal" type="Node2D" parent="."] +script = ExtResource( 7 ) + +[node name="Sprite" type="Sprite" parent="Principal"] +texture = ExtResource( 1 ) +centered = false + +[node name="MarginContainer" type="MarginContainer" parent="Principal"] +margin_right = 1024.0 +margin_bottom = 600.0 +custom_constants/margin_right = 40 +custom_constants/margin_top = 40 +custom_constants/margin_left = 40 +custom_constants/margin_bottom = 40 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="VBoxContainer" type="VBoxContainer" parent="Principal/MarginContainer"] +margin_left = 40.0 +margin_top = 40.0 +margin_right = 1064.0 +margin_bottom = 610.0 +size_flags_horizontal = 5 +custom_constants/separation = -24 + +[node name="TextureRect" type="TextureRect" parent="Principal/MarginContainer/VBoxContainer"] +margin_right = 1024.0 +margin_bottom = 222.0 +texture = ExtResource( 2 ) + +[node name="VBoxContainer" type="VBoxContainer" parent="Principal/MarginContainer/VBoxContainer"] +margin_left = 350.0 +margin_top = 198.0 +margin_right = 674.0 +margin_bottom = 570.0 +size_flags_horizontal = 4 + +[node name="Jouer" type="TextureButton" parent="Principal/MarginContainer/VBoxContainer/VBoxContainer"] +margin_right = 324.0 +margin_bottom = 184.0 +texture_normal = ExtResource( 3 ) +texture_focused = ExtResource( 4 ) + +[node name="Quitter" type="TextureButton" parent="Principal/MarginContainer/VBoxContainer/VBoxContainer"] +margin_top = 188.0 +margin_right = 324.0 +margin_bottom = 372.0 +texture_normal = ExtResource( 6 ) +texture_focused = ExtResource( 5 ) +[connection signal="pressed" from="Principal/MarginContainer/VBoxContainer/VBoxContainer/Jouer" to="Principal" method="_on_Jouer_pressed"] +[connection signal="pressed" from="Principal/MarginContainer/VBoxContainer/VBoxContainer/Quitter" to="Principal" method="_on_Quitter_pressed"] diff --git a/scripts/PortailDeFin.gd b/scripts/PortailDeFin.gd index 8d26856..b57be19 100644 --- a/scripts/PortailDeFin.gd +++ b/scripts/PortailDeFin.gd @@ -5,4 +5,5 @@ func _ready(): func _on_Portail_de_fin_body_entered(body): if "Joueur" in body.name: - get_tree().quit() + if get_tree().change_scene("res://scenes/Menu.tscn") != OK: + print("Impossible de charger le jeu.") diff --git a/scripts/menuPrincipal.gd b/scripts/menuPrincipal.gd new file mode 100644 index 0000000..a67b293 --- /dev/null +++ b/scripts/menuPrincipal.gd @@ -0,0 +1,17 @@ +extends Node2D + +func _ready(): + $MarginContainer/VBoxContainer/VBoxContainer/Jouer.grab_focus() + +func _physics_process(_delta): + if $MarginContainer/VBoxContainer/VBoxContainer/Jouer.is_hovered() == true: + $MarginContainer/VBoxContainer/VBoxContainer/Jouer.grab_focus() + if $MarginContainer/VBoxContainer/VBoxContainer/Quitter.is_hovered() == true: + $MarginContainer/VBoxContainer/VBoxContainer/Quitter.grab_focus() + +func _on_Jouer_pressed(): + if get_tree().change_scene("res://scenes/Monde1.tscn") != OK: + print("Impossible de charger le jeu.") + +func _on_Quitter_pressed(): + get_tree().quit()