A Smoll game engine
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

36 rader
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;
}
}
}