Adds android web support

master
TechieDamien 2025-08-02 12:39:07 +01:00
parent 8695929012
commit c35e3cbb20
Signed by: TechieDamien
GPG Key ID: 2ACE3574E164B780
1 changed files with 27 additions and 3 deletions

View File

@ -15,9 +15,9 @@ var buffered_direction : Vector2 = Vector2.ZERO
var should_buffer_direction : bool = false
var inputs : Dictionary[String, Vector2] = {"right": Vector2.RIGHT,
"down": Vector2.DOWN,
"left": Vector2.LEFT,
"up": Vector2.UP,
"down": Vector2.DOWN}
"up": Vector2.UP,}
var possible_x : Array
var possible_y : Array
@ -58,6 +58,10 @@ var commanding_head : SnakePart = null
var skip_next_move_propagation : bool = false
var queued_growth : int = 0
var screen_touching : bool = false
var screen_start_pos : Vector2 = Vector2.ZERO
var screen_tracking_index : int = 0
signal on_movement(new_dir, prevent_move)
signal on_death
signal on_ouroboros
@ -406,7 +410,26 @@ func _unhandled_input(event: InputEvent) -> void:
# Change direction if we are the head
if event is InputEventKey and part_type == PartTypes.HEAD:
for dir in inputs.keys():
if event.is_action_pressed(dir) and current_direction != -inputs[dir]:
if event.is_action_pressed(dir) and current_direction != -inputs[dir] and current_direction != inputs[dir]:
if should_buffer_direction:
buffered_direction = inputs[dir]
else:
current_direction = inputs[dir]
should_buffer_direction = true
if event is InputEventScreenTouch and part_type == PartTypes.HEAD:# Start of drag
if event.is_pressed() and !screen_touching:
screen_start_pos = event.position
screen_tracking_index = event.index
screen_touching = true
# End of drag
elif !event.is_pressed() and screen_touching and event.index == screen_tracking_index:
screen_touching = false
var drag_angle : float = (event.position - screen_start_pos).angle()
var idx_direction : int = roundi(drag_angle / (PI / 2))
var dir : String = inputs.keys()[idx_direction]
if current_direction != -inputs[dir] and current_direction != inputs[dir]:
if should_buffer_direction:
buffered_direction = inputs[dir]
else:
@ -414,6 +437,7 @@ func _unhandled_input(event: InputEvent) -> void:
should_buffer_direction = true
# If we leave the arena
#func _on_level_area_exited(_area: Area2D) -> void:
#lose_game()