37 lines
1.1 KiB
GDScript
37 lines
1.1 KiB
GDScript
extends RigidBody2D
|
|
|
|
@export var player : Player
|
|
|
|
@onready var dirmodule: DirModule = $dirmodule
|
|
@onready var shootmodule: ShootModule = $shootmodule
|
|
|
|
@onready var thruster: Thruster = $thruster
|
|
|
|
@export var thrust: float = 0.3
|
|
|
|
func _ready() -> void:
|
|
player.radar.declare_threat(self)
|
|
func _exit_tree() -> void:
|
|
player.radar.release_threat(self)
|
|
|
|
func _physics_process(_delta: float) -> void:
|
|
if player == null:
|
|
print("no target for enemy!")
|
|
return
|
|
|
|
dirmodule.active = true
|
|
dirmodule.target_position = player.global_position - 2.0 * linear_velocity.project((global_position-player.global_position).normalized().rotated(PI/2))
|
|
var diff : float = Vector2.UP.rotated(global_rotation).dot((global_position - dirmodule.target_position).normalized())
|
|
|
|
if diff < -0.3:
|
|
apply_central_impulse(thrust * Vector2.UP.rotated(global_rotation))
|
|
thruster.active = true
|
|
else:
|
|
thruster.active = false
|
|
|
|
if diff < -0.9 && not $animations.is_playing() && shootmodule.can_shoot:
|
|
$animations.play("shoot")
|
|
player.radar.declare_danger(self)
|
|
|
|
func done_shooting() -> void:
|
|
player.radar.release_danger(self)
|