2021-05-08 20:38:16 +02:00
|
|
|
extends Spatial
|
|
|
|
|
|
2021-05-12 13:51:34 +02:00
|
|
|
const time_max = 3000 # msec
|
2021-05-12 16:54:15 +02:00
|
|
|
const gyroscope_max_diff = 0.1
|
|
|
|
|
|
|
|
|
|
# var gyroscope_value_old = Vector2(0, 0)
|
|
|
|
|
var gyroscope_value_old = Vector3(0, 0, 0)
|
2021-05-12 13:51:34 +02:00
|
|
|
|
|
|
|
|
onready var meshes = {
|
|
|
|
|
"dagger": {
|
|
|
|
|
"mesh": $"Main Scene Props/dagger",
|
|
|
|
|
"value": 0.0,
|
|
|
|
|
"label": "Dagger",
|
|
|
|
|
"lock": false,
|
|
|
|
|
"tick_reference": null
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func _ready():
|
2021-05-12 14:55:59 +02:00
|
|
|
$Dialog/ConfirmEscape.set_title(tr("SCENE_WARCRAFT_DIALOG_QUIT_TITLE"))
|
|
|
|
|
$Dialog/ConfirmEscape.set_text(tr("SCENE_WARCRAFT_DIALOG_QUIT_QUESTION"))
|
2021-05-12 13:51:34 +02:00
|
|
|
|
2021-05-09 17:10:40 +02:00
|
|
|
func _process(_delta):
|
2021-05-12 16:54:15 +02:00
|
|
|
_check_quit_scene()
|
|
|
|
|
_check_dissolve_mesh()
|
|
|
|
|
_check_change_angle_camera()
|
|
|
|
|
|
|
|
|
|
func _check_quit_scene():
|
2021-05-09 17:10:40 +02:00
|
|
|
# Event key "escape" and "godot event" ui_end
|
|
|
|
|
if Input.is_action_just_pressed("ui_end"):
|
2021-05-09 22:03:42 +02:00
|
|
|
_confirm_before_quit()
|
2021-05-12 16:54:15 +02:00
|
|
|
|
|
|
|
|
func _check_dissolve_mesh():
|
2021-05-12 13:51:34 +02:00
|
|
|
# Event dissolve in object searched by gamer
|
|
|
|
|
for mesh in meshes:
|
|
|
|
|
if meshes[mesh]["lock"] == true and meshes[mesh]["mesh"] != null:
|
|
|
|
|
if meshes[mesh]["tick_reference"] == null:
|
|
|
|
|
meshes[mesh]["tick_reference"] = OS.get_ticks_msec()
|
|
|
|
|
|
|
|
|
|
if OS.get_ticks_msec() < meshes[mesh]["tick_reference"] + time_max:
|
|
|
|
|
meshes[mesh]["value"] += 0.01
|
|
|
|
|
meshes[mesh]["mesh"].get_surface_material(0).set("shader_param/dissolve_amount", meshes[mesh]["value"])
|
|
|
|
|
else:
|
|
|
|
|
meshes[mesh]["mesh"].call_deferred("free")
|
|
|
|
|
meshes[mesh]["mesh"] = null
|
2021-05-08 20:38:16 +02:00
|
|
|
|
2021-05-12 16:54:15 +02:00
|
|
|
func _check_change_angle_camera():
|
|
|
|
|
var camera = $"Main Camera"
|
|
|
|
|
var gyroscope = Input.get_gyroscope()
|
|
|
|
|
|
|
|
|
|
if camera.h_offset >= -0.2:
|
|
|
|
|
if _action_pressed("ui_left") or _gyroscope_changed_left(gyroscope):
|
|
|
|
|
# print("[warcraft#_ready] move camera angle to left")
|
|
|
|
|
$"Main Camera".h_offset -= 0.01
|
|
|
|
|
|
|
|
|
|
if camera.h_offset <= 0.2:
|
|
|
|
|
if _action_pressed("ui_right") or _gyroscope_changed_right(gyroscope):
|
|
|
|
|
# print("[warcraft#_ready] move camera angle to right")
|
|
|
|
|
$"Main Camera".h_offset += 0.01
|
|
|
|
|
|
|
|
|
|
if camera.v_offset >= -0.2:
|
|
|
|
|
if _action_pressed("ui_down") or _gyroscope_changed_down(gyroscope):
|
|
|
|
|
# print("[warcraft#_ready] move camera angle to right")
|
|
|
|
|
$"Main Camera".v_offset -= 0.01
|
|
|
|
|
|
|
|
|
|
if camera.v_offset <= 0.2:
|
|
|
|
|
if _action_pressed("ui_up") or _gyroscope_changed_up(gyroscope):
|
|
|
|
|
# print("[warcraft#_ready] move camera angle to right")
|
|
|
|
|
$"Main Camera".v_offset += 0.01
|
|
|
|
|
|
|
|
|
|
gyroscope_value_old = gyroscope
|
|
|
|
|
|
|
|
|
|
func _action_pressed(action):
|
|
|
|
|
return Input.is_action_just_pressed(action)
|
|
|
|
|
|
|
|
|
|
func _gyroscope_changed_left(gyroscope):
|
|
|
|
|
if (gyroscope.y - gyroscope_value_old.y) > gyroscope_max_diff:
|
|
|
|
|
# print("[warcraft#_ready] (left)")
|
|
|
|
|
print("[warcraft#_ready] (left) y "+String(gyroscope.y)+" - y.old "+String(gyroscope_value_old.y)+" = "+String(gyroscope.y - gyroscope_value_old.y))
|
|
|
|
|
return true
|
|
|
|
|
else:
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
|
|
func _gyroscope_changed_right(gyroscope):
|
|
|
|
|
if (gyroscope.y - gyroscope_value_old.y) > gyroscope_max_diff and gyroscope.y > 0:
|
|
|
|
|
print("[warcraft#_ready] (right)")
|
|
|
|
|
# print("[warcraft#_ready] (right) y "+String(gyroscope.y)+" - x.old "+String(gyroscope_value_old.y)+" = "+String(gyroscope.y - gyroscope_value_old.y))
|
|
|
|
|
return true
|
|
|
|
|
else:
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
|
|
func _gyroscope_changed_down(gyroscope):
|
|
|
|
|
if (gyroscope.z - gyroscope_value_old.z) > gyroscope_max_diff:
|
|
|
|
|
print("[warcraft#_ready] (down)")
|
|
|
|
|
# print("[warcraft#_ready] (down) x "+String(gyroscope.x)+" - x.old "+String(gyroscope_value_old.x)+" = "+String(gyroscope.x - gyroscope_value_old.x))
|
|
|
|
|
return true
|
|
|
|
|
else:
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
|
|
func _gyroscope_changed_up(gyroscope):
|
|
|
|
|
if (gyroscope.z - gyroscope_value_old.z) > gyroscope_max_diff and gyroscope.z > 0:
|
|
|
|
|
print("[warcraft#_ready] (up)")
|
|
|
|
|
# print("[warcraft#_ready] (up) x "+String(gyroscope.x)+" - x.old "+String(gyroscope_value_old.x)+" = "+String(gyroscope.x - gyroscope_value_old.x))
|
|
|
|
|
return true
|
|
|
|
|
else:
|
|
|
|
|
return false
|
|
|
|
|
|
2021-05-08 20:38:16 +02:00
|
|
|
func _notification(what):
|
2021-05-09 17:10:40 +02:00
|
|
|
# Notification for android back action
|
2021-05-08 20:38:16 +02:00
|
|
|
if what == MainLoop.NOTIFICATION_WM_GO_BACK_REQUEST:
|
2021-05-09 22:03:42 +02:00
|
|
|
_confirm_before_quit()
|
|
|
|
|
|
|
|
|
|
func _confirm_before_quit():
|
2021-05-12 13:51:34 +02:00
|
|
|
$Dialog/ConfirmEscape.popup()
|
2021-05-09 17:10:40 +02:00
|
|
|
|
|
|
|
|
# Back to main scene
|
|
|
|
|
func _quit_to_menu():
|
|
|
|
|
Global.goto_scene("res://scenes/main.tscn")
|
2021-05-12 13:51:34 +02:00
|
|
|
|
|
|
|
|
# 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 _initialize_mesh_ref(meshInstance, event):
|
|
|
|
|
if meshes[meshInstance]["lock"] == false and (event is InputEventMouseButton or event is InputEventScreenTouch):
|
|
|
|
|
meshes[meshInstance]["lock"] = true
|
|
|
|
|
|
|
|
|
|
func _on_ConfirmEscape_confirmed():
|
|
|
|
|
_quit_to_menu()
|