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(); } public override void Update(float deltaTimeSeconds) { transform ??= owner.GetComponent(); 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; } } }