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.

35 lines
1.5 KiB

8 months ago
8 months ago
8 months ago
8 months ago
  1. using Smoll;
  2. using Raylib_cs;
  3. using System.Numerics;
  4. using Smoll.Ex2;
  5. namespace Smoll.Ex1
  6. {
  7. class ExampleInputComponent : Component {
  8. InertiaComponent? transform;
  9. public float speedPixelPerSecond;
  10. public float angularSpeedTurnPerSecond;
  11. public ExampleInputComponent(float speedPixelPerSecond, float angularSpeedTurnPerSecond) {
  12. this.speedPixelPerSecond = speedPixelPerSecond;
  13. this.angularSpeedTurnPerSecond = angularSpeedTurnPerSecond;
  14. }
  15. public override void OnAttached()
  16. {
  17. base.OnAttached();
  18. transform = owner.GetComponent<InertiaComponent>();
  19. }
  20. public override void Update(float deltaTimeSeconds)
  21. {
  22. transform ??= owner.GetComponent<InertiaComponent>();
  23. if(transform == null) throw new Exception("Example Input used on immovable object");
  24. transform.transform.position -= Raylib.IsKeyDown(KeyboardKey.Up) * speedPixelPerSecond * deltaTimeSeconds * Complex.ImaginaryOne;
  25. transform.transform.position += Raylib.IsKeyDown(KeyboardKey.Down) * speedPixelPerSecond * deltaTimeSeconds * Complex.ImaginaryOne;
  26. transform.transform.position -= Raylib.IsKeyDown(KeyboardKey.Left) * speedPixelPerSecond * deltaTimeSeconds;
  27. transform.transform.position += Raylib.IsKeyDown(KeyboardKey.Right) * speedPixelPerSecond * deltaTimeSeconds;
  28. transform.transform.angle += Raylib.IsKeyDown(KeyboardKey.L) * angularSpeedTurnPerSecond * 2 * float.Pi * deltaTimeSeconds;
  29. }
  30. }
  31. }