adds keyboard input
This commit is contained in:
@@ -29,9 +29,42 @@ func _input(event):
|
||||
_handle_keyboard_input(event)
|
||||
|
||||
|
||||
func step_next():
|
||||
""" Step this module state to the next cell """
|
||||
current_cell = next_cell
|
||||
var current_idx = track.find(current_cell)
|
||||
var next_idx = current_idx + 1 if current_idx < track.size() - 1 else 0
|
||||
next_cell = track[next_idx]
|
||||
emit_signal("player_moved", laps + get_track_offset(current_cell))
|
||||
emit_signal("wrong_way", Vector2(-1, -1)) # Cancel any wrong way sign
|
||||
|
||||
func _handle_keyboard_input(event):
|
||||
if event is InputEventKey:
|
||||
print_debug("Input Ignored: KEYBOARD MODE")
|
||||
var direction_to_next = current_cell.direction_to(next_cell)
|
||||
if event.is_action_pressed("ui_up"):
|
||||
print_debug("Up key")
|
||||
if direction_to_next == Vector2(0, -1):
|
||||
step_next()
|
||||
else:
|
||||
emit_signal("wrong_way", map.map_to_world(Vector2(current_cell.x, current_cell.y - 1)))
|
||||
elif event.is_action_pressed("ui_right"):
|
||||
print_debug("Right key")
|
||||
if direction_to_next == Vector2(1, 0):
|
||||
step_next()
|
||||
else:
|
||||
emit_signal("wrong_way", map.map_to_world(Vector2(current_cell.x + 1, current_cell.y)))
|
||||
elif event.is_action_pressed("ui_left"):
|
||||
print_debug("Left key")
|
||||
if direction_to_next == Vector2(-1, 0):
|
||||
step_next()
|
||||
else:
|
||||
emit_signal("wrong_way", map.map_to_world(Vector2(current_cell.x - 1, current_cell.y)))
|
||||
elif event.is_action_pressed("ui_down"):
|
||||
print_debug("Key down")
|
||||
if direction_to_next == Vector2(0, 1):
|
||||
step_next()
|
||||
else:
|
||||
emit_signal("wrong_way", map.map_to_world(Vector2(current_cell.x, current_cell.y + 1)))
|
||||
|
||||
|
||||
func _handle_mouse_input(event):
|
||||
@@ -50,11 +83,7 @@ func _handle_mouse_input(event):
|
||||
laps += 1
|
||||
# We use the loop property of PathFollow2D to embed
|
||||
# laps count inside the offset.
|
||||
emit_signal("player_moved", laps + get_track_offset(hover_cell))
|
||||
emit_signal("wrong_way", Vector2(-1, -1))
|
||||
current_cell = next_cell
|
||||
var next_idx = cell_idx + 1 if cell_idx < track.size() - 1 else 0
|
||||
next_cell = track[next_idx]
|
||||
step_next()
|
||||
else:
|
||||
emit_signal("wrong_way", map.map_to_world(hover_cell))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user