Rotating prism

This commit is contained in:
Marco 2025-05-27 17:35:48 +02:00
commit dbb81b7642
2 changed files with 34 additions and 10 deletions

File diff suppressed because one or more lines are too long

View file

@ -5,7 +5,7 @@ namespace Cirno.Scripts.Actors;
public partial class Prism : Area2D public partial class Prism : Area2D
{ {
[Export] public float ReflectionAngle { get; private set; } = 90f; [Export] public float ReflectionAngle { get; private set; } = 90f;
[Export] public float RotationAngle { get; set; } [Export] public float RotationSpeed { get; set; } = 0f;
private Sprite2D _sprite; private Sprite2D _sprite;
@ -18,13 +18,28 @@ public partial class Prism : Area2D
} }
public override void _PhysicsProcess(double delta)
{
if (RotationSpeed > 0)
{
var angleDifference = (float)(RotationSpeed * delta);
var newAngle = ReflectionAngle + angleDifference;
if (newAngle > 360)
{
newAngle = 0;
}
SetReflectionAngle(newAngle);
}
}
public void SetReflectionAngle(float angle) public void SetReflectionAngle(float angle)
{ {
ReflectionAngle = angle; ReflectionAngle = angle;
var frames = _sprite.Hframes; var frames = _sprite.Hframes;
var frame = (int)(frames * angle / 360); var frame = (int)(frames * angle / 360);
_sprite.Frame = frame - 1; _sprite.SetFrame(Mathf.Clamp(frame -1, 0, _sprite.Hframes) );
} }
private void OnCollision(Area2D other) private void OnCollision(Area2D other)