From f27937e6e9b6a7146dd09fc711d2d293ecf5abbf Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sun, 14 Apr 2024 21:49:20 +0200 Subject: update --- Scenes/Components/MapArea.gd | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'Scenes/Components/MapArea.gd') diff --git a/Scenes/Components/MapArea.gd b/Scenes/Components/MapArea.gd index f46216a..6aaa811 100644 --- a/Scenes/Components/MapArea.gd +++ b/Scenes/Components/MapArea.gd @@ -1,8 +1,10 @@ extends Area2D + + func _ready(): - self.add_area_edges() + pass func add_area_edges(): @@ -45,21 +47,44 @@ func _on_player_entered(player: Player): if exited_area: exited_area.get_node("TileMap").process_mode = PROCESS_MODE_DISABLED + # animate sprite + var sprite: AnimatedSprite2D = player.get_node("AnimatedSprite2D") + var bounds: Rect2 = Utilities.get_collision_shape_bounds($CollisionShape2D) + + var sprite_direction = "" + if player.position.x <= bounds.position.x: + sprite_direction = "right" + elif player.position.x >= bounds.end.x: + sprite_direction = "left" + elif player.position.y <= bounds.position.y: + sprite_direction = "down" + elif player.position.y >= bounds.end.y: + sprite_direction = "up" + + var sprite_tween = get_tree().create_tween().set_loops(5) + sprite_tween.tween_interval(0.25) + sprite_tween.tween_callback(func(): + sprite.play(sprite_direction) + ) + var tween = get_tree().create_tween() tween.tween_property( player, "position", player.position + player.DIRECTION * 16, 1.25 ) tween.tween_callback(func(): exited_area.get_node("TileMap").visible = false + sprite_tween.kill() + sprite.play("idle_" + sprite_direction) ) Global.last_area = self + + # TODO: handle different child entity groups inside TileMap func adjust_camera_to_area(player: Player) -> Camera2D: var camera: Camera2D = player.get_node("Camera2D") var bounds: Rect2 = Utilities.get_collision_shape_bounds($CollisionShape2D) - #var enter_direction_vector = player.position - collision_shape.position var duration = 0 if Global.last_area: -- cgit v1.2.3