25 lines
675 B
GDScript
25 lines
675 B
GDScript
extends Area2D
|
|
|
|
signal shooted
|
|
@export var bullet: PackedScene
|
|
@onready var timer: Timer = %Timer
|
|
var is_shooting := false
|
|
|
|
func _physics_process(_delta: float) -> void:
|
|
var enemies_in_range = get_overlapping_bodies()
|
|
is_shooting = enemies_in_range.size() > 0
|
|
if is_shooting:
|
|
var target = enemies_in_range.front()
|
|
look_at(target.global_position)
|
|
|
|
func shoot() -> void:
|
|
if is_shooting:
|
|
var new_bullet = bullet.instantiate()
|
|
new_bullet.global_position = %ShootingPoint.global_position
|
|
new_bullet.global_rotation = %ShootingPoint.global_rotation
|
|
%ShootingPoint.add_child(new_bullet)
|
|
shooted.emit()
|
|
|
|
func _on_player_level_up() -> void:
|
|
timer.wait_time *= 0.95
|