diff --git a/addons/escoria-core/game/core-scripts/behaviors/esc_movable.gd b/addons/escoria-core/game/core-scripts/behaviors/esc_movable.gd index 3ba07abc..2f12dd79 100644 --- a/addons/escoria-core/game/core-scripts/behaviors/esc_movable.gd +++ b/addons/escoria-core/game/core-scripts/behaviors/esc_movable.gd @@ -267,10 +267,9 @@ func walk_stop(pos: Vector2) -> void: # 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 any), can be ESCItem or ESCLocation if walk_context.target_object and \ - walk_context.target_object.node.player_orients_on_arrival and \ - walk_context.target_object.interactive: + walk_context.target_object.node.player_orients_on_arrival: var orientation = walk_context.target_object.node.interaction_direction last_dir = orientation parent.get_animation_player().play( @@ -488,6 +487,25 @@ func set_angle(deg: int, immediate = true) -> void: update_terrain() +# Turns the character to face another item or character. +# +# #### Parameters +# +# - item_id id of the object to face. +# - immediate +# If true, direction is switched immediately. Else, successive +# animations are used so that the character turns to target angle. +func turn_to(item: Node, immediate = true) -> void: + set_angle( + wrapi( + rad2deg(parent.get_position().angle_to_point(item.get_position())), + 0, + 360 + ), + immediate + ) + + # Returns the angle that corresponds to the current direction of the object. func _get_angle() -> int: return parent.animations.dir_angles[last_dir].angle_start diff --git a/addons/escoria-core/game/core-scripts/esc/commands/turn_to.gd b/addons/escoria-core/game/core-scripts/esc/commands/turn_to.gd index 327a18cb..4af1a9d5 100644 --- a/addons/escoria-core/game/core-scripts/esc/commands/turn_to.gd +++ b/addons/escoria-core/game/core-scripts/esc/commands/turn_to.gd @@ -1,11 +1,6 @@ -# `turn_to object degrees [immediate]` +# `turn_to object object_to_face [immediate]` # -# Turns object to a degrees angle with a directions animation. -# -# 0 sets object facing forward, 90 sets it 90 degrees clockwise ("east") etc. -# When turning to the destination angle, animations are played if they're -# defined in animations. object must be player or interactive. degrees must -# be between [0, 360] or an error is reported. +# Turns object to face another object. # # Set immediate to true to show directly switch to the direction and not # show intermediate angles @@ -19,7 +14,7 @@ class_name TurnToCommand func configure() -> ESCCommandArgumentDescriptor: return ESCCommandArgumentDescriptor.new( 2, - [TYPE_STRING, TYPE_INT, TYPE_BOOL], + [TYPE_STRING, TYPE_STRING, TYPE_BOOL], [null, null, false] ) @@ -34,11 +29,11 @@ func validate(arguments: Array): ] ) return false - if arguments[1] < 0 or arguments[1] > 360: + if not escoria.object_manager.objects.has(arguments[1]): escoria.logger.report_errors( - "turn_to: invalid degrees", + "turn_to: invalid target object", [ - "Degree %d not between 0 and 360" % arguments[1] + "Object with global id %s not found" % arguments[1] ] ) return false @@ -48,8 +43,8 @@ func validate(arguments: Array): # Run the command func run(command_params: Array) -> int: (escoria.object_manager.get_object(command_params[0]).node as ESCItem)\ - .set_angle( - command_params[1], + .turn_to( + escoria.object_manager.get_object(command_params[1]).node, command_params[2] ) return ESCExecution.RC_OK diff --git a/addons/escoria-core/game/core-scripts/esc_controller.gd b/addons/escoria-core/game/core-scripts/esc_controller.gd index 284530df..0943c826 100644 --- a/addons/escoria-core/game/core-scripts/esc_controller.gd +++ b/addons/escoria-core/game/core-scripts/esc_controller.gd @@ -41,8 +41,8 @@ func perform_walk( target_position = destination.node.interact_position var walk_context = ESCWalkContext.new( - destination.node, - Vector2(), + destination, + target_position, is_fast, true ) diff --git a/addons/escoria-core/game/core-scripts/esc_item.gd b/addons/escoria-core/game/core-scripts/esc_item.gd index 563539ae..78a069af 100644 --- a/addons/escoria-core/game/core-scripts/esc_item.gd +++ b/addons/escoria-core/game/core-scripts/esc_item.gd @@ -231,6 +231,7 @@ func get_interact_position() -> Vector2: for c in get_children(): if c is Position2D: if c.get_owner() == self: + interact_position = global_position continue interact_position = c.global_position @@ -360,7 +361,18 @@ func get_sprite() -> Node: # angles func set_angle(deg: int, immediate = true): _movable.set_angle(deg, immediate) - + + +# Turn to face another object +# +# #### Parameters +# +# - deg: The angle degree to set +# - immediate: Set the angle immediately. If false will show intermediate +# angles +func turn_to(object: Node, immediate = true): + _movable.turn_to(object, immediate) + # Play the talking animation func start_talking(): diff --git a/addons/escoria-core/game/scenes/inventory/inventory_ui.gd b/addons/escoria-core/game/scenes/inventory/inventory_ui.gd index a43e1fa7..c0e9d2e0 100644 --- a/addons/escoria-core/game/scenes/inventory/inventory_ui.gd +++ b/addons/escoria-core/game/scenes/inventory/inventory_ui.gd @@ -67,6 +67,7 @@ func add_new_item_by_id(item_id: String) -> void: var item_inventory_button = ( escoria.object_manager.get_object(item_id).node as ESCItem ).inventory_item.duplicate() + item_inventory_button.global_id = item_id items_ids_in_inventory[item_id] = item_inventory_button get_node(inventory_ui_container).add_item(item_inventory_button) diff --git a/docs/api/ESCItem.md b/docs/api/ESCItem.md index d150a7d8..35320348 100644 --- a/docs/api/ESCItem.md +++ b/docs/api/ESCItem.md @@ -362,6 +362,20 @@ Set the angle #### Parameters +- deg: The angle degree to set +- immediate: Set the angle immediately. If false will show intermediate + angles + +### turn\_to + +```gdscript +func turn_to(object: Node, immediate = true) +``` + +Turn to face another object + +#### Parameters + - deg: The angle degree to set - immediate: Set the angle immediately. If false will show intermediate angles diff --git a/docs/api/ESCMovable.md b/docs/api/ESCMovable.md index 772d254c..5cf7de79 100644 --- a/docs/api/ESCMovable.md +++ b/docs/api/ESCMovable.md @@ -182,6 +182,21 @@ Sets character's angle and plays according animation. If true, direction is switched immediately. Else, successive animations are used so that the character turns to target angle. +### turn\_to + +```gdscript +func turn_to(item: Node, immediate = true) -> void +``` + +Turns the character to face another item or character. + +#### Parameters + +- item_id id of the object to face. +- immediate + If true, direction is switched immediately. Else, successive + animations are used so that the character turns to target angle. + ### get\_shortest\_way\_to\_dir ```gdscript diff --git a/docs/api/TurnToCommand.md b/docs/api/TurnToCommand.md index b163f060..4ef7c0ff 100644 --- a/docs/api/TurnToCommand.md +++ b/docs/api/TurnToCommand.md @@ -6,14 +6,9 @@ ## Description -`turn_to object degrees [immediate]` +`turn_to object object_to_face [immediate]` -Turns object to a degrees angle with a directions animation. - -0 sets object facing forward, 90 sets it 90 degrees clockwise ("east") etc. -When turning to the destination angle, animations are played if they're -defined in animations. object must be player or interactive. degrees must -be between [0, 360] or an error is reported. +Turns object to face another object. Set immediate to true to show directly switch to the direction and not show intermediate angles diff --git a/docs/esc.md b/docs/esc.md index 001ccf69..0cd87620 100644 --- a/docs/esc.md +++ b/docs/esc.md @@ -351,14 +351,9 @@ Sets the position of object1 to the position (x,y). #### `transition transition_name in|out` [API-Doc](api/TransitionCommand.md) Performs a transition in our out manually. -#### `turn_to object degrees [immediate]` [API-Doc](api/TurnToCommand.md) +#### `turn_to object object_to_face [immediate]` [API-Doc](api/TurnToCommand.md) -Turns object to a degrees angle with a directions animation. - -0 sets object facing forward, 90 sets it 90 degrees clockwise ("east") etc. -When turning to the destination angle, animations are played if they're -defined in animations. object must be player or interactive. degrees must -be between [0, 360] or an error is reported. +Turns object to face another object. Set immediate to true to show directly switch to the direction and not show intermediate angles diff --git a/game/items/escitems/r9_bottle.tscn b/game/items/escitems/r9_bottle.tscn index 8b97d538..b50e2193 100644 --- a/game/items/escitems/r9_bottle.tscn +++ b/game/items/escitems/r9_bottle.tscn @@ -8,6 +8,7 @@ extents = Vector2( 28.3873, 74.7806 ) [node name="bottle" type="Area2D"] +pause_mode = 1 z_index = 1 script = ExtResource( 3 ) global_id = "r9_bottle" @@ -19,6 +20,7 @@ combine_if_action_used_among = PoolStringArray( "use" ) use_from_inventory_only = true inventory_item_scene_file = ExtResource( 2 ) dialog_color = Color( 1, 1, 1, 1 ) +animations = null [node name="sprite" type="Sprite" parent="."] texture = ExtResource( 1 ) diff --git a/game/rooms/room01/esc/room01.esc b/game/rooms/room01/esc/room01.esc index da073089..558a8eec 100644 --- a/game/rooms/room01/esc/room01.esc +++ b/game/rooms/room01/esc/room01.esc @@ -17,10 +17,14 @@ set_sound_state _music res://game/sfx/contemplation.ogg true set_global room1_visited true set_global dialog_advance 0 set_global dialog_popup_advance 0 - walk player r1_destination_point + walk_block player r1_destination_point wait 2 - walk player r1_destination_point2 + walk_block player r1_destination_point2 wait 2 set_angle player 225 false + wait 2 + walk_block player r1_destination_point3 + wait 1 + turn_to player r1_r_exit false diff --git a/game/rooms/room01/item.tscn b/game/rooms/room01/item.tscn new file mode 100644 index 00000000..9b29dd31 --- /dev/null +++ b/game/rooms/room01/item.tscn @@ -0,0 +1,27 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://addons/escoria-core/game/core-scripts/esc_item.gd" type="Script" id=1] +[ext_resource path="res://addons/escoria-core/game/core-scripts/esc_location.gd" type="Script" id=2] + +[node name="item" type="Area2D"] +pause_mode = 1 +script = ExtResource( 1 ) +tooltip_name = "Item on the wall" +default_action = "look" +dialog_color = Color( 1, 1, 1, 1 ) +animations = null + +[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."] +position = Vector2( -652.737, -162.85 ) +polygon = PoolVector2Array( 635.586, 253.345, 568.928, 60.1716, 709.047, 120.028, 699.524, 247.903 ) + +[node name="Line2D" type="Line2D" parent="."] +position = Vector2( -655.406, -430.678 ) +points = PoolVector2Array( 634.097, 516.751, 578.861, 335.008, 701.805, 386.68, 696.459, 509.624, 634.097, 516.751 ) +__meta__ = { +"_editor_description_": "" +} + +[node name="ESCLocation" type="Position2D" parent="."] +position = Vector2( 0, 236.267 ) +script = ExtResource( 2 ) diff --git a/game/rooms/room01/r_door.tscn b/game/rooms/room01/r_door.tscn index 39b4fa38..5fb1e616 100644 --- a/game/rooms/room01/r_door.tscn +++ b/game/rooms/room01/r_door.tscn @@ -18,8 +18,9 @@ dialog_color = Color( 1, 1, 1, 1 ) animations = null [node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."] +position = Vector2( -1229.68, -223.006 ) polygon = PoolVector2Array( 1177.94, 348.61, 1175.95, 45.3759, 1276.06, 92.0953, 1277.95, 399.407 ) [node name="Position2D" type="Position2D" parent="."] -position = Vector2( 1225.47, 353.99 ) +position = Vector2( -0.432617, 124.685 ) script = ExtResource( 2 ) diff --git a/game/rooms/room01/room01.tscn b/game/rooms/room01/room01.tscn index a44bf45e..42406de0 100644 --- a/game/rooms/room01/room01.tscn +++ b/game/rooms/room01/room01.tscn @@ -4,10 +4,10 @@ [ext_resource path="res://game/rooms/room01/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://addons/escoria-core/game/core-scripts/esc_item.gd" type="Script" id=5] [ext_resource path="res://addons/escoria-core/game/core-scripts/esc_room.gd" type="Script" id=6] [ext_resource path="res://addons/escoria-core/game/core-scripts/esc_location.gd" type="Script" id=7] [ext_resource path="res://game/rooms/room01/r_door.tscn" type="PackedScene" id=8] +[ext_resource path="res://game/rooms/room01/item.tscn" type="PackedScene" id=9] [node name="room1" type="Node2D"] script = ExtResource( 6 ) @@ -49,99 +49,66 @@ position = Vector2( 3.5636, 0 ) [node name="Hotspots" type="Node2D" parent="."] [node name="r_door" parent="Hotspots" instance=ExtResource( 8 )] +position = Vector2( 1225.9, 217.966 ) [node name="ESCLocation" type="Position2D" parent="Hotspots/r_door"] -position = Vector2( 1229.68, 355.298 ) +position = Vector2( 1.35498, 136.453 ) script = ExtResource( 7 ) -[node name="item" type="Area2D" parent="Hotspots"] -pause_mode = 1 -position = Vector2( -217.19, 0 ) -script = ExtResource( 5 ) +[node name="item" parent="Hotspots" instance=ExtResource( 9 )] +position = Vector2( 480.542, 146.832 ) global_id = "r1_wall_item1" esc_script = "res://game/rooms/room01/esc/wall_item.esc" -tooltip_name = "Item on the wall" -default_action = "look" -dialog_color = Color( 1, 1, 1, 1 ) -animations = null - -[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Hotspots/item"] -polygon = PoolVector2Array( 635.586, 253.345, 568.928, 60.1716, 709.047, 120.028, 699.524, 247.903 ) - -[node name="Position2D" type="Position2D" parent="Hotspots/item"] -position = Vector2( 671.798, 373.035 ) -script = ExtResource( 7 ) -global_id = "r1_left_object_interaction" - -[node name="Line2D" type="Line2D" parent="Hotspots/item"] -position = Vector2( 0, -267.828 ) -points = PoolVector2Array( 634.097, 516.751, 578.861, 335.008, 701.805, 386.68, 696.459, 509.624, 634.097, 516.751 ) -__meta__ = { -"_editor_description_": "" -} [node name="Label" type="Label" parent="Hotspots/item"] -margin_left = 563.635 -margin_top = 265.925 -margin_right = 759.635 -margin_bottom = 279.925 +margin_left = -105.12 +margin_top = 121.762 +margin_right = 122.88 +margin_bottom = 142.762 custom_fonts/font = ExtResource( 3 ) text = "Character talks with text above" __meta__ = { -"_edit_use_anchors_": false -} - -[node name="item2" type="Area2D" parent="Hotspots"] -pause_mode = 1 -position = Vector2( 189.644, 0 ) -script = ExtResource( 5 ) -global_id = "r1_wall_item2" -esc_script = "res://game/rooms/room01/esc/wall_item_popupdialog.esc" -tooltip_name = "Item on the wall" -default_action = "look" -dialog_color = Color( 1, 1, 1, 1 ) -animations = null - -[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Hotspots/item2"] -polygon = PoolVector2Array( 635.586, 253.345, 568.928, 60.1716, 709.047, 120.028, 699.524, 247.903 ) - -[node name="Position2D" type="Position2D" parent="Hotspots/item2"] -position = Vector2( 671.798, 373.035 ) -script = ExtResource( 7 ) -global_id = "r2_left_object_interaction" - -[node name="Line2D" type="Line2D" parent="Hotspots/item2"] -position = Vector2( -4.23779, -267.828 ) -points = PoolVector2Array( 634.097, 516.751, 578.861, 335.008, 701.805, 386.68, 696.459, 509.624, 634.097, 516.751 ) -__meta__ = { +"_edit_use_anchors_": false, "_editor_description_": "" } -[node name="Label2" type="Label" parent="Hotspots/item2"] -margin_left = 556.218 -margin_top = 265.925 -margin_right = 752.218 -margin_bottom = 279.925 +[node name="item2" parent="Hotspots" instance=ExtResource( 9 )] +position = Vector2( 839.614, 146.832 ) +global_id = "r1_wall_item2" +esc_script = "res://game/rooms/room01/esc/wall_item_popupdialog.esc" + +[node name="Label" type="Label" parent="Hotspots/item2"] +margin_left = -105.12 +margin_top = 121.762 +margin_right = 122.88 +margin_bottom = 142.762 custom_fonts/font = ExtResource( 3 ) text = "Character talks with popup" __meta__ = { -"_edit_use_anchors_": false +"_edit_use_anchors_": false, +"_editor_description_": "" } [node name="player_start" type="Position2D" parent="."] -position = Vector2( 653.761, 443.306 ) +position = Vector2( 172.471, 434.487 ) script = ExtResource( 7 ) global_id = "r1_start" is_start_location = true -[node name="destination_point" type="Position2D" parent="."] -position = Vector2( 476.984, 487.146 ) +[node name="orients_down_on_arrival" type="Position2D" parent="."] +position = Vector2( 400.129, 432.969 ) script = ExtResource( 7 ) global_id = "r1_destination_point" interaction_direction = 4 -[node name="destination_point2" type="Position2D" parent="."] -position = Vector2( 994.586, 458.862 ) +[node name="set_angle_by_esc" type="Position2D" parent="."] +position = Vector2( 934.11, 502.959 ) script = ExtResource( 7 ) global_id = "r1_destination_point2" player_orients_on_arrival = false + +[node name="turn_to_r_door_by_esc" type="Position2D" parent="."] +position = Vector2( 660.468, 381.489 ) +script = ExtResource( 7 ) +global_id = "r1_destination_point3" +player_orients_on_arrival = false