|
|
@ -2,17 +2,24 @@ class_name World |
|
|
|
extends Node3D |
|
|
|
|
|
|
|
|
|
|
|
@export var default_spawn_position: Vector3 = Vector3.ZERO |
|
|
|
|
|
|
|
@export_group("Nodes and Scenes") |
|
|
|
@export var blocks_container: Node3D |
|
|
|
@export var dropped_items_container: Node3D |
|
|
|
@export var player: PackedScene |
|
|
|
|
|
|
|
|
|
|
|
func _ready() -> void: |
|
|
|
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED |
|
|
|
EntityManager.create_block.connect(_create_block.bind()) |
|
|
|
EntityManager.drop_block.connect(_create_dropped_block.bind()) |
|
|
|
EntityManager.clear_blocks.connect(_on_clear_blocks.bind()) |
|
|
|
EntityManager.spawn_player.connect(_spawn_player.bind()) |
|
|
|
|
|
|
|
_initialize_ground() |
|
|
|
_create_test_blocks() |
|
|
|
_spawn_player(default_spawn_position) |
|
|
|
|
|
|
|
|
|
|
|
func _create_block(id: String, block_position: Vector3) -> void: |
|
|
@ -35,6 +42,13 @@ func _create_test_blocks() -> void: |
|
|
|
_create_block("00" + str(index), Vector3(index, 3, -5)) |
|
|
|
_create_dropped_block("00" + str(index), Vector3(index, 2, -3)) |
|
|
|
|
|
|
|
func _spawn_player(player_position: Vector3) -> void: |
|
|
|
if has_node("Player"): |
|
|
|
$Player.queue_free() |
|
|
|
|
|
|
|
var _player: Player = player.instantiate() |
|
|
|
_player.position = player_position |
|
|
|
add_child(_player) |
|
|
|
|
|
|
|
func _initialize_ground() -> void: |
|
|
|
for x: int in range(-10, 11): |
|
|
@ -47,3 +61,11 @@ func _initialize_ground() -> void: |
|
|
|
EntityManager.create_block.emit("001", ground_position) |
|
|
|
else: |
|
|
|
EntityManager.create_block.emit("002", ground_position) |
|
|
|
|
|
|
|
## Generally for resetting/emptying the world to allow for load_game |
|
|
|
func _on_clear_blocks() -> void: |
|
|
|
for block: Block in blocks_container.get_children(): |
|
|
|
block.queue_free() |
|
|
|
|
|
|
|
for block: DroppedBlock in dropped_items_container.get_children(): |
|
|
|
block.queue_free() |