A Smoll game engine
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.5 KiB

using Smoll;
using Raylib_cs;
using System.Numerics;
using Smoll.Ex3;
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;
}
}
}