Browse Source

:tada: Implemente le champ de la balle electrique

DricomDragon 8 months ago
parent
commit
968bff57f1

+ 29 - 1
godot/composants/objets/balle/balle_elec/balle_electrique.gd

@@ -1,20 +1,42 @@
 class_name BalleElectrique
 extends Balle
+# Balle electrique qui fait des degats a distance quand chargee
 
 
+signal charge
+signal decharge
+
 const BalleElectriqueScene: PackedScene = preload("res://composants/objets/balle/balle_elec/balle_electrique.tscn")
 const duree_clignotement_max: float = 0.05 # sec
 
 var _duree_clignotement: float = 0.0
 var surchargee: bool = true # vrai si l'electricite deborde
 
-@onready var image: Sprite2D = $Image
+@onready var image: Sprite2D = $ImageSurcharge
 
 
 func _process(delta: float) -> void:
 	_clignoter(delta)
 
 
+func electrise(brique: Brique) -> void:
+	assert(surchargee, "Ne peut pas electriser si non chargee")
+	brique.frapper(1)
+	decharge.emit()
+	surchargee = false
+
+
+func recharge() -> void:
+	charge.emit()
+	surchargee = true
+
+
+## La balle electrique se recharge au contact de la raquette
+func _mettre_en_mouvement(dir: Vector2) -> void:
+	super._mettre_en_mouvement(dir)
+	recharge()
+
+
 func _clignoter(delta: float) -> void:
 	if not surchargee:
 		return
@@ -44,3 +66,9 @@ static func transformer(balle: Balle) -> void:
 	balle.add_sibling.call_deferred(balle_elec) # Appeler plus tard sinon Godot pas content
 	balle_elec.recopier(balle)
 	balle.queue_free()
+
+
+func _quand_champ_electrique_detecte_coprs(body: Node2D) -> void:
+	print(body, " dans champ electrique")
+	if surchargee and body is Brique:
+		electrise(body)

+ 26 - 2
godot/composants/objets/balle/balle_elec/balle_electrique.tscn

@@ -1,11 +1,15 @@
-[gd_scene load_steps=4 format=3 uid="uid://crpfyx6e5kn45"]
+[gd_scene load_steps=6 format=3 uid="uid://crpfyx6e5kn45"]
 
 [ext_resource type="Script" path="res://composants/objets/balle/balle_elec/balle_electrique.gd" id="1_fuild"]
 [ext_resource type="Texture2D" uid="uid://blttr4e575gkk" path="res://composants/objets/balle/balle_elec/09.png" id="2_rvm4r"]
+[ext_resource type="Texture2D" uid="uid://86sugnk085c1" path="res://composants/objets/balle/balle_elec/10.png" id="3_r4arp"]
 
 [sub_resource type="CircleShape2D" id="CircleShape2D_lab73"]
 radius = 5.42
 
+[sub_resource type="CircleShape2D" id="CircleShape2D_cg8wg"]
+radius = 13.0
+
 [node name="BalleElectrique" type="CharacterBody2D" groups=["groupe_des_balles"]]
 collision_mask = 22
 motion_mode = 1
@@ -14,9 +18,29 @@ platform_floor_layers = 2
 platform_wall_layers = 4
 script = ExtResource("1_fuild")
 
-[node name="Image" type="Sprite2D" parent="."]
+[node name="ImageSurcharge" type="Sprite2D" parent="."]
 position = Vector2(-3, 0)
 texture = ExtResource("2_rvm4r")
 
+[node name="ImageStatique" type="Sprite2D" parent="."]
+visible = false
+position = Vector2(-3, 0)
+texture = ExtResource("3_r4arp")
+
 [node name="Forme" type="CollisionShape2D" parent="."]
 shape = SubResource("CircleShape2D_lab73")
+
+[node name="ChampElectrique" type="Area2D" parent="."]
+collision_mask = 16
+
+[node name="PorteeChamp" type="CollisionShape2D" parent="ChampElectrique"]
+shape = SubResource("CircleShape2D_cg8wg")
+debug_color = Color(1, 0.6, 0.701961, 0.419608)
+
+[connection signal="charge" from="." to="ImageSurcharge" method="show"]
+[connection signal="charge" from="." to="ImageStatique" method="hide"]
+[connection signal="charge" from="." to="ChampElectrique" method="set_monitoring" binds= [true]]
+[connection signal="decharge" from="." to="ImageSurcharge" method="hide"]
+[connection signal="decharge" from="." to="ImageStatique" method="show"]
+[connection signal="decharge" from="." to="ChampElectrique" method="set_monitoring" binds= [false]]
+[connection signal="body_entered" from="ChampElectrique" to="." method="_quand_champ_electrique_detecte_coprs"]