This commit is contained in:
2025-03-10 15:44:54 +08:00
parent 438eff1f7a
commit 495c9c64a5
97 changed files with 532 additions and 32 deletions
+90 -2
View File
@@ -9,7 +9,7 @@
# [x] Grab tile is working, you can grab the tile from gridmap to playerboard
# -------------------------------------------------------------------------------------
# [ ] Implement the Boosts tile, that can be used to boost player movement to next tile
# [ ] Implement the Obstacle tile, that can be used to block player movement to next tile
# [x] Implement the Obstacle tile, that can be used to block player movement to next tile
# -------------------------------------------------------------------------------------
# [x] Added multiplayer support - with act as server and client
# [x] Added UPnP support for automatic port forwarding, for android and desktop
@@ -62,7 +62,18 @@ enum ActionState {
GRABBING,
PUTTING,
RANDOMIZING,
ARRANGING
ARRANGING,
PLACING_OBSTACLE
}
# Obstacle
var current_obstacle_direction = ObstacleDirection.VERTICAL
var obstacle_item_index = 12 # Default obstacle item index in mesh library
var current_obstacle_item = 12 # Starting with first obstacle item (12)
enum ObstacleDirection {
VERTICAL,
HORIZONTAL
}
var current_action_state = ActionState.NONE
@@ -88,6 +99,8 @@ func _ready():
multiplayer_peer.peer_disconnected.connect(_on_peer_disconnected)
setup_action_buttons()
setup_playerboard_ui()
# Obstacles
setup_obstacle_ui()
func _process(delta):
if multiplayer.is_server() and game_started:
@@ -206,6 +219,47 @@ func set_action_state(new_state):
ActionState.ARRANGING:
show_arrangement_ui()
local_player_character.highlight_occupied_playerboard_slots()
ActionState.PLACING_OBSTACLE:
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()
# 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
# 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 update_button_states():
if not local_player_character or local_player_character.is_in_group("Bots"):
@@ -932,6 +986,40 @@ func sync_playerboard(player_id: int, new_playerboard: Array):
for slot_idx in range(25):
update_board_slot(board_ui, slot_idx, new_playerboard[slot_idx])
# Update the obstacle UI setup function
func setup_obstacle_ui():
# Create the obstacle button
var obstacle_button = Button.new()
obstacle_button.text = "Place Obstacle"
obstacle_button.pressed.connect(func(): set_action_state(ActionState.PLACING_OBSTACLE))
$ActionMenu/ActionButtonContainer.add_child(obstacle_button)
# Create the direction toggle button
var direction_button = Button.new()
direction_button.text = "Direction: Vertical"
direction_button.pressed.connect(func():
current_obstacle_direction = ObstacleDirection.HORIZONTAL if current_obstacle_direction == ObstacleDirection.VERTICAL else ObstacleDirection.VERTICAL
direction_button.text = "Direction: " + ("Horizontal" if current_obstacle_direction == ObstacleDirection.HORIZONTAL else "Vertical")
)
$ActionMenu/ActionButtonContainer.add_child(direction_button)
# Create the type cycle button
var type_button = Button.new()
type_button.text = "Type: 1"
type_button.pressed.connect(func():
type_button.text = cycle_obstacle_type()
)
$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 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))
if slot_node: