Rotating prism sprite

This commit is contained in:
Marco 2025-05-27 15:38:08 +02:00
commit ec64f272c4
6 changed files with 55 additions and 3 deletions

View file

@ -4,12 +4,27 @@ namespace Cirno.Scripts.Actors;
public partial class Prism : Area2D
{
[Export] public float ReflectionAngle { get; set; } = 90f;
[Export] public float ReflectionAngle { get; private set; } = 90f;
[Export] public float RotationAngle { get; set; }
private Sprite2D _sprite;
public override void _Ready()
{
this.AreaEntered += OnCollision;
_sprite = this.GetNode<Sprite2D>("Sprite2D");
SetReflectionAngle(ReflectionAngle);
}
public void SetReflectionAngle(float angle)
{
ReflectionAngle = angle;
var frames = _sprite.Hframes;
var frame = (int)(frames * angle / 360);
_sprite.Frame = frame - 1;
}
private void OnCollision(Area2D other)
@ -17,7 +32,6 @@ public partial class Prism : Area2D
if (other is not Bullet bullet) return;
bullet.RotateBullet(ReflectionAngle);
}
}