fuzzyworld

godot-shooter / commit

Try handling the mobile touch event.

a71b5173c5f3dbfe803c8b80d9d2f8d0a817613e · Pavel Safronov · 2023-11-01 22:40:08 -0700 · parents 8c2ffd3fc0d9

Try handling the mobile touch event.
 World.gd | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/World.gd b/World.gd
index b254518..e78bb5b 100644
--- a/World.gd
+++ b/World.gd
@@ -28,14 +28,15 @@ func add_new_enemy(should_be_visible: bool = false) -> void:
 	enemy.add_to_group("enemies")
 	add_child(enemy)
 
+func _input(event: InputEvent) -> void:
+	if event is InputEventScreenTouch:
+		if event.pressed && !$Player.dead:
+			set_destination(event.position)
+
 func _process(_delta: float) -> void:
 	if Input.is_action_just_pressed("click") and !$Player.dead:
 		var pos = get_global_mouse_position()
-		destination = pos
-		is_destination_set = true
-		$Destination.position = pos
-		$Destination.visible = true
-		$Player.	global_rotation = global_position.direction_to(get_global_mouse_position()).angle() + PI/2.0
+		set_destination(pos)
 
 	if is_destination_set:
 		var diff = destination - $Player.position
@@ -47,6 +48,13 @@ func _process(_delta: float) -> void:
 		$Destination.visible = false
 		$Player.velocity = Vector2.ZERO
 
+func set_destination(pos: Vector2) -> void:
+	destination = pos
+	is_destination_set = true
+	$Destination.position = pos
+	$Destination.visible = true
+	$Player.	global_rotation = global_position.direction_to(get_global_mouse_position()).angle() + PI/2.0
+
 func _on_Destination_body_entered(_body: Node) -> void:
 	is_destination_set = false