Add NPC and items walking.

This commit is contained in:
Julian Murgia
2020-12-28 08:39:57 +01:00
parent af8a9ea086
commit ff89dc1677
205 changed files with 972 additions and 488 deletions

View File

@@ -0,0 +1,3 @@
source_md5="b946c37b13cf1a4a30756a56241626fa"
dest_md5="0f060bc954d07897e282b77947f5156f"

View File

@@ -0,0 +1,3 @@
source_md5="c43bbfd31df43b225aae52ed905f8d6b"
dest_md5="1e5309d492e90a912e2b03a0347e5452"

View File

@@ -0,0 +1,3 @@
source_md5="25d99ab7c6873801de269a22a61a0bcd"
dest_md5="f2e1fa2d3aadb57a90d9186c7b5955eb"

View File

@@ -0,0 +1,3 @@
source_md5="928e8043d309247339be1b5ebf031b7e"
dest_md5="5062f1817b62903f643a889b606e2c1c"

View File

@@ -0,0 +1,3 @@
source_md5="b641d9d88040368d746220a8082a7107"
dest_md5="3010c5f30eef5799a6ee178864d9677b"

View File

@@ -0,0 +1,3 @@
source_md5="0243a94c02dcdda6504f8446d37903ee"
dest_md5="60665a3bf962c434279abbdb4d5d8d07"

View File

@@ -0,0 +1,3 @@
source_md5="dfaf76256a1788f9b75dfb239e4f0ed0"
dest_md5="77f684796e7aadacc3825e00aa74a765"

View File

@@ -0,0 +1,3 @@
source_md5="a23dbb0093396fa6a19051ca7372c895"
dest_md5="e97240ec6178f931667341fd9617e3b0"

View File

@@ -0,0 +1,3 @@
source_md5="f5300e58c17659d4ce875c88b1dabb48"
dest_md5="796261e999a68e909826a4b7d25b77bd"

View File

@@ -0,0 +1,3 @@
source_md5="cdc6b735a4f688ddfdeee3bd7cc323a5"
dest_md5="a9b45e00a7eb92e47fab619d10e9a0c5"

View File

@@ -0,0 +1,3 @@
source_md5="c64598c0b2696f8ca5faa46c6eea7b26"
dest_md5="71f4ace5330cca799ff530308ae2a02b"

View File

@@ -0,0 +1,3 @@
source_md5="752ba71cd564740e0d2b1dc5c6fd4249"
dest_md5="b7880763217fdc88bcbb27eb0ac8abf5"

View File

@@ -0,0 +1,3 @@
source_md5="18a5dec5fff4c8f0075165b22988cf05"
dest_md5="867e266fddaef6a1e1a96b9f029e8bfb"

View File

@@ -0,0 +1,3 @@
source_md5="490c24edd0484c9a112b9e2862338e3d"
dest_md5="58eff0e7e9050e4237d9ee3c3b59e5a4"

View File

@@ -0,0 +1,3 @@
source_md5="cd99b13c124851e632285bbfba856307"
dest_md5="c841193b8e06e7f09f0f85c59a563d60"

View File

@@ -0,0 +1,3 @@
source_md5="88551aa2a87aec71032189578282f697"
dest_md5="5417f7cafd9f643130e074ad5c11679e"

View File

@@ -0,0 +1,3 @@
source_md5="587f7011c870f69d557901c615cf721c"
dest_md5="2db765545a5ddfb8802fdbd48db5403d"

View File

@@ -0,0 +1,3 @@
source_md5="32609c929d833db2b38069c17652f012"
dest_md5="102cab26b27fb477fcdbc1f72b66d40d"

View File

@@ -0,0 +1,3 @@
source_md5="1ec6e1e1f5b3797d7a0f8aac5980c0c9"
dest_md5="5d72d8e0f3e92edd15c011b081a7ef81"

View File

@@ -0,0 +1,3 @@
source_md5="4b2d6018cdb0d5c81d166c8d6df3905a"
dest_md5="cee1ec0394fe166171ab3462815f6540"

View File

@@ -0,0 +1,3 @@
source_md5="599b3fb079112d9c8f1ed5983c37fd9c"
dest_md5="ef6602a0188343b4ed2b5a52746f26e9"

View File

@@ -0,0 +1,3 @@
source_md5="03bb6588d1d344afe8f282322a728f3c"
dest_md5="b6d51047efeded7bf45b4e4cdbaa21a1"

View File

@@ -0,0 +1,3 @@
source_md5="655518693854b27f815e435133f68b3a"
dest_md5="8a1bae3182cc7e592a155001324af207"

View File

@@ -0,0 +1,3 @@
source_md5="9b7180d5631b0c83050537a7ffe496c1"
dest_md5="519026f59c7de7b7310a59e6cb2981f7"

View File

@@ -0,0 +1,3 @@
source_md5="0cd163a9f68ebdc09672dc97784f8257"
dest_md5="87bac89e53a5847aeba3852ee95c25c9"

View File

@@ -0,0 +1,3 @@
source_md5="175d4162682828fe86bfb3e668f21efa"
dest_md5="77d10036458249eeb53f96c026369d2e"

View File

@@ -0,0 +1,3 @@
source_md5="99200b95d37584de12d1886bab0dd111"
dest_md5="fc47ab4b5884f8bf7e21f97b48955d1e"

View File

@@ -0,0 +1,3 @@
source_md5="fdee315f652c33bd0d3caee46ffe7374"
dest_md5="afdbc0b078fd93df0c2978c9b9bb7f33"

View File

@@ -0,0 +1,3 @@
source_md5="2e86f3ed289407aa0a64ba7c27a6fe27"
dest_md5="1caef2cc83416c0d613c2ed80484e307"

View File

@@ -0,0 +1,3 @@
source_md5="f993b3d5d19fcb40274d59ab93d4db7b"
dest_md5="649b6997fc748bedda9fbcb06d5097be"

View File

@@ -0,0 +1,3 @@
source_md5="658800dea2e09f76a4a6c68389109dd4"
dest_md5="0eb638bdd41ba1e0aebaf58d01d2abcc"

View File

@@ -0,0 +1,3 @@
source_md5="19d232177d311dafadc2c9cffe63bea2"
dest_md5="689dc0a98018314cbc4e06c79a5659b6"

View File

@@ -0,0 +1,3 @@
source_md5="e8cadb3b0fae8d5711620964bc7714f3"
dest_md5="8953ee379892394cfe3b43c6ea9ad36a"

View File

@@ -0,0 +1,3 @@
source_md5="d31c7844a0e5ab9c94f4e17d007f49cb"
dest_md5="3ef3fc27d4e6da38589f1964d18bc572"

View File

@@ -0,0 +1,3 @@
source_md5="617ffc95cccea66231292c0c1651bfa5"
dest_md5="9ed7dfc3474e0781070e243f64d29ba4"

View File

@@ -0,0 +1,3 @@
source_md5="227775f6f3d855fb7ad1e072908b1720"
dest_md5="aa408f17a1736d8ee443e496ce369c90"

View File

@@ -0,0 +1,3 @@
source_md5="c795c7668bbe2e1d22739dfcf788de58"
dest_md5="6fa82439df7d2104dc6de17c450adfb4"

View File

@@ -0,0 +1,3 @@
source_md5="fa641be0237a2dd40cfef31a9dd51a93"
dest_md5="98e3c0dd411f6e7a3e36826616306e43"

View File

@@ -0,0 +1,3 @@
source_md5="e95b2e5deaddf0a807e1bbaac991e8fb"
dest_md5="ee6e4d7b1e2e5536a5eb20b616d94339"

View File

@@ -0,0 +1,3 @@
source_md5="133f584afd464efe5fa945a12b03f094"
dest_md5="a3fefd945444ed1bdcae55250aa06666"

View File

@@ -0,0 +1,3 @@
source_md5="9e3213f2b74dbc88078670599f964d4b"
dest_md5="51b46f896eb47c39443e7fc0ca456140"

View File

@@ -0,0 +1,3 @@
source_md5="5255f3554e5b6864a0da844e10c68a2b"
dest_md5="4340b4cd9862ce3b9572e3e5bfbc07f5"

View File

@@ -0,0 +1,3 @@
source_md5="de2b6577a774b1065d1321f734bde0f1"
dest_md5="c77b50583dcbd23048f1bbafcaa41478"

View File

@@ -0,0 +1,3 @@
source_md5="5da19ba8137b8bb117b929295bce53d2"
dest_md5="3be68466cdcacfbb9408ec74d6e1bc5e"

View File

@@ -0,0 +1,3 @@
source_md5="74ccd07df39dc043fff8a02c3219f544"
dest_md5="d216e23ebff1c36fd23549df82803fd8"

View File

@@ -73,6 +73,7 @@ var commands = {
"turn_to": { "min_args": 2 },
"wait": true,
"walk": { "min_args": 2 },
"walk_to_pos": { "min_args": 3},
"walk_block": { "min_args": 2 },
"%": { "alias": "label", "min_args": 1},

View File

@@ -153,10 +153,10 @@ func add_level(p_event, p_root : bool):
func instance_level(p_event : esctypes.ESCEvent, p_root : bool):
var new_level = {
"ip": 0,
"instructions": p_event.ev_level,
"waiting": false,
"break_stop": p_root,
"ip": 0, # Current instruction id
"instructions": p_event.ev_level, # List of instructions (commands)
"waiting": false, # If true, wait for current command to be finished (esc_runner_level.finished())
"break_stop": p_root,
"labels": {},
"flags": p_event.ev_flags
}
@@ -514,8 +514,9 @@ func activate(p_action : String, p_param : Array):
else:
var errors = ["Attempted to execute inexisting action " + \
p_action + " between item " + combine_with.global_id + " and item " + what.global_id]
if combine_with.combine_is_one_way:
errors.append("Reason: " + combine_with.global_id + "'s item interaction is one-way.")
if combine_with.get("combine_is_one_way") != null \
and combine_with.combine_is_one_way:
errors.append("Reason: " + combine_with.global_id + "'s item interaction is one-way.")
escoria.report_warnings("esc_runner.gd:activate()", errors)
return esctypes.EVENT_LEVEL_STATE.YIELD
@@ -595,15 +596,24 @@ func set_state(global_id : String, p_params : Array):
if animation_node:
animation_node.stop()
if animation_node.has_animation(p_params[0]):
var actual_animator
if animation_node is AnimationPlayer:
actual_animator = animation_node
elif animation_node is AnimatedSprite:
actual_animator = animation_node.frames
if actual_animator.has_animation(p_params[0]):
if !immediate:
animation_node.play(p_params[0])
else:
# The animation is not played, we directly set it at its last frame
animation_node.current_animation = p_params[0]
var animation = animation_node.get_animation(p_params[0])
var animation_length = animation.length
animation_node.seek(animation_length)
if animation_node is AnimatedSprite:
animation_node.animation = p_params[0]
else:
animation_node.current_animation = p_params[0]
var animation = actual_animator.get_animation(p_params[0])
var animation_length = animation.length
animation_node.seek(animation_length)
"""
@@ -611,10 +621,11 @@ When object is active, it is VISIBLE.
When object is inactive, it is HIDDEN.
"""
func set_active(name : String, active):
if objects[name] is ESCInventoryItem:
return
actives[name] = active
if objects.has(name) and is_instance_valid(objects[name]):
if objects[name] is ESCInventoryItem:
return
if active:
objects[name].show()
else:
@@ -656,3 +667,11 @@ func object_exit_scene(name : String):
# break
# else:
# stack.remove(stack.size()-1)
func check_obj(name, cmd):
var obj = escoria.esc_runner.get_object(name)
if obj == null:
escoria.report_errors("", ["Global id "+name+" not found for " + cmd])
return false
return true

View File

@@ -20,14 +20,6 @@ func finished(context = null):
escoria.current_state = escoria.GAME_STATE.DEFAULT
func check_obj(name, cmd):
var obj = escoria.esc_runner.get_object(name)
if obj == null:
escoria.report_errors("", ["Global id "+name+" not found for " + cmd])
return false
return true
func resume(context):
current_context = context
if context.waiting:
@@ -111,7 +103,7 @@ Optional parameters:
flip_y flips the y axis of the object's sprites when true (object's root node needs to be Node2D)
"""
func anim(command_params : Array):
if !check_obj(command_params[0], "anim"):
if !escoria.esc_runner.check_obj(command_params[0], "anim"):
return esctypes.EVENT_LEVEL_STATE.RETURN
private_play_animation(command_params)
return esctypes.EVENT_LEVEL_STATE.RETURN
@@ -248,7 +240,7 @@ Optional parameters:
(object's root node needs to be Node2D)
"""
func cut_scene(command_params : Array):
if !check_obj(command_params[0], "cut_scene"):
if !escoria.esc_runner.check_obj(command_params[0], "cut_scene"):
return esctypes.EVENT_LEVEL_STATE.RETURN
private_play_animation(command_params)
return esctypes.EVENT_LEVEL_STATE.YIELD
@@ -437,7 +429,7 @@ Sets object as active or inactive. Active objects are displayed in scene and res
to inputs. Inactives are hidden.
"""
func set_active(command_params : Array):
if !check_obj(command_params[0], "set_active"):
if !escoria.esc_runner.check_obj(command_params[0], "set_active"):
return esctypes.EVENT_LEVEL_STATE.RETURN
var name : String = command_params[0]
var value = command_params[1]
@@ -448,7 +440,7 @@ Set the angle of an object.
Usage: set_angle object_id angle_degrees
"""
func set_angle(command_params : Array):
if !check_obj(command_params[0], "set_angle"):
if !escoria.esc_runner.check_obj(command_params[0], "set_angle"):
return esctypes.EVENT_LEVEL_STATE.RETURN
var obj = escoria.esc_runner.get_object(command_params[0])
obj.set_angle(int(command_params[1]))
@@ -539,9 +531,9 @@ angle to angle_degrees.
Usage: teleport obj1 obj2 [angle_degrees]
"""
func teleport(command_params : Array):
if !check_obj(command_params[0], "teleport"):
if !escoria.esc_runner.check_obj(command_params[0], "teleport"):
return esctypes.EVENT_LEVEL_STATE.RETURN
if !check_obj(command_params[1], "teleport"):
if !escoria.esc_runner.check_obj(command_params[1], "teleport"):
return esctypes.EVENT_LEVEL_STATE.RETURN
var angle
@@ -585,7 +577,19 @@ Make object1 walk towards object2. This command is not blocking (user input not
Usage: walk object_id1 object_id2
"""
func walk(command_params : Array):
current_context.waiting = true
escoria.do("walk", command_params)
return esctypes.EVENT_LEVEL_STATE.YIELD
"""
Make object1 walk towards object2. This command is not blocking (user input not disabled)
Usage: walk_to_pos object_id1 pos_x pos_y
"""
func walk_to_pos(command_params : Array):
current_context.waiting = true
var destination_pos = Vector2(command_params[1], command_params[2])
escoria.do("walk", [command_params[0], destination_pos])
return esctypes.EVENT_LEVEL_STATE.YIELD
"""

View File

@@ -41,7 +41,6 @@ var terrain : ESCTerrain
# If the terrain node type is scalenodes
var terrain_is_scalenodes : bool
var check_maps = true
var pose_scale : int
var last_scale : Vector2
@@ -59,7 +58,6 @@ func _ready():
init_interact_position_with_node()
terrain = escoria.room_terrain
update_terrain()

View File

@@ -41,20 +41,65 @@ export(PackedScene) var inventory_item_scene_file : PackedScene
export(Color) var dialog_color = ColorN("white")
# Animation node (null if none was found)
var animation
var animation_sprite
onready var interact_positions : Dictionary = { "default": null}
# Animations script (for walking, idling...)
export(Script) var animations
# TERRAIN
var terrain : ESCTerrain
# If the terrain node type is scalenodes
var terrain_is_scalenodes : bool
var check_maps = true
var pose_scale : int
var last_scale : Vector2
var collision
# WALKING
# State machine defining the current interact state of the player
enum INTERACT_STATES {
INTERACT_STARTED, # 
INTERACT_NONE, #
INTERACT_WALKING # Player is walking
}
var interact_status # Current interact status, type INTERACT_STATES
var walk_path : Array = []
var walk_destination : Vector2
var walk_context
var target_object : Object = null
var moved : bool
var path_ofs : float
export(int) var speed : int = 300
export(float) var v_speed_damp : float = 1.0
var orig_speed : float
enum PLAYER_TASKS {
NONE,
WALK,
SLIDE
}
var task # type PLAYER_TASKS
var params_queue : Array
# PRIVATE VARS
var area : Area2D
# Size of the item
var size : Vector2
var last_deg : int
var last_dir : int
func _ready():
for n in get_children():
if n is AnimatedSprite:
animation_sprite = n
continue
if n is AnimationPlayer:
animation = n
animation_sprite = n
continue
if n is Area2D:
area = n
@@ -66,7 +111,8 @@ func _ready():
area.connect("input_event", self, "manage_input")
init_interact_position_with_node()
terrain = escoria.room_terrain
if !Engine.is_editor_hint():
escoria.register_object(self)
connect("mouse_entered_item", escoria.inputs_manager, "_on_mouse_entered_item")
@@ -75,13 +121,79 @@ func _ready():
connect("mouse_double_left_clicked_item", escoria.inputs_manager, "_on_mouse_left_double_clicked_item")
connect("mouse_right_clicked_item", escoria.inputs_manager, "_on_mouse_right_clicked_item")
update_terrain()
func _process(time):
if Engine.is_editor_hint():
return
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 get_animation_player():
if animation == null:
if animation_sprite == null:
for n in get_children():
if n is AnimationPlayer:
animation = n
return animation
animation_sprite = n
return animation_sprite
"""
@@ -94,12 +206,15 @@ position instead.
func init_interact_position_with_node():
for c in get_children():
if c is Position2D:
# If the position2D node is part of the hotspot, it means it is not an interact position
# but a dialog position for example. Interact position node must be set in the room scene.
if c.get_owner() == self:
continue
interact_positions.default = c.global_position
break
if c is CollisionShape2D or c is CollisionPolygon2D:
interact_positions.default = c.global_position
if interact_positions.default == null:
interact_positions.default = self.global_position
interact_positions.default = c.global_position
func manage_input(viewport : Viewport, event : InputEvent, shape_idx : int):
if event is InputEventMouseButton:
@@ -121,3 +236,192 @@ func _on_mouse_entered():
func _on_mouse_exited():
emit_signal("mouse_exited_item")
func update_terrain(on_event_finished_name = null):
if !terrain or terrain == null or !is_instance_valid(terrain):
return
if on_event_finished_name != null and on_event_finished_name != "setup":
return
if is_exit:
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 $texture
if pose_scale == -1 and $texture.scale.x > 0:
$texture.scale.x *= pose_scale
collision.scale.x *= pose_scale
elif pose_scale == 1 and $texture.scale.x < 0:
$texture.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)
func teleport(target, angle : Object = null) -> void:
"""
Teleports the item on target position.
target can be Vector2 or Object
"""
if typeof(target) == TYPE_VECTOR2:
printt("Item teleported at position", target, "with angle", angle)
position = target
elif typeof(target) == TYPE_OBJECT:
if target.get("interact_positions") != null:
position = target.interact_positions.default #.global_position
else:
position = target.position
printt("Item teleported at", target.name, "position", position, "with angle", angle)
else:
escoria.report_errors("escitem.gd:teleport()", ["Target to teleport to is null or unusable (" + target + ")"])
# PUBLIC FUNCTION
func walk_to(pos : Vector2, p_walk_context = null):
if not terrain:
return walk_stop(get_position())
if interact_status == INTERACT_STATES.INTERACT_WALKING:
return
if interact_status == INTERACT_STATES.INTERACT_STARTED:
interact_status = INTERACT_STATES.INTERACT_WALKING
walk_path = terrain.get_terrain_path(get_position(), pos)
walk_context = p_walk_context
if walk_path.size() == 0:
task = PLAYER_TASKS.NONE
walk_stop(get_position())
set_process(false)
return
moved = true
walk_destination = walk_path[walk_path.size()-1]
if terrain.is_solid(pos):
walk_destination = walk_path[walk_path.size()-1]
path_ofs = 0.0
task = PLAYER_TASKS.WALK
set_process(true)
# PRIVATE FUNCTION
func walk(target_pos, p_speed, context = null):
if p_speed:
orig_speed = speed
speed = p_speed
walk_to(target_pos, context)
# PRIVATE FUNCTION
func walk_stop(pos):
position = pos
interact_status = INTERACT_STATES.INTERACT_NONE
walk_path = []
if orig_speed:
speed = orig_speed
orig_speed = 0.0
task = PLAYER_TASKS.NONE
moved = false
set_process(false)
if params_queue != null && !params_queue.empty():
if animations.dir_angles.size() > 0:
if params_queue[0].interact_angle == -1:
escoria.tools.resolve_angle_to(params_queue[0])
else:
last_dir = _get_dir_deg(params_queue[0].interact_angle, animations)
animation_sprite.play(animations.idles[last_dir][0])
pose_scale = animations.idles[last_dir][1]
update_terrain()
else:
animation_sprite.play(animations.idles[last_dir][0])
pose_scale = animations.idles[last_dir][1]
get_tree().call_group_flags(SceneTree.GROUP_CALL_DEFAULT, "game", "interact", params_queue)
# Clear params queue to prevent the same action from being triggered again
params_queue = []
else:
# 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 walk_context.has("target_object") and walk_context.target_object.player_orients_on_arrival \
and escoria.esc_runner.get_interactive(walk_context.target_object.global_id):
var orientation = walk_context["target_object"].interaction_direction
animation_sprite.play(animations.idles[orientation][0])
pose_scale = animations.idles[orientation][1]
else:
animation_sprite.play(animations.idles[last_dir][0])
pose_scale = animations.idles[last_dir][1]
update_terrain()
if walk_context != null:
# escoria.esc_level_runner.finished(walk_context)
escoria.esc_level_runner.finished()
walk_context = null
emit_signal("arrived")
func _get_dir(angle : float, animations) -> int:
var deg = escoria.utils._get_deg_from_rad(angle)
return _get_dir_deg(deg, animations)
func _get_dir_deg(deg : int, animations) -> int:
# We turn the angle by -90° because angle_to_point gives the angle against X axis, not Y
deg = wrapi(deg - 90, 0, 360)
var dir = -1
var i = 0
for arr_angle_zone in animations.dir_angles:
if is_angle_in_interval(deg, arr_angle_zone):
dir = i
break
else:
i += 1
continue
# It's an error to have the animations misconfigured
if dir == -1:
escoria.report_errors("escitem.gd:_get_dir_deg()", ["No direction found for " + str(deg)])
return dir
"""
Returns true if given angle is inside the interval given by a starting_angle and the size.
@param angle : Angle to test
@param: interval : Array of size 2, containing the starting angle, and the size of interval
 eg: [90, 40] corresponds to angle between 90° and 130°
"""
func is_angle_in_interval(angle: float, interval : Array) -> bool:
angle = wrapi(angle, 0, 360)
if angle == 0:
angle = 360
var start_angle = wrapi(interval[0], 0, 360)
var angle_area = interval[1]
var end_angle = wrapi(interval[0] + angle_area, 0, 360)
if (angle >= 270 and angle <= 360) or (angle >= 0 and angle <= 90):
if wrapi(angle+180, 0, 360) > wrapi(interval[0]+ 180, 0, 360) \
&& wrapi(angle+180, 0, 360) <= wrapi(interval[0] + angle_area + 180, 0, 360):
return true
else:
if wrapi(angle, 0, 360) > start_angle && wrapi(angle, 0, 360) <= end_angle:
return true
return false

View File

@@ -68,6 +68,7 @@ var last_dir : int
var last_scale : Vector2
var pose_scale : int
# Animations script (for walking, idling...)
export(Script) var animations
# AnimatedSprite node (if any)
@@ -227,10 +228,13 @@ func update_terrain(on_event_finished_name = null):
# for s in sprites:
# s.set_modulate(color)
# Sets player angle and plays according animation.
"""
Sets player angle and plays according animation.
"""
func set_angle(deg):
if deg < 0 or deg > 360:
escoria.report_errors("player.gd:set_angle()", ["Invalid degree to turn to " + str(deg)])
escoria.report_errors("escplayer.gd:set_angle()", ["Invalid degree to turn to " + str(deg)])
moved = true
last_deg = deg
last_dir = _get_dir_deg(deg, animations)
@@ -242,12 +246,11 @@ func set_angle(deg):
pose_scale = animations.idles[last_dir][1]
update_terrain()
"""
Teleports the player on target position.
target can be Vector2 or Object
"""
func teleport(target, angle : Object = null) -> void:
"""
Teleports the player on target position.
target can be Vector2 or Object
"""
if typeof(target) == TYPE_VECTOR2:
printt("Player teleported at position", target, "with angle", angle)
position = target
@@ -374,7 +377,7 @@ func _get_dir_deg(deg : int, animations) -> int:
# It's an error to have the animations misconfigured
if dir == -1:
escoria.report_errors("player", ["No direction found for " + str(deg)])
escoria.report_errors("escplayer.gd:_get_dir_deg()", ["No direction found for " + str(deg)])
return dir

View File

@@ -111,32 +111,42 @@ func do(action : String, params : Array = []) -> void:
if current_state == GAME_STATE.DEFAULT:
match action:
"walk":
# Reset current action
# Reset current action.
esc_runner.set_current_action("")
# Walk to position2D
if params[1] is Vector2:
# Check moving object.
if !escoria.esc_runner.check_obj(params[0], "escoria.do(walk)"):
report_errors("escoria.gd:do()",
["Walk action requested on inexisting object: " + params[0]])
return
var moving_obj = escoria.esc_runner.get_object(params[0])
# Walk to Position2D.
if params[1] is Vector2:
var target_position = params[1]
var is_fast : bool = false
if params.size() > 2 and params[2] == true:
is_fast = true
var walk_context = {"fast": is_fast}
main.current_scene.player.walk_to(target_position, walk_context)
moving_obj.walk_to(target_position, walk_context)
# Walk to object from its id
elif params[1] is String:
elif params[1] is String:
if !escoria.esc_runner.check_obj(params[1], "escoria.do(walk)"):
report_errors("escoria.gd:do()",
["Walk action requested TOWARDS inexisting object: " + params[1]])
return
var object = escoria.esc_runner.get_object(params[1])
if object:
var target_position : Vector2 = object.interact_position
var is_fast : bool = false
if params.size() > 2 and params[2] == true:
is_fast = true
var walk_context = {"fast": is_fast, "target_object" : object}
if params[0] == main.current_scene.player.global_id:
var is_fast : bool = false
if params.size() > 2 and params[2] == true:
is_fast = true
var walk_context = {"fast": is_fast, "target_object" : object}
main.current_scene.player.walk_to(target_position, walk_context)
else:
report_errors("escoria.gd: do() > walk", ["TODO: code NPC walking"])
moving_obj.walk_to(target_position, walk_context)
"hotspot_left_click", "item_left_click":
if params[0] is String:

View File

@@ -45,6 +45,10 @@ func add_new_item_by_id(item_id : String) -> void:
if item_id.begins_with("i/"):
item_id = item_id.rsplit("i/", false)[0]
if !items_ids_in_inventory.has(item_id):
if !escoria.esc_runner.check_obj(item_id, "add_new_item_by_id"):
escoria.report_errors("inventory_ui.gd:add_new_item_by_id()",
["Item global id '"+ item_id + "' does not exist.",
"Check item's id in ESCORIA_ALL_ITEMS scene."])
var item_inventory_button = all_items.get_inventory_item(item_id).duplicate()
items_ids_in_inventory[item_id] = item_inventory_button
get_node(items_container).add_item(item_inventory_button)

View File

@@ -0,0 +1,128 @@
[gd_scene load_steps=48 format=2]
[ext_resource path="res://addons/escoria-core/game/core-scripts/escitem.gd" type="Script" id=1]
[ext_resource path="res://game/characters/android/png/03_07.png" type="Texture" id=2]
[ext_resource path="res://game/characters/android/png/02_05.png" type="Texture" id=3]
[ext_resource path="res://game/characters/android/png/06_02.png" type="Texture" id=4]
[ext_resource path="res://game/characters/android/png/03_04.png" type="Texture" id=5]
[ext_resource path="res://game/characters/android/png/02_08.png" type="Texture" id=6]
[ext_resource path="res://game/characters/android/png/03_01.png" type="Texture" id=7]
[ext_resource path="res://game/characters/android/png/04_06.png" type="Texture" id=8]
[ext_resource path="res://game/characters/android/png/04_08.png" type="Texture" id=9]
[ext_resource path="res://game/characters/tools/debug_label.tscn" type="PackedScene" id=10]
[ext_resource path="res://game/characters/android/png/03_05.png" type="Texture" id=11]
[ext_resource path="res://game/characters/android/png/05_07.png" type="Texture" id=12]
[ext_resource path="res://game/characters/android/png/04_03.png" type="Texture" id=13]
[ext_resource path="res://game/characters/android/png/02_06.png" type="Texture" id=14]
[ext_resource path="res://game/characters/android/png/06_08.png" type="Texture" id=15]
[ext_resource path="res://game/characters/android/png/04_09.png" type="Texture" id=16]
[ext_resource path="res://game/characters/android/png/05_08.png" type="Texture" id=17]
[ext_resource path="res://game/characters/android/png/03_06.png" type="Texture" id=18]
[ext_resource path="res://game/characters/android/png/06_03.png" type="Texture" id=19]
[ext_resource path="res://game/characters/android/png/06_04.png" type="Texture" id=20]
[ext_resource path="res://game/characters/android/png/02_04.png" type="Texture" id=21]
[ext_resource path="res://game/characters/android/png/03_03.png" type="Texture" id=22]
[ext_resource path="res://game/characters/android/png/06_09.png" type="Texture" id=23]
[ext_resource path="res://game/characters/android/png/06_05.png" type="Texture" id=24]
[ext_resource path="res://game/characters/android/png/03_08.png" type="Texture" id=25]
[ext_resource path="res://game/characters/android/png/06_06.png" type="Texture" id=26]
[ext_resource path="res://game/characters/android/png/05_06.png" type="Texture" id=27]
[ext_resource path="res://game/characters/android/png/04_07.png" type="Texture" id=28]
[ext_resource path="res://game/characters/android/png/02_02.png" type="Texture" id=29]
[ext_resource path="res://game/characters/android/png/04_04.png" type="Texture" id=30]
[ext_resource path="res://game/characters/android/png/05_09.png" type="Texture" id=31]
[ext_resource path="res://game/characters/android/png/06_07.png" type="Texture" id=32]
[ext_resource path="res://game/characters/android/png/02_01.png" type="Texture" id=33]
[ext_resource path="res://game/characters/android/png/05_03.png" type="Texture" id=34]
[ext_resource path="res://game/characters/android/png/04_02.png" type="Texture" id=35]
[ext_resource path="res://game/characters/android/png/03_02.png" type="Texture" id=36]
[ext_resource path="res://game/characters/android/png/02_03.png" type="Texture" id=37]
[ext_resource path="res://game/characters/android/png/05_04.png" type="Texture" id=38]
[ext_resource path="res://game/characters/android/png/06_01.png" type="Texture" id=39]
[ext_resource path="res://game/characters/android/png/02_09.png" type="Texture" id=40]
[ext_resource path="res://game/characters/android/png/04_01.png" type="Texture" id=41]
[ext_resource path="res://game/characters/android/png/04_05.png" type="Texture" id=42]
[ext_resource path="res://game/characters/android/png/02_07.png" type="Texture" id=43]
[ext_resource path="res://game/characters/android/png/03_09.png" type="Texture" id=44]
[ext_resource path="res://game/characters/android/png/05_05.png" type="Texture" id=45]
[ext_resource path="res://game/characters/android/android_anims.gd" type="Script" id=46]
[sub_resource type="SpriteFrames" id=1]
animations = [ {
"frames": [ ExtResource( 34 ) ],
"loop": true,
"name": "default",
"speed": 5.0
}, {
"frames": [ ExtResource( 39 ), ExtResource( 4 ), ExtResource( 19 ), ExtResource( 20 ), ExtResource( 24 ), ExtResource( 26 ), ExtResource( 32 ), ExtResource( 15 ), ExtResource( 23 ) ],
"loop": true,
"name": "walk_down",
"speed": 8.0
}, {
"frames": [ ExtResource( 34 ) ],
"loop": true,
"name": "idle_down_right",
"speed": 5.0
}, {
"frames": [ ExtResource( 7 ), ExtResource( 36 ), ExtResource( 22 ), ExtResource( 5 ), ExtResource( 11 ), ExtResource( 18 ), ExtResource( 2 ), ExtResource( 25 ), ExtResource( 44 ) ],
"loop": true,
"name": "walk_up_right",
"speed": 8.0
}, {
"frames": [ ExtResource( 41 ), ExtResource( 35 ), ExtResource( 13 ), ExtResource( 30 ), ExtResource( 42 ), ExtResource( 8 ), ExtResource( 28 ), ExtResource( 9 ), ExtResource( 16 ) ],
"loop": true,
"name": "walk_right",
"speed": 8.0
}, {
"frames": [ ExtResource( 32 ) ],
"loop": true,
"name": "idle_down",
"speed": 5.0
}, {
"frames": [ ExtResource( 33 ), ExtResource( 29 ), ExtResource( 37 ), ExtResource( 21 ), ExtResource( 3 ), ExtResource( 14 ), ExtResource( 43 ), ExtResource( 6 ), ExtResource( 40 ) ],
"loop": true,
"name": "walk_up",
"speed": 8.0
}, {
"frames": [ ExtResource( 29 ) ],
"loop": true,
"name": "idle_up",
"speed": 5.0
}, {
"frames": [ ExtResource( 18 ) ],
"loop": true,
"name": "idle_up_right",
"speed": 5.0
}, {
"frames": [ ExtResource( 34 ), ExtResource( 38 ), ExtResource( 45 ), ExtResource( 27 ), ExtResource( 12 ), ExtResource( 17 ), ExtResource( 31 ) ],
"loop": true,
"name": "walk_down_right",
"speed": 8.0
} ]
[node name="android" type="Sprite"]
script = ExtResource( 1 )
global_id = "android"
esc_script = "res://game/rooms/room6/esc/android.esc"
tooltip_name = "Man"
default_action = "talk"
dialog_color = Color( 1, 0, 0, 1 )
animations = ExtResource( 46 )
[node name="dialog_position" type="Position2D" parent="."]
position = Vector2( 6.35642, -321.19 )
__meta__ = {
"_editor_description_": ""
}
[node name="texture" type="AnimatedSprite" parent="."]
position = Vector2( -4.01764, -117.666 )
scale = Vector2( 0.6, 0.6 )
frames = SubResource( 1 )
[node name="debug" parent="." instance=ExtResource( 10 )]
[node name="Area2D" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionPolygon2D" parent="Area2D"]
polygon = PoolVector2Array( 6.2341, -279.169, -17.8076, -269.27, -16.3933, -235.329, -38.3136, -223.308, -37.3678, -123.59, -22.7573, -86.8364, -30.5355, -1.27643, 20.3762, 24.1794, 45.8321, 12.1586, 23.2047, -8.3475, 35.2255, -149.062, 65.6311, -108.757, 77.6519, -126.434, 39.4681, -200.681, 27.4473, -265.734 )

View File

@@ -0,0 +1,59 @@
#const dir_angles = [
# 0, # 0 NORTH FACE CAMERA
# 45, # 1 NORTHEAST
# 90, # 2 EAST
# 135, # 3 SOUTHEAST
# 180, # 4 SOUTH BACK TO CAMERA
# 225, # 5 SOUTHWEST
# 270, # 6 WEST
# 315, # 7 NORTHWEST
#]
# Angle is [from_angle, area_angle]
# example : on a clock, [180, 45] starts exactly from 6 o'clock (180°)
# and stops between 7 o'clock and 8 o'clock (45° from 6 o'clock)
const dir_angles = [
[340, 40], # 0 UP
[20, 50], # 1 RIGHT UP
[70, 40], # 2 RIGHT
[110, 50], # 3 RIGHT DOWN
[160, 40], # 4 DOWN
[200, 50], # 5 LEFT DOWN
[250, 40], # 6 LEFT
[290, 50] # 7 LEFT UP
]
# Array of animations for each direction, from UP to RIGHT_UP clockwise
# [animation_name, scale] : scale parameter can be set to -1 to mirror the animation
const directions = [
["walk_up", 1], # 0 UP
["walk_up_right", 1], # 1 RIGHT UP
["walk_right", 1], # 2 RIGHT
["walk_down_right", 1], # 3 RIGHT DOWN
["walk_down", 1], # 4 DOWN
["walk_down_right", -1], # 5 LEFT DOWN
["walk_right", -1], # 6 LEFT
["walk_up_right", -1] # 7 LEFT UP
]
const idles = [
["idle_up", 1], # 0 UP
["idle_up_right", 1], # 1 RIGHT UP
["idle_up_right", 1], # 2 RIGHT
["idle_up_right", 1], # 3 RIGHT DOWN
["idle_down", 1], # 4 DOWN
["idle_down_right", -1], # 5 LEFT DOWN
["idle_down_right", -1], # 6 LEFT
["idle_up_right", -1] # 7 LEFT UP
]
const speaks = [
["idle_up", 1], # 0 UP
["idle_up_right", 1], # 1 RIGHT UP
["idle_up_right", 1], # 2 RIGHT
["idle_up_right", 1], # 3 RIGHT DOWN
["idle_down", 1], # 4 DOWN
["idle_down_right", -1], # 5 LEFT DOWN
["idle_down_right", -1], # 6 LEFT
["idle_up_right", -1] # 7 LEFT UP
]

Some files were not shown because too many files have changed in this diff Show More