A Smoll game engine
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

35 líneas
1.5 KiB

hace 8 meses
hace 8 meses
hace 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. }