fx: input extracted to own node
This commit is contained in:
@@ -23,8 +23,6 @@ var healthPoints: int = 100
|
||||
var isAlive: bool = true
|
||||
@onready var invulnerable_cooldown_timer: Timer = $InvulnerableCooldownTimer
|
||||
var hasiframes: bool = false # only used for iframe after collision for now
|
||||
var target = Vector2.ZERO # either vector2 or Node2D
|
||||
var updating_target: bool = false # TODO: overhaul; make own node/script and actually expand logic properly
|
||||
|
||||
func _ready() -> void:
|
||||
var screen_size = get_viewport_rect().size
|
||||
@@ -37,27 +35,14 @@ func _ready() -> void:
|
||||
sprite.play("default")
|
||||
|
||||
|
||||
func _input(event):
|
||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
|
||||
if event.pressed:
|
||||
# start tracking
|
||||
target = get_global_mouse_position()
|
||||
updating_target = true
|
||||
else:
|
||||
# stop tracking
|
||||
updating_target = false
|
||||
func set_target(target) -> void:
|
||||
$Input.target = target
|
||||
|
||||
func _physics_process(delta):
|
||||
var pos
|
||||
if typeof(target) == TYPE_VECTOR2:
|
||||
pos = target
|
||||
elif "position" in target:
|
||||
pos = target.position
|
||||
else:
|
||||
return
|
||||
var dir: Vector2 = position.direction_to(pos)
|
||||
var target_pos = $Input.get_target_position()
|
||||
var dir: Vector2 = position.direction_to(target_pos)
|
||||
|
||||
if position.distance_to(pos) > 2:
|
||||
if position.distance_to(target_pos) > 2:
|
||||
self.desired_rotation = atan2(dir.y, dir.x)
|
||||
move_and_collide(speed * dir * delta)
|
||||
position = GameManager.get_boundaried_position(position)
|
||||
@@ -72,9 +57,6 @@ func _process(delta):
|
||||
if self.rotation != self.desired_rotation:
|
||||
self.rotation = lerp_angle(self.rotation, self.desired_rotation, clampf(4 * delta, 0, 1))
|
||||
|
||||
if typeof(target) == TYPE_VECTOR2 and updating_target:
|
||||
target = get_global_mouse_position()
|
||||
|
||||
|
||||
func try_attack() -> void:
|
||||
if not can_attack:
|
||||
|
||||
Reference in New Issue
Block a user