Fix des timer attaque + ajout tableau slot attaque

This commit is contained in:
Elouan 2025-01-24 22:51:25 +01:00
parent e9952f4ec9
commit 4040779923
11 changed files with 155 additions and 106 deletions

View file

@ -15,14 +15,7 @@ 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 _process(delta) -> void:
@ -45,16 +38,3 @@ func spawn_balle(player_position: Vector2, direction_balle: Vector2, angle: floa
color_index = (1 +color_index)% len(color_list)
balle.get_node("Sprite2D").texture = color_list[color_index]
scene_node.add_child(balle)
# Démarrez le cooldown après ce tir
start_cooldown()
# 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

@ -0,0 +1,28 @@
class_name Lyre
var scene_node = null
func set_scene_parent(node: Node) -> void:
scene_node = node
func jouer_melodie(player_position: Vector2, direction_balles: Vector2, angle: float) -> void:
spawn_onde(player_position, direction_balles, angle)
func spawn_onde(player_position: Vector2, direction_balles: Vector2, angle: float) -> void:
if scene_node == null:
print("Erreur : Aucun nœud parent défini pour ajouter fusil.")
return
var fusil_scene = preload("res://scenes/attaques/FusilPompe.tscn")
var fusil = fusil_scene.instantiate()
if fusil:
fusil.position = player_position + direction_balles * 50
fusil.rotation = angle
scene_node.add_child(fusil)
else:
print("Erreur : Impossible de créer fusil.")

View file

@ -1,19 +1,12 @@
class_name Tambour
var scene_node = null
@export var cooldown = 0.9 # Durée du cooldown en secondes
@export var cooldown = 3 # Durée du cooldown en secondes
var is_on_cooldown = false # Indique si le cooldown est actif
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:
@ -27,29 +20,12 @@ func spawn_onde(player_position: Vector2) -> void:
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_scene = preload("res://scenes/attaques/Bombes.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

@ -1,7 +1,6 @@
extends Area2D
@export var speed: float = 300 # Définir la vitesse de la balle
@export var raycast: RayCast2D
# Direction initiale du mouvement
var initial_direction: Vector2 = Vector2(1, 0) # Exemple par défaut : vers la droite

View file

@ -0,0 +1,14 @@
extends Area2D
var timer = 0.0
var cooldown = 0.35
func _process(delta: float) -> void:
timer += delta
if timer >= cooldown:
queue_free()
func Collision(body: Node2D) -> void:
if body.is_in_group("Enemies") :
queue_free()

View file

@ -1,20 +1,14 @@
extends CharacterBody2D
extends Area2D
var cooldown_timer = null
var timer = 0.0
var cooldown = 1.5
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)
timer += delta
if timer >= cooldown:
queue_free()
# 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()
func Collision(body: Node2D) -> void:
if body.is_in_group("Enemies") :
queue_free()

View file

@ -9,20 +9,30 @@ var boost_speed = 0
var flute = null
var tambour = null
var lyre = null
# Slot actif (0 = Flûte, 1 = Tambour)
var active_slot = 0
var flute_timer = 0.0
var tambour_timer = 0.0
var lyre_timer = 0.0
var flute_timer = 0
var flute_cooldown = 0.5
var tambour_cooldown = 3.0
var lyre_cooldown = 1
var slot = [null, null]
func _ready() -> void:
flute = load("res://scripts/Instrument/Flute.gd").new()
flute.set_scene_parent(get_tree().get_root())
slot.append(flute)
tambour = load("res://scripts/Instrument/Tambour.gd").new()
tambour.set_scene_parent(get_tree().get_root())
lyre = load("res://scripts/Instrument/Lyre.gd").new()
lyre.set_scene_parent(get_tree().get_root())
slot.append(lyre)
func _physics_process(delta: float) -> void:
move_and_slide()
@ -32,7 +42,6 @@ func _process(delta: float) -> void:
direction.x = Input.get_action_raw_strength("BOUGER_DROITE") - Input.get_action_raw_strength("BOUGER_GAUCHE")
direction.y = Input.get_action_raw_strength("BOUGER_BAS") - Input.get_action_raw_strength("BOUGER_HAUT")
if direction != Vector2.ZERO:
if direction == previous_direction:
if direction.x != 0 and direction.y != 0:
@ -42,31 +51,51 @@ func _process(delta: float) -> void:
else:
boost_speed = 0
previous_direction = direction
velocity = direction * (move_speed + boost_speed)
if Input.is_action_just_pressed("CHANGER_SLOT"):
active_slot = (active_slot + 1) % 2
previous_direction = direction
velocity = direction * (move_speed + boost_speed)
else:
velocity = Vector2.ZERO
var direction_balle = Vector2.ZERO
var angle = 0
var angle_lyre = 0
if Input.is_action_pressed("JOUER_MUSIQUE_HAUT"):
direction_balle = Vector2(0, -1)
angle = 180
angle_lyre = 270
elif Input.is_action_pressed("JOUER_MUSIQUE_BAS"):
direction_balle = Vector2(0, 1)
angle = 0
angle_lyre = 90
elif Input.is_action_pressed("JOUER_MUSIQUE_DROITE"):
direction_balle = Vector2(1, 0)
angle = 270
elif Input.is_action_pressed("JOUER_MUSIQUE_GAUCHE"):
direction_balle = Vector2(-1, 0)
angle = 90
if direction_balle != Vector2.ZERO :
if active_slot == 0: # Slot Flûte
flute.jouer_melodie(position, direction_balle, angle)
elif active_slot == 1: # Slot Tambour
tambour.jouer_melodie(position)
angle_lyre = 180
if flute_timer > 0:
flute_timer -= delta
pass
if tambour_timer > 0:
tambour_timer -= delta
if lyre_timer > 0:
lyre_timer -= delta
if flute and flute_timer <= 0.0 and direction_balle != Vector2.ZERO:
flute.jouer_melodie(position, direction_balle, angle)
flute_timer = flute_cooldown
if tambour and tambour_timer <= 0.0 and direction_balle != Vector2.ZERO:
tambour.jouer_melodie(position)
tambour_timer = tambour_cooldown
if lyre and lyre_timer <= 0.0 and direction_balle != Vector2.ZERO:
lyre.jouer_melodie(position, direction_balle, angle_lyre)
lyre_timer = lyre_cooldown