Add test about gyroscope movement camera

This commit is contained in:
VAILLANT Jeremy
2021-05-12 16:54:15 +02:00
parent d6eeb9a86e
commit b8018bdffd
2 changed files with 83 additions and 1 deletions
+72 -1
View File
@@ -1,6 +1,10 @@
extends Spatial extends Spatial
const time_max = 3000 # msec 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 = { onready var meshes = {
"dagger": { "dagger": {
@@ -17,10 +21,16 @@ func _ready():
$Dialog/ConfirmEscape.set_text(tr("SCENE_WARCRAFT_DIALOG_QUIT_QUESTION")) $Dialog/ConfirmEscape.set_text(tr("SCENE_WARCRAFT_DIALOG_QUIT_QUESTION"))
func _process(_delta): 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 # Event key "escape" and "godot event" ui_end
if Input.is_action_just_pressed("ui_end"): if Input.is_action_just_pressed("ui_end"):
_confirm_before_quit() _confirm_before_quit()
func _check_dissolve_mesh():
# Event dissolve in object searched by gamer # Event dissolve in object searched by gamer
for mesh in meshes: for mesh in meshes:
if meshes[mesh]["lock"] == true and meshes[mesh]["mesh"] != null: 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"].call_deferred("free")
meshes[mesh]["mesh"] = null 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): func _notification(what):
# Notification for android back action # Notification for android back action
if what == MainLoop.NOTIFICATION_WM_GO_BACK_REQUEST: if what == MainLoop.NOTIFICATION_WM_GO_BACK_REQUEST:
+11
View File
@@ -3,7 +3,10 @@ extends Node
export (PackedScene) var about = load("res://scenes/UI/About.tscn") export (PackedScene) var about = load("res://scenes/UI/About.tscn")
export (PackedScene) var scenes = load("res://scenes/UI/ChooseScene.tscn") export (PackedScene) var scenes = load("res://scenes/UI/ChooseScene.tscn")
const max_diff = 0.08
var current_scene = null var current_scene = null
var value_old = Vector2(0, 0)
func _ready(): func _ready():
print(tr("MESSAGE_READY")) print(tr("MESSAGE_READY"))
@@ -12,6 +15,14 @@ func _ready():
$Grid/Menu/Action/About.text = tr("MAIN_BUTTON_ABOUT") $Grid/Menu/Action/About.text = tr("MAIN_BUTTON_ABOUT")
$Grid/Menu/Action/Quit.text = tr("MAIN_BUTTON_QUIT") $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 # Quit the game
func _on_Quit_pressed(): func _on_Quit_pressed():
get_tree().quit(0) get_tree().quit(0)