character now teleports to specified marker when switching maps

pull/6/head
John Montagu, the 4th Earl of Sandvich 2023-08-15 19:52:15 -07:00
parent 8d20d96059
commit 9de1b41acd
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
8 changed files with 52 additions and 82 deletions

View File

@ -29,20 +29,13 @@ public partial class ConnectorBox : Area2D
[Export] [Export]
public InteractionTrigger InteractionTrigger { get; set; } public InteractionTrigger InteractionTrigger { get; set; }
[Export]
public CollisionShape2D Collision { get; set; }
private Player _player = null; private Player _player = null;
public override void _Ready() public override void _Ready()
{ {
if (Collision is null)
{
throw new NullReferenceException("Collision not specified");
}
BodyEntered += (Node2D body) => BodyEntered += (Node2D body) =>
{ {
GD.Print(body.Name + " entered");
if (body is Player && InteractionTrigger is null) if (body is Player && InteractionTrigger is null)
{ {
OnInteraction(); OnInteraction();

View File

@ -29,13 +29,11 @@ offset_bottom = -28.0
[node name="Label" parent="InteractionTrigger/Popup" index="0"] [node name="Label" parent="InteractionTrigger/Popup" index="0"]
text = "Enter" text = "Enter"
[node name="Area2D" type="Area2D" parent="." node_paths=PackedStringArray("InteractionTrigger", "Collision")] [node name="Area2D" type="Area2D" parent="." node_paths=PackedStringArray("InteractionTrigger")]
script = ExtResource("3_4rsih") script = ExtResource("3_4rsih")
ToArea = "res://Scenes/Maps/Arena.tscn" ToArea = "res://Scenes/Maps/Arena.tscn"
ToConnector = "entrance" ToConnector = "Entrance"
Identifier = "arena_entrance"
InteractionTrigger = NodePath("../InteractionTrigger") InteractionTrigger = NodePath("../InteractionTrigger")
Collision = NodePath("CollisionShape2D")
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] [node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
shape = SubResource("RectangleShape2D_djn8q") shape = SubResource("RectangleShape2D_djn8q")

View File

@ -1832,7 +1832,7 @@ background_mode = 3
glow_enabled = true glow_enabled = true
glow_hdr_threshold = 1.4 glow_hdr_threshold = 1.4
[node name="TileMap" type="TileMap" node_paths=PackedStringArray("Entities", "Areas", "Spawners")] [node name="TileMap" type="TileMap" node_paths=PackedStringArray("Entities", "Areas", "Spawners", "Markers")]
y_sort_enabled = true y_sort_enabled = true
texture_filter = 3 texture_filter = 3
tile_set = SubResource("TileSet_18c7j") tile_set = SubResource("TileSet_18c7j")
@ -1878,11 +1878,7 @@ script = ExtResource("2_4m0a1")
Entities = NodePath("Entities") Entities = NodePath("Entities")
Areas = NodePath("Areas") Areas = NodePath("Areas")
Spawners = NodePath("Spawners") Spawners = NodePath("Spawners")
CameraLowerBound = null Markers = NodePath("Markers")
CameraUpperBound = null
ClearColor = null
AreaName = null
MapName = null
[node name="CanvasModulate" type="CanvasModulate" parent="."] [node name="CanvasModulate" type="CanvasModulate" parent="."]

View File

@ -14,6 +14,9 @@ public partial class Map : TileMap
[Export] [Export]
public Node2D Spawners { get; set; } public Node2D Spawners { get; set; }
[Export]
public Node2D Markers { get; set; }
[Export] [Export]
public Vector2 CameraLowerBound { get; set; } public Vector2 CameraLowerBound { get; set; }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -27,6 +27,7 @@ public partial class LocationDisplay : CenterContainer
_subtitle.Visible = map.AreaName != map.MapName; _subtitle.Visible = map.AreaName != map.MapName;
_mapName.Text = map.MapName; _mapName.Text = map.MapName;
_subtitle.Text = map.AreaName; _subtitle.Text = map.AreaName;
_animPlayer.Stop();
_animPlayer.Play("show"); _animPlayer.Play("show");
} }
} }

View File

@ -97,7 +97,7 @@ public partial class World : Node
EventBus = this.GetEventBus(); EventBus = this.GetEventBus();
EventBus.RequestMoveToArea += (Events.RequestAreaArgs args) => EventBus.RequestMoveToArea += (Events.RequestAreaArgs args) =>
{ {
MoveToArea(args.Area, args.Connector); CallDeferred(MethodName.MoveToArea, args.Area, args.Connector);
}; };
EventBus.RegisteredBoss += RegisterBoss; EventBus.RegisteredBoss += RegisterBoss;
EventBus.DeregisteredBoss += DeregisterBoss; EventBus.DeregisteredBoss += DeregisterBoss;
@ -138,14 +138,17 @@ public partial class World : Node
{ {
GD.Print("Loading map " + map.Name); GD.Print("Loading map " + map.Name);
var root = GetTree().Root;
if (CurrentMap is not null) if (CurrentMap is not null)
{ {
_maps.Update(CurrentMap.SceneFilePath);
CurrentMap.Entities.RemoveChild(CurrentPlayer); CurrentMap.Entities.RemoveChild(CurrentPlayer);
GetTree().Root.RemoveChild(CurrentMap); root.RemoveChild(CurrentMap);
CurrentMap.Active = false; CurrentMap.Active = false;
} }
GetTree().Root.AddChild(map); root.AddChild(map);
InitTilemap(map); InitTilemap(map);
CurrentMap = map; CurrentMap = map;
@ -168,11 +171,6 @@ public partial class World : Node
public void LoadScene(PackedScene scene) public void LoadScene(PackedScene scene)
{ {
if (CurrentMap is not null)
{
_maps.Update(CurrentMap.SceneFilePath);
}
Map map; Map map;
string path = scene.ResourcePath; string path = scene.ResourcePath;
@ -251,19 +249,8 @@ public partial class World : Node
private void MovePlayerToConnector(string name) private void MovePlayerToConnector(string name)
{ {
// find the first connector with the specified name var marker = CurrentMap.Markers.GetNode<Marker2D>(name);
// TODO: replace this with event buses CurrentPlayer.GlobalPosition = marker?.GlobalPosition ?? Vector2.Zero;
//var connector = CurrentMap.Areas.GetChildren().First((child) =>
//{
// if (child is BoundingBoxes.ConnectorBox connector)
// {
// return connector.Identifier == name;
// }
// return false;
//}) as BoundingBoxes.ConnectorBox;
//CurrentPlayer.GlobalPosition = connector.GlobalPosition;
CurrentPlayer.GlobalPosition = Vector2.Zero;
} }
public void MoveToArea(string path, string connector) public void MoveToArea(string path, string connector)