mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 08:45:33 +00:00
Rotating prism
This commit is contained in:
parent
ec64f272c4
commit
dbb81b7642
2 changed files with 34 additions and 10 deletions
File diff suppressed because one or more lines are too long
|
|
@ -5,7 +5,7 @@ namespace Cirno.Scripts.Actors;
|
|||
public partial class Prism : Area2D
|
||||
{
|
||||
[Export] public float ReflectionAngle { get; private set; } = 90f;
|
||||
[Export] public float RotationAngle { get; set; }
|
||||
[Export] public float RotationSpeed { get; set; } = 0f;
|
||||
|
||||
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)
|
||||
{
|
||||
ReflectionAngle = angle;
|
||||
var frames = _sprite.Hframes;
|
||||
var frame = (int)(frames * angle / 360);
|
||||
|
||||
_sprite.Frame = frame - 1;
|
||||
_sprite.SetFrame(Mathf.Clamp(frame -1, 0, _sprite.Hframes) );
|
||||
}
|
||||
|
||||
private void OnCollision(Area2D other)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue