Initial door placement implemented
This commit is contained in:
parent
2534a72265
commit
a1dec4b25c
@ -1,10 +1,10 @@
|
|||||||
extends Node3D
|
extends Node3D
|
||||||
|
|
||||||
var tile_grid_size = 64
|
var tile_grid_size = 64
|
||||||
var astar_grid_room = AStarGrid2D.new()
|
|
||||||
|
|
||||||
var load_tile = preload("res://tiles/base_tile/base_tile.tscn")
|
var load_tile = preload("res://tiles/base_tile/base_tile.tscn")
|
||||||
var load_room = preload("res://places/base_place/base_room.tscn")
|
var load_room = preload("res://places/base_place/base_room.tscn")
|
||||||
|
var load_door = preload("res://tiles/base_tile/base_door.tscn")
|
||||||
|
|
||||||
var place_tile_dict = {}
|
var place_tile_dict = {}
|
||||||
|
|
||||||
@ -18,7 +18,14 @@ var tile_count_z_hist = null
|
|||||||
|
|
||||||
var build_allowed = true
|
var build_allowed = true
|
||||||
|
|
||||||
|
var current_room = null
|
||||||
|
var current_room_walls = []
|
||||||
|
var current_door = null
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
|
||||||
|
#connect("wall_built", record_walls)
|
||||||
|
|
||||||
#Sets up a simple 2D grid of blank tiles.
|
#Sets up a simple 2D grid of blank tiles.
|
||||||
|
|
||||||
for x in range(tile_grid_size):
|
for x in range(tile_grid_size):
|
||||||
@ -164,10 +171,12 @@ func build_selection():
|
|||||||
var tile_selected = place_tile_dict[i]
|
var tile_selected = place_tile_dict[i]
|
||||||
tile_selected.update(1, 4)
|
tile_selected.update(1, 4)
|
||||||
|
|
||||||
create_room()
|
var room = create_room()
|
||||||
|
|
||||||
selection_dict.clear()
|
selection_dict.clear()
|
||||||
|
|
||||||
|
return room
|
||||||
|
|
||||||
func clear_selection():
|
func clear_selection():
|
||||||
#When the clear button is clicked, it clears the selected tiles without doing anything.
|
#When the clear button is clicked, it clears the selected tiles without doing anything.
|
||||||
|
|
||||||
@ -197,3 +206,50 @@ func create_room():
|
|||||||
|
|
||||||
for i in room.room_tile_dict:
|
for i in room.room_tile_dict:
|
||||||
place_tile_dict[i].room_id = room
|
place_tile_dict[i].room_id = room
|
||||||
|
|
||||||
|
current_room = room
|
||||||
|
|
||||||
|
return room
|
||||||
|
|
||||||
|
#func record_walls():
|
||||||
|
|
||||||
|
|
||||||
|
func create_door():
|
||||||
|
|
||||||
|
for i in current_room.room_tile_dict.keys():
|
||||||
|
for j in current_room.room_tile_dict[i].wall_dict.keys():
|
||||||
|
current_room_walls.append((Vector3(i) + Vector3(0.5, 0, 0.5)) + Vector3(j) / 2)
|
||||||
|
|
||||||
|
current_door = true
|
||||||
|
|
||||||
|
var door = load_door.instantiate()
|
||||||
|
|
||||||
|
door.room = current_room
|
||||||
|
|
||||||
|
add_child(door)
|
||||||
|
|
||||||
|
return door
|
||||||
|
|
||||||
|
func hover_door(position):
|
||||||
|
|
||||||
|
if not current_door:
|
||||||
|
current_door = create_door()
|
||||||
|
|
||||||
|
var closest = null
|
||||||
|
var closest_distance = INF
|
||||||
|
|
||||||
|
for i in current_room_walls:
|
||||||
|
var distance = position.distance_to(i)
|
||||||
|
if closest_distance > distance:
|
||||||
|
closest_distance = distance
|
||||||
|
closest = i
|
||||||
|
|
||||||
|
current_door.position = closest
|
||||||
|
current_door.rotation_degrees = Vector3(0, 180 * fmod(closest.x, 1), 0)
|
||||||
|
|
||||||
|
func build_door():
|
||||||
|
current_room = null
|
||||||
|
current_room_walls = []
|
||||||
|
current_door = null
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,5 @@
|
|||||||
[node name="BasePlace" type="Node3D"]
|
[node name="BasePlace" type="Node3D"]
|
||||||
script = ExtResource("1_uq3a8")
|
script = ExtResource("1_uq3a8")
|
||||||
|
|
||||||
[node name="Grid" type="Node3D" parent="."]
|
|
||||||
|
|
||||||
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 0.345446, 0.938439, 0, -0.938439, 0.345446, 41.393, 18.7409, 34.4224)
|
transform = Transform3D(1, 0, 0, 0, 0.345446, 0.938439, 0, -0.938439, 0.345446, 41.393, 18.7409, 34.4224)
|
||||||
|
|||||||
@ -16,10 +16,11 @@ func _ready():
|
|||||||
|
|
||||||
init_path_grid()
|
init_path_grid()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func init_path_grid():
|
func init_path_grid():
|
||||||
print(self.name)
|
|
||||||
|
|
||||||
for i in room_tile_dict.keys():
|
for i in room_tile_dict.keys():
|
||||||
var id = path_grid.get_available_point_id()
|
var id = path_grid.get_available_point_id()
|
||||||
|
|||||||
@ -5,6 +5,9 @@ var place = load_place.instantiate()
|
|||||||
|
|
||||||
var build_enabled = false
|
var build_enabled = false
|
||||||
var is_building = false
|
var is_building = false
|
||||||
|
var is_placing_door = false
|
||||||
|
|
||||||
|
var last_room = null
|
||||||
|
|
||||||
var build_start_pos = null
|
var build_start_pos = null
|
||||||
|
|
||||||
@ -21,30 +24,40 @@ func _on_build_toggle(toggled_on):
|
|||||||
if not toggled_on:
|
if not toggled_on:
|
||||||
place.clear_selection()
|
place.clear_selection()
|
||||||
|
|
||||||
func start_build(event):
|
|
||||||
is_building = event.button_mask
|
|
||||||
|
|
||||||
func _on_area_3d_input_event(_camera, event, event_position, _normal, _shade_id):
|
func _on_area_3d_input_event(_camera, event, event_position, _normal, _shade_id):
|
||||||
#Checks input events from the mouse planex
|
#Checks input events from the mouse planex
|
||||||
|
|
||||||
if event.is_action_pressed("select") && build_enabled:
|
if event.is_action_pressed("select") && build_enabled:
|
||||||
build_start_pos = event_position
|
build_start_pos = event_position
|
||||||
start_build(event)
|
is_building = event
|
||||||
place.draw_tile_click(build_start_pos)
|
place.draw_tile_click(build_start_pos)
|
||||||
|
|
||||||
if is_building:
|
elif is_building:
|
||||||
if event.button_mask:
|
if Input.is_action_pressed("select"):
|
||||||
var build_mouse_pos = event_position
|
place.init_select_drag(build_start_pos, event_position)
|
||||||
place.init_select_drag(build_start_pos, build_mouse_pos)
|
|
||||||
|
|
||||||
if not event.button_mask:
|
else:
|
||||||
start_build(event)
|
is_building = event
|
||||||
place.end_select_drag()
|
place.end_select_drag()
|
||||||
|
|
||||||
func _on_confirm_button_pressed() -> void:
|
elif is_placing_door:
|
||||||
if place.build_allowed:
|
if not event.button_mask:
|
||||||
place.build_selection()
|
place.hover_door(event_position)
|
||||||
is_building = false
|
|
||||||
|
if event.is_action_pressed("select"):
|
||||||
|
is_placing_door = false
|
||||||
|
place.build_door()
|
||||||
emit_signal("room_built")
|
emit_signal("room_built")
|
||||||
|
|
||||||
|
|
||||||
|
func _on_confirm_button_pressed() -> void:
|
||||||
|
if is_building:
|
||||||
|
if place.build_allowed:
|
||||||
|
last_room = place.build_selection()
|
||||||
|
build_enabled = false
|
||||||
|
is_building = false
|
||||||
|
is_placing_door = true
|
||||||
|
|
||||||
|
#
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|||||||
3
tiles/base_tile/base_door.gd
Normal file
3
tiles/base_tile/base_door.gd
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
extends Node3D
|
||||||
|
|
||||||
|
var room = null
|
||||||
1
tiles/base_tile/base_door.gd.uid
Normal file
1
tiles/base_tile/base_door.gd.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://dptw3xl225fxk
|
||||||
12
tiles/base_tile/base_door.tscn
Normal file
12
tiles/base_tile/base_door.tscn
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
[gd_scene load_steps=3 format=3 uid="uid://b6qehpvvnv5r3"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://dptw3xl225fxk" path="res://tiles/base_tile/base_door.gd" id="1_8olbq"]
|
||||||
|
|
||||||
|
[sub_resource type="PrismMesh" id="PrismMesh_2crd3"]
|
||||||
|
|
||||||
|
[node name="BaseDoor" type="Node3D"]
|
||||||
|
script = ExtResource("1_8olbq")
|
||||||
|
|
||||||
|
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
|
||||||
|
mesh = SubResource("PrismMesh_2crd3")
|
||||||
@ -67,6 +67,8 @@ var wall_dict = {}
|
|||||||
|
|
||||||
var room_id = null
|
var room_id = null
|
||||||
|
|
||||||
|
signal wall_built
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
$Label3D.text = str(grid_pos)
|
$Label3D.text = str(grid_pos)
|
||||||
pass
|
pass
|
||||||
@ -94,6 +96,8 @@ func update_face(neighbor_index, mode):
|
|||||||
|
|
||||||
wall_dict[face] = wall
|
wall_dict[face] = wall
|
||||||
|
|
||||||
|
emit_signal("wall_built", room_id)
|
||||||
|
|
||||||
add_child(wall)
|
add_child(wall)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user