A Smoll game engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 regels
1.5 KiB

using Smoll;
using Raylib_cs;
using System.Numerics;
using Smoll.Ex2;
namespace Smoll.Ex1
{
class ExampleInputComponent : Component {
InertiaComponent? transform;
public float speedPixelPerSecond;
public float angularSpeedTurnPerSecond;
public ExampleInputComponent(float speedPixelPerSecond, float angularSpeedTurnPerSecond) {
this.speedPixelPerSecond = speedPixelPerSecond;
this.angularSpeedTurnPerSecond = angularSpeedTurnPerSecond;
}
public override void OnAttached()
{
base.OnAttached();
transform = owner.GetComponent<InertiaComponent>();
}
public override void Update(float deltaTimeSeconds)
{
transform ??= owner.GetComponent<InertiaComponent>();
if(transform == null) throw new Exception("Example Input used on immovable object");
transform.transform.position -= Raylib.IsKeyDown(KeyboardKey.Up) * speedPixelPerSecond * deltaTimeSeconds * Complex.ImaginaryOne;
transform.transform.position += Raylib.IsKeyDown(KeyboardKey.Down) * speedPixelPerSecond * deltaTimeSeconds * Complex.ImaginaryOne;
transform.transform.position -= Raylib.IsKeyDown(KeyboardKey.Left) * speedPixelPerSecond * deltaTimeSeconds;
transform.transform.position += Raylib.IsKeyDown(KeyboardKey.Right) * speedPixelPerSecond * deltaTimeSeconds;
transform.transform.angle += Raylib.IsKeyDown(KeyboardKey.L) * angularSpeedTurnPerSecond * 2 * float.Pi * deltaTimeSeconds;
}
}
}