A Smoll game engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

35 lignes
1.5 KiB

il y a 8 mois
il y a 8 mois
il y a 8 mois
il y a 8 mois
  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. }