summaryrefslogtreecommitdiff
path: root/Scenes/Components/MapArea.gd
diff options
context:
space:
mode:
Diffstat (limited to 'Scenes/Components/MapArea.gd')
-rw-r--r--Scenes/Components/MapArea.gd29
1 files changed, 20 insertions, 9 deletions
diff --git a/Scenes/Components/MapArea.gd b/Scenes/Components/MapArea.gd
index 4a69815..31e567a 100644
--- a/Scenes/Components/MapArea.gd
+++ b/Scenes/Components/MapArea.gd
@@ -40,11 +40,21 @@ func _on_body_entered(body):
func _on_player_entered(player: Player):
var exited_area = Global.last_area
+ if Global.last_area == self:
+ return
+
+ if exited_area:
+ exited_area.set_collision_mask_value(Utilities.Collision.Layer.PLAYER, false)
+
$TileMap.process_mode = PROCESS_MODE_INHERIT
$TileMap.visible = true
self.adjust_camera_to_area(player)
+ if not player.get_parent() == $TileMap:
+ (func(): player.reparent($TileMap)).call_deferred()
+
+ var position_tween: Tween
if exited_area:
exited_area.get_node("TileMap").process_mode = PROCESS_MODE_DISABLED
@@ -53,13 +63,13 @@ func _on_player_entered(player: Player):
var bounds: Rect2 = Utilities.get_collision_shape_bounds($CollisionShape2D)
var sprite_direction = ""
- if player.position.x <= bounds.position.x:
+ if player.global_position.x <= bounds.position.x:
sprite_direction = "right"
- elif player.position.x >= bounds.end.x:
+ elif player.global_position.x >= bounds.end.x:
sprite_direction = "left"
- elif player.position.y <= bounds.position.y:
+ elif player.global_position.y <= bounds.position.y:
sprite_direction = "down"
- elif player.position.y >= bounds.end.y:
+ elif player.global_position.y >= bounds.end.y:
sprite_direction = "up"
var sprite_tween = get_tree().create_tween().set_loops(5)
@@ -68,16 +78,17 @@ func _on_player_entered(player: Player):
sprite.play(sprite_direction)
)
- var tween = get_tree().create_tween()
- tween.tween_property(
- player, "position", player.position + player.DIRECTION * 16, 1.25
+ position_tween = get_tree().create_tween()
+ position_tween.tween_property(
+ player, "global_position", player.global_position + player.DIRECTION * 16, 1.25
)
- tween.tween_callback(func():
+ position_tween.tween_callback(func():
exited_area.get_node("TileMap").visible = false
sprite_tween.kill()
sprite.play("idle_" + sprite_direction)
+ exited_area.set_collision_mask_value(Utilities.Collision.Layer.PLAYER, true)
)
-
+
Global.last_area = self
# TODO: handle different child entity groups inside TileMap