Remove signal; use ray method

This commit is contained in:
VAILLANT Jeremy
2021-05-14 22:14:38 +02:00
parent 21a6f70aee
commit d8e81345e9
2 changed files with 89 additions and 106 deletions
+27 -48
View File
@@ -4,11 +4,14 @@ const TIME_MAX = 3000 # msec
const GYROSCOPE_MAX_DIFF = 0.5
const OFFSET_CAMERA_MAX = 0.12
const OFFSET_STEP_CHANGE = 0.01
const RAY_LENGTH = 1000
onready var gyroscope_value_old = Vector3(0, 0, 0)
onready var table = Global.database.get_table_by_name("scenes")
onready var meshes = {}
onready var meshes2 = null
onready var from = null
onready var to = null
var mscene = load("res://db/MScene.gd")
@@ -35,13 +38,16 @@ func _check_dissolve_mesh():
if OS.get_ticks_msec() < meshes[key].tick_reference() + TIME_MAX:
meshes[key].set_value(meshes[key].value() + 0.01)
node_to_mesh(key).get_surface_material(0).set("shader_param/dissolve_amount", meshes[key].value())
_node_to_mesh(key).get_surface_material(0).set("shader_param/dissolve_amount", meshes[key].value())
else:
node_to_mesh(key).call_deferred("free")
_node_to_mesh(key).call_deferred("free")
meshes[key].set_mesh(null)
func node_to_mesh(key):
func _node_to_mesh(key):
return get_node(meshes[key].mesh())
func _node_to_area(key):
return get_node(meshes[key].mesh()+"/Area")
func _check_change_angle_camera():
var camera = $"Main Camera"
@@ -117,53 +123,10 @@ func _confirm_before_quit():
func _quit_to_menu():
Global.goto_scene("res://scenes/main.tscn")
func _initialize_mesh_ref(key, event):
if meshes[key].lock() == false and (event is InputEventMouseButton or event is InputEventScreenTouch):
func _start_dissolve(key):
if meshes[key].lock() == false:
meshes[key].set_lock(true)
# Event when user click/touch dagger
func _on_dagger_input_event(_camera, event, _click_position, _click_normal, _shape_idx):
_initialize_mesh_ref("dagger", event)
func _on_fiole1_input_event(_camera, event, _click_position, _click_normal, _shape_idx):
_initialize_mesh_ref("fiole1", event)
func _on_fiole2_input_event(_camera, event, _click_position, _click_normal, _shape_idx):
_initialize_mesh_ref("fiole2", event)
func _on_fiole3_input_event(_camera, event, _click_position, _click_normal, _shape_idx):
_initialize_mesh_ref("fiole3", event)
func _on_spyglass_input_event(_camera, event, _click_position, _click_normal, _shape_idx):
_initialize_mesh_ref("spyglass", event)
func _on_pinte_beer_input_event(_camera, event, _click_position, _click_normal, _shape_idx):
_initialize_mesh_ref("beer", event)
func _on_weapon_gun_input_event(_camera, event, _click_position, _click_normal, _shape_idx):
_initialize_mesh_ref("weapon", event)
func _on_apple_1_input_event(_camera, event, _click_position, _click_normal, _shape_idx):
_initialize_mesh_ref("apple1", event)
func _on_apple_2_input_event(_camera, event, _click_position, _click_normal, _shape_idx):
_initialize_mesh_ref("apple2", event)
func _on_apple_3_input_event(_camera, event, _click_position, _click_normal, _shape_idx):
_initialize_mesh_ref("apple3", event)
func _on_apple_4_input_event(_camera, event, _click_position, _click_normal, _shape_idx):
_initialize_mesh_ref("apple4", event)
func _on_gold_1_input_event(_camera, event, _click_position, _click_normal, _shape_idx):
_initialize_mesh_ref("coin1", event)
func _on_gold_2_input_event(_camera, event, _click_position, _click_normal, _shape_idx):
_initialize_mesh_ref("coin2", event)
func _on_gold_3_input_event(_camera, event, _click_position, _click_normal, _shape_idx):
_initialize_mesh_ref("coin3", event)
func _on_ConfirmEscape_confirmed():
_quit_to_menu()
@@ -183,3 +146,19 @@ func _load_meshes():
for key in meshes:
meshes[key].search_keys()
func _input(event):
if event is InputEventMouseButton or event is InputEventScreenTouch:
var camera = $"Main Camera"
from = camera.project_ray_origin(event.position)
to = from + camera.project_ray_normal(event.position) * RAY_LENGTH
func _physics_process(_delta):
var space_state = get_world().direct_space_state
if from != null and to != null:
var result = space_state.intersect_ray(from, to, [], 1, false, true)
from = null
to = null
var node = result["collider"].get_parent()
if node != null:
_start_dissolve(node.name)