jeu/HUD: début de HUD pour les prouts
Maintenant 3 geauges de prout sont présentes et permettent au joueur de savoir si il a du pet de dispo ou pas. Le joueur peut accumuler jusqu'à trois prouts. Le temps de recharge est de 3 secondes par prout. C'est peut être trop long. Il faudra probablement bouger du code que j'ai mis dans game au dans le code de niveau. Mais bon j'y réfléchirai le prochain coup.
This commit is contained in:
35
HUD/fart_gauge.gd
Normal file
35
HUD/fart_gauge.gd
Normal file
@@ -0,0 +1,35 @@
|
||||
class_name FartGauge extends Node2D
|
||||
|
||||
|
||||
@onready var animationPlayer := $AnimationPlayer as AnimationPlayer
|
||||
|
||||
signal reload_done()
|
||||
signal dash_done()
|
||||
|
||||
var loading = false
|
||||
var loaded = false
|
||||
|
||||
func load_cheese() -> bool:
|
||||
if not loading and not loaded:
|
||||
animationPlayer.play("reload")
|
||||
loading = true
|
||||
return true
|
||||
return false
|
||||
|
||||
func dash_fart() -> bool:
|
||||
if loaded:
|
||||
animationPlayer.play("DASH")
|
||||
return loaded
|
||||
|
||||
func reset():
|
||||
animationPlayer.play("RESET")
|
||||
loaded = false
|
||||
|
||||
func _on_animation_player_animation_finished(anim_name: StringName) -> void:
|
||||
if anim_name == "reload":
|
||||
loading = false
|
||||
loaded = true
|
||||
reload_done.emit()
|
||||
if anim_name == "DASH":
|
||||
loaded = false
|
||||
dash_done.emit()
|
||||
115
HUD/fart_gauge.tscn
Normal file
115
HUD/fart_gauge.tscn
Normal file
@@ -0,0 +1,115 @@
|
||||
[gd_scene load_steps=7 format=3 uid="uid://dsgt6b1bqi6ui"]
|
||||
|
||||
[ext_resource type="Script" path="res://HUD/fart_gauge.gd" id="1_jculu"]
|
||||
[ext_resource type="Texture2D" uid="uid://c8r4ylb5ygl5c" path="res://sprite/jauge-de-prout.png" id="1_rt22i"]
|
||||
|
||||
[sub_resource type="Animation" id="Animation_nsc8d"]
|
||||
resource_name = "DASH"
|
||||
length = 0.25
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Full:position")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.2),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 0,
|
||||
"values": [Vector2(0, 0), Vector2(0, -72)]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("Full:region_rect")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0, 0.2),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 0,
|
||||
"values": [Rect2(16, 0, 16, 144), Rect2(16, 0, 16, 0)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_8hnm2"]
|
||||
resource_name = "RESET"
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Full:region_rect")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Rect2(16, 0, 16, 0)]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("Full:position")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Vector2(0, -72)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_eh7ry"]
|
||||
resource_name = "reload"
|
||||
length = 3.0
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Full:region_rect")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 3),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 0,
|
||||
"values": [Rect2(16, 0, 16, 0), Rect2(16, 0, 16, 144)]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("Full:position")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0, 3),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 0,
|
||||
"values": [Vector2(0, -70), Vector2(0, 0)]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_hfkd0"]
|
||||
_data = {
|
||||
"DASH": SubResource("Animation_nsc8d"),
|
||||
"RESET": SubResource("Animation_8hnm2"),
|
||||
"reload": SubResource("Animation_eh7ry")
|
||||
}
|
||||
|
||||
[node name="FartGauge" type="Node2D"]
|
||||
script = ExtResource("1_jculu")
|
||||
|
||||
[node name="Empty" type="Sprite2D" parent="."]
|
||||
texture = ExtResource("1_rt22i")
|
||||
region_enabled = true
|
||||
region_rect = Rect2(0, 0, 16, 144)
|
||||
|
||||
[node name="Full" type="Sprite2D" parent="."]
|
||||
position = Vector2(0, -72)
|
||||
texture = ExtResource("1_rt22i")
|
||||
region_enabled = true
|
||||
region_rect = Rect2(16, 0, 16, 0)
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
libraries = {
|
||||
"": SubResource("AnimationLibrary_hfkd0")
|
||||
}
|
||||
|
||||
[connection signal="animation_finished" from="AnimationPlayer" to="." method="_on_animation_player_animation_finished"]
|
||||
36
HUD/hud.gd
Normal file
36
HUD/hud.gd
Normal file
@@ -0,0 +1,36 @@
|
||||
class_name HUD extends CanvasLayer
|
||||
|
||||
@onready var gauge1 := $FartGauge1 as FartGauge
|
||||
@onready var gauge2 := $FartGauge2 as FartGauge
|
||||
@onready var gauge3 := $FartGauge3 as FartGauge
|
||||
|
||||
signal fart_reloaded()
|
||||
|
||||
var cheese_number = 0
|
||||
var gauges = []
|
||||
|
||||
func _ready() -> void:
|
||||
gauge1.connect("reload_done", cheese_loaded)
|
||||
gauge2.connect("reload_done", cheese_loaded)
|
||||
gauge3.connect("reload_done", cheese_loaded)
|
||||
gauges = [gauge1, gauge2, gauge3]
|
||||
|
||||
|
||||
func reset():
|
||||
cheese_number = 0
|
||||
for gauge in gauges:
|
||||
gauge.reset()
|
||||
|
||||
func load_cheese():
|
||||
for gauge in gauges:
|
||||
if gauge.load_cheese():
|
||||
return
|
||||
|
||||
func dash_fart():
|
||||
for x in gauges.size():
|
||||
var gauge = gauges[-x-1]
|
||||
if gauge.dash_fart():
|
||||
return
|
||||
|
||||
func cheese_loaded():
|
||||
fart_reloaded.emit()
|
||||
20
HUD/hud.tscn
Normal file
20
HUD/hud.tscn
Normal file
@@ -0,0 +1,20 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dvlb4thqhqke"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dsgt6b1bqi6ui" path="res://HUD/fart_gauge.tscn" id="1_4e2i3"]
|
||||
|
||||
[node name="HUD" type="CanvasLayer"]
|
||||
|
||||
[node name="FartGauge3" parent="." instance=ExtResource("1_4e2i3")]
|
||||
position = Vector2(242, 6)
|
||||
rotation = -1.5708
|
||||
scale = Vector2(0.7, 0.7)
|
||||
|
||||
[node name="FartGauge2" parent="." instance=ExtResource("1_4e2i3")]
|
||||
position = Vector2(147, 6)
|
||||
rotation = -1.5708
|
||||
scale = Vector2(0.7, 0.7)
|
||||
|
||||
[node name="FartGauge1" parent="." instance=ExtResource("1_4e2i3")]
|
||||
position = Vector2(51, 6)
|
||||
rotation = -1.5708
|
||||
scale = Vector2(0.7, 0.7)
|
||||
25
game.gd
25
game.gd
@@ -1,5 +1,6 @@
|
||||
class_name Game extends Node
|
||||
|
||||
@onready var hud := $HUD as HUD
|
||||
|
||||
var current_scene : Node
|
||||
var level0 = preload("res://levels/level_0.tscn")
|
||||
@@ -10,20 +11,25 @@ var current_scence
|
||||
var prev_scene
|
||||
var last_spawn_point = null
|
||||
|
||||
var princesse : Princess = null
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
go_to(scene_name, null)
|
||||
|
||||
func reload_current_scene() -> void:
|
||||
go_to(scene_name, last_spawn_point)
|
||||
hud.reset()
|
||||
|
||||
func enter_door(destination : String, other_side_position : Vector2):
|
||||
call_deferred("go_to", destination, other_side_position)
|
||||
|
||||
func go_to(destination : String, spawn_point):
|
||||
var old_princesse :Princess
|
||||
var old_princesse :Princess = null
|
||||
if current_scence:
|
||||
old_princesse = current_scence.find_child("Princesse")
|
||||
old_princesse.disconnect("cheese_collected", hud_load_cheese)
|
||||
old_princesse.disconnect("dash_fart", hud_unload_cheese)
|
||||
remove_child(current_scence)
|
||||
|
||||
if destination == "level_1":
|
||||
@@ -40,9 +46,24 @@ func go_to(destination : String, spawn_point):
|
||||
door.connect("door_openned", enter_door, ConnectFlags.CONNECT_ONE_SHOT)
|
||||
add_child(current_scence)
|
||||
|
||||
princesse= current_scence.find_child("Princesse")
|
||||
if spawn_point:
|
||||
var princesse :Princess = current_scence.find_child("Princesse")
|
||||
princesse.position = spawn_point
|
||||
last_spawn_point = spawn_point
|
||||
if old_princesse:
|
||||
princesse.copy_from(old_princesse)
|
||||
princesse.connect("cheese_collected", hud_load_cheese)
|
||||
princesse.connect("dash_fart", hud_unload_cheese)
|
||||
|
||||
# vient de la princesse quand elle a ramassé un fromage
|
||||
func hud_load_cheese():
|
||||
Input.start_joy_vibration(0, 0, 1, 0.1)
|
||||
hud.load_cheese()
|
||||
|
||||
# vient de la princesse quand elle ^ète
|
||||
func hud_unload_cheese():
|
||||
hud.dash_fart()
|
||||
|
||||
# quand le fromage est chargé, le jeu le signale à la princesse
|
||||
func _on_hud_fart_reloaded() -> void:
|
||||
princesse.reload_fart()
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dn0b30kvaeasf"]
|
||||
[gd_scene load_steps=4 format=3 uid="uid://dn0b30kvaeasf"]
|
||||
|
||||
[ext_resource type="Script" path="res://game.gd" id="1_yny56"]
|
||||
[ext_resource type="PackedScene" uid="uid://dvlb4thqhqke" path="res://HUD/hud.tscn" id="2_0fnfe"]
|
||||
[ext_resource type="Script" path="res://HUD/hud.gd" id="3_x1wcj"]
|
||||
|
||||
[node name="game" type="Node"]
|
||||
script = ExtResource("1_yny56")
|
||||
|
||||
[node name="HUD" parent="." instance=ExtResource("2_0fnfe")]
|
||||
script = ExtResource("3_x1wcj")
|
||||
|
||||
[connection signal="fart_reloaded" from="HUD" to="." method="_on_hud_fart_reloaded"]
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
class_name normal_cheese extends Area2D
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
@@ -9,7 +9,7 @@ var picked :bool = false
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
if not picked:
|
||||
animation_player.play(&"picked")
|
||||
(body as Princess).cheese_collected.emit()
|
||||
(body as Princess).you_got_cheese()
|
||||
picked = true
|
||||
# Le fromage peut être à utilisation unique
|
||||
if CHEESE_RESPAWN_TIME > 0:
|
||||
|
||||
14
princesse.gd
14
princesse.gd
@@ -43,10 +43,12 @@ var DASH_SPEED = WALKING_SPEED * 2
|
||||
@export var WALK_INCR_GROUND : int = 1
|
||||
@export var WALK_INCR_AIR : int = 3
|
||||
|
||||
@export var MAX_FARTS : int = 1
|
||||
@export var MAX_FARTS : int = 3
|
||||
|
||||
signal cheese_collected()
|
||||
signal princesse_is_dead()
|
||||
signal cheese_collected() # utilisé pour remplir le HUD qui apelera
|
||||
# ensuite la fonction reload_fart quand il aura fini
|
||||
signal dash_fart() # utilisé pour vider le HUD
|
||||
signal princesse_is_dead() # signal au jeu de recharger la scene
|
||||
|
||||
var locked = true
|
||||
|
||||
@@ -428,6 +430,7 @@ func read_input() -> void:
|
||||
Input.start_joy_vibration(0, 1, 0.5, 0.2)
|
||||
available_dashs -=1
|
||||
dashing = true
|
||||
dash_fart.emit()
|
||||
var axis_x = Input.get_axis(
|
||||
"move_left" + action_suffix,
|
||||
"move_right" + action_suffix
|
||||
@@ -521,9 +524,12 @@ func _physics_process(_delta: float) -> void:
|
||||
move_and_handle_collisions()
|
||||
play_animation()
|
||||
|
||||
func you_got_cheese() -> void:
|
||||
cheese_collected.emit()
|
||||
|
||||
func reload_fart() -> void:
|
||||
available_dashs = min(available_dashs+1, MAX_FARTS)
|
||||
Input.start_joy_vibration(0, 0, 1, 0.1)
|
||||
Input.start_joy_vibration(0, 0, 1, 0.2)
|
||||
|
||||
func death() -> void:
|
||||
if not dead:
|
||||
|
||||
@@ -313,5 +313,4 @@ energy = 0.4
|
||||
texture = SubResource("GradientTexture2D_irtut")
|
||||
texture_scale = 1.29
|
||||
|
||||
[connection signal="cheese_collected" from="." to="." method="reload_fart"]
|
||||
[connection signal="animation_finished" from="Death player" to="." method="_on_death_player_animation_finished"]
|
||||
|
||||
Reference in New Issue
Block a user