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.gd40
1 files changed, 31 insertions, 9 deletions
diff --git a/Scenes/Components/MapArea.gd b/Scenes/Components/MapArea.gd
index 080a3f7..c221273 100644
--- a/Scenes/Components/MapArea.gd
+++ b/Scenes/Components/MapArea.gd
@@ -1,12 +1,21 @@
+class_name MapArea
extends Area2D
signal transitioned_to
@export var can_plant_bomb: bool = true
+@export_node_path("TileMap") var _tilemap: NodePath
+
+var tilemap: TileMap
func _ready():
+ if not _tilemap:
+ tilemap = $TileMap
+ else:
+ tilemap = get_node(_tilemap)
+
add_area_edges()
@@ -46,33 +55,42 @@ func _on_player_entered(player: Player):
return
if exited_area:
+ player.process_mode = Node.PROCESS_MODE_ALWAYS
exited_area.set_collision_mask_value(Utilities.Collision.Layer.PLAYER, false)
+ else:
+ tilemap.process_mode = Node.PROCESS_MODE_INHERIT
- $TileMap.process_mode = PROCESS_MODE_INHERIT
- $TileMap.visible = true
+ self.set_collision_mask_value(Utilities.Collision.Layer.PLAYER, false)
+ tilemap.visible = true
self.adjust_camera_to_area(player)
- if not player.get_parent() == $TileMap:
- (func(): player.reparent($TileMap)).call_deferred()
+ 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
+ tilemap.process_mode = Node.PROCESS_MODE_DISABLED
+ exited_area.tilemap.process_mode = Node.PROCESS_MODE_DISABLED
# animate sprite
var sprite: AnimatedSprite2D = player.get_node("AnimatedSprite2D")
var bounds: Rect2 = Utilities.get_collision_shape_bounds($CollisionShape2D)
var sprite_direction = ""
+ var direction = Vector2.UP
if player.global_position.x <= bounds.position.x:
sprite_direction = "right"
+ direction = Vector2.RIGHT
elif player.global_position.x >= bounds.end.x:
sprite_direction = "left"
+ direction = Vector2.LEFT
elif player.global_position.y <= bounds.position.y:
sprite_direction = "down"
+ direction = Vector2.DOWN
elif player.global_position.y >= bounds.end.y:
sprite_direction = "up"
+ direction = Vector2.UP
var sprite_tween = get_tree().create_tween().set_loops(5)
sprite_tween.tween_interval(0.25)
@@ -80,12 +98,18 @@ func _on_player_entered(player: Player):
sprite.play(sprite_direction)
)
+ player.set_process(false)
+
position_tween = get_tree().create_tween()
position_tween.tween_property(
- player, "global_position", player.global_position + player.DIRECTION * (16 + 8), 1.25
+ player, "global_position", player.global_position + direction * (16 + 8), 1.25
)
position_tween.tween_callback(func():
- exited_area.get_node("TileMap").visible = false
+ tilemap.process_mode = Node.PROCESS_MODE_INHERIT
+ player.process_mode = Node.PROCESS_MODE_INHERIT
+ player.set_process(true)
+
+ exited_area.tilemap.visible = false
sprite_tween.kill()
sprite.play("idle_" + sprite_direction)
exited_area.set_collision_mask_value(Utilities.Collision.Layer.PLAYER, true)
@@ -94,8 +118,6 @@ func _on_player_entered(player: Player):
)
Global.last_area = self
-
- # TODO: handle different child entity groups inside TileMap
func adjust_camera_to_area(player: Player) -> Camera2D: