basic connecting areas
parent
7f042f0130
commit
72a1ace2f1
|
@ -1,14 +1,66 @@
|
|||
using Godot;
|
||||
using System;
|
||||
using SupaLidlGame.Characters;
|
||||
|
||||
namespace SupaLidlGame.BoundingBoxes
|
||||
{
|
||||
public partial class ConnectorBox : Area2D
|
||||
{
|
||||
[Signal]
|
||||
public delegate void RequestedEnterEventHandler(
|
||||
ConnectorBox box,
|
||||
Player player);
|
||||
|
||||
[Export]
|
||||
public string ToArea { get; set; }
|
||||
|
||||
[Export]
|
||||
public string ToConnector { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the connector requires the user to interact to enter
|
||||
/// the connector
|
||||
/// </summary>
|
||||
[Export]
|
||||
public bool RequiresInteraction { get; set; } = true;
|
||||
|
||||
[Export]
|
||||
public CollisionShape2D Collision { get; set; }
|
||||
|
||||
private Player _player = null;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (Collision is null)
|
||||
{
|
||||
throw new NullReferenceException("Collision not specified");
|
||||
}
|
||||
|
||||
BodyEntered += (Node2D body) =>
|
||||
{
|
||||
if (body is Player player)
|
||||
{
|
||||
_player = player;
|
||||
}
|
||||
};
|
||||
|
||||
BodyExited += (Node2D body) =>
|
||||
{
|
||||
if (body is Player)
|
||||
{
|
||||
_player = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Input.IsActionJustPressed("interact"))
|
||||
{
|
||||
EmitSignal(SignalName.RequestedEnter, this, _player);
|
||||
}
|
||||
|
||||
base._Process(delta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
[gd_scene load_steps=8 format=3 uid="uid://dd6xy1y0m8smm"]
|
||||
[gd_scene load_steps=10 format=3 uid="uid://dd6xy1y0m8smm"]
|
||||
|
||||
[ext_resource type="Script" path="res://Utils/World.cs" id="1_1k6ew"]
|
||||
[ext_resource type="Texture2D" uid="uid://gm2pcnfg7h8j" path="res://Assets/Sprites/tileset.png" id="1_k6myx"]
|
||||
[ext_resource type="PackedScene" uid="uid://b2254pup8k161" path="res://Characters/Player.tscn" id="1_m35hr"]
|
||||
[ext_resource type="PackedScene" uid="uid://ddcf6bfv212wj" path="res://Characters/ExampleEnemy.tscn" id="2_uti3y"]
|
||||
[ext_resource type="PackedScene" uid="uid://dhl071rj5wyvx" path="res://Entities/Campfire.tscn" id="4_6awvs"]
|
||||
[ext_resource type="Script" path="res://BoundingBoxes/ConnectorBox.cs" id="6_eol7a"]
|
||||
|
||||
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_1pa1q"]
|
||||
texture = ExtResource("1_k6myx")
|
||||
|
@ -1110,6 +1111,9 @@ texture = ExtResource("1_k6myx")
|
|||
physics_layer_0/collision_layer = 1
|
||||
sources/0 = SubResource("TileSetAtlasSource_1pa1q")
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_drg0k"]
|
||||
size = Vector2(34, 14)
|
||||
|
||||
[node name="World" type="Node2D"]
|
||||
script = ExtResource("1_1k6ew")
|
||||
|
||||
|
@ -1177,3 +1181,13 @@ scale = Vector2(1.00571, 1)
|
|||
Faction = 1
|
||||
|
||||
[node name="Spawners" type="Node2D" parent="TileMap/Entities"]
|
||||
|
||||
[node name="Areas" type="Node2D" parent="TileMap"]
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="TileMap/Areas" node_paths=PackedStringArray("Collision")]
|
||||
script = ExtResource("6_eol7a")
|
||||
Collision = NodePath("CollisionShape2D")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="TileMap/Areas/Area2D"]
|
||||
position = Vector2(158, -24)
|
||||
shape = SubResource("RectangleShape2D_drg0k")
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace SupaLidlGame.Utils
|
|||
base._Process(delta);
|
||||
}
|
||||
|
||||
public void MoveToArea(string area, string connector)
|
||||
public void MoveToArea(string area, string connector, Player player)
|
||||
{
|
||||
if (area != CurrentArea)
|
||||
{
|
||||
|
@ -45,5 +45,12 @@ namespace SupaLidlGame.Utils
|
|||
|
||||
_currentConnector = connector;
|
||||
}
|
||||
|
||||
public void _on_area_2d_requested_enter(
|
||||
BoundingBoxes.ConnectorBox box,
|
||||
Player player)
|
||||
{
|
||||
MoveToArea(box.ToArea, box.ToConnector, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,6 +61,11 @@ equip={
|
|||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
interact={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":70,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[layer_names]
|
||||
|
||||
|
|
Loading…
Reference in New Issue