ft: switch to click movement

This commit is contained in:
2026-03-07 14:33:22 +01:00
parent a59255d9d6
commit 01f1b52086
9 changed files with 50 additions and 19 deletions

View File

@@ -23,6 +23,7 @@ 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
func _ready() -> void:
var screen_size = get_viewport_rect().size
@@ -35,31 +36,37 @@ func _ready() -> void:
sprite.play("default")
func _input(event):
# TODO: only does clicks/taps; accept mouse drags
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
target = get_global_mouse_position()
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)
if position.distance_to(pos) > 2:
self.desired_rotation = atan2(dir.y, dir.x)
move_and_collide(speed * dir * delta)
position = GameManager.get_boundaried_position(position)
func _process(delta):
if isAlive:
velocity = Vector2.ZERO
if Input.is_action_pressed("move_right"):
velocity.x += 1
if Input.is_action_pressed("move_left"):
velocity.x -= 1
if Input.is_action_pressed("move_down"):
velocity.y += 1
if Input.is_action_pressed("move_up"):
velocity.y -= 1
if Input.is_action_pressed("try_attack"):
try_attack()
if not velocity.is_zero_approx():
self.desired_rotation = atan2(velocity.y, velocity.x)
# smoothly rotate
if self.rotation != self.desired_rotation:
self.rotation = lerp_angle(self.rotation, self.desired_rotation, clampf(4 * delta, 0, 1))
move_and_collide(speed * velocity * delta)
position = GameManager.get_boundaried_position(position)
func try_attack() -> void:
if not can_attack:
return