213847e95c
Co-authored-by: VAILLANT Jeremy <vaillant.jeremy@dev-crea.com> Reviewed-on: Athena/game-source#74 Co-authored-by: darknight <vaillant.jeremy@dev-crea.com> Co-committed-by: darknight <vaillant.jeremy@dev-crea.com>
229 lines
7.2 KiB
GDScript
229 lines
7.2 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
|
|
const RAY_LENGTH = 1000
|
|
|
|
export (PackedScene) var object_first = load("res://scenes/levels/parts/ObjectListFirst.tscn")
|
|
export (PackedScene) var object_std = load("res://scenes/levels/parts/ObjectListStandard.tscn")
|
|
export (PackedScene) var object_last = load("res://scenes/levels/parts/ObjectListLast.tscn")
|
|
|
|
onready var gyroscope_value_old = Vector3(0, 0, 0)
|
|
onready var table = Global.database.get_table_by_name("scenes")
|
|
onready var meshes = {}
|
|
onready var from = null
|
|
onready var to = null
|
|
onready var mlevel = load("res://db/MLevel.gd")
|
|
onready var mscene = load("res://db/MScene.gd")
|
|
onready var victory_condition = 0
|
|
onready var victory_progress = 0
|
|
onready var last_btn = null
|
|
|
|
func _ready():
|
|
_load_translations()
|
|
_load_meshes()
|
|
_back_button()
|
|
_prepare_victory_condition()
|
|
_display_hud_menu()
|
|
_play_ambient_sound()
|
|
|
|
func _back_button():
|
|
var _back = $Quit/TextureButton.connect("pressed", Event, "_on_main_scene_pressed")
|
|
|
|
func _display_hud_menu():
|
|
var counter = 0
|
|
var scene = null
|
|
var label_counter = null
|
|
|
|
for key in meshes:
|
|
scene = meshes[key]
|
|
_create_button_info(scene, counter, label_counter)
|
|
label_counter = scene.label_counter()
|
|
counter = counter + 1
|
|
|
|
func _create_button_info(scene, counter, label_counter):
|
|
var btn = null
|
|
|
|
if counter == 0:
|
|
btn = object_first.instance()
|
|
elif counter == meshes.size() - 1:
|
|
btn = object_last.instance()
|
|
else:
|
|
btn = object_std.instance()
|
|
|
|
if label_counter != null and label_counter == scene.label_counter():
|
|
last_btn.get_node("Label").set_text(last_btn.get_node("Label").text + " " + String(scene.counter()))
|
|
last_btn.set_meta("name", scene.label())
|
|
last_btn.set_meta("counter", scene.counter())
|
|
last_btn.set_meta("counted", 0)
|
|
else:
|
|
$ListObjects/ListContainer.add_child(btn)
|
|
btn.get_node("Label").set_text(scene.label())
|
|
btn.set_meta("name", scene.label())
|
|
btn.set_meta("counter", scene.counter())
|
|
btn.set_meta("counted", 0)
|
|
|
|
last_btn = btn
|
|
|
|
func _play_ambient_sound():
|
|
if Setting.get_setting_ambient_sound():
|
|
$AmbientSound.play()
|
|
$AmbientSound.stream_paused = false
|
|
|
|
func _prepare_victory_condition():
|
|
var level = mlevel.new(Global.current_scene_int)
|
|
|
|
victory_condition = level.object_to_find()
|
|
victory_progress = level.object_finding()
|
|
|
|
func _process(_delta):
|
|
_check_dissolve_mesh()
|
|
_check_change_angle_camera()
|
|
_check_victory_condition()
|
|
|
|
func _check_dissolve_mesh():
|
|
# Event dissolve in object searched by gamer
|
|
for key in meshes:
|
|
if bool(meshes[key].lock()) == true and meshes[key].mesh() != null:
|
|
if meshes[key].tick_reference() == 0:
|
|
meshes[key].set_tick_reference(OS.get_ticks_msec())
|
|
_node_object_list(key)
|
|
|
|
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())
|
|
else:
|
|
_clean_mesh(key)
|
|
|
|
func _clean_mesh(key):
|
|
victory_progress = mlevel.new(Global.current_scene_int).object_finding()
|
|
_node_to_mesh(key).call_deferred("free")
|
|
meshes[key].set_mesh(null)
|
|
|
|
func _check_change_angle_camera():
|
|
var camera = $"MainCamera"
|
|
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 Setting.get_setting_gyrosocpe():
|
|
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 _start_dissolve(key):
|
|
if bool(meshes[key].lock()) == false:
|
|
meshes[key].set_lock(int(true))
|
|
$ObjectFind.stream = meshes[key].audio_sound()
|
|
$ObjectFind.play()
|
|
|
|
func _check_victory_condition():
|
|
if victory_condition == victory_progress:
|
|
print("[levels#_check_victory_condition] \\o/")
|
|
Global.goto_scene("res://scenes/UI/ending/Ending.tscn")
|
|
|
|
func _node_to_mesh(key):
|
|
return get_node(meshes[key].mesh())
|
|
|
|
func _node_to_area(key):
|
|
return get_node(meshes[key].mesh()+"/Area")
|
|
|
|
func _node_object_list(key):
|
|
for child in $ListObjects/ListContainer.get_children():
|
|
if child.get_meta("name") == meshes[key].label():
|
|
child.set_meta("counted", child.get_meta("counted") + 1)
|
|
|
|
if child.get_meta("counter") == child.get_meta("counted"):
|
|
child.visible = false
|
|
else:
|
|
var diff = child.get_meta("counter") - child.get_meta("counted")
|
|
var txt = child.get_meta("name")
|
|
if diff != 1:
|
|
txt = txt + " " + String(diff)
|
|
child.get_node("Label").set_text(txt)
|
|
|
|
func _load_translations():
|
|
pass
|
|
|
|
func _load_meshes():
|
|
var scene_detail = null
|
|
|
|
for row_index in range(0, table.m_rows_count):
|
|
scene_detail = mscene.new(row_index)
|
|
|
|
if scene_detail.key() != null:
|
|
meshes[scene_detail.key()] = scene_detail
|
|
|
|
func _input(event):
|
|
if event is InputEventMouseButton or event is InputEventScreenTouch:
|
|
var camera = $"MainCamera"
|
|
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:
|
|
_check_collider(space_state)
|
|
|
|
func _check_collider(space_state):
|
|
var result = space_state.intersect_ray(from, to, [], 1, false, true)
|
|
from = null
|
|
to = null
|
|
if result.has("collider"):
|
|
var node = result["collider"].get_parent()
|
|
if node != null:
|
|
_start_dissolve(node.name)
|