Init Tambour
This commit is contained in:
parent
5cf819a4ba
commit
b5a9a54f94
15 changed files with 370 additions and 21 deletions
|
@ -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
|
||||
|
|
|
@ -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é.")
|
||||
|
|
20
scripts/Instrument/onde.gd
Normal file
20
scripts/Instrument/onde.gd
Normal 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()
|
Loading…
Add table
Add a link
Reference in a new issue