Fixes for prisms

This commit is contained in:
Marco 2025-05-28 14:37:42 +02:00
commit f25bce557d
3 changed files with 45 additions and 32 deletions

View file

@ -8,6 +8,12 @@ public partial class Prism : Area2D
[Export] public float RotationSpeed { get; set; } = 0f;
private Sprite2D _sprite;
[Export] public float[] Angles { get; set; } = [-90f, -45f, 180f, 45f, 90f];
private int _angleIndex = 0;
private double _rotateTimer = 0;
public override void _Ready()
{
@ -22,13 +28,25 @@ public partial class Prism : Area2D
{
if (RotationSpeed > 0)
{
var angleDifference = (float)(RotationSpeed * delta);
var newAngle = ReflectionAngle + angleDifference;
if (newAngle > 360)
_rotateTimer += delta;
}
if (_rotateTimer > RotationSpeed)
{
_rotateTimer = 0;
_angleIndex++;
if (_angleIndex >= Angles.Length)
{
newAngle = 0;
_angleIndex = 0;
}
//var angleDifference = (float)(RotationSpeed * delta);
//var newAngle = ReflectionAngle + angleDifference;
// if (newAngle > 360)
// {
// newAngle = 0;
//
// }
var newAngle = Angles[_angleIndex];
SetReflectionAngle(newAngle);
}
}