A Minecraft style clone in Godot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

39 lines
1.1 KiB

class_name World
extends Node3D
const BLOCK_PREFAB: PackedScene = preload("res://scenes/blocks/block.tscn")
func _ready() -> void:
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
EntityManager.create_block.connect(create_block.bind())
_initialize_ground()
create_block("001", Vector3(2,1, 2))
create_block("002", Vector3(2,1, 1))
create_block("003", Vector3(1,1, 2))
create_block("004", Vector3(1,2, 2))
create_block("003", Vector3(-2,3, 2))
func create_block(id: String, block_position: Vector3) -> void:
var block: Block = BLOCK_PREFAB.instantiate()
block.position = block_position
block.set_id(id)
add_child(block)
func _initialize_ground() -> void:
for x: int in range(-10, 11):
for z: int in range(-10, 11):
var ground_position: Vector3 = Vector3(x, 0, z)
var random: int = randi_range(0, 1)
if random:
# Just for testing.. Would probably make mmore sense to just call create_block() directly if still in World
EntityManager.create_block.emit("001", ground_position)
else:
EntityManager.create_block.emit("002", ground_position)