Update input actions and UI layout
Added new input actions for movement and actions in project.godot. Adjusted UI element positions, visibility, and sizing in main.tscn. Added a temporary scene file and updated player.gd.
This commit is contained in:
+91
-1
@@ -464,12 +464,54 @@ func _physics_process(delta):
|
||||
if current_position in finish_locations and can_finish and not is_player_moving:
|
||||
start_new_lap()
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# Input
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
func _unhandled_input(event):
|
||||
# Early return if not authorized human player
|
||||
if not is_multiplayer_authority() or is_bot or is_in_group("Bots"):
|
||||
set_process_unhandled_input(false)
|
||||
return
|
||||
|
||||
var main = get_node("/root/Main")
|
||||
|
||||
# --- Real-time Keyboard/Touch Input ---
|
||||
if not main.turn_based_mode and not is_player_moving:
|
||||
var target_position = current_position
|
||||
var input_handled = true
|
||||
|
||||
if Input.is_action_just_pressed("move_north"):
|
||||
target_position += Vector2i(0, -1)
|
||||
elif Input.is_action_just_pressed("move_northeast"):
|
||||
target_position += Vector2i(1, -1)
|
||||
elif Input.is_action_just_pressed("move_east"):
|
||||
target_position += Vector2i(1, 0)
|
||||
elif Input.is_action_just_pressed("move_southeast"):
|
||||
target_position += Vector2i(1, 1)
|
||||
elif Input.is_action_just_pressed("move_south"):
|
||||
target_position += Vector2i(0, 1)
|
||||
elif Input.is_action_just_pressed("move_southwest"):
|
||||
target_position += Vector2i(-1, 1)
|
||||
elif Input.is_action_just_pressed("move_west"):
|
||||
target_position += Vector2i(-1, 0)
|
||||
elif Input.is_action_just_pressed("move_northwest"):
|
||||
target_position += Vector2i(-1, -1)
|
||||
elif Input.is_action_just_pressed("action_grab"):
|
||||
grab_item(current_position) # Try to grab from current position [cite: 59]
|
||||
elif Input.is_action_just_pressed("action_put"):
|
||||
auto_put_item()
|
||||
else:
|
||||
input_handled = false # No relevant key was pressed
|
||||
|
||||
if target_position != current_position:
|
||||
simple_move_to(target_position)
|
||||
|
||||
if input_handled:
|
||||
get_viewport().set_input_as_handled() # Consume the event
|
||||
return # Don't process turn-based or spawn logic
|
||||
# --- End Real-time Input ---
|
||||
|
||||
# Handle spawn point selection if not yet selected
|
||||
if not spawn_point_selected and highlighted_spawn_points.size() > 0:
|
||||
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
|
||||
@@ -483,10 +525,10 @@ func _unhandled_input(event):
|
||||
return # Spawn point selected successfully
|
||||
|
||||
# Use get_node_or_null for safer node access
|
||||
var main = get_tree().get_root().get_node_or_null("Main")
|
||||
if not main:
|
||||
return
|
||||
|
||||
# Turn-based mouse input
|
||||
if not is_multiplayer_authority() or (main.turn_based_mode and (not is_my_turn or is_player_moving)):
|
||||
return
|
||||
|
||||
@@ -695,6 +737,54 @@ func is_within_movement_range(target_position: Vector2i) -> bool:
|
||||
distance = abs(target_position.x - current_position.x) + abs(target_position.y - current_position.y)
|
||||
return distance <= movement_range
|
||||
|
||||
# -----------------------------------------------------------------
|
||||
# Movement
|
||||
# -----------------------------------------------------------------
|
||||
|
||||
func simple_move_to(grid_position: Vector2i):
|
||||
if not is_multiplayer_authority() or is_player_moving:
|
||||
return
|
||||
|
||||
# Check if target is within 1-tile range
|
||||
var distance: int
|
||||
if use_diagonal_movement:
|
||||
distance = max(abs(grid_position.x - current_position.x), abs(grid_position.y - current_position.y))
|
||||
else:
|
||||
distance = abs(grid_position.x - current_position.x) + abs(grid_position.y - current_position.y)
|
||||
|
||||
if distance != 1:
|
||||
return # Only single-step moves allowed
|
||||
|
||||
# Check for finish line
|
||||
if grid_position in finish_locations:
|
||||
if not can_finish:
|
||||
can_finish = check_pattern_match()
|
||||
if not can_finish:
|
||||
return # Cannot move to finish line
|
||||
|
||||
var is_valid_finish = grid_position in finish_locations if current_lap == 0 else grid_position in spawn_locations
|
||||
|
||||
# Check walkability and obstacles
|
||||
var cell_item = enhanced_gridmap.get_cell_item(Vector3i(grid_position.x, 0, grid_position.y))
|
||||
if cell_item in enhanced_gridmap.non_walkable_items or is_position_occupied(grid_position):
|
||||
return
|
||||
|
||||
if enhanced_gridmap.is_blocked_by_obstacle(current_position, grid_position, 3):
|
||||
return
|
||||
|
||||
# All checks passed, perform move
|
||||
rotate_towards_target(grid_position)
|
||||
|
||||
var path = [Vector2(current_position.x, current_position.y), Vector2(grid_position.x, grid_position.y)]
|
||||
path.pop_front()
|
||||
|
||||
# Use the existing RPC to move
|
||||
rpc("start_movement_along_path", path, not (is_bot or is_in_group("Bots")))
|
||||
|
||||
# Handle finish line crossing
|
||||
if is_valid_finish and can_finish:
|
||||
rpc("finish_race")
|
||||
|
||||
func move_player_to_clicked_position(grid_position: Vector2i):
|
||||
|
||||
if not is_multiplayer_authority() or is_player_moving or action_points <= 0:
|
||||
|
||||
Reference in New Issue
Block a user