2026-05-16 19:18:27 +02:00
|
|
|
extends Node3D
|
2021-05-14 22:17:44 +02:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
2026-05-16 19:18:27 +02:00
|
|
|
@export var object_first: PackedScene = load("res://scenes/levels/parts/ObjectListFirst.tscn")
|
|
|
|
|
@export var object_std: PackedScene = load("res://scenes/levels/parts/ObjectListStandard.tscn")
|
|
|
|
|
@export var object_last: PackedScene = 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_button = null
|
|
|
|
|
@onready var animation_player = null
|
2021-05-14 22:17:44 +02:00
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
|
_load_translations()
|
|
|
|
|
_load_meshes()
|
2021-06-06 16:54:38 +02:00
|
|
|
_load_back_button()
|
|
|
|
|
_load_prepare_victory_condition()
|
|
|
|
|
_load_hud_menu()
|
|
|
|
|
_load_ambient_sound()
|
2021-06-05 14:11:47 +02:00
|
|
|
|
2021-06-06 16:54:38 +02:00
|
|
|
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
|
2021-06-26 15:33:34 +02:00
|
|
|
create_dissolve_mesh(scene_detail.key())
|
2021-06-06 16:54:38 +02:00
|
|
|
|
|
|
|
|
func _load_back_button():
|
2026-05-16 21:50:00 +02:00
|
|
|
$Quit/TextureButton.pressed.connect(Event._on_main_scene_pressed)
|
2021-06-05 14:11:47 +02:00
|
|
|
|
2021-06-06 16:54:38 +02:00
|
|
|
func _load_prepare_victory_condition():
|
|
|
|
|
var level = mlevel.new(Global.current_scene_int)
|
|
|
|
|
|
|
|
|
|
victory_condition = level.object_to_find()
|
|
|
|
|
victory_progress = level.object_finding()
|
|
|
|
|
|
|
|
|
|
func _load_hud_menu():
|
2021-06-05 14:11:47 +02:00
|
|
|
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
|
|
|
|
|
|
2021-06-06 16:54:38 +02:00
|
|
|
func _load_ambient_sound():
|
|
|
|
|
if Setting.get_setting_ambient_sound():
|
|
|
|
|
$AmbientSound.play()
|
|
|
|
|
$AmbientSound.stream_paused = false
|
|
|
|
|
|
2021-06-05 14:11:47 +02:00
|
|
|
func _create_button_info(scene, counter, label_counter):
|
2021-06-06 16:54:38 +02:00
|
|
|
var button = _search_button_to_use(counter)
|
2026-05-16 21:28:22 +02:00
|
|
|
var label_name = scene.label()
|
|
|
|
|
|
2021-06-06 16:54:38 +02:00
|
|
|
if label_counter != null and label_counter == scene.label_counter():
|
2026-05-16 21:28:22 +02:00
|
|
|
label_name = last_button.get_node("Label").text + " " + str(scene.counter())
|
|
|
|
|
_configure_button_object(last_button, scene, label_name)
|
|
|
|
|
_create_animation_warning(_get_node_animated().get_node("Label"), label_name)
|
2021-06-05 14:11:47 +02:00
|
|
|
else:
|
2021-06-06 16:54:38 +02:00
|
|
|
$ListObjects/ListContainer.add_child(button)
|
2026-05-16 21:28:22 +02:00
|
|
|
_configure_button_object(button, scene, label_name)
|
|
|
|
|
_create_animation_slide(_get_node_animated(), label_name)
|
2021-06-05 14:11:47 +02:00
|
|
|
|
2021-06-06 16:54:38 +02:00
|
|
|
last_button = button
|
|
|
|
|
|
|
|
|
|
func _get_node_animated():
|
|
|
|
|
return $ListObjects/ListContainer.get_child($ListObjects/ListContainer.get_child_count() - 1 )
|
|
|
|
|
|
|
|
|
|
func _search_button_to_use(counter):
|
|
|
|
|
if counter == 0:
|
2026-05-16 19:18:27 +02:00
|
|
|
return object_first.instantiate()
|
2021-06-06 16:54:38 +02:00
|
|
|
elif counter == meshes.size() - 1:
|
2026-05-16 19:18:27 +02:00
|
|
|
return object_last.instantiate()
|
2021-06-05 14:11:47 +02:00
|
|
|
else:
|
2026-05-16 19:18:27 +02:00
|
|
|
return object_std.instantiate()
|
2021-06-05 14:11:47 +02:00
|
|
|
|
2021-06-06 16:54:38 +02:00
|
|
|
func _configure_button_object(button, scene, label):
|
|
|
|
|
button.get_node("Label").set_text(label)
|
|
|
|
|
button.set_meta("animation", label)
|
|
|
|
|
button.set_meta("name", scene.label())
|
|
|
|
|
button.set_meta("counter", scene.counter())
|
|
|
|
|
button.set_meta("counted", 0)
|
2021-06-05 14:11:47 +02:00
|
|
|
|
2026-05-16 21:28:22 +02:00
|
|
|
func _create_animation_slide(node, p_name):
|
2026-05-16 21:50:00 +02:00
|
|
|
_add_animation_to_player(p_name, GameAnimation.level_hud_slide(node))
|
2021-05-29 21:09:10 +02:00
|
|
|
|
2026-05-16 21:28:22 +02:00
|
|
|
func _create_animation_warning(node, p_name):
|
2026-05-16 21:50:00 +02:00
|
|
|
_add_animation_to_player(p_name, GameAnimation.level_hud_warning(node))
|
2026-05-16 19:40:03 +02:00
|
|
|
|
2026-05-16 21:28:22 +02:00
|
|
|
func _add_animation_to_player(p_name: String, anim: Animation) -> void:
|
2026-05-16 19:40:03 +02:00
|
|
|
var player = $ListObjects/AnimationPlayer
|
|
|
|
|
var lib = player.get_animation_library("")
|
|
|
|
|
if lib == null:
|
|
|
|
|
lib = AnimationLibrary.new()
|
|
|
|
|
player.add_animation_library("", lib)
|
2026-05-16 21:28:22 +02:00
|
|
|
lib.add_animation(p_name, anim)
|
2021-05-14 22:17:44 +02:00
|
|
|
|
|
|
|
|
func _process(_delta):
|
|
|
|
|
_check_dissolve_mesh()
|
|
|
|
|
_check_change_angle_camera()
|
2021-05-29 21:09:10 +02:00
|
|
|
_check_victory_condition()
|
2021-05-14 22:17:44 +02:00
|
|
|
|
2021-06-26 15:33:34 +02:00
|
|
|
func create_dissolve_mesh(key):
|
2026-05-16 19:40:03 +02:00
|
|
|
var mesh = _node_to_mesh(key)
|
|
|
|
|
if mesh == null:
|
|
|
|
|
return
|
|
|
|
|
var material = mesh.get_active_material(0)
|
|
|
|
|
if material == null:
|
|
|
|
|
return
|
|
|
|
|
material.set_shader_parameter("dissolve_amount", 0.0)
|
2021-06-26 15:33:34 +02:00
|
|
|
|
2021-05-14 22:17:44 +02:00
|
|
|
func _check_dissolve_mesh():
|
|
|
|
|
# Event dissolve in object searched by gamer
|
|
|
|
|
for key in meshes:
|
2021-05-29 21:09:10 +02:00
|
|
|
if bool(meshes[key].lock()) == true and meshes[key].mesh() != null:
|
2026-05-16 19:40:03 +02:00
|
|
|
var mesh = _node_to_mesh(key)
|
|
|
|
|
if mesh == null:
|
|
|
|
|
continue
|
2021-05-14 22:17:44 +02:00
|
|
|
if meshes[key].tick_reference() == 0:
|
2026-05-16 19:18:27 +02:00
|
|
|
meshes[key].set_tick_reference(Time.get_ticks_msec())
|
2021-05-30 15:04:33 +02:00
|
|
|
_node_object_list(key)
|
2026-05-16 21:50:00 +02:00
|
|
|
GameAnimation.start_dissolve(mesh, mesh.get_active_material(0))
|
2021-05-14 22:17:44 +02:00
|
|
|
|
2026-05-16 19:18:27 +02:00
|
|
|
if Time.get_ticks_msec() < meshes[key].tick_reference() + TIME_MAX:
|
2021-05-14 22:17:44 +02:00
|
|
|
meshes[key].set_value(meshes[key].value() + 0.01)
|
|
|
|
|
else:
|
2021-05-30 15:04:33 +02:00
|
|
|
_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)
|
2021-05-14 22:17:44 +02:00
|
|
|
|
|
|
|
|
func _check_change_angle_camera():
|
2021-06-05 14:11:47 +02:00
|
|
|
var camera = $"MainCamera"
|
2021-05-14 22:17:44 +02:00
|
|
|
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")
|
2026-05-16 19:18:27 +02:00
|
|
|
$"Main Camera3D".h_offset -= OFFSET_STEP_CHANGE
|
2021-05-14 22:17:44 +02:00
|
|
|
|
|
|
|
|
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")
|
2026-05-16 19:18:27 +02:00
|
|
|
$"Main Camera3D".h_offset += OFFSET_STEP_CHANGE
|
2021-05-14 22:17:44 +02:00
|
|
|
|
|
|
|
|
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")
|
2026-05-16 19:18:27 +02:00
|
|
|
$"Main Camera3D".v_offset -= OFFSET_STEP_CHANGE
|
2021-05-14 22:17:44 +02:00
|
|
|
|
|
|
|
|
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")
|
2026-05-16 19:18:27 +02:00
|
|
|
$"Main Camera3D".v_offset += OFFSET_STEP_CHANGE
|
2021-05-14 22:17:44 +02:00
|
|
|
|
|
|
|
|
gyroscope_value_old = gyroscope
|
|
|
|
|
|
|
|
|
|
func _action_pressed(action):
|
|
|
|
|
return Input.is_action_pressed(action)
|
|
|
|
|
|
|
|
|
|
func _action_gyroscope(action, gyroscope):
|
2021-06-03 22:18:50 +02:00
|
|
|
if Setting.get_setting_gyrosocpe():
|
2021-05-14 22:17:44 +02:00
|
|
|
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):
|
2021-05-29 21:09:10 +02:00
|
|
|
if bool(meshes[key].lock()) == false:
|
|
|
|
|
meshes[key].set_lock(int(true))
|
2021-05-23 15:10:20 +02:00
|
|
|
$ObjectFind.stream = meshes[key].audio_sound()
|
|
|
|
|
$ObjectFind.play()
|
2021-05-14 22:17:44 +02:00
|
|
|
|
2021-05-29 21:09:10 +02:00
|
|
|
func _check_victory_condition():
|
|
|
|
|
if victory_condition == victory_progress:
|
2021-06-06 16:54:38 +02:00
|
|
|
print("[levels#_check_victory_condition] \\o/\\o/ \\o/ \\o/ \\o/\\o/")
|
|
|
|
|
print("[levels#_check_victory_condition] Win !!")
|
2021-06-05 14:11:47 +02:00
|
|
|
Global.goto_scene("res://scenes/UI/ending/Ending.tscn")
|
2021-05-29 21:09:10 +02:00
|
|
|
|
|
|
|
|
func _node_to_mesh(key):
|
2026-05-16 19:40:03 +02:00
|
|
|
return get_node_or_null(meshes[key].mesh())
|
2021-06-26 15:33:34 +02:00
|
|
|
|
2021-05-29 21:09:10 +02:00
|
|
|
func _node_to_area(key):
|
2026-05-16 19:40:03 +02:00
|
|
|
return get_node_or_null(meshes[key].mesh() + "/Area3D")
|
2021-05-30 15:04:33 +02:00
|
|
|
|
|
|
|
|
func _node_object_list(key):
|
2021-06-06 16:54:38 +02:00
|
|
|
var animation_played = null
|
2026-05-16 21:28:22 +02:00
|
|
|
|
2021-05-30 15:04:33 +02:00
|
|
|
for child in $ListObjects/ListContainer.get_children():
|
2021-06-26 15:33:34 +02:00
|
|
|
if child.has_meta("name"):
|
2021-06-26 15:42:02 +02:00
|
|
|
if child.get_meta("name") == meshes[key].label():
|
2021-06-26 15:33:34 +02:00
|
|
|
child.set_meta("counted", child.get_meta("counted") + 1)
|
|
|
|
|
|
|
|
|
|
if child.get_meta("counter") == child.get_meta("counted"):
|
2021-06-26 15:42:02 +02:00
|
|
|
animation_played = child.get_meta("name")
|
2021-06-26 15:33:34 +02:00
|
|
|
else:
|
|
|
|
|
var diff = child.get_meta("counter") - child.get_meta("counted")
|
2021-06-26 15:42:02 +02:00
|
|
|
var txt = child.get_meta("name")
|
2021-06-26 15:33:34 +02:00
|
|
|
if diff != 1:
|
2026-05-16 19:40:03 +02:00
|
|
|
txt = txt + " " + str(diff)
|
2021-06-26 15:33:34 +02:00
|
|
|
animation_played = child.get_meta("animation")
|
|
|
|
|
child.get_node("Label").set_text(txt)
|
|
|
|
|
|
|
|
|
|
$ListObjects/AnimationPlayer.queue(animation_played)
|
2021-05-14 22:17:44 +02:00
|
|
|
|
|
|
|
|
func _input(event):
|
|
|
|
|
if event is InputEventMouseButton or event is InputEventScreenTouch:
|
2021-06-05 14:11:47 +02:00
|
|
|
var camera = $"MainCamera"
|
2021-05-14 22:17:44 +02:00
|
|
|
from = camera.project_ray_origin(event.position)
|
|
|
|
|
to = from + camera.project_ray_normal(event.position) * RAY_LENGTH
|
|
|
|
|
|
|
|
|
|
func _physics_process(_delta):
|
2026-05-16 19:18:27 +02:00
|
|
|
var space_state = get_world_3d().direct_space_state
|
2021-05-14 22:17:44 +02:00
|
|
|
if from != null and to != null:
|
2021-05-23 15:10:20 +02:00
|
|
|
_check_collider(space_state)
|
|
|
|
|
|
|
|
|
|
func _check_collider(space_state):
|
2026-05-16 19:40:03 +02:00
|
|
|
var query = PhysicsRayQueryParameters3D.create(from, to)
|
|
|
|
|
query.collision_mask = 1
|
|
|
|
|
query.collide_with_bodies = false
|
|
|
|
|
query.collide_with_areas = true
|
|
|
|
|
var result = space_state.intersect_ray(query)
|
2021-05-23 15:10:20 +02:00
|
|
|
from = null
|
|
|
|
|
to = null
|
|
|
|
|
if result.has("collider"):
|
|
|
|
|
var node = result["collider"].get_parent()
|
|
|
|
|
if node != null:
|
|
|
|
|
_start_dissolve(node.name)
|