Init Tambour

This commit is contained in:
Elouan 2025-01-24 18:45:09 +01:00
parent 5cf819a4ba
commit b5a9a54f94
15 changed files with 370 additions and 21 deletions

View file

@ -1,28 +1,66 @@
class_name Flute
var scene_node = null
var balle_scenes = [
preload("res://scenes/attaques/Balle1.tscn"),
preload("res://scenes/attaques/Balle2.tscn"),
preload("res://scenes/attaques/Balle3.tscn")
]
var current_balle_index = 0
@export var cooldown = 0.15 # Durée du cooldown en secondes
var is_on_cooldown = false # Indique si le cooldown est en cours
func set_scene_parent(node: Node) -> void:
scene_node = node
# Si scene_node est défini pour la première fois, on ajoute un Timer
if not scene_node.has_node("TirCooldownTimer"):
var cooldown_timer = Timer.new()
cooldown_timer.name = "TirCooldownTimer"
cooldown_timer.one_shot = true
cooldown_timer.wait_time = cooldown
cooldown_timer.connect("timeout", Callable(self, "_on_cooldown_timeout"))
scene_node.add_child(cooldown_timer)
func jouer_melodie(player_position, direction_balle, angle) -> void:
spawn_balle(player_position, direction_balle, angle)
func _process(delta) -> void:
pass # Cette fonction est requise pour que delta fonctionne correctement
func spawn_balle(player_position, direction_balle, angle) -> void:
func jouer_melodie(player_position: Vector2, direction_balle: Vector2, angle: float) -> void:
if not is_on_cooldown: # Vérifiez si nous pouvons tirer
spawn_balle(player_position, direction_balle, angle)
func spawn_balle(player_position: Vector2, direction_balle: Vector2, angle: float) -> void:
if scene_node == null:
print("Erreur : Aucun nœud parent défini pour ajouter la balle.")
return
var balle = preload("res://scenes/attaques/Balle.tscn").instantiate()
var current_balle_scene = balle_scenes[current_balle_index]
var balle = current_balle_scene.instantiate()
if balle:
balle.position = player_position
balle.position = player_position
balle.initial_direction = direction_balle
balle.rotation = deg_to_rad(angle)
scene_node.add_child(balle)
# Basculer vers la prochaine balle pour le prochain tir
current_balle_index = (current_balle_index + 1) % len(balle_scenes)
# Démarrez le cooldown après ce tir
start_cooldown()
else:
print("Erreur : la création de la balle a échoué.")
# Démarrer le timer pour le cooldown
func start_cooldown() -> void:
is_on_cooldown = true
var cooldown_timer = scene_node.get_node("TirCooldownTimer")
cooldown_timer.start()
func _on_cooldown_timeout() -> void:
is_on_cooldown = false # Réinitialisez l'état de cooldown après expiration du Timer

View file

@ -1,5 +1,55 @@
class_name Tambour
var scene_node = null
@export var cooldown = 0.9 # Durée du cooldown en secondes
var is_on_cooldown = false # Indique si le cooldown est actif
func faire_roulement() -> void:
print("Le tambour fait un roulement.")
func set_scene_parent(node: Node) -> void:
scene_node = node
# Si scene_node est défini pour la première fois, on ajoute un Timer
if not scene_node.has_node("TambourCooldownTimer2"): # Changement du nom du Timer unique pour le Tambour
var cooldown_timer = Timer.new()
cooldown_timer.name = "TambourCooldownTimer2" # Nom unique pour éviter les conflits
cooldown_timer.one_shot = true
cooldown_timer.wait_time = cooldown
cooldown_timer.connect("timeout", Callable(self, "_on_cooldown_timeout"))
scene_node.add_child(cooldown_timer)
func jouer_melodie(player_position: Vector2) -> void:
if not is_on_cooldown: # Vérifiez si nous sommes en cooldown
spawn_onde(player_position)
func spawn_onde(player_position: Vector2) -> void:
if scene_node == null:
print("Erreur : Aucun nœud parent défini pour ajouter l'onde.")
return
var onde_scene = preload("res://scenes/attaques/Onde.tscn") # Chargez la scène de l'onde
var onde = onde_scene.instantiate()
if onde:
onde.position = player_position
scene_node.add_child(onde)
# Démarrez le cooldown après avoir ajouté l'onde
start_cooldown()
else:
print("Erreur : Impossible de créer l'onde.")
# Démarrer le Timer pour le cooldown
func start_cooldown() -> void:
is_on_cooldown = true
var cooldown_timer = scene_node.get_node("TambourCooldownTimer2") # Assurez-vous que le Timer est bien trouvé
if cooldown_timer:
cooldown_timer.start()
else:
print("Erreur : Timer introuvable.")
func _on_cooldown_timeout() -> void:
is_on_cooldown = false # Réinitialiser le cooldown lorsque le Timer se termine
print("Cooldown terminé.")

View file

@ -0,0 +1,20 @@
extends CharacterBody2D
var cooldown_timer = null
func _process(delta: float) -> void:
if cooldown_timer == null:
cooldown_timer = Timer.new()
cooldown_timer.name = "OndeCooldownTimer"
cooldown_timer.one_shot = true
cooldown_timer.connect("timeout", Callable(self, "_on_cooldown_timeout"))
get_tree().root.add_child(cooldown_timer)
# Démarrer le timer pour le cooldown
func start_cooldown() -> void:
cooldown_timer.start()
func _on_cooldown_timeout() -> void:
cooldown_timer.queue_free()
cooldown_timer = null
queue_free()

View file

@ -6,11 +6,20 @@ const max_boost_speed = 800
var previous_direction = Vector2.ZERO
var boost_speed = 0
var flute = null
var tambour = null
# Slot actif (0 = Flûte, 1 = Tambour)
var active_slot = 0
func _ready() -> void:
flute = load("res://scripts/Instrument/Flute.gd").new()
flute.set_scene_parent(get_tree().get_root())
tambour = load("res://scripts/Instrument/Tambour.gd").new()
tambour.set_scene_parent(get_tree().get_root())
@ -35,21 +44,28 @@ func _process(delta: float) -> void:
previous_direction = direction
velocity = direction * (move_speed + boost_speed)
if Input.is_action_just_pressed("JOUER_MUSIQUE_HAUT") or Input.is_action_just_pressed("JOUER_MUSIQUE_BAS") or Input.is_action_just_pressed("JOUER_MUSIQUE_DROITE") or Input.is_action_just_pressed("JOUER_MUSIQUE_GAUCHE"):
if Input.is_action_just_pressed("CHANGER_SLOT"):
active_slot = (active_slot + 1) % 2
if Input.is_action_pressed("JOUER_MUSIQUE_HAUT") or Input.is_action_pressed("JOUER_MUSIQUE_BAS") or Input.is_action_pressed("JOUER_MUSIQUE_DROITE") or Input.is_action_pressed("JOUER_MUSIQUE_GAUCHE"):
var direction_balle = Vector2.ZERO
var angle = 0
if Input.is_action_just_pressed("JOUER_MUSIQUE_HAUT"):
if Input.is_action_pressed("JOUER_MUSIQUE_HAUT"):
direction_balle = Vector2(0, -1)
angle = 180
elif Input.is_action_just_pressed("JOUER_MUSIQUE_BAS"):
elif Input.is_action_pressed("JOUER_MUSIQUE_BAS"):
direction_balle = Vector2(0, 1)
angle = 0
elif Input.is_action_just_pressed("JOUER_MUSIQUE_DROITE"):
elif Input.is_action_pressed("JOUER_MUSIQUE_DROITE"):
direction_balle = Vector2(1, 0)
angle = 270
elif Input.is_action_just_pressed("JOUER_MUSIQUE_GAUCHE"):
elif Input.is_action_pressed("JOUER_MUSIQUE_GAUCHE"):
direction_balle = Vector2(-1, 0)
angle = 90
flute.jouer_melodie(position, direction_balle, angle)
if active_slot == 0: # Slot Flûte
flute.jouer_melodie(position, direction_balle, angle)
elif active_slot == 1: # Slot Tambour
tambour.jouer_melodie(position)
pass