Browse Source

Adding block spawning and block types

pull/1/head
Ryan Reed 3 months ago
parent
commit
47c1de35a2
4 changed files with 85 additions and 2 deletions
  1. +10
    -2
      scenes/blocks/block.gd
  2. +23
    -0
      scenes/world/world.gd
  3. +1
    -0
      scenes/world/world.gd.uid
  4. +51
    -0
      scenes/world/world.tscn

+ 10
- 2
scenes/blocks/block.gd View File

@ -1,6 +1,11 @@
class_name Block
extends StaticBody3D
enum Types {
DIRT,
STONE,
}
@export var material: StandardMaterial3D
@ -8,9 +13,12 @@ extends StaticBody3D
func _ready() -> void:
apply_materials()
_apply_materials()
func set_material(block_material: StandardMaterial3D):
material = block_material
func apply_materials() -> void:
func _apply_materials() -> void:
for face: MeshInstance3D in block_faces.get_children():
face.set_surface_override_material(0, material)

+ 23
- 0
scenes/world/world.gd View File

@ -0,0 +1,23 @@
class_name World
extends Node3D
const BLOCK_PREFAB: PackedScene = preload("res://scenes/blocks/block.tscn")
const BLOCK_MATERIALS: Dictionary[Block.Types, StandardMaterial3D] = {
Block.Types.DIRT: preload("res://assets/materials/dirt.tres"),
Block.Types.STONE: preload("res://assets/materials/stone.tres"),
}
func _ready() -> void:
create_block(Block.Types.DIRT, Vector3.ZERO)
create_block(Block.Types.STONE, Vector3.ONE)
func create_block(block_type: Block.Types, block_position: Vector3) -> void:
var block: Block = BLOCK_PREFAB.instantiate()
block.position = block_position
block.name = "%s" % [block_position]
block.set_material(BLOCK_MATERIALS[block_type])
add_child(block)

+ 1
- 0
scenes/world/world.gd.uid View File

@ -0,0 +1 @@
uid://c0jbvki2cylct

+ 51
- 0
scenes/world/world.tscn View File

@ -0,0 +1,51 @@
[gd_scene load_steps=8 format=3 uid="uid://mkfitwqnerku"]
[ext_resource type="Script" uid="uid://c0jbvki2cylct" path="res://scenes/world/world.gd" id="1_6m72w"]
[ext_resource type="PackedScene" uid="uid://col07xd76y60h" path="res://scenes/blocks/block.tscn" id="1_dphjl"]
[ext_resource type="Material" uid="uid://uex0dq00xomt" path="res://assets/materials/dirt.tres" id="2_sl2e5"]
[ext_resource type="Material" uid="uid://cx7m27qa4ds4s" path="res://assets/materials/stone.tres" id="3_1fp7r"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_4rhad"]
sky_horizon_color = Color(0.662243, 0.671743, 0.686743, 1)
ground_horizon_color = Color(0.662243, 0.671743, 0.686743, 1)
[sub_resource type="Sky" id="Sky_dphjl"]
sky_material = SubResource("ProceduralSkyMaterial_4rhad")
[sub_resource type="Environment" id="Environment_sl2e5"]
background_mode = 2
sky = SubResource("Sky_dphjl")
tonemap_mode = 2
glow_enabled = true
[node name="World" type="Node3D"]
script = ExtResource("1_6m72w")
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_sl2e5")
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(-0.866025, -0.433013, 0.25, 0, 0.5, 0.866025, -0.5, 0.75, -0.433013, 0, 0, 0)
shadow_enabled = true
[node name="Camera3D" type="Camera3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 0.866025, 0.5, 0, -0.5, 0.866025, 0.1, 1.86802, 3.38687)
[node name="Block" parent="." instance=ExtResource("1_dphjl")]
visible = false
material = ExtResource("2_sl2e5")
[node name="Block2" parent="." instance=ExtResource("1_dphjl")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1)
visible = false
material = ExtResource("2_sl2e5")
[node name="Block3" parent="." instance=ExtResource("1_dphjl")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1, 0, 1)
visible = false
material = ExtResource("3_1fp7r")
[node name="Block4" parent="." instance=ExtResource("1_dphjl")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1, 0, 0)
visible = false
material = ExtResource("3_1fp7r")

Loading…
Cancel
Save