Fix mobile restart and swipe aiming while firing

This commit is contained in:
enne2
2026-10-11 00:13:06 +02:00
parent dee0b387ba
commit f246ede94f
5 changed files with 107 additions and 7 deletions
+1 -1
View File
@@ -146,7 +146,7 @@ func _process(_dt: float) -> void:
if player.touch_mode:
hud.text += "\ntrascina a sinistra: muovi · a destra: guarda"
if player.hp <= 0:
hud.text += "\nSEI MORTO — premi R per ricominciare"
hud.text += "\nSEI MORTO — tocca RICOMINCIA" if player.touch_mode else "\nSEI MORTO — premi R per ricominciare"
func zombies_for_wave(number: int) -> int:
return 4 + number * 2
+28 -1
View File
@@ -68,6 +68,16 @@ func _ready() -> void:
if DisplayServer.get_name() != "headless" and not OS.has_feature("web"):
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
var restart_button: Button
func _input(event: InputEvent) -> void:
# Touch nativo: funziona anche con emulate_mouse_from_touch disattivato.
if event is InputEventScreenTouch and event.pressed and is_instance_valid(restart_button):
if not restart_button.disabled and restart_button.get_global_rect().has_point(event.position):
restart_button.disabled = true
get_viewport().set_input_as_handled()
get_tree().call_deferred("reload_current_scene")
func _unhandled_input(event: InputEvent) -> void:
if OS.has_feature("web") and not touch_mode and event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT and not death_started:
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
@@ -211,10 +221,27 @@ func _die() -> void:
tween.tween_property(camera, "rotation:x", 0.08, 0.9)
tween.tween_property(death_overlay, "color:a", 1.0, 1.8).set_delay(0.7)
var message := Label.new()
message.text = "SEI MORTO\nPremi R per ricominciare"
message.text = "SEI MORTO" if touch_mode else "SEI MORTO\nPremi R per ricominciare"
message.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
message.add_theme_font_size_override("font_size", 36)
message.modulate.a = 0
layer.add_child(message)
message.set_anchors_and_offsets_preset(Control.PRESET_CENTER)
tween.tween_property(message, "modulate:a", 1.0, 0.5).set_delay(2.2)
if touch_mode:
var restart := Button.new()
restart_button = restart
restart.name = "RestartButton"
restart.text = "RICOMINCIA"
restart.add_theme_font_size_override("font_size", 28)
layer.add_child(restart)
restart.set_anchors_and_offsets_preset(Control.PRESET_CENTER)
restart.offset_left = -150
restart.offset_right = 150
restart.offset_top = 90
restart.offset_bottom = 162
restart.disabled = true
get_tree().create_timer(0.6).timeout.connect(func(): restart.disabled = false)
restart.pressed.connect(func():
restart.disabled = true
get_tree().reload_current_scene())
+27 -4
View File
@@ -15,7 +15,8 @@ const JOY_RADIUS := 92.0
const KNOB_RADIUS := 40.0
const BTN_RADIUS := 46.0
const BTN_FIRE_RADIUS := 62.0
const LOOK_SENSITIVITY := 1.7 # moltiplicatore del trascinamento nell'area di puntamento
const LOOK_TURN_RADIANS := PI # swipe largo quanto lo schermo = 180 gradi
const LOOK_VERTICAL_RATIO := 0.75
const EDGE := 24.0
const COLOR_BASE := Color(1, 1, 1, 0.09)
@@ -137,7 +138,7 @@ func _input(event: InputEvent) -> void:
elif event is InputEventScreenDrag:
index = event.index
pos = event.position
relative = event.relative
relative = event.screen_relative
is_drag = true
elif mouse_fallback and event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
index = MOUSE_INDEX
@@ -218,9 +219,31 @@ func _drag(index: int, pos: Vector2, relative: Vector2) -> void:
_joy_knob = (pos - _joy_origin).limit_length(JOY_RADIUS)
_apply_move()
_root.queue_redraw()
Role.LOOK:
Role.LOOK, Role.FIRE:
if player and player.has_method("apply_look"):
player.apply_look(relative * LOOK_SENSITIVITY)
player.apply_look(_look_delta(relative, _screen_width()))
## Stessa frazione di swipe = stessa rotazione, senza stretch o delta temporale.
static func _look_delta(relative: Vector2, screen_width: float) -> Vector2:
return relative * Vector2(1.0, LOOK_VERTICAL_RATIO) * LOOK_TURN_RADIANS / maxf(screen_width, 1.0) / 0.0025
func _screen_width() -> float:
return _size.x if DisplayServer.get_name() == "headless" else float(DisplayServer.window_get_size().x)
func release_all() -> void:
for index in _touches.keys():
_release(index)
for action in MOVE_ACTIONS + ["shoot", "grenade", "reload", "jump"]:
Input.action_release(action)
func _process(_dt: float) -> void:
if player and player.hp <= 0 and enabled:
release_all()
enabled = false
_root.hide()
func _exit_tree() -> void:
release_all()
## Traduce il vettore del joystick nelle azioni di movimento (analogiche).
func _apply_move() -> void: