|
@@ -1,6 +1,6 @@
|
|
|
+class_name Launcher
|
|
|
extends Node2D
|
|
|
|
|
|
-export (float) var visor_ratio = 1.0
|
|
|
|
|
|
signal get_firing
|
|
|
signal is_full
|
|
@@ -8,6 +8,7 @@ signal gain_new_bullet
|
|
|
signal interrupt_wave
|
|
|
signal move_visor
|
|
|
|
|
|
+
|
|
|
enum State {
|
|
|
READY,
|
|
|
FIRING,
|
|
@@ -16,43 +17,47 @@ enum State {
|
|
|
DEAD
|
|
|
}
|
|
|
|
|
|
-export var BULLET_SPEED = 500.0
|
|
|
|
|
|
const visor_min_heigth = 10
|
|
|
const visor_start_shift = Vector2(0, -visor_min_heigth)
|
|
|
|
|
|
-var _ballScene = preload("res://component/entity/ball/Ball.tscn")
|
|
|
+const Ball = preload("res://component/entity/ball/Ball.tscn")
|
|
|
+
|
|
|
+
|
|
|
+export (float) var bullet_speed = 500.0
|
|
|
+export (float) var visor_ratio = 1.0
|
|
|
+
|
|
|
+
|
|
|
+var nbAmmo := 0
|
|
|
+var nbStorage := 1
|
|
|
+var current_state = State.WAITING
|
|
|
|
|
|
-var nbAmmo = 0
|
|
|
-var nbStorage = 1
|
|
|
|
|
|
onready var target = $TargetLine
|
|
|
onready var visor = $TargetLine/TargetVisor
|
|
|
onready var source = $Source
|
|
|
onready var shootDelay = $ShootDelay
|
|
|
|
|
|
-onready var current_state = State.WAITING
|
|
|
-
|
|
|
|
|
|
-func _ready():
|
|
|
+func _ready() -> void:
|
|
|
get_ready()
|
|
|
|
|
|
|
|
|
-func _input(event):
|
|
|
- if event is InputEventMouseButton and event.is_pressed() :
|
|
|
+func _input(event: InputEvent) -> void:
|
|
|
+ if event is InputEventMouseButton and event.is_pressed():
|
|
|
trigger(event.position)
|
|
|
elif event is InputEventMouseMotion and current_state == State.READY:
|
|
|
aim_at(event.position)
|
|
|
|
|
|
|
|
|
-func aim_at(cursor:Vector2):
|
|
|
+func aim_at(cursor: Vector2) -> void:
|
|
|
var visor_pos = (cursor - source.position) * visor_ratio
|
|
|
if abs(visor_pos.y) > visor_min_heigth:
|
|
|
visor.position = visor_pos
|
|
|
emit_signal("move_visor")
|
|
|
|
|
|
|
|
|
-func trigger(aim:Vector2):
|
|
|
+func trigger(aim: Vector2) -> void:
|
|
|
if (current_state == State.READY):
|
|
|
current_state = State.FIRING
|
|
|
emit_signal("get_firing")
|
|
@@ -61,42 +66,42 @@ func trigger(aim:Vector2):
|
|
|
emit_signal("interrupt_wave")
|
|
|
|
|
|
|
|
|
-func shoot():
|
|
|
- var bullet = _ballScene.instance()
|
|
|
+func shoot() -> void:
|
|
|
+ var bullet = Ball.instance()
|
|
|
bullet.position = source.position
|
|
|
bullet.linear_velocity = (target.get_visor_pos() - source.position).normalized()
|
|
|
- bullet.linear_velocity *= BULLET_SPEED
|
|
|
+ bullet.linear_velocity *= bullet_speed
|
|
|
add_child(bullet)
|
|
|
bullet.connect("tree_exited", self, "_on_Ball_tree_exited")
|
|
|
self.connect("interrupt_wave", bullet, "_on_Launcher_interrupt_wave")
|
|
|
|
|
|
|
|
|
-func gain_new_bullet():
|
|
|
+func gain_new_bullet() -> void:
|
|
|
load_bullet(1)
|
|
|
emit_signal("gain_new_bullet")
|
|
|
|
|
|
|
|
|
-func load_bullet(n:int):
|
|
|
+func load_bullet(n: int) -> void:
|
|
|
nbStorage += n
|
|
|
|
|
|
|
|
|
-func end_of_round():
|
|
|
+func end_of_round() -> void:
|
|
|
if (current_state != State.DEAD):
|
|
|
get_ready()
|
|
|
|
|
|
|
|
|
-func get_ready():
|
|
|
+func get_ready() -> void:
|
|
|
current_state = State.READY
|
|
|
target.set_visor_pos(source.position + visor_start_shift)
|
|
|
nbAmmo = nbStorage
|
|
|
nbStorage = 0
|
|
|
|
|
|
|
|
|
-func die():
|
|
|
+func die() -> void:
|
|
|
current_state = State.DEAD
|
|
|
|
|
|
|
|
|
-func _on_ShootDelay_timeout():
|
|
|
+func _on_ShootDelay_timeout() -> void:
|
|
|
shoot()
|
|
|
nbAmmo -= 1
|
|
|
if (nbAmmo <= 0):
|
|
@@ -105,11 +110,11 @@ func _on_ShootDelay_timeout():
|
|
|
emit_signal("get_firing")
|
|
|
|
|
|
|
|
|
-func _on_Launcher_get_firing():
|
|
|
+func _on_Launcher_get_firing() -> void:
|
|
|
shootDelay.start()
|
|
|
|
|
|
|
|
|
-func _on_Ball_tree_exited():
|
|
|
+func _on_Ball_tree_exited() -> void:
|
|
|
if get_tree() == null:
|
|
|
return # Game is exiting
|
|
|
|
|
@@ -118,13 +123,13 @@ func _on_Ball_tree_exited():
|
|
|
emit_signal("is_full")
|
|
|
|
|
|
|
|
|
-func _on_Grid_has_moved():
|
|
|
+func _on_Grid_has_moved() -> void:
|
|
|
end_of_round()
|
|
|
|
|
|
|
|
|
-func _on_Grid_kace_broken():
|
|
|
+func _on_Grid_kace_broken() -> void:
|
|
|
gain_new_bullet()
|
|
|
|
|
|
|
|
|
-func _on_DeadLine_game_lost():
|
|
|
+func _on_DeadLine_game_lost() -> void:
|
|
|
die()
|