2023-07-22 20:23:48 -07:00
|
|
|
using Godot;
|
|
|
|
|
|
|
|
namespace SupaLidlGame.BoundingBoxes;
|
|
|
|
|
2023-08-26 01:00:18 -07:00
|
|
|
public partial class CameraBounds : Node2D
|
2023-07-22 20:23:48 -07:00
|
|
|
{
|
2023-08-17 22:14:06 -07:00
|
|
|
[Export]
|
|
|
|
public Area2D Trigger { get; set; }
|
|
|
|
|
2023-08-26 01:00:18 -07:00
|
|
|
//[Export]
|
|
|
|
//public Rect2I Bounds { get; set; }
|
|
|
|
|
|
|
|
[Export]
|
|
|
|
public Marker2D TopLeft { get; set; }
|
|
|
|
|
2023-08-17 22:14:06 -07:00
|
|
|
[Export]
|
2023-08-26 01:00:18 -07:00
|
|
|
public Marker2D BottomRight { get; set; }
|
2023-08-17 22:14:06 -07:00
|
|
|
|
2023-07-22 20:23:48 -07:00
|
|
|
public override void _Ready()
|
|
|
|
{
|
2024-06-06 13:05:10 -07:00
|
|
|
//Trigger.BodyEntered += OnBodyEntered;
|
|
|
|
//Trigger.BodyExited += OnBodyExited;
|
2023-07-22 20:23:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private void OnBodyEntered(Node2D body)
|
|
|
|
{
|
|
|
|
if (body is Characters.Player player)
|
|
|
|
{
|
|
|
|
var camera = player.Camera;
|
2023-08-26 01:00:18 -07:00
|
|
|
var rect = new Rect2I();
|
|
|
|
rect.Position = (Vector2I)TopLeft.GlobalPosition;
|
|
|
|
rect.End = (Vector2I)BottomRight.GlobalPosition;
|
|
|
|
camera.SetCameraBounds(rect);
|
2023-08-17 22:14:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnBodyExited(Node2D body)
|
|
|
|
{
|
|
|
|
if (body is Characters.Player player)
|
|
|
|
{
|
|
|
|
var camera = player.Camera;
|
2023-08-26 01:00:18 -07:00
|
|
|
camera.LimitLeft = int.MinValue;
|
|
|
|
camera.LimitTop = int.MinValue;
|
|
|
|
camera.LimitRight = int.MaxValue;
|
|
|
|
camera.LimitBottom = int.MaxValue;
|
2023-07-22 20:23:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|