From f01362e4d1a264caed09b8f5f9466a53a21e0835 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Wed, 7 Apr 2021 18:15:41 +0200 Subject: [PATCH] changement fonctionnement balles --- scenes/Balle.tscn | 24 +++++++++--------------- scripts/Balle.gd | 16 ++++++++++++++++ scripts/Joueur.gd | 4 +--- 3 files changed, 26 insertions(+), 18 deletions(-) create mode 100644 scripts/Balle.gd diff --git a/scenes/Balle.tscn b/scenes/Balle.tscn index 70db48d..2d50348 100644 --- a/scenes/Balle.tscn +++ b/scenes/Balle.tscn @@ -1,23 +1,17 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=4 format=2] [ext_resource path="res://images/balle.png" type="Texture" id=1] +[ext_resource path="res://scripts/Balle.gd" type="Script" id=2] -[sub_resource type="RectangleShape2D" id=1] -extents = Vector2( 2, 0.5 ) +[sub_resource type="RectangleShape2D" id=2] +extents = Vector2( 4, 1.5 ) -[node name="Balle" type="RigidBody2D"] +[node name="Area2D" type="Area2D"] +script = ExtResource( 2 ) -[node name="CollisionShape2D_devant" type="CollisionShape2D" parent="."] -position = Vector2( -2, 0 ) -shape = SubResource( 1 ) - -[node name="CollisionShape2D_haut" type="CollisionShape2D" parent="."] -position = Vector2( 2, -1 ) -shape = SubResource( 1 ) - -[node name="CollisionShape2D_bas" type="CollisionShape2D" parent="."] -position = Vector2( 2, 1 ) -shape = SubResource( 1 ) +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource( 2 ) [node name="Sprite" type="Sprite" parent="."] texture = ExtResource( 1 ) +[connection signal="body_entered" from="." to="." method="_on_Area2D_body_entered"] diff --git a/scripts/Balle.gd b/scripts/Balle.gd new file mode 100644 index 0000000..f36e72d --- /dev/null +++ b/scripts/Balle.gd @@ -0,0 +1,16 @@ +extends Area2D + +var vitesseBalle = 700 + +func _ready(): + pass + +func _physics_process(delta): + position += transform.x * vitesseBalle * delta + +func _on_Area2D_body_entered(body): + if "Murs" in body.name: + queue_free() + if "Ennemi" in body.name: + queue_free() + body.queue_free() diff --git a/scripts/Joueur.gd b/scripts/Joueur.gd index b08404f..ed9b687 100644 --- a/scripts/Joueur.gd +++ b/scripts/Joueur.gd @@ -1,7 +1,6 @@ extends KinematicBody2D var vitesseDeplacement = 500 -var vitesseBalle = 2000 var balle = preload("res://scenes/Balle.tscn") @@ -31,11 +30,10 @@ func tir(): var objectBalle = balle.instance() # création object balle objectBalle.position = get_global_position() # récupération de la position objectBalle.rotation_degrees = rotation_degrees # récupération du degré de rotation - objectBalle.apply_impulse(Vector2(), Vector2(vitesseBalle, 0).rotated(rotation)) # lancement de la balle get_tree().get_root().call_deferred("add_child", objectBalle) # ajout de la balle func mort(): - get_tree().reload_current_scene() + get_tree().reload_current_scene() # reccomence au début func _on_Area2D_body_entered(body): if "Ennemi" in body.name: # collision avec l'ennemi