ft: drag to move
This commit is contained in:
@@ -24,7 +24,7 @@ var isAlive: bool = true
|
|||||||
@onready var invulnerable_cooldown_timer: Timer = $InvulnerableCooldownTimer
|
@onready var invulnerable_cooldown_timer: Timer = $InvulnerableCooldownTimer
|
||||||
var hasiframes: bool = false # only used for iframe after collision for now
|
var hasiframes: bool = false # only used for iframe after collision for now
|
||||||
var target = Vector2.ZERO # either vector2 or Node2D
|
var target = Vector2.ZERO # either vector2 or Node2D
|
||||||
var updating_target: bool = false
|
var updating_target: bool = false # TODO: overhaul; make own node/script and actually expand logic properly
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
var screen_size = get_viewport_rect().size
|
var screen_size = get_viewport_rect().size
|
||||||
@@ -38,9 +38,6 @@ func _ready() -> void:
|
|||||||
|
|
||||||
|
|
||||||
func _input(event):
|
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()
|
|
||||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
|
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
|
||||||
if event.pressed:
|
if event.pressed:
|
||||||
# start tracking
|
# start tracking
|
||||||
@@ -50,9 +47,6 @@ func _input(event):
|
|||||||
# stop tracking
|
# stop tracking
|
||||||
updating_target = false
|
updating_target = false
|
||||||
|
|
||||||
if updating_target and event is InputEventMouseMotion:
|
|
||||||
target = get_global_mouse_position()
|
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
var pos
|
var pos
|
||||||
if typeof(target) == TYPE_VECTOR2:
|
if typeof(target) == TYPE_VECTOR2:
|
||||||
@@ -78,6 +72,9 @@ func _process(delta):
|
|||||||
if self.rotation != self.desired_rotation:
|
if self.rotation != self.desired_rotation:
|
||||||
self.rotation = lerp_angle(self.rotation, self.desired_rotation, clampf(4 * delta, 0, 1))
|
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:
|
func try_attack() -> void:
|
||||||
if not can_attack:
|
if not can_attack:
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ tile_set = SubResource("TileSet_ojt85")
|
|||||||
position = Vector2(112, 64)
|
position = Vector2(112, 64)
|
||||||
|
|
||||||
[node name="Camera2D" type="Camera2D" parent="player" unique_id=1614218911]
|
[node name="Camera2D" type="Camera2D" parent="player" unique_id=1614218911]
|
||||||
zoom = Vector2(5, 5)
|
zoom = Vector2(3, 3)
|
||||||
limit_enabled = false
|
limit_enabled = false
|
||||||
limit_left = 0
|
limit_left = 0
|
||||||
limit_top = 0
|
limit_top = 0
|
||||||
|
|||||||
@@ -69,9 +69,3 @@ func _on_sight_body_entered(body: Node2D) -> void:
|
|||||||
|
|
||||||
func _on_attack_cooldown_timer_timeout() -> void:
|
func _on_attack_cooldown_timer_timeout() -> void:
|
||||||
can_attack = true
|
can_attack = true
|
||||||
|
|
||||||
|
|
||||||
func _on_collision_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
|
|
||||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
|
|
||||||
if player:
|
|
||||||
player.target = self.collision
|
|
||||||
|
|||||||
@@ -42,9 +42,3 @@ func become_injured() -> void:
|
|||||||
func _on_sight_body_entered(body: Node2D) -> void:
|
func _on_sight_body_entered(body: Node2D) -> void:
|
||||||
if body.is_in_group("predator") or (health < maxHealth and body.is_in_group("player")):
|
if body.is_in_group("predator") or (health < maxHealth and body.is_in_group("player")):
|
||||||
fsm.transition_to_next_state(fsm.States.FLEEING, {"threat": body})
|
fsm.transition_to_next_state(fsm.States.FLEEING, {"threat": body})
|
||||||
|
|
||||||
|
|
||||||
func _on_collision_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
|
|
||||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
|
|
||||||
if player:
|
|
||||||
player.target = self.collision
|
|
||||||
|
|||||||
@@ -37,3 +37,8 @@ func play_sprite(anim: String) -> void:
|
|||||||
self.sprite.play(anim)
|
self.sprite.play(anim)
|
||||||
if "wrapper" in self:
|
if "wrapper" in self:
|
||||||
self.wrapper.play_sprite(anim)
|
self.wrapper.play_sprite(anim)
|
||||||
|
|
||||||
|
func _on_collision_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
|
||||||
|
if player:
|
||||||
|
if player.updating_target and event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
|
||||||
|
player.target = self.collision
|
||||||
|
|||||||
Reference in New Issue
Block a user