59 lines
1.2 KiB
C#
59 lines
1.2 KiB
C#
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using Godot;
|
|
using Godot.Bridge;
|
|
using Godot.NativeInterop;
|
|
|
|
[ScriptPath("res://Scripts/Puzzles/CamOffset.cs")]
|
|
public partial class CamOffset : Area2D
|
|
{
|
|
[Export(PropertyHint.None, "")]
|
|
private Vector2 offset;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private bool returnOnExit = true;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private float step = 0.01f;
|
|
|
|
private Entity inside;
|
|
|
|
public override void _Ready()
|
|
{
|
|
base.BodyEntered += Enter;
|
|
base.BodyExited += Exit;
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
if (Main.inEvent == null)
|
|
{
|
|
if (inside == Player.instance.controlling)
|
|
{
|
|
CameraController.instance.offset = CameraController.instance.offset.Lerp(offset, step * Main.deltaTime);
|
|
}
|
|
else if (returnOnExit)
|
|
{
|
|
CameraController.instance.offset = CameraController.instance.offset.Lerp(Room.current.camOffset, step * Main.deltaTime);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Enter(Node other)
|
|
{
|
|
if (other == Player.instance?.controlling)
|
|
{
|
|
inside = Player.instance.controlling;
|
|
}
|
|
}
|
|
|
|
private void Exit(Node other)
|
|
{
|
|
if (other == Player.instance?.controlling)
|
|
{
|
|
inside = null;
|
|
}
|
|
}
|
|
|
|
}
|