A Smoll game engine
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

35 linhas
1.5 KiB

há 8 meses
há 8 meses
há 8 meses
  1. using Smoll;
  2. using Raylib_cs;
  3. using System.Numerics;
  4. using Smoll.Ex3;
  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. }