cirnogodot/Scripts/Actors/Prism.cs

37 lines
831 B
C#
Raw Normal View History

2025-05-27 15:11:02 +02:00
using Godot;
namespace Cirno.Scripts.Actors;
public partial class Prism : Area2D
{
2025-05-27 15:38:08 +02:00
[Export] public float ReflectionAngle { get; private set; } = 90f;
2025-05-27 15:11:02 +02:00
[Export] public float RotationAngle { get; set; }
2025-05-27 15:38:08 +02:00
private Sprite2D _sprite;
2025-05-27 15:11:02 +02:00
public override void _Ready()
{
this.AreaEntered += OnCollision;
2025-05-27 15:38:08 +02:00
_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;
2025-05-27 15:11:02 +02:00
}
private void OnCollision(Area2D other)
{
if (other is not Bullet bullet) return;
bullet.RotateBullet(ReflectionAngle);
}
}