262 lines
7.8 KiB
GDScript
262 lines
7.8 KiB
GDScript
extends Spatial
|
|
|
|
const TIME_MAX = 3000 # msec
|
|
const GYROSCOPE_MAX_DIFF = 0.5
|
|
const OFFSET_CAMERA_MAX = 0.12
|
|
const OFFSET_STEP_CHANGE = 0.01
|
|
|
|
var gyroscope_value_old = Vector3(0, 0, 0)
|
|
|
|
onready var meshes = {
|
|
"dagger": {
|
|
"mesh": $"Hidden Objects Items/dagger",
|
|
"value": 0.0,
|
|
"label": "Dagger",
|
|
"lock": false,
|
|
"tick_reference": null
|
|
},
|
|
"fiole1": {
|
|
"mesh": $"Hidden Objects Items/Fioles x3/sm_fiole1",
|
|
"value": 0.0,
|
|
"label": "Fiole",
|
|
"lock": false,
|
|
"tick_reference": null
|
|
},
|
|
"fiole2": {
|
|
"mesh": $"Hidden Objects Items/Fioles x3/sm_fiole2",
|
|
"value": 0.0,
|
|
"label": "Fiole",
|
|
"lock": false,
|
|
"tick_reference": null
|
|
},
|
|
"fiole3": {
|
|
"mesh": $"Hidden Objects Items/Fioles x3/sm_fiole_socle/sm_fiole3",
|
|
"value": 0.0,
|
|
"label": "Fiole",
|
|
"lock": false,
|
|
"tick_reference": null
|
|
},
|
|
"spyglass": {
|
|
"mesh": $"Hidden Objects Items/sm_spyglass",
|
|
"value": 0.0,
|
|
"label": "Spyglass",
|
|
"lock": false,
|
|
"tick_reference": null
|
|
},
|
|
"coin1": {
|
|
"mesh": $"Hidden Objects Items/golds/sm_stackgold_1",
|
|
"value": 0.0,
|
|
"label": "Coins",
|
|
"lock": false,
|
|
"tick_reference": null
|
|
},
|
|
"coin2": {
|
|
"mesh": $"Hidden Objects Items/golds/sm_stackgold_2",
|
|
"value": 0.0,
|
|
"label": "Coins",
|
|
"lock": false,
|
|
"tick_reference": null
|
|
},
|
|
"coin3": {
|
|
"mesh": $"Hidden Objects Items/golds/sm_stackgold_3",
|
|
"value": 0.0,
|
|
"label": "Coins",
|
|
"lock": false,
|
|
"tick_reference": null
|
|
},
|
|
"weapon": {
|
|
"mesh": $"Hidden Objects Items/sm_weapon_gun",
|
|
"value": 0.0,
|
|
"label": "Weapon Gun",
|
|
"lock": false,
|
|
"tick_reference": null
|
|
},
|
|
"beer": {
|
|
"mesh": $"Hidden Objects Items/sm_pinte_beer",
|
|
"value": 0.0,
|
|
"label": "Beer Pinte",
|
|
"lock": false,
|
|
"tick_reference": null
|
|
},
|
|
"apple1": {
|
|
"mesh": $"Hidden Objects Items/apples/sm_apple_1",
|
|
"value": 0.0,
|
|
"label": "Apple",
|
|
"lock": false,
|
|
"tick_reference": null
|
|
},
|
|
"apple2": {
|
|
"mesh": $"Hidden Objects Items/apples/sm_apple_2",
|
|
"value": 0.0,
|
|
"label": "Apple",
|
|
"lock": false,
|
|
"tick_reference": null
|
|
},
|
|
"apple3": {
|
|
"mesh": $"Hidden Objects Items/apples/sm_apple_3",
|
|
"value": 0.0,
|
|
"label": "Apple",
|
|
"lock": false,
|
|
"tick_reference": null
|
|
},
|
|
"apple4": {
|
|
"mesh": $"Hidden Objects Items/apples/sm_apple_4",
|
|
"value": 0.0,
|
|
"label": "Apple",
|
|
"lock": false,
|
|
"tick_reference": null
|
|
}
|
|
}
|
|
|
|
func _ready():
|
|
$Dialog/ConfirmEscape.set_title(tr("SCENE_WARCRAFT_DIALOG_QUIT_TITLE"))
|
|
$Dialog/ConfirmEscape.set_text(tr("SCENE_WARCRAFT_DIALOG_QUIT_QUESTION"))
|
|
|
|
func _process(_delta):
|
|
_check_quit_scene()
|
|
_check_dissolve_mesh()
|
|
_check_change_angle_camera()
|
|
|
|
func _check_quit_scene():
|
|
# Event key "escape" and "godot event" ui_end
|
|
if Input.is_action_just_pressed("ui_end"):
|
|
_confirm_before_quit()
|
|
|
|
func _check_dissolve_mesh():
|
|
# 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
|
|
|
|
func _check_change_angle_camera():
|
|
var camera = $"Main Camera"
|
|
var gyroscope = Input.get_gyroscope()
|
|
|
|
if camera.h_offset >= -OFFSET_CAMERA_MAX:
|
|
if _action_pressed("ui_left") or _action_gyroscope("left", gyroscope):
|
|
print("[warcraft#_ready] move camera angle to left")
|
|
$"Main Camera".h_offset -= OFFSET_STEP_CHANGE
|
|
|
|
if camera.h_offset <= OFFSET_CAMERA_MAX:
|
|
if _action_pressed("ui_right") or _action_gyroscope("right", gyroscope):
|
|
print("[warcraft#_ready] move camera angle to right")
|
|
$"Main Camera".h_offset += OFFSET_STEP_CHANGE
|
|
|
|
if camera.v_offset >= -OFFSET_CAMERA_MAX:
|
|
if _action_pressed("ui_down") or _action_gyroscope("down", gyroscope):
|
|
print("[warcraft#_ready] move camera angle to down")
|
|
$"Main Camera".v_offset -= OFFSET_STEP_CHANGE
|
|
|
|
if camera.v_offset <= OFFSET_CAMERA_MAX:
|
|
if _action_pressed("ui_up") or _action_gyroscope("up", gyroscope):
|
|
print("[warcraft#_ready] move camera angle to up")
|
|
$"Main Camera".v_offset += OFFSET_STEP_CHANGE
|
|
|
|
gyroscope_value_old = gyroscope
|
|
|
|
func _action_pressed(action):
|
|
return Input.is_action_pressed(action)
|
|
|
|
func _action_gyroscope(action, gyroscope):
|
|
if Global.gyroscope_enabled():
|
|
var expression = Expression.new()
|
|
|
|
expression.parse("_gyroscope_changed_"+action+"(gyroscope)", ["gyroscope"])
|
|
|
|
if expression.execute([gyroscope], self):
|
|
return true
|
|
else:
|
|
return false
|
|
else:
|
|
return false
|
|
|
|
func _gyroscope_changed_left(gyroscope):
|
|
return (gyroscope.abs().y - gyroscope_value_old.abs().y) > GYROSCOPE_MAX_DIFF and \
|
|
gyroscope.y < gyroscope_value_old.y
|
|
|
|
func _gyroscope_changed_right(gyroscope):
|
|
return (gyroscope.abs().y - gyroscope_value_old.abs().y) > GYROSCOPE_MAX_DIFF and \
|
|
gyroscope.y > gyroscope_value_old.y
|
|
|
|
func _gyroscope_changed_down(gyroscope):
|
|
return (gyroscope.abs().z - gyroscope_value_old.abs().z) > GYROSCOPE_MAX_DIFF and \
|
|
gyroscope.z > gyroscope_value_old.z or \
|
|
(gyroscope.abs().x - gyroscope_value_old.abs().x) > GYROSCOPE_MAX_DIFF and \
|
|
gyroscope.x > gyroscope_value_old.x
|
|
|
|
func _gyroscope_changed_up(gyroscope):
|
|
return (gyroscope.abs().z - gyroscope_value_old.abs().z) > GYROSCOPE_MAX_DIFF and \
|
|
gyroscope.z < gyroscope_value_old.z or \
|
|
(gyroscope.abs().x - gyroscope_value_old.abs().x) > GYROSCOPE_MAX_DIFF and \
|
|
gyroscope.x < gyroscope_value_old.x
|
|
|
|
func _notification(what):
|
|
# Notification for android back action
|
|
if what == MainLoop.NOTIFICATION_WM_GO_BACK_REQUEST:
|
|
_confirm_before_quit()
|
|
|
|
func _confirm_before_quit():
|
|
$Dialog/ConfirmEscape.popup()
|
|
|
|
# Back to main scene
|
|
func _quit_to_menu():
|
|
Global.goto_scene("res://scenes/main.tscn")
|
|
|
|
func _initialize_mesh_ref(meshInstance, event):
|
|
if meshes[meshInstance]["lock"] == false and (event is InputEventMouseButton or event is InputEventScreenTouch):
|
|
meshes[meshInstance]["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()
|