Browse Source

Adding ability to delete blocks

pull/1/head
Ryan Reed 1 month ago
parent
commit
7546dfe049
4 changed files with 18 additions and 1 deletions
  1. +5
    -0
      project.godot
  2. +9
    -1
      scenes/blocks/block.gd
  3. +3
    -0
      scenes/player/ray_cast_3d.gd
  4. +1
    -0
      scenes/ui/waila.gd

+ 5
- 0
project.godot View File

@ -76,6 +76,11 @@ interact={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":70,"key_label":0,"unicode":102,"location":0,"echo":false,"script":null)
]
}
left_click_interact={
"deadzone": 0.2,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(67, 28),"global_position":Vector2(76, 74),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null)
]
}
[layer_names]


+ 9
- 1
scenes/blocks/block.gd View File

@ -15,6 +15,10 @@ var id: String
var resource: BlockResource
func _exit_tree() -> void:
if Waila.ref.get_target() == self:
Waila.ref.release_target()
func _ready() -> void:
_apply_materials()
@ -25,6 +29,10 @@ func get_id() -> String:
func hook() -> void:
highlight_mesh.visible = true
# TODO: Rename to something else (maybe remove())
func interact_left_click() -> void:
queue_free()
func release() -> void:
highlight_mesh.visible = false
@ -35,7 +43,7 @@ func set_id(block_id: String) -> void:
## Apply a specific material to a MeshInstance3D
## If material is null, the EastFace material will be used
## If material is null, the EastFace material from the BlockResource will be utilized
func _apply_material(face: MeshInstance3D, material: StandardMaterial3D) -> void:
if material == null:
material = resource.material_east # Default to East face (first)


+ 3
- 0
scenes/player/ray_cast_3d.gd View File

@ -6,6 +6,9 @@ func _process(_delta: float) -> void:
var collider: Object = get_collider()
if collider is Block:
if Input.is_action_just_pressed("left_click_interact"):
collider.interact_left_click()
if Waila.ref.get_target() == collider:
return
if not Waila.ref.get_target():


+ 1
- 0
scenes/ui/waila.gd View File

@ -37,6 +37,7 @@ func hook_target(id: String) -> void:
## Not looking at anything, hide Waila
func release_target() -> void:
visible = false
set_target(null)
func set_target(target_block: Block) -> void:
_target = target_block

Loading…
Cancel
Save