changement fonctionnement balles

This commit is contained in:
Mylloon 2021-04-07 18:15:41 +02:00
parent 9a0f4ff13d
commit f01362e4d1
3 changed files with 26 additions and 18 deletions

View file

@ -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://images/balle.png" type="Texture" id=1]
[ext_resource path="res://scripts/Balle.gd" type="Script" id=2]
[sub_resource type="RectangleShape2D" id=1] [sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 2, 0.5 ) 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="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2( -2, 0 ) shape = SubResource( 2 )
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="Sprite" type="Sprite" parent="."] [node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 1 ) texture = ExtResource( 1 )
[connection signal="body_entered" from="." to="." method="_on_Area2D_body_entered"]

16
scripts/Balle.gd Normal file
View file

@ -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()

View file

@ -1,7 +1,6 @@
extends KinematicBody2D extends KinematicBody2D
var vitesseDeplacement = 500 var vitesseDeplacement = 500
var vitesseBalle = 2000
var balle = preload("res://scenes/Balle.tscn") var balle = preload("res://scenes/Balle.tscn")
@ -31,11 +30,10 @@ func tir():
var objectBalle = balle.instance() # création object balle var objectBalle = balle.instance() # création object balle
objectBalle.position = get_global_position() # récupération de la position objectBalle.position = get_global_position() # récupération de la position
objectBalle.rotation_degrees = rotation_degrees # récupération du degré de rotation 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 get_tree().get_root().call_deferred("add_child", objectBalle) # ajout de la balle
func mort(): func mort():
get_tree().reload_current_scene() get_tree().reload_current_scene() # reccomence au début
func _on_Area2D_body_entered(body): func _on_Area2D_body_entered(body):
if "Ennemi" in body.name: # collision avec l'ennemi if "Ennemi" in body.name: # collision avec l'ennemi