balle tout droit
This commit is contained in:
parent
f10063de24
commit
a01f4fc93c
9 changed files with 123 additions and 25 deletions
28
scripts/Instrument/Flute.gd
Normal file
28
scripts/Instrument/Flute.gd
Normal file
|
@ -0,0 +1,28 @@
|
|||
class_name Flute
|
||||
|
||||
var scene_node = null
|
||||
|
||||
func set_scene_parent(node: Node) -> void:
|
||||
scene_node = node
|
||||
|
||||
|
||||
|
||||
func jouer_melodie(player_position, direction_balle, angle) -> void:
|
||||
spawn_balle(player_position, direction_balle, angle)
|
||||
|
||||
|
||||
func spawn_balle(player_position, direction_balle, angle) -> 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()
|
||||
if balle:
|
||||
balle.position = player_position
|
||||
balle.initial_direction = direction_balle
|
||||
balle.rotation = deg_to_rad(angle)
|
||||
scene_node.add_child(balle)
|
||||
|
||||
|
||||
else:
|
||||
print("Erreur : la création de la balle a échoué.")
|
5
scripts/Instrument/Tambour.gd
Normal file
5
scripts/Instrument/Tambour.gd
Normal file
|
@ -0,0 +1,5 @@
|
|||
class_name Tambour
|
||||
|
||||
|
||||
func faire_roulement() -> void:
|
||||
print("Le tambour fait un roulement.")
|
20
scripts/Instrument/balle.gd
Normal file
20
scripts/Instrument/balle.gd
Normal file
|
@ -0,0 +1,20 @@
|
|||
extends CharacterBody2D
|
||||
|
||||
@export var speed: float = 400 # 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
|
||||
|
||||
func _ready() -> void:
|
||||
# Configurer la vitesse sur l'axe désiré
|
||||
velocity = initial_direction * speed # Multiplie la direction initiale par la vitesse
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
move_and_collide(velocity * delta)
|
||||
if raycast.is_colliding():
|
||||
queue_free()
|
||||
|
||||
|
|
@ -9,7 +9,9 @@ var boost_speed = 0
|
|||
var flute = null
|
||||
|
||||
func _ready() -> void:
|
||||
flute = load("res://Instrument/Flute.gd").new()
|
||||
flute = load("res://scripts/Instrument/Flute.gd").new()
|
||||
flute.set_scene_parent(get_tree().get_root())
|
||||
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
|
@ -22,7 +24,7 @@ func _process(delta: float) -> void:
|
|||
|
||||
|
||||
if direction != Vector2.ZERO:
|
||||
if direction.normalized() == previous_direction.normalized():
|
||||
if direction == previous_direction:
|
||||
if direction.x != 0 and direction.y != 0:
|
||||
boost_speed = min(boost_speed + acceleration / 16, (max_boost_speed - move_speed) / 8)
|
||||
else:
|
||||
|
@ -33,6 +35,21 @@ func _process(delta: float) -> void:
|
|||
previous_direction = direction
|
||||
velocity = direction * (move_speed + boost_speed)
|
||||
|
||||
if Input.is_action_just_pressed("JOUER_MUSIQUE"):
|
||||
flute.jouer_melodie(position)
|
||||
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"):
|
||||
var direction_balle = Vector2.ZERO
|
||||
var angle = 0
|
||||
if Input.is_action_just_pressed("JOUER_MUSIQUE_HAUT"):
|
||||
direction_balle = Vector2(0, -1)
|
||||
angle = 180
|
||||
elif Input.is_action_just_pressed("JOUER_MUSIQUE_BAS"):
|
||||
direction_balle = Vector2(0, 1)
|
||||
angle = 0
|
||||
elif Input.is_action_just_pressed("JOUER_MUSIQUE_DROITE"):
|
||||
direction_balle = Vector2(1, 0)
|
||||
angle = 270
|
||||
elif Input.is_action_just_pressed("JOUER_MUSIQUE_GAUCHE"):
|
||||
direction_balle = Vector2(-1, 0)
|
||||
angle = 90
|
||||
|
||||
flute.jouer_melodie(position, direction_balle, angle)
|
||||
pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue