A Smoll game engine
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.5 KiB

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