diff --git a/scenes/levels/warcraft/WarCraft.gd b/scenes/levels/warcraft/WarCraft.gd index 6e83d15..5a297c3 100644 --- a/scenes/levels/warcraft/WarCraft.gd +++ b/scenes/levels/warcraft/WarCraft.gd @@ -1,6 +1,10 @@ extends Spatial const time_max = 3000 # msec +const gyroscope_max_diff = 0.1 + +# var gyroscope_value_old = Vector2(0, 0) +var gyroscope_value_old = Vector3(0, 0, 0) onready var meshes = { "dagger": { @@ -17,10 +21,16 @@ func _ready(): $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: @@ -34,6 +44,67 @@ func _process(_delta): 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 >= -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 + func _notification(what): # Notification for android back action if what == MainLoop.NOTIFICATION_WM_GO_BACK_REQUEST: diff --git a/scenes/main.gd b/scenes/main.gd index db48726..5dacb77 100644 --- a/scenes/main.gd +++ b/scenes/main.gd @@ -3,7 +3,10 @@ extends Node export (PackedScene) var about = load("res://scenes/UI/About.tscn") export (PackedScene) var scenes = load("res://scenes/UI/ChooseScene.tscn") +const max_diff = 0.08 + var current_scene = null +var value_old = Vector2(0, 0) func _ready(): print(tr("MESSAGE_READY")) @@ -12,6 +15,14 @@ func _ready(): $Grid/Menu/Action/About.text = tr("MAIN_BUTTON_ABOUT") $Grid/Menu/Action/Quit.text = tr("MAIN_BUTTON_QUIT") +func _process(delta): + var gyroscope = Input.get_gyroscope().abs() + var value = Vector2(gyroscope[0], gyroscope[1]) + if value[0] > value_old[0] + max_diff and value[1] > value_old[1] + max_diff: + print("[main#_process] " + String(value)) + + value_old = value + # Quit the game func _on_Quit_pressed(): get_tree().quit(0)