Added check on "arrived" event in Movable so that the right context continues, not others.

To continue: move walk_* variables in ESCPlayer into Movable makes camera go wrong.
This commit is contained in:
Julian Murgia
2021-01-27 17:02:13 +01:00
parent 41e289cce9
commit 183439337a
12 changed files with 120 additions and 58 deletions

View File

@@ -13,8 +13,22 @@ onready var parent = get_parent()
# If character misses an animation, bypass it and proceed.
onready var bypass_missing_animation = false
#var walk_path : Array = []
#var walk_destination : Vector2
#var walk_context
#var moved : bool
#var path_ofs : float
#
#var last_deg : int
#var last_dir : int
#var last_scale : Vector2
#var pose_scale : int
func _ready():
parent.add_user_signal("arrived")
parent.last_scale = parent.scale
func _process(time):
if Engine.is_editor_hint():
@@ -167,7 +181,8 @@ func walk_stop(pos):
# If we're heading to an object and reached its interaction position,
# orient towards the defined interaction direction set on the object (if any)
if parent.walk_context.has("target_object") and parent.walk_context.target_object.player_orients_on_arrival \
if parent.walk_context.has("target_object") \
and parent.walk_context.target_object.player_orients_on_arrival \
and escoria.esc_runner.get_interactive(parent.walk_context.target_object.global_id):
var orientation = parent.walk_context["target_object"].interaction_direction
parent.last_dir = orientation
@@ -179,12 +194,12 @@ func walk_stop(pos):
update_terrain()
if parent.walk_context != null:
# escoria.esc_level_runner.finished(walk_context)
escoria.esc_level_runner.finished()
parent.walk_context = null
escoria.esc_level_runner.finished(parent.walk_context)
# escoria.esc_level_runner.finished()
# walk_context = null
yield(parent.animation_sprite, "animation_finished")
parent.emit_signal("arrived")
parent.emit_signal("arrived", parent.walk_context)
func update_terrain(on_event_finished_name = null):
@@ -209,7 +224,7 @@ func update_terrain(on_event_finished_name = null):
parent.last_scale = scal
parent.scale = parent.last_scale
# Do not flip the entire player character, because that would conflict
# Do not flip the entire character, because that would conflict
# with shadows that expect to be siblings of $texture
if parent.pose_scale == -1 and parent.get_node("sprite").scale.x > 0:
parent.get_node("sprite").scale.x *= parent.pose_scale
@@ -273,3 +288,31 @@ func is_angle_in_interval(angle: float, interval : Array) -> bool:
return true
return false
"""
Sets character's angle and plays according animation.
- deg int angle to set the character
- immediate bool (currently unused, see TODO below)
If true, direction is switched immediately. Else, successive animations are
used so that the character turns to target angle.
TODO: depending on current angle and current angle, the character may directly turn around
with no "progression". We may enhance this by calculating successive directions to turn the
character to, so that he doesn't switch to opposite direction too fast.
For example, if character looks WEST and set_angle(EAST) is called, we may want the character
to first turn SOUTHWEST, then SOUTH, then SOUTHEAST and finally EAST, all more or less fast.
Whatever the implementation, this should be activated using "parameter "immediate" set to false.
"""
func set_angle(deg : int, immediate = true):
if deg < 0 or deg > 360:
escoria.report_errors("movable.gd:set_angle()", ["Invalid degree to turn to " + str(deg)])
parent.moved = true
parent.last_deg = deg
parent.last_dir = _get_dir_deg(deg, parent.animations)
# The character may have a state animation from before, which would be
# resumed, so we immediately force the correct idle animation
if parent.animation_sprite.animation != parent.animations.idles[parent.last_dir][0]:
parent.animation_sprite.play(parent.animations.idles[parent.last_dir][0])
parent.pose_scale = parent.animations.idles[parent.last_dir][1]
update_terrain()

View File

@@ -19,7 +19,6 @@ export var global_id : String
var params_queue : Array
var terrain : ESCTerrain
var camera : ESCCamera
# If the terrain node type is scalenodes
var terrain_is_scalenodes : bool

View File

@@ -240,7 +240,9 @@ func ev_left_click_on_item(obj, event, default_action = false):
main.current_scene.player.walk_to(destination_position, walk_context)
# Wait for the player to arrive before continuing with action.
yield(main.current_scene.player, "arrived")
var context = yield(main.current_scene.player, "arrived")
if context.target_object != walk_context.target_object:
dont_interact = true
# If no interaction should happen after player has arrived, leave immediately.
if dont_interact:

BIN
bin/Escoria--demo-win64.zip Normal file

Binary file not shown.

View File

@@ -4,12 +4,10 @@
[ext_resource path="res://game/rooms/room2/background.tscn" type="PackedScene" id=2]
[ext_resource path="res://game/ui/commons/fonts/caslonantique.tres" type="DynamicFont" id=3]
[ext_resource path="res://game/characters/mark/mark.tscn" type="PackedScene" id=4]
[ext_resource path="res://game/rooms/room2/button/button.tscn" type="PackedScene" id=5]
[ext_resource path="res://addons/escoria-core/game/core-scripts/escroom.gd" type="Script" id=6]
[ext_resource path="res://addons/escoria-core/game/core-scripts/escitem.gd" type="Script" id=7]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 28.6442, 23.5021 )
[node name="room2" type="Node2D"]
script = ExtResource( 6 )
global_id = "room2"
@@ -82,47 +80,33 @@ polygon = PoolVector2Array( -1.37926, 443.158, 7.96461, 122.796, 84.0504, 77.411
[node name="Position2D" type="Position2D" parent="Hotspots/l_door"]
position = Vector2( 52.1462, 384.691 )
[node name="button_left" type="Area2D" parent="Hotspots"]
script = ExtResource( 7 )
global_id = "r2_button"
esc_script = "res://game/rooms/room2/esc/button.esc"
tooltip_name = "Button"
default_action = "use"
dialog_color = Color( 1, 1, 1, 1 )
interact_positions = {
"default": Vector2( 338.117, 370.025 )
}
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hotspots/button_left"]
position = Vector2( 346.507, 150.721 )
shape = SubResource( 1 )
[node name="action_pos" type="Position2D" parent="Hotspots/button_left"]
position = Vector2( 338.117, 370.025 )
[node name="dialog_position" type="Position2D" parent="Hotspots/button_left"]
position = Vector2( 333.879, 84.4147 )
[node name="button_right" type="Area2D" parent="Hotspots"]
script = ExtResource( 7 )
[node name="button_right" parent="Hotspots" instance=ExtResource( 5 )]
global_id = "r2_button_right"
esc_script = "res://game/rooms/room2/esc/button.esc"
tooltip_name = "Button"
default_action = "use"
dialog_color = Color( 1, 1, 1, 1 )
interact_positions = {
"default": Vector2( 962.822, 370.025 )
"default": Vector2( 971.212, 150.721 )
}
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hotspots/button_right"]
position = Vector2( 971.212, 150.721 )
shape = SubResource( 1 )
[node name="button_left" parent="Hotspots/button_right" instance=ExtResource( 5 )]
visible = false
position = Vector2( -625.523, 0 )
global_id = "r2_button"
esc_script = "res://game/rooms/room2/esc/button.esc"
interact_positions = {
"default": Vector2( 971.212, 150.721 )
}
[node name="action_pos" type="Position2D" parent="Hotspots/button_right"]
[node name="Position2D" type="Position2D" parent="Hotspots/button_right"]
position = Vector2( 962.822, 370.025 )
__meta__ = {
"_editor_description_": ""
}
[node name="dialog_position" type="Position2D" parent="Hotspots/button_right"]
position = Vector2( 958.584, 84.4147 )
[node name="Position2D2" type="Position2D" parent="Hotspots/button_right"]
position = Vector2( 337.299, 370.025 )
__meta__ = {
"_editor_description_": ""
}
[node name="player_start" type="Position2D" parent="."]
position = Vector2( 76.7617, 437.649 )

View File

@@ -22,6 +22,9 @@ margin_right = 40.0
margin_bottom = 14.0
custom_fonts/font = ExtResource( 3 )
text = "ROOM 3"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="walkable_area" parent="." instance=ExtResource( 1 )]
@@ -102,5 +105,17 @@ __meta__ = {
"_editor_description_": ""
}
[node name="button_label" type="Label" parent="Hotspots/button"]
margin_left = 398.135
margin_top = 132.292
margin_right = 642.135
margin_bottom = 167.292
custom_fonts/font = ExtResource( 3 )
text = "I know, this doesn't sound logical
but you should try talking with this button..."
__meta__ = {
"_edit_use_anchors_": false
}
[node name="player_start" type="Position2D" parent="."]
position = Vector2( 63.3074, 444.653 )

View File

@@ -55,6 +55,14 @@ margin_bottom = 14.0
custom_fonts/font = ExtResource( 3 )
text = "ROOM 4"
[node name="Label" type="Label" parent="background"]
margin_left = 214.299
margin_top = 93.6566
margin_right = 1008.3
margin_bottom = 109.657
custom_fonts/font = ExtResource( 3 )
text = "This room demonstrates how to use a background image AND using a large image width AND setting a depth map on the ESCTerrain node"
[node name="walkable_area" type="Navigation2D" parent="."]
script = ExtResource( 1 )
scales = ExtResource( 8 )

View File

@@ -129,7 +129,7 @@ esc_script = "res://game/rooms/room5/esc/wall_item.esc"
tooltip_name = "Item on the wall"
default_action = "look"
interact_positions = {
"default": Vector2( 657, 377 )
"default": Vector2( 622.513, 359.162 )
}
[node name="Position2D2" type="Position2D" parent="Hotspots/item_wall"]
@@ -150,12 +150,14 @@ position = Vector2( -77.4207, 0 )
[node name="pen" parent="Hotspots" instance=ExtResource( 10 )]
position = Vector2( 909.908, 443.451 )
dialog_color = Color( 1, 1, 1, 1 )
interact_positions = {
"default": Vector2( 909.908, 443.451 )
}
[node name="empty_sheet" parent="Hotspots" instance=ExtResource( 9 )]
position = Vector2( 1059.84, 440.932 )
dialog_color = Color( 1, 1, 1, 1 )
interact_positions = {
"default": Vector2( 1059.84, 440.932 )
}

View File

@@ -3,11 +3,20 @@
:setup
set_state r7_button_push button_repaired
set_state r7_button_shift button_repaired
set_state r7_button_follow button_repaired
set_state r7_button_zoom button_repaired
> [eq ESC_LAST_SCENE room6]
teleport player r7_l_exit
# Set player look right
set_angle player 180
stop
> [eq ESC_LAST_SCENE room8]
teleport player r7_r_exit
# Set player look left
set_angle player 270
stop
> [!last_scene]
teleport player player_start
stop

View File

@@ -281,7 +281,7 @@ __meta__ = {
[node name="button_camera_shift" parent="Hotspots" instance=ExtResource( 3 )]
position = Vector2( 9.393, 1464.03 )
global_id = "r7_button_push"
global_id = "r7_button_shift"
esc_script = "res://game/rooms/room7/esc/button_shift.esc"
interact_positions = {
"default": Vector2( 359.651, 1765.65 )

View File

@@ -12,7 +12,7 @@ vertices = PoolVector2Array( 1143.08, 613.35, 1267.68, 669.029, 1275.03, 799.721
polygons = [ PoolIntArray( 0, 1, 2, 3, 4, 5, 6 ), PoolIntArray( 7, 8, 9, 10 ), PoolIntArray( 4, 11, 12, 5 ), PoolIntArray( 5, 13, 14, 15 ), PoolIntArray( 7, 10, 6, 15 ), PoolIntArray( 6, 16, 0 ), PoolIntArray( 6, 5, 15 ) ]
outlines = [ PoolVector2Array( -6.44019, 711.297, 3.15687, 646.051, 59.2201, 628.698, 84.5821, 654.06, 129.634, 615.792, 530.631, 612.332, 550.79, 623.672, 581.028, 613.592, 583.548, 574.535, 707.02, 574.535, 714.58, 611.072, 742.298, 623.672, 783.875, 609.812, 1143.08, 613.35, 1267.68, 669.029, 1275.03, 799.721, -9.16094, 803.802 ) ]
[sub_resource type="Animation" id=3]
[sub_resource type="Animation" id=2]
resource_name = "door_close"
tracks/0/type = "value"
tracks/0/path = NodePath("door:polygon")
@@ -39,7 +39,7 @@ tracks/1/keys = {
"values": [ false ]
}
[sub_resource type="Animation" id=4]
[sub_resource type="Animation" id=3]
resource_name = "door_open"
tracks/0/type = "value"
tracks/0/path = NodePath("door:polygon")
@@ -66,7 +66,7 @@ tracks/1/keys = {
"values": [ false, true ]
}
[sub_resource type="RectangleShape2D" id=2]
[sub_resource type="RectangleShape2D" id=4]
extents = Vector2( 20.3273, 18.0047 )
[node name="room8" type="Node2D"]
@@ -155,7 +155,7 @@ esc_script = "res://game/rooms/room8/esc/middle_exit.esc"
tooltip_name = "Exit"
dialog_color = Color( 1, 1, 1, 1 )
interact_positions = {
"default": Vector2( 1225.47, 353.99 )
"default": Vector2( 653.466, 366.589 )
}
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Hotspots/m_door"]
@@ -169,8 +169,8 @@ color = Color( 0.4, 0.501961, 1, 1 )
polygon = PoolVector2Array( 557.104, 45.8, 743.623, 45.8, 746.798, 345.025, 557.898, 347.406 )
[node name="AnimationPlayer" type="AnimationPlayer" parent="Hotspots/m_door"]
anims/door_close = SubResource( 3 )
anims/door_open = SubResource( 4 )
anims/door_close = SubResource( 2 )
anims/door_open = SubResource( 3 )
[node name="r8_mini_puzzle_button" type="Area2D" parent="Hotspots"]
script = ExtResource( 5 )
@@ -180,7 +180,7 @@ tooltip_name = "Button"
default_action = "use"
dialog_color = Color( 1, 1, 1, 1 )
interact_positions = {
"default": null
"default": Vector2( 474.801, 369.29 )
}
[node name="button" type="Line2D" parent="Hotspots/r8_mini_puzzle_button"]
@@ -190,7 +190,7 @@ default_color = Color( 0.4, 0.501961, 1, 1 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hotspots/r8_mini_puzzle_button"]
position = Vector2( 474.343, 201.414 )
shape = SubResource( 2 )
shape = SubResource( 4 )
[node name="Position2D" type="Position2D" parent="Hotspots/r8_mini_puzzle_button"]
position = Vector2( 474.801, 369.29 )
@@ -215,7 +215,7 @@ tooltip_name = "Button"
default_action = "use"
dialog_color = Color( 1, 1, 1, 1 )
interact_positions = {
"default": Vector2( 474.801, 369.29 )
"default": Vector2( 335.616, 369.29 )
}
[node name="button" type="Line2D" parent="Hotspots/r8_reset_puzzle_button"]
@@ -225,7 +225,7 @@ default_color = Color( 0.4, 0.501961, 1, 1 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hotspots/r8_reset_puzzle_button"]
position = Vector2( 474.343, 201.414 )
shape = SubResource( 2 )
shape = SubResource( 4 )
[node name="Position2D" type="Position2D" parent="Hotspots/r8_reset_puzzle_button"]
position = Vector2( 474.801, 369.29 )

View File

@@ -20,7 +20,7 @@
# 7/ long room with camera shift to object 2 if look on object 1
# and stairs with camera shift too
#change_scene res://game/rooms/room7/room7.tscn
change_scene res://game/rooms/room7/room7.tscn
# 8/ puzzle in superposed scene
change_scene res://game/rooms/room8/room8.tscn
#change_scene res://game/rooms/room8/room8.tscn