Added new room demonstrating a puzzle scene superposed on top of the room.

Need ESC commands to hide escoria.main.current_room and escoria.main.game.ui.*
This commit is contained in:
Julian Murgia
2021-01-22 14:00:57 +01:00
parent 6890d927f5
commit 9fd1d6738d
15 changed files with 606 additions and 107 deletions

View File

@@ -182,6 +182,8 @@ func walk_stop(pos):
# escoria.esc_level_runner.finished(walk_context)
escoria.esc_level_runner.finished()
parent.walk_context = null
yield(parent.animation_sprite, "animation_finished")
parent.emit_signal("arrived")

View File

@@ -69,6 +69,7 @@ var commands = {
"slide_block": { "min_args": 2 },
"spawn": { "min_args": 1 },
"stop": true,
"superpose_scene": { "min_args": 1, "types": [TYPE_STRING, TYPE_BOOL] },
"teleport": { "min_args": 2, "types": [TYPE_STRING, TYPE_STRING, TYPE_INT] },
"teleport_pos": { "min_args": 3 },
"turn_to": { "min_args": 2 },

View File

@@ -393,6 +393,68 @@ func change_scene(params, context, run_events=true):
# cam_target = null
# autosave_pending = true
func superpose_scene(params, context, run_events=true):
printt("superposing scene ", params[0], " with run_events ", run_events)
# check_cache()
# main.clear_scene()
# camera = null
# event_queue = []
# Regular events need to be reset immediately, so we don't
# accidentally `yield()` on them, for performance reasons.
# This does not affect `stack` so execution is fine anyway.
if running_event and running_event.ev_name != "load":
emit_signal("event_done", running_event.ev_name)
running_event = null
var res_room = resource_cache.get_resource(params[0])
var res_game = resource_cache.get_resource(ProjectSettings.get_setting("escoria/ui/game_scene"))
if !res_room:
escoria.report_errors("esc_runner.gd:superpose_scene()",
["Resource not found: " + params[0]])
if !res_game:
escoria.report_errors("esc_runner.gd:superpose_scene()",
["Resource not found: " + ProjectSettings.get_setting("escoria/ui/game_scene")])
resource_cache.clear()
# Load game scene
var game_scene = res_game.instance()
if !game_scene:
escoria.report_errors("esc_runner.gd:superpose_scene()",
["Failed loading scene " + ProjectSettings.get_setting("escoria/ui/game_scene")])
# Load room scene
var room_scene = res_room.instance()
if room_scene:
get_node("/root").add_child(room_scene)
escoria.inputs_manager.is_hotspot_focused = false
if !scenes_cache_list.has(params[0]):
scenes_cache_list.push_back(params[0])
if room_scene.get("global_id"):
scenes_cache[room_scene.global_id] = params[0]
else:
scenes_cache[room_scene.name] = params[0]
else:
escoria.report_errors("esc_runner.gd:superpose_scene()",
["Failed loading scene " + params[0]])
if context != null:
context.waiting = false
# Re-apply actives
for active in actives:
set_active(active, actives[active])
# cam_target = null
# autosave_pending = true
func run_game(actions : Dictionary):
set_process(true)
# `load` and `ready` are exclusive because you probably don't want to

View File

@@ -543,6 +543,35 @@ func spawn(command_params : Array):
func stop(command_params : Array):
return esctypes.EVENT_LEVEL_STATE.BREAK
"""
superpose_scene path [run_events]
Loads a new scene, specified by "path" and displays it OVER the current one.
This is useful to display puzzle scenes over the current room, so that you don't
loose any progression and continuity.
- path String Path to the scene to superpose.
- run_events Boolean (default true) which you never want to set
manually! It's there only to benefit save games, so they don't conflict with the
scene's events.
"""
func superpose_scene(command_params : Array):
# Savegames must have events disabled, so saving the game adds a false to params
var run_events = true
if command_params.size() == 2:
run_events = bool(command_params[1])
# looking for localized string format in scene. this should be somewhere else
var sep = command_params[0].find(":\"")
if sep >= 0:
var path = command_params[0].substr(sep + 2, command_params[0].length() - (sep + 2))
escoria.esc_runner.call_deferred("superpose_scene", [path], current_context, run_events)
else:
escoria.esc_runner.call_deferred("superpose_scene", command_params, current_context, run_events)
current_context.waiting = true
return esctypes.EVENT_LEVEL_STATE.YIELD
"""
Teleports obj1 at obj2's position. If angle_degrees is set (int), sets obj1's
angle to angle_degrees.

View File

@@ -148,98 +148,6 @@ func _process(time):
if Engine.is_editor_hint():
return
$debug.text = str(z_index)
# if task == PLAYER_TASKS.WALK or task == PLAYER_TASKS.SLIDE:
# var pos = get_position()
# var old_pos = pos
# var next
# if walk_path.size() > 1:
# next = walk_path[path_ofs + 1]
# else:
# next = walk_path[path_ofs]
#
# var dist = speed * time * pow(last_scale.x, 2) * terrain.player_speed_multiplier
# if walk_context and "fast" in walk_context and walk_context.fast:
# dist *= terrain.player_doubleclick_speed_multiplier
# var dir = (next - pos).normalized()
#
# # assume that x^2 + y^2 == 1, apply v_speed_damp the y axis
# #printt("dir before", dir)
# dir = dir * (dir.x * dir.x + dir.y * dir.y * v_speed_damp)
# #printt("dir after", dir, dist)
#
# var new_pos
# if pos.distance_to(next) < dist:
# new_pos = next
# path_ofs += 1
# else:
# new_pos = pos + dir * dist
#
# if path_ofs >= walk_path.size() - 1:
# walk_stop(walk_destination)
# return
#
# pos = new_pos
#
# var angle = (old_pos.angle_to_point(pos))
# set_position(pos)
#
# if task == PLAYER_TASKS.WALK:
# last_deg = escoria.utils._get_deg_from_rad(angle)
# last_dir = _get_dir_deg(last_deg, animations)
#
# var current_animation = ""
# if animation_sprite != null:
# current_animation = animation_sprite.animation
## elif animation != null:
## current_animation = animation.current_animation
#
# if current_animation != animations.directions[last_dir][0]:
# animation_sprite.play(animations.directions[last_dir][0])
#
# pose_scale = animations.directions[last_dir][1]
#
# update_terrain()
# else:
# moved = false
# set_process(false)
#func update_terrain(on_event_finished_name = null):
# if !terrain:
# return
# if on_event_finished_name != null and on_event_finished_name != "setup":
# return
#
# var pos = position
# z_index = pos.y if pos.y <= VisualServer.CANVAS_ITEM_Z_MAX else VisualServer.CANVAS_ITEM_Z_MAX
#
# var color
# if terrain_is_scalenodes:
# last_scale = terrain.get_terrain(pos)
# self.scale = last_scale
# elif check_maps:
# color = terrain.get_terrain(pos)
# var scal = terrain.get_scale_range(color.b)
# if scal != get_scale():
# last_scale = scal
# self.scale = last_scale
#
# # Do not flip the entire player character, because that would conflict
# # with shadows that expect to be siblings of $"sprite"
# if pose_scale == -1 and $"sprite".scale.x > 0:
# $"sprite".scale.x *= pose_scale
# collision.scale.x *= pose_scale
# elif pose_scale == 1 and $"sprite".scale.x < 0:
# $"sprite".scale.x *= -1
# collision.scale.x *= -1
#
## if check_maps:
## color = terrain.get_light(pos)
##
## if color:
## for s in sprites:
## s.set_modulate(color)
"""