This repository has been archived on 2022-03-31. You can view files and clone it, but cannot push or open issues or pull requests.
Tyra/scripts/Balle.gd

23 lines
798 B
GDScript3
Raw Permalink Normal View History

2021-04-07 18:15:41 +02:00
extends Area2D
2021-04-08 19:06:14 +02:00
var vitesseBalle = 700 # vitesse de la balle
2021-04-07 18:15:41 +02:00
2021-04-08 13:55:24 +02:00
var sonMortEnnemi = preload("res://scenes/SonMortEnnemi.tscn") # récupération Son
2021-04-07 18:15:41 +02:00
func _ready():
pass
2021-04-08 03:02:23 +02:00
func _physics_process(delta): # déplacement de la balle
2021-04-07 18:15:41 +02:00
position += transform.x * vitesseBalle * delta
func _on_Area2D_body_entered(body):
2021-04-08 03:02:23 +02:00
if "Murs" in body.name: # supprime la balle quand elle percute un mur
2021-04-07 18:15:41 +02:00
queue_free()
2021-04-08 19:06:14 +02:00
if "Ennemi" in body.name: # quand le joueur touche qq1
queue_free() # supprime l'ennemi
2021-04-08 13:55:24 +02:00
var son = sonMortEnnemi.instance() # création object son
son.position = get_global_position() # récupération de la position
get_tree().get_root().call_deferred("add_child", son) # ajout du son
2021-04-08 19:06:14 +02:00
global.ennemisTues += 1 # ajoute un ennemi tuer au compteur
body.queue_free() # supprime aussi la balle