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:
+1
View File
@@ -0,0 +1 @@
uid://co1ads72by6na
+7 -6
View File
@@ -1,8 +1,8 @@
[gd_scene load_steps=26 format=3 uid="uid://dxn87yj8qnfpp"]
[ext_resource type="MeshLibrary" uid="uid://54tpx8cmksfc" path="res://addons/enhanced_gridmap/meshlibrary/default.tres" id="1_110wo"]
[ext_resource type="Script" path="res://scenes/main.gd" id="1_xcpe3"]
[ext_resource type="Script" path="res://addons/enhanced_gridmap/enhanced_gridmap.gd" id="2_hbe1v"]
[ext_resource type="Script" uid="uid://co1ads72by6na" path="res://scenes/main.gd" id="1_xcpe3"]
[ext_resource type="Script" uid="uid://bja8ixryvthu0" path="res://addons/enhanced_gridmap/enhanced_gridmap.gd" id="2_hbe1v"]
[ext_resource type="Environment" uid="uid://jbptgqvstei3" path="res://assets/main-environment.tres" id="4_ky38j"]
[ext_resource type="StyleBox" uid="uid://dlw1ogamn741n" path="res://assets/styles/box_flat.tres" id="5_dvx6y"]
[ext_resource type="Texture2D" uid="uid://2yrc6rl4dmd8" path="res://assets/textures/player_board_and_blue_print/tile_null.tres" id="6_2vy7d"]
@@ -44,8 +44,9 @@ data = {
script = ExtResource("2_hbe1v")
columns = 14
rows = 12
floors = 2
metadata/_editor_floor_ = Vector3(0, 1, 0)
obstacle_items = Array[int]([12])
obstacle_directions = Array[int]([11, 10, 12, 13])
metadata/_editor_floor_ = Vector3(0, 2, 0)
[node name="Camera3D" type="Camera3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 0.422618, 0.906308, 0, -0.906308, 0.422618, 7, 26, 17)
@@ -935,8 +936,8 @@ anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -145.0
offset_top = -218.0
offset_left = -160.0
offset_top = -384.0
grow_horizontal = 0
grow_vertical = 0
+35
View File
@@ -225,6 +225,9 @@ func handle_grid_click(grid_position: Vector2i):
main.ActionState.RANDOMIZING:
if grid_position in highlighted_cells:
main.randomize_item_at_position(grid_position)
main.ActionState.PLACING_OBSTACLE:
if grid_position in highlighted_cells:
main.place_obstacle(grid_position)
func is_position_occupied(pos: Vector2i) -> bool:
for player in get_tree().get_nodes_in_group("Players"):
@@ -1215,3 +1218,35 @@ func sync_position(pos: Vector2i):
cell_size.y,
current_position.y * cell_size.z + cell_size.z * 0.5
) + cell_offset
func highlight_valid_obstacle_cells():
if not is_multiplayer_authority() or is_bot or is_in_group("Bots"):
return
clear_highlights()
var cells_to_highlight = []
# Highlight all empty cells on the grid except those occupied by players or obstacles
for x in range(enhanced_gridmap.columns):
for z in range(enhanced_gridmap.rows):
var pos = Vector2i(x, z)
var cell = Vector3i(x, 3, z) # Check floor 3 for occupancy
var occupied_by_player = false
var occupied_by_obstacle = false
# Check if cell is occupied by any player
for player in get_tree().get_nodes_in_group("Players"):
if player.current_position == pos:
occupied_by_player = true
break
# Check if cell is occupied by an obstacle
if enhanced_gridmap.get_cell_item(cell) in enhanced_gridmap.obstacle_items:
occupied_by_obstacle = true
# Only add to highlights if not occupied by player or obstacle
if not occupied_by_player and not occupied_by_obstacle:
cells_to_highlight.append(pos)
highlight_cells_if_authorized(cells_to_highlight)
+1
View File
@@ -0,0 +1 @@
uid://c78jcadupsdro
+15 -15
View File
@@ -1,25 +1,25 @@
[gd_scene load_steps=25 format=3 uid="uid://1dbdbg3q5778"]
[ext_resource type="Script" path="res://scenes/player.gd" id="1_qecr4"]
[ext_resource type="Script" uid="uid://c78jcadupsdro" path="res://scenes/player.gd" id="1_qecr4"]
[ext_resource type="PackedScene" uid="uid://ejeamn0pyey4" path="res://assets/characters/Bob.glb" id="2_3e0d5"]
[ext_resource type="Texture2D" uid="uid://b4y41h16q6m34" path="res://assets/textures/bub.png" id="2_5w327"]
[ext_resource type="PackedScene" uid="uid://1vk0mjnwkngi" path="res://assets/characters/Masbro.glb" id="2_mjsl8"]
[ext_resource type="PackedScene" uid="uid://d4cul3w3wem5w" path="res://assets/characters/Gatot.glb" id="4_3tlf6"]
[ext_resource type="PackedScene" uid="uid://bmln7v6v5kvxg" path="res://assets/characters/Oldpop.glb" id="5_alfd1"]
[ext_resource type="AnimationLibrary" uid="uid://c3pyopnwibckj" path="res://assets/characters/animations/animation-pack.res" id="6_5oq5w"]
[ext_resource type="Script" path="res://scripts/bot_behavior.gd" id="8_1o2fn"]
[ext_resource type="Script" path="res://addons/beehave/nodes/composites/selector.gd" id="9_jspru"]
[ext_resource type="Script" path="res://addons/beehave/nodes/composites/sequence.gd" id="10_hv4ee"]
[ext_resource type="Script" path="res://scripts/behaviors/conditions/has_ap.gd" id="11_7fhpq"]
[ext_resource type="Script" path="res://scripts/behaviors/actions/do_arrange.gd" id="12_1ppih"]
[ext_resource type="Script" path="res://scripts/behaviors/conditions/can_arrange.gd" id="12_hr248"]
[ext_resource type="Script" path="res://scripts/behaviors/conditions/can_grab.gd" id="13_41jsv"]
[ext_resource type="Script" path="res://scripts/behaviors/actions/do_grab.gd" id="15_5h472"]
[ext_resource type="Script" path="res://scripts/behaviors/conditions/can_put.gd" id="16_ac2sy"]
[ext_resource type="Script" path="res://scripts/behaviors/actions/do_put.gd" id="17_e03nk"]
[ext_resource type="Script" path="res://scripts/behaviors/conditions/should_move.gd" id="18_2ghcp"]
[ext_resource type="Script" path="res://scripts/behaviors/actions/do_move.gd" id="19_dl4fn"]
[ext_resource type="Script" path="res://scripts/bot_blackboard.gd" id="20_24ja6"]
[ext_resource type="Script" uid="uid://6g75rh3nj2s6" path="res://scripts/bot_behavior.gd" id="8_1o2fn"]
[ext_resource type="Script" uid="uid://dtctf507t71tj" path="res://addons/beehave/nodes/composites/selector.gd" id="9_jspru"]
[ext_resource type="Script" uid="uid://t6e8rtdiqhg5" path="res://addons/beehave/nodes/composites/sequence.gd" id="10_hv4ee"]
[ext_resource type="Script" uid="uid://b17qem72laaeb" path="res://scripts/behaviors/conditions/has_ap.gd" id="11_7fhpq"]
[ext_resource type="Script" uid="uid://b4fxorcb1yq17" path="res://scripts/behaviors/actions/do_arrange.gd" id="12_1ppih"]
[ext_resource type="Script" uid="uid://b25qg75d0xgkh" path="res://scripts/behaviors/conditions/can_arrange.gd" id="12_hr248"]
[ext_resource type="Script" uid="uid://cui40g7qjf1y3" path="res://scripts/behaviors/conditions/can_grab.gd" id="13_41jsv"]
[ext_resource type="Script" uid="uid://cuyorbwefmh0y" path="res://scripts/behaviors/actions/do_grab.gd" id="15_5h472"]
[ext_resource type="Script" uid="uid://b7y30e5mxygj0" path="res://scripts/behaviors/conditions/can_put.gd" id="16_ac2sy"]
[ext_resource type="Script" uid="uid://bdw5bwmr32h63" path="res://scripts/behaviors/actions/do_put.gd" id="17_e03nk"]
[ext_resource type="Script" uid="uid://bc7jpc1bwy4dg" path="res://scripts/behaviors/conditions/should_move.gd" id="18_2ghcp"]
[ext_resource type="Script" uid="uid://cireifbxafgf2" path="res://scripts/behaviors/actions/do_move.gd" id="19_dl4fn"]
[ext_resource type="Script" uid="uid://d2cr28ak2s1rr" path="res://scripts/bot_blackboard.gd" id="20_24ja6"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_xqgey"]
albedo_color = Color(0.85, 0.085, 0.238, 1)
@@ -56,7 +56,7 @@ visible = false
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
root_node = NodePath("../Masbro")
libraries = {
"animation-pack": ExtResource("6_5oq5w")
&"animation-pack": ExtResource("6_5oq5w")
}
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]