Browse Source

Get ready again when every bullet is down

DricomDragon 3 năm trước cách đây
mục cha
commit
718e285c3d
2 tập tin đã thay đổi với 17 bổ sung1 xóa
  1. 1 1
      godot/scripts/Catcher.gd
  2. 16 0
      godot/scripts/Launcher.gd

+ 1 - 1
godot/scripts/Catcher.gd

@@ -6,4 +6,4 @@ signal kace_catch
 func _on_Catcher_body_entered(body):
 	if (body.is_in_group("ball")):
 		body.queue_free()
-	emit_signal("kace_catch")
+		emit_signal("kace_catch")

+ 16 - 0
godot/scripts/Launcher.gd

@@ -13,6 +13,7 @@ const BULLET_SPEED = 200.0
 var _ballScene = preload("res://scenes/Ball.tscn")
 
 var nbAmmo = 5
+var nbStorage = 0
 
 onready var target = $Target
 onready var source = $Source
@@ -39,6 +40,11 @@ func shoot():
 		bullet.linear_velocity = (target.position - source.position).normalized()
 		bullet.linear_velocity *= BULLET_SPEED
 		add_child(bullet)
+		bullet.connect("tree_exited", self, "_on_Ball_tree_exited")
+
+
+func loadBullet(n:int):
+	nbStorage += 1
 
 
 func _on_ShootDelay_timeout():
@@ -52,3 +58,13 @@ func _on_ShootDelay_timeout():
 
 func _on_Launcher_get_firing():
 	shootDelay.start()
+
+
+func _on_Ball_tree_exited():
+	loadBullet(1)
+	print(get_tree().get_nodes_in_group("ball").size())
+	if (get_tree().get_nodes_in_group("ball").size() == 0):
+		current_state = State.READY
+		target.position = source.position
+		nbAmmo = nbStorage
+		nbStorage = 0