extends Node3D
# ==========================================
# CONFIGURAÇÕES E TIPOS DE BLOCOS (PBR)
# ==========================================
enum BlockType {
AIR = 0,
GRASS = 1,
SAND = 2,
PUMPKIN = 3,
MUSHROOM = 4,
ORE = 5,
WATER = 6,
FIRE = 7,
DIAMOND = 8,
RUBY = 9,
EMERALD = 10
}
const BLOCK_DATA = {
BlockType.GRASS: {"name": "Grama", "color": Color(0.2, 0.75, 0.25)},
BlockType.SAND: {"name": "Areia", "color": Color(0.92, 0.85, 0.60)},
BlockType.PUMPKIN: {"name": "Abóbora", "color": Color(0.95, 0.5, 0.05)},
BlockType.MUSHROOM: {"name": "Cogumelo", "color": Color(0.9, 0.2, 0.3)},
BlockType.ORE: {"name": "Minério de Ouro", "color": Color(0.95, 0.75, 0.1)},
BlockType.WATER: {"name": "Água Cristalina", "color": Color(0.05, 0.55, 0.90, 0.80)},
BlockType.FIRE: {"name": "Fogo", "color": Color(1.0, 0.4, 0.1)},
BlockType.DIAMOND: {"name": "Diamante", "color": Color(0.1, 0.85, 0.95)},
BlockType.RUBY: {"name": "Rubi", "color": Color(0.9, 0.1, 0.2)},
BlockType.EMERALD: {"name": "Esmeralda", "color": Color(0.1, 0.9, 0.3)}
}
const MAP_SIZE_X = 28
const MAP_SIZE_Z = 28
const MAP_HEIGHT = 8
# Armazenamento e Nós
var world_grid: Dictionary = {}
var materials_cache: Dictionary = {}
var world_node: Node3D
var enemies_node: Node3D
var weather_node: Node3D
var clouds_node: Node3D
# Jogador e Câmera
var player: CharacterBody3D
var camera: Camera3D
var raycast: RayCast3D
# UI
var ui_layer: CanvasLayer
var menu_container: Control
var hud_container: Control
var hotbar_labels = []
var active_block_display_label: Label
var target_block_display_label: Label
var hp_label: Label
var time_label: Label
var theme_label: Label
# Estado do Jogo e Minérios Desbloqueados
var is_playing: bool = false
var player_hp: int = 100
var selected_block: BlockType = BlockType.GRASS
var hotbar_keys = [
BlockType.GRASS, BlockType.SAND, BlockType.PUMPKIN, BlockType.MUSHROOM,
BlockType.ORE, BlockType.WATER, BlockType.FIRE,
BlockType.DIAMOND, BlockType.RUBY, BlockType.EMERALD
]
var unlocked_blocks: Dictionary = {
BlockType.GRASS: true,
BlockType.SAND: true,
BlockType.PUMPKIN: true,
BlockType.MUSHROOM: true,
BlockType.ORE: true,
BlockType.WATER: true,
BlockType.FIRE: true,
BlockType.DIAMOND: false,
BlockType.RUBY: false,
BlockType.EMERALD: false
}
var active_slot_index: int = 0
var elapsed_game_time: float = 0.0
# Física e Mouse
var mouse_sensitivity: float = 0.0025
var player_speed: float = 6.5
var jump_force: float = 5.0
var gravity: float = 15.0
var camera_rot_x: float = 0.0
# Sistema de Dia/Noite, Clima e Halloween
var sun_light: DirectionalLight3D
var world_environment: WorldEnvironment
var time_of_day: float = 0.25 # Começa de dia
var day_duration: float = 120.0
var rain_particles: CPUParticles3D
var is_horror_theme: bool = false
var is_raining_day: bool = false
# Inimigos de Halloween
var enemies_list: Array = []
# ==========================================
# CICLO DE VIDA DO JOGO
# ==========================================
func _ready() -> void:
get_window().size = Vector2i(1000, 500)
_init_paradise_materials()
_setup_world_node()
_generate_paradise_terrain()
_build_giant_pumpkin_castle()
_setup_realistic_clouds()
_setup_global_rain()
_setup_player()
_setup_ui()
_spawn_halloween_enemies()
_show_menu()
func _unhandled_input(event: InputEvent) -> void:
if not is_playing:
return
if event is InputEventMouseMotion:
player.rotate_y(-event.relative.x * mouse_sensitivity)
camera_rot_x = clamp(camera_rot_x - event.relative.y * mouse_sensitivity, deg_to_rad(-89.0), deg_to_rad(89.0))
camera.rotation.x = camera_rot_x
if event is InputEventMouseButton and event.is_pressed():
if event.button_index == MOUSE_BUTTON_WHEEL_UP:
_cycle_hotbar(-1)
elif event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
_cycle_hotbar(1)
if event is InputEventKey and event.is_pressed():
if event.keycode >= KEY_1 and event.keycode <= KEY_9:
var target_index = event.keycode - KEY_1
if target_index < hotbar_keys.size():
var b_type = hotbar_keys[target_index]
if unlocked_blocks[b_type]:
active_slot_index = target_index
_update_active_block()
if event is InputEventMouseButton and event.is_pressed():
if event.button_index == MOUSE_BUTTON_LEFT:
_break_block()
elif event.button_index == MOUSE_BUTTON_RIGHT:
_place_block()
if event.is_action_pressed("ui_cancel") or (event is InputEventKey and event.keycode == KEY_ESCAPE and event.is_pressed()):
_show_menu()
func _physics_process(delta: float) -> void:
if not is_playing or not player:
return
elapsed_game_time += delta
_update_day_night_cycle(delta)
_update_targeted_block_ui()
_update_weather_and_clouds(delta)
_update_hud_displays()
var velocity = player.velocity
if not player.is_on_floor():
velocity.y -= gravity * delta
if (Input.is_key_pressed(KEY_SPACE) or Input.is_action_pressed("ui_accept")) and player.is_on_floor():
velocity.y = jump_force
var input_x = 0.0
var input_z = 0.0
if Input.is_key_pressed(KEY_D) or Input.is_action_pressed("ui_right"): input_x += 1.0
if Input.is_key_pressed(KEY_A) or Input.is_action_pressed("ui_left"): input_x -= 1.0
if Input.is_key_pressed(KEY_S) or Input.is_action_pressed("ui_down"): input_z += 1.0
if Input.is_key_pressed(KEY_W) or Input.is_action_pressed("ui_up"): input_z -= 1.0
var direction = (player.transform.basis * Vector3(input_x, 0, input_z)).normalized()
if direction != Vector3.ZERO:
velocity.x = direction.x * player_speed
velocity.z = direction.z * player_speed
else:
velocity.x = move_toward(velocity.x, 0, player_speed)
velocity.z = move_toward(velocity.z, 0, player_speed)
player.velocity = velocity
player.move_and_slide()
_update_halloween_enemies(delta)
# ==========================================
# MATERIAIS PBR, NUVENS E CLIMA
# ==========================================
func _create_procedural_noise_texture() -> NoiseTexture2D:
var noise = FastNoiseLite.new()
noise.noise_type = FastNoiseLite.TYPE_SIMPLEX
noise.frequency = 0.12
noise.fractal_octaves = 3
var texture = NoiseTexture2D.new()
texture.width = 128
texture.height = 128
texture.seamless = true
texture.noise = noise
return texture
func _init_paradise_materials() -> void:
var general_noise_tex = _create_procedural_noise_texture()
for key in BLOCK_DATA.keys():
var data = BLOCK_DATA[key]
var mat = StandardMaterial3D.new()
mat.albedo_color = data["color"]
match key:
BlockType.GRASS:
mat.roughness = 0.8
mat.normal_enabled = true
mat.normal_scale = 0.5
mat.normal_texture = general_noise_tex
BlockType.SAND:
mat.roughness = 0.95
mat.normal_enabled = true
mat.normal_scale = 0.3
mat.normal_texture = general_noise_tex
BlockType.PUMPKIN:
mat.roughness = 0.4
mat.emission_enabled = true
mat.emission = Color(0.5, 0.2, 0.0)
mat.emission_energy_multiplier = 0.5
BlockType.MUSHROOM:
mat.roughness = 0.5
mat.rim_enabled = true
mat.rim = 0.8
BlockType.ORE, BlockType.DIAMOND, BlockType.RUBY, BlockType.EMERALD:
mat.roughness = 0.15
mat.metallic = 0.9
mat.emission_enabled = true
mat.emission = data["color"]
mat.emission_energy_multiplier = 1.5
BlockType.WATER:
mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
mat.roughness = 0.05
mat.specular = 1.0
mat.refraction_enabled = true
mat.refraction_scale = 0.08
BlockType.FIRE:
mat.roughness = 0.1
mat.emission_enabled = true
mat.emission = data["color"]
mat.emission_energy_multiplier = 3.0
materials_cache[key] = mat
func _setup_world_node() -> void:
world_node = Node3D.new()
world_node.name = "World"
add_child(world_node)
enemies_node = Node3D.new()
enemies_node.name = "Enemies"
add_child(enemies_node)
sun_light = DirectionalLight3D.new()
sun_light.shadow_enabled = true
sun_light.directional_shadow_max_distance = 60.0
add_child(sun_light)
world_environment = WorldEnvironment.new()
var environment = Environment.new()
environment.background_mode = Environment.BG_SKY
environment.sky = Sky.new()
environment.sky.sky_material = ProceduralSkyMaterial.new()
environment.ambient_light_source = Environment.AMBIENT_SOURCE_SKY
environment.glow_enabled = true
environment.glow_intensity = 0.8
world_environment.environment = environment
add_child(world_environment)
func _setup_realistic_clouds() -> void:
clouds_node = Node3D.new()
clouds_node.name = "Clouds"
add_child(clouds_node)
var cloud_mat = StandardMaterial3D.new()
cloud_mat.albedo_color = Color(0.9, 0.9, 0.95, 0.7)
cloud_mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
for i in range(20):
var puff = MeshInstance3D.new()
var sphere = SphereMesh.new()
sphere.radius = randf_range(3.0, 5.5)
sphere.height = 2.0
sphere.material = cloud_mat
puff.mesh = sphere
puff.position = Vector3(
randf_range(-15, MAP_SIZE_X + 15),
18 + randf_range(0, 2),
randf_range(-15, MAP_SIZE_Z + 15)
)
clouds_node.add_child(puff)
func _setup_global_rain() -> void:
weather_node = Node3D.new()
weather_node.name = "Weather"
add_child(weather_node)
rain_particles = CPUParticles3D.new()
rain_particles.emitting = false
rain_particles.amount = 1000
rain_particles.lifetime = 1.5
rain_particles.emission_shape = CPUParticles3D.EMISSION_SHAPE_BOX
rain_particles.emission_box_extents = Vector3(MAP_SIZE_X * 0.8, 1, MAP_SIZE_Z * 0.8)
rain_particles.position = Vector3(MAP_SIZE_X / 2.0, 20.0, MAP_SIZE_Z / 2.0)
rain_particles.direction = Vector3(-0.15, -1, 0)
rain_particles.spread = 3.0
rain_particles.initial_velocity_min = 18.0
rain_particles.initial_velocity_max = 24.0
var rain_mesh = BoxMesh.new()
rain_mesh.size = Vector3(0.03, 0.7, 0.03)
var rain_mat = StandardMaterial3D.new()
rain_mat.albedo_color = Color(0.65, 0.75, 0.95, 0.6)
rain_mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
rain_mesh.material = rain_mat
rain_particles.mesh = rain_mesh
weather_node.add_child(rain_particles)
func _update_day_night_cycle(delta: float) -> void:
time_of_day = fmod(time_of_day + (delta / day_duration), 1.0)
var sun_angle = time_of_day * TAU
var sun_x = cos(sun_angle) * 30.0
var sun_y = sin(sun_angle) * 30.0
sun_light.position = Vector3(sun_x, sun_y, 0)
sun_light.look_at(Vector3.ZERO, Vector3.UP)
var light_energy = clamp(sin(sun_angle) * 1.5, 0.0, 1.3)
sun_light.light_energy = light_energy
var hour = int((time_of_day * 24.0) + 6.0) % 24
is_horror_theme = (hour < 6 or hour >= 18)
if is_horror_theme:
is_raining_day = true
else:
if randf() < 0.0005:
is_raining_day = not is_raining_day
if rain_particles:
rain_particles.emitting = is_horror_theme or is_raining_day
var sky_mat = world_environment.environment.sky.sky_material as ProceduralSkyMaterial
var env = world_environment.environment
if sky_mat:
if not is_horror_theme:
sky_mat.sky_top_color = Color(0.3, 0.6, 0.95) if not is_raining_day else Color(0.4, 0.45, 0.55)
sky_mat.sky_horizon_color = Color(0.75, 0.88, 0.98) if not is_raining_day else Color(0.6, 0.65, 0.7)
env.fog_enabled = is_raining_day
env.fog_density = 0.015
else:
sky_mat.sky_top_color = Color(0.02, 0.01, 0.05)
sky_mat.sky_horizon_color = Color(0.12, 0.02, 0.03)
env.fog_enabled = true
env.fog_light_color = Color(0.08, 0.02, 0.02)
env.fog_density = 0.04
func _update_weather_and_clouds(delta: float) -> void:
if clouds_node:
for cloud in clouds_node.get_children():
cloud.position.x += delta * 0.4
if cloud.position.x > MAP_SIZE_X + 20:
cloud.position.x = -20
func _generate_paradise_terrain() -> void:
for x in range(MAP_SIZE_X):
for z in range(MAP_SIZE_Z):
var dist_center = Vector2(x - MAP_SIZE_X/2, z - MAP_SIZE_Z/2).length()
var height = int(2 + sin(x * 0.3) * 1.5 + cos(z * 0.3) * 1.5)
for y in range(height + 1):
var pos = Vector3i(x, y, z)
var block_type = BlockType.SAND
if y == height:
if dist_center < MAP_SIZE_X * 0.35:
block_type = BlockType.GRASS
if randf() < 0.06:
_set_block_in_world(Vector3i(x, y + 1, z), BlockType.MUSHROOM)
else:
block_type = BlockType.SAND
elif y < height - 1:
var r = randf()
if r < 0.08:
block_type = BlockType.ORE
elif r < 0.10:
block_type = BlockType.DIAMOND
elif r < 0.12:
block_type = BlockType.RUBY
elif r < 0.14:
block_type = BlockType.EMERALD
_set_block_in_world(pos, block_type)
func _build_giant_pumpkin_castle() -> void:
# Constrói um Castelo de Abóbora Gigante no centro do mapa
var cx = MAP_SIZE_X / 2
var cz = MAP_SIZE_Z / 2
var base_y = 3
# Torres e Paredes do Castelo usando blocos de Abóbora
for x in range(cx - 3, cx + 4):
for z in range(cz - 3, cz + 4):
# Deixa o interior oco (paredes e torres)
if x == cx - 3 or x == cx + 3 or z == cz - 3 or z == cz + 3:
for y in range(base_y, base_y + 5):
_set_block_in_world(Vector3i(x, y, z), BlockType.PUMPKIN)
# Torre Central Gigante de Abóbora
for x in range(cx - 1, cx + 2):
for z in range(cz - 1, cz + 2):
for y in range(base_y, base_y + 8):
_set_block_in_world(Vector3i(x, y, z), BlockType.PUMPKIN)
func _set_block_in_world(pos: Vector3i, type: BlockType) -> void:
var key = str(pos)
if world_grid.has(key):
world_grid[key].queue_free()
world_grid.erase(key)
if type == BlockType.AIR:
return
var body = StaticBody3D.new()
body.position = Vector3(pos) + Vector3(0.5, 0.5, 0.5)
var mesh_instance = MeshInstance3D.new()
var box_mesh = BoxMesh.new()
box_mesh.size = Vector3(1, 1, 1)
box_mesh.material = materials_cache[type]
mesh_instance.mesh = box_mesh
body.add_child(mesh_instance)
var col_shape = CollisionShape3D.new()
var box_shape = BoxShape3D.new()
box_shape.size = Vector3(1, 1, 1)
col_shape.shape = box_shape
body.add_child(col_shape)
body.set_meta("grid_pos", pos)
body.set_meta("block_type", type)
world_node.add_child(body)
world_grid[key] = body
# ==========================================
# JOGADOR E INIMIGOS DE HALLOWEEN
# ==========================================
func _setup_player() -> void:
player = CharacterBody3D.new()
player.position = Vector3(MAP_SIZE_X / 2.0, MAP_HEIGHT + 4, MAP_SIZE_Z / 2.0)
var col = CollisionShape3D.new()
var caps = CapsuleShape3D.new()
caps.radius = 0.4
caps.height = 1.8
col.shape = caps
player.add_child(col)
camera = Camera3D.new()
camera.position = Vector3(0, 0.6, 0)
player.add_child(camera)
raycast = RayCast3D.new()
raycast.target_position = Vector3(0, 0, -6.0)
raycast.enabled = true
camera.add_child(raycast)
add_child(player)
func _spawn_halloween_enemies() -> void:
for i in range(4):
var rx = randf_range(2.0, MAP_SIZE_X - 2.0)
var rz = randf_range(2.0, MAP_SIZE_Z - 2.0)
_spawn_ghost(Vector3(rx, MAP_HEIGHT + 3, rz))
func _spawn_ghost(pos: Vector3) -> void:
var enemy = CharacterBody3D.new()
enemy.position = pos
var col = CollisionShape3D.new()
var caps = CapsuleShape3D.new()
caps.radius = 0.4
caps.height = 1.6
col.shape = caps
enemy.add_child(col)
var ghost_mat = StandardMaterial3D.new()
ghost_mat.albedo_color = Color(0.9, 0.9, 0.95, 0.85)
ghost_mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
var body_mesh = MeshInstance3D.new()
var sphere = SphereMesh.new()
sphere.radius = 0.5
sphere.height = 1.2
sphere.material = ghost_mat
body_mesh.mesh = sphere
body_mesh.position = Vector3(0, 0.5, 0)
enemy.add_child(body_mesh)
var eye_mat = StandardMaterial3D.new()
eye_mat.albedo_color = Color(1.0, 0.4, 0.0)
eye_mat.emission_enabled = true
eye_mat.emission = Color(1.0, 0.4, 0.0)
eye_mat.emission_energy_multiplier = 5.0
for offset_x in [-0.15, 0.15]:
var eye = MeshInstance3D.new()
var eye_mesh = BoxMesh.new()
eye_mesh.size = Vector3(0.12, 0.12, 0.12)
eye_mesh.material = eye_mat
eye.mesh = eye_mesh
eye.position = Vector3(offset_x, 0.7, -0.4)
enemy.add_child(eye)
enemies_node.add_child(enemy)
enemies_list.append(enemy)
func _update_halloween_enemies(delta: float) -> void:
for enemy in enemies_list:
if not is_instance_valid(enemy):
continue
if not enemy.is_on_floor():
enemy.velocity.y -= gravity * 0.5 * delta
var to_player = player.global_position - enemy.global_position
to_player.y = 0
var dist = to_player.length()
if dist < 15.0 and dist > 1.2:
to_player = to_player.normalized()
enemy.velocity.x = to_player.x * 3.0
enemy.velocity.z = to_player.z * 3.0
enemy.look_at(Vector3(player.global_position.x, enemy.global_position.y, player.global_position.z), Vector3.UP)
else:
enemy.velocity.x = move_toward(enemy.velocity.x, 0, 2.0)
enemy.velocity.z = move_toward(enemy.velocity.z, 0, 2.0)
if dist < 1.3:
player_hp = max(0, player_hp - int(10 * delta))
_update_hp_display()
if player_hp <= 0:
_respawn_player()
enemy.move_and_slide()
func _respawn_player() -> void:
player_hp = 100
player.position = Vector3(MAP_SIZE_X / 2.0, MAP_HEIGHT + 4, MAP_SIZE_Z / 2.0)
_update_hp_display()
func _update_targeted_block_ui() -> void:
if not target_block_display_label:
return
if raycast.is_colliding():
var collider = raycast.get_collider()
if collider and collider.has_meta("block_type"):
var b_type = collider.get_meta("block_type")
if BLOCK_DATA.has(b_type):
var b_name = BLOCK_DATA[b_type]["name"]
target_block_display_label.text = "⛏️ Minerando: " + b_name
return
target_block_display_label.text = "⛏️ Minerando: Nenhum"
func _break_block() -> void:
if raycast.is_colliding():
var collider = raycast.get_collider()
if collider and collider.has_meta("grid_pos"):
var pos = collider.get_meta("grid_pos")
var block_type = collider.get_meta("block_type")
if unlocked_blocks.has(block_type) and not unlocked_blocks[block_type]:
unlocked_blocks[block_type] = true
_refresh_hud_display()
_spawn_particles(collider.global_position, materials_cache[block_type])
_set_block_in_world(pos, BlockType.AIR)
func _place_block() -> void:
if raycast.is_colliding():
var collider = raycast.get_collider()
if collider and collider.has_meta("grid_pos"):
var norm = raycast.get_collision_normal()
var hit_pos = collider.get_meta("grid_pos")
var target_pos = hit_pos + Vector3i(round(norm.x), round(norm.y), round(norm.z))
var player_grid_pos = Vector3i(player.global_position.floor())
if target_pos == player_grid_pos or target_pos == player_grid_pos + Vector3i(0, 1, 0):
return
_set_block_in_world(target_pos, selected_block)
func _spawn_particles(pos: Vector3, material: Material) -> void:
var particles = CPUParticles3D.new()
particles.position = pos
particles.emitting = true
particles.one_shot = true
particles.explosiveness = 1.0
particles.amount = 16
particles.lifetime = 0.4
particles.mesh = BoxMesh.new()
particles.mesh.size = Vector3(0.18, 0.18, 0.18)
particles.mesh.material = material
particles.direction = Vector3(0, 1, 0)
particles.spread = 180.0
particles.initial_velocity_min = 2.5
particles.initial_velocity_max = 5.5
world_node.add_child(particles)
get_tree().create_timer(0.5).timeout.connect(particles.queue_free)
func _cycle_hotbar(direction: int) -> void:
var start_slot = active_slot_index
while true:
active_slot_index = (active_slot_index + direction) % hotbar_keys.size()
if active_slot_index < 0:
active_slot_index = hotbar_keys.size() - 1
var current_btype = hotbar_keys[active_slot_index]
if unlocked_blocks[current_btype] or active_slot_index == start_slot:
break
_update_active_block()
func _update_active_block() -> void:
selected_block = hotbar_keys[active_slot_index]
_refresh_hud_display()
# ==========================================
# INTERFACE E HUD (1000x500)
# ==========================================
func _setup_ui() -> void:
ui_layer = CanvasLayer.new()
add_child(ui_layer)
# --- MENU PRINCIPAL ---
menu_container = PanelContainer.new()
menu_container.anchors_preset = Control.PRESET_FULL_RECT
var center = CenterContainer.new()
menu_container.add_child(center)
var vbox = VBoxContainer.new()
vbox.add_theme_constant_override("separation", 20)
center.add_child(vbox)
var title = Label.new()
title.text = "MINICRAFT 3D - CASTELO DE ABÓBORA"
title.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
title.add_theme_font_size_override("font_size", 26)
vbox.add_child(title)
var btn_start = Button.new()
btn_start.text = "Explorar o Castelo"
btn_start.custom_minimum_size = Vector2(240, 45)
btn_start.pressed.connect(_start_game)
vbox.add_child(btn_start)
var btn_exit = Button.new()
btn_exit.text = "Sair"
btn_exit.custom_minimum_size = Vector2(240, 45)
btn_exit.pressed.connect(func(): get_tree().quit())
vbox.add_child(btn_exit)
ui_layer.add_child(menu_container)
# --- HUD ---
hud_container = Control.new()
hud_container.anchors_preset = Control.PRESET_FULL_RECT
hud_container.visible = false
# Mira
var cross_h = ColorRect.new()
cross_h.set_anchors_preset(Control.PRESET_CENTER)
cross_h.size = Vector2(10, 2)
cross_h.position = -Vector2(5, 1)
cross_h.color = Color(1, 1, 1, 0.7)
hud_container.add_child(cross_h)
var cross_v = ColorRect.new()
cross_v.set_anchors_preset(Control.PRESET_CENTER)
cross_v.size = Vector2(2, 10)
cross_v.position = -Vector2(1, 5)
cross_v.color = Color(1, 1, 1, 0.7)
hud_container.add_child(cross_v)
# 1. HP / Modo
hp_label = Label.new()
hp_label.position = Vector2(20, 15)
hp_label.add_theme_font_size_override("font_size", 16)
hp_label.add_theme_color_override("font_color", Color(1, 0.2, 0.2))
hud_container.add_child(hp_label)
_update_hp_display()
# 2. Relógio
time_label = Label.new()
time_label.position = Vector2(20, 40)
time_label.add_theme_font_size_override("font_size", 14)
time_label.add_theme_color_override("font_color", Color(0.9, 0.9, 0.9))
hud_container.add_child(time_label)
# 3. Tema Atual
theme_label = Label.new()
theme_label.position = Vector2(20, 65)
theme_label.add_theme_font_size_override("font_size", 14)
hud_container.add_child(theme_label)
# 4. Nome do Bloco Minerado (Abaixo do Tema)
target_block_display_label = Label.new()
target_block_display_label.position = Vector2(20, 90)
target_block_display_label.add_theme_font_size_override("font_size", 14)
target_block_display_label.add_theme_color_override("font_color", Color(0.8, 0.9, 1.0))
hud_container.add_child(target_block_display_label)
# --- PAINEL SUPERIOR DIREITO: BLOCO EM CONSTRUÇÃO ---
var info_build_panel = PanelContainer.new()
info_build_panel.set_anchors_preset(Control.PRESET_TOP_RIGHT)
info_build_panel.position = Vector2(-220, 15)
info_build_panel.custom_minimum_size = Vector2(200, 60)
var active_vbox = VBoxContainer.new()
var title_lbl = Label.new()
title_lbl.text = "CONSTRUINDO AGORA:"
title_lbl.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
title_lbl.add_theme_font_size_override("font_size", 10)
active_vbox.add_child(title_lbl)
active_block_display_label = Label.new()
active_block_display_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
active_block_display_label.add_theme_font_size_override("font_size", 15)
active_vbox.add_child(active_block_display_label)
info_build_panel.add_child(active_vbox)
hud_container.add_child(info_build_panel)
# Hotbar
var hotbar_panel = PanelContainer.new()
hotbar_panel.set_anchors_preset(Control.PRESET_BOTTOM_WIDE)
hotbar_panel.offset_left = 40
hotbar_panel.offset_right = -40
hotbar_panel.offset_top = -65
hotbar_panel.offset_bottom = -15
var hotbar_hbox = HBoxContainer.new()
hotbar_hbox.alignment = BoxContainer.ALIGNMENT_CENTER
hotbar_hbox.add_theme_constant_override("separation", 3)
hotbar_labels.clear()
for i in range(hotbar_keys.size()):
var slot_label = Label.new()
slot_label.custom_minimum_size = Vector2(75, 38)
slot_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
slot_label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
hotbar_hbox.add_child(slot_label)
hotbar_labels.append(slot_label)
hotbar_panel.add_child(hotbar_hbox)
hud_container.add_child(hotbar_panel)
ui_layer.add_child(hud_container)
_update_active_block()
func _update_hp_display() -> void:
if hp_label:
hp_label.text = "❤️ HP: " + str(player_hp) + "%"
func _update_hud_displays() -> void:
if time_label and theme_label:
var hour = int((time_of_day * 24.0) + 6.0) % 24
var minute = int(fmod(time_of_day * 24.0 * 60.0, 60.0))
var time_str = "%02d:%02d" % [hour, minute]
time_label.text = "🕒 Horário: " + time_str
if is_horror_theme:
theme_label.text = "🎃 TEMA: HALLOWEEN & CASTELO"
theme_label.add_theme_color_override("font_color", Color(1, 0.4, 0.1))
elif is_raining_day:
theme_label.text = "🌧️ TEMA: DIA CHUVOSO"
theme_label.add_theme_color_override("font_color", Color(0.3, 0.7, 1))
else:
theme_label.text = "🌴 TEMA: ILHA PARADISÍACA"
theme_label.add_theme_color_override("font_color", Color(0.2, 1, 0.3))
func _refresh_hud_display() -> void:
if hotbar_labels.is_empty() or not active_block_display_label:
return
var current_name = BLOCK_DATA[selected_block]["name"]
active_block_display_label.text = "🔹 " + current_name.to_upper() + " 🔹"
for i in range(hotbar_keys.size()):
var b_type = hotbar_keys[i]
var b_name = BLOCK_DATA[b_type]["name"]
var lbl = hotbar_labels[i]
if not unlocked_blocks[b_type]:
lbl.text = "[🔒 ???]"
lbl.add_theme_color_override("font_color", Color(0.4, 0.4, 0.4))
elif i == active_slot_index:
lbl.text = "> " + b_name + " <"
lbl.add_theme_color_override("font_color", Color(1, 0.9, 0.2))
else:
lbl.text = b_name
lbl.remove_theme_color_override("font_color")
func _show_menu() -> void:
is_playing = false
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
menu_container.visible = true
hud_container.visible = false
func _start_game() -> void:
is_playing = true
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
menu_container.visible = false
hud_container.visible = true