StrawberryBF/SampleGame/src/MovingJumpThru.bf

51 lines
896 B
Brainfuck
Raw Normal View History

2020-05-09 12:05:29 +08:00
namespace Strawberry.Sample
{
public class MovingJumpThru : JumpThru
{
private Point moveFrom;
private Point moveTo;
private float moveTime;
private float movingLerp;
private bool movingPositive;
public this(Point pos, int width, Point moveTo, float moveTime)
: base(pos, width)
{
moveFrom = Position;
this.moveTo = moveTo;
this.moveTime = moveTime;
movingLerp = 0;
movingPositive = true;
}
public override void Update()
{
base.Update();
if (movingPositive)
{
movingLerp += Time.Delta / moveTime;
if (movingLerp >= 1)
{
movingLerp = 1;
movingPositive = false;
}
}
else
{
movingLerp -= Time.Delta / moveTime;
if (movingLerp <= 0)
{
movingLerp = 0;
movingPositive = true;
}
}
let target = Vector.Lerp(moveFrom, moveTo, Ease.CubeInOut(movingLerp));
MoveTo(target);
}
}
}