|
|
- using Smoll;
- using Raylib_cs;
- using System.Numerics;
-
- namespace Smoll.Ex1
- {
- class ExampleInputComponent : Component {
- Transform2DComponent? 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<Transform2DComponent>();
- }
-
- public override void Update(float deltaTimeSeconds)
- {
- transform ??= owner.GetComponent<Transform2DComponent>();
- 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;
- }
- }
- }
|