mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-08 06:55:54 +00:00
Rotating prism sprite
This commit is contained in:
parent
dbca78c0b7
commit
ec64f272c4
6 changed files with 55 additions and 3 deletions
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue