Added enemy movement
This commit is contained in:
@@ -1,11 +1,27 @@
|
||||
class_name EnemyController
|
||||
extends Node
|
||||
|
||||
|
||||
signal accelerate(direction: Vector2, delta: float)
|
||||
signal shoot(weapon_index: int)
|
||||
signal shoot()
|
||||
|
||||
|
||||
@export var ship: AbstractEnemyShip
|
||||
|
||||
|
||||
var target_position : Vector2
|
||||
var direction : Vector2
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
for i in 10:
|
||||
shoot.emit(i)
|
||||
accelerate.emit(Vector2.ZERO, delta)
|
||||
if ship.is_on_screen:
|
||||
shoot.emit()
|
||||
accelerate.emit(direction, delta)
|
||||
|
||||
|
||||
func _on_direction_timer_timeout() -> void:
|
||||
direction = get_acceleration_direction()
|
||||
|
||||
|
||||
func get_acceleration_direction() -> Vector2:
|
||||
return (target_position - ship.position).normalized()
|
||||
|
||||
@@ -4,3 +4,10 @@
|
||||
|
||||
[node name="EnemyController" type="Node"]
|
||||
script = ExtResource("1_10a67")
|
||||
|
||||
[node name="DirectionTimer" type="Timer" parent="."]
|
||||
process_callback = 0
|
||||
wait_time = 0.25
|
||||
autostart = true
|
||||
|
||||
[connection signal="timeout" from="DirectionTimer" to="." method="_on_direction_timer_timeout"]
|
||||
|
||||
@@ -7,14 +7,16 @@ signal accelerate(direction: Vector2, delta: float)
|
||||
signal shoot(weapon_index: int)
|
||||
|
||||
|
||||
const WEAPON_ACTIONS := {
|
||||
0: "shoot_weapon_1",
|
||||
1: "shoot_weapon_2",
|
||||
}
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
var input_direction := Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
accelerate.emit(input_direction, delta)
|
||||
|
||||
var weapon_actions := {
|
||||
0: "shoot_weapon_1",
|
||||
1: "shoot_weapon_2",
|
||||
}
|
||||
for index : int in weapon_actions:
|
||||
if Input.is_action_pressed(weapon_actions[index]):
|
||||
for index : int in WEAPON_ACTIONS:
|
||||
if Input.is_action_pressed(WEAPON_ACTIONS[index]):
|
||||
shoot.emit(index)
|
||||
|
||||
Reference in New Issue
Block a user