make the orientation of obstacle align with four side of cell on gridmap
This commit is contained in:
+75
-38
@@ -68,7 +68,7 @@ enum ActionState {
|
||||
|
||||
# Obstacle
|
||||
# Add these properties to track the current obstacle direction
|
||||
var current_obstacle_direction = EnhancedGridMap.Direction.NORTH # Default to NORTH
|
||||
var current_obstacle_orientation = ObstacleOrientation.NORTH # Default to NORTH
|
||||
var current_obstacle_item = 12 # Starting with first obstacle item (12)
|
||||
|
||||
enum ObstacleDirection {
|
||||
@@ -76,6 +76,13 @@ enum ObstacleDirection {
|
||||
HORIZONTAL
|
||||
}
|
||||
|
||||
enum ObstacleOrientation {
|
||||
NORTH = 0,
|
||||
EAST = 1,
|
||||
SOUTH = 2,
|
||||
WEST = 3
|
||||
}
|
||||
|
||||
var current_action_state = ActionState.NONE
|
||||
|
||||
@onready var action_menu = $ActionMenu
|
||||
@@ -223,46 +230,92 @@ func set_action_state(new_state):
|
||||
local_player_character.highlight_valid_obstacle_cells()
|
||||
|
||||
# Update the place_obstacle function for floor 3
|
||||
#func place_obstacle(grid_position: Vector2i):
|
||||
#if not local_player_character or local_player_character.action_points < 1:
|
||||
#return false
|
||||
#
|
||||
#var floor_index = 3 # Always place on floor 3
|
||||
#var direction = EnhancedGridMap.Direction.BLOCKED_NORTH
|
||||
#
|
||||
#match current_obstacle_direction:
|
||||
#ObstacleDirection.VERTICAL:
|
||||
#direction = EnhancedGridMap.Direction.BLOCKED_NORTH # Block movement along east-west axis
|
||||
#ObstacleDirection.HORIZONTAL:
|
||||
#direction = EnhancedGridMap.Direction.BLOCKED_EAST # Block movement along north-south axis
|
||||
#
|
||||
#var success = $EnhancedGridMap.place_obstacle(
|
||||
#Vector3i(grid_position.x, floor_index, grid_position.y),
|
||||
#current_obstacle_item,
|
||||
#direction
|
||||
#)
|
||||
#
|
||||
#if success:
|
||||
#local_player_character.action_points -= 1
|
||||
#local_player_character.clear_highlights()
|
||||
#
|
||||
## Don't exit the obstacle placement mode to allow multiple placements
|
||||
#local_player_character.highlight_valid_obstacle_cells()
|
||||
#
|
||||
## Exit obstacle placement mode and return to default state
|
||||
#set_action_state(ActionState.NONE)
|
||||
#
|
||||
## Sync the obstacle with other clients
|
||||
#if is_multiplayer_authority():
|
||||
#rpc("sync_place_obstacle", grid_position.x, grid_position.y, floor_index, current_obstacle_item, direction)
|
||||
#
|
||||
#return true
|
||||
#return false
|
||||
|
||||
func place_obstacle(grid_position: Vector2i):
|
||||
if not local_player_character or local_player_character.action_points < 1:
|
||||
return false
|
||||
|
||||
var floor_index = 3 # Always place on floor 3
|
||||
var direction = EnhancedGridMap.Direction.BLOCKED_NORTH
|
||||
|
||||
match current_obstacle_direction:
|
||||
ObstacleDirection.VERTICAL:
|
||||
direction = EnhancedGridMap.Direction.BLOCKED_NORTH # Block movement along east-west axis
|
||||
ObstacleDirection.HORIZONTAL:
|
||||
direction = EnhancedGridMap.Direction.BLOCKED_EAST # Block movement along north-south axis
|
||||
var floor_index = 3 # Always place on floor 3
|
||||
|
||||
var success = $EnhancedGridMap.place_obstacle(
|
||||
Vector3i(grid_position.x, floor_index, grid_position.y),
|
||||
current_obstacle_item,
|
||||
direction
|
||||
current_obstacle_orientation
|
||||
)
|
||||
|
||||
if success:
|
||||
local_player_character.action_points -= 1
|
||||
local_player_character.clear_highlights()
|
||||
|
||||
# Don't exit the obstacle placement mode to allow multiple placements
|
||||
local_player_character.highlight_valid_obstacle_cells()
|
||||
# Clear all highlights after placing obstacle
|
||||
local_player_character.clear_highlights()
|
||||
|
||||
# Exit obstacle placement mode and return to default state
|
||||
set_action_state(ActionState.NONE)
|
||||
|
||||
# Sync the obstacle with other clients
|
||||
if is_multiplayer_authority():
|
||||
rpc("sync_place_obstacle", grid_position.x, grid_position.y, floor_index, current_obstacle_item, direction)
|
||||
rpc("sync_place_obstacle", grid_position.x, grid_position.y, floor_index, current_obstacle_item, current_obstacle_orientation)
|
||||
|
||||
return true
|
||||
return false
|
||||
|
||||
# Updated function to cycle through the four orientations
|
||||
func cycle_obstacle_orientation():
|
||||
var orientations = [ObstacleOrientation.NORTH, ObstacleOrientation.EAST, ObstacleOrientation.SOUTH, ObstacleOrientation.WEST]
|
||||
var current_index = orientations.find(current_obstacle_orientation)
|
||||
current_index = (current_index + 1) % orientations.size()
|
||||
current_obstacle_orientation = orientations[current_index]
|
||||
|
||||
var direction_names = ["North", "East", "South", "West"]
|
||||
return "Direction: " + direction_names[current_index]
|
||||
|
||||
# Function to cycle through obstacle types
|
||||
func cycle_obstacle_type():
|
||||
var obstacle_types = [12, 13, 14, 15]
|
||||
var current_index = obstacle_types.find(current_obstacle_item)
|
||||
current_index = (current_index + 1) % obstacle_types.size()
|
||||
current_obstacle_item = obstacle_types[current_index]
|
||||
return "Type: " + str(current_index + 1)
|
||||
|
||||
# Update the RPC for obstacle synchronization
|
||||
@rpc("any_peer", "call_local")
|
||||
func sync_place_obstacle(x: int, y: int, floor_index: int, item_index: int, direction: int):
|
||||
$EnhancedGridMap.place_obstacle(Vector3i(x, floor_index, y), item_index, direction)
|
||||
func sync_place_obstacle(x: int, y: int, floor_index: int, item_index: int, orientation: int):
|
||||
$EnhancedGridMap.place_obstacle(Vector3i(x, floor_index, y), item_index, orientation)
|
||||
|
||||
func update_button_states():
|
||||
if not local_player_character or local_player_character.is_in_group("Bots"):
|
||||
@@ -997,13 +1050,13 @@ func setup_obstacle_ui():
|
||||
obstacle_button.pressed.connect(func(): set_action_state(ActionState.PLACING_OBSTACLE))
|
||||
$ActionMenu/ActionButtonContainer.add_child(obstacle_button)
|
||||
|
||||
# Create the direction cycle button
|
||||
var direction_button = Button.new()
|
||||
direction_button.text = "Direction: North"
|
||||
direction_button.pressed.connect(func():
|
||||
direction_button.text = cycle_obstacle_direction()
|
||||
# Create the rotation/orientation cycle button
|
||||
var orientation_button = Button.new()
|
||||
orientation_button.text = "Direction: North"
|
||||
orientation_button.pressed.connect(func():
|
||||
orientation_button.text = cycle_obstacle_orientation()
|
||||
)
|
||||
$ActionMenu/ActionButtonContainer.add_child(direction_button)
|
||||
$ActionMenu/ActionButtonContainer.add_child(orientation_button)
|
||||
|
||||
# Create the type cycle button
|
||||
var type_button = Button.new()
|
||||
@@ -1013,22 +1066,6 @@ func setup_obstacle_ui():
|
||||
)
|
||||
$ActionMenu/ActionButtonContainer.add_child(type_button)
|
||||
|
||||
# Add a function to cycle through obstacle types
|
||||
func cycle_obstacle_type():
|
||||
var obstacle_types = [12, 13, 14, 15]
|
||||
var current_index = obstacle_types.find(current_obstacle_item)
|
||||
current_index = (current_index + 1) % obstacle_types.size()
|
||||
current_obstacle_item = obstacle_types[current_index]
|
||||
return "Type: " + str(current_index + 1)
|
||||
|
||||
func cycle_obstacle_direction():
|
||||
var directions = [EnhancedGridMap.Direction.NORTH, EnhancedGridMap.Direction.EAST, EnhancedGridMap.Direction.SOUTH, EnhancedGridMap.Direction.WEST]
|
||||
var current_index = directions.find(current_obstacle_direction)
|
||||
current_index = (current_index + 1) % directions.size()
|
||||
current_obstacle_direction = directions[current_index]
|
||||
|
||||
var direction_names = ["North", "East", "South", "West"]
|
||||
return "Direction: " + direction_names[current_index]
|
||||
|
||||
func update_board_slot(board_ui: Node, slot_idx: int, value: int):
|
||||
var slot_node = board_ui.get_node_or_null("Slot%d" % (slot_idx + 1))
|
||||
|
||||
Reference in New Issue
Block a user