2022-11-25 11:07:23 -08:00
|
|
|
using Godot;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace SupaLidlGame.Utils
|
|
|
|
{
|
|
|
|
public partial class PlayerCamera : Camera2D
|
|
|
|
{
|
|
|
|
protected float _intensity;
|
|
|
|
|
|
|
|
protected double _timeLeft;
|
|
|
|
|
|
|
|
public override void _Ready()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void _Process(double delta)
|
|
|
|
{
|
|
|
|
if (_timeLeft > 0)
|
|
|
|
{
|
|
|
|
_timeLeft -= delta;
|
|
|
|
Offset = RandomOffset(_intensity);
|
|
|
|
}
|
2022-11-25 13:56:38 -08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Offset = Vector2.Zero;
|
|
|
|
}
|
2022-11-25 11:07:23 -08:00
|
|
|
|
|
|
|
if (_intensity > 0)
|
|
|
|
{
|
|
|
|
_intensity = Mathf.MoveToward(_intensity, 0.0f, (float)delta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Shake(float intensity, double time)
|
|
|
|
{
|
2022-11-25 13:56:38 -08:00
|
|
|
_intensity = Mathf.Max(_intensity, intensity);
|
|
|
|
_timeLeft = Math.Max(_timeLeft, time);
|
2022-11-25 11:07:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
private Vector2 RandomOffset(float intensity)
|
|
|
|
{
|
|
|
|
Vector2 ret = Vector2.Zero;
|
|
|
|
var rng = new RandomNumberGenerator();
|
2022-11-25 11:59:55 -08:00
|
|
|
ret.x = (rng.Randf() - 0.5f) * intensity;
|
|
|
|
ret.y = (rng.Randf() - 0.5f) * intensity;
|
2022-11-25 11:07:23 -08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|