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.

39 lignes
1.6 KiB

il y a 7 mois
  1. using Smoll;
  2. using Raylib_cs;
  3. using System.Numerics;
  4. using Smoll.Ex1;
  5. namespace Smoll.Ex2
  6. {
  7. class ExampleShootingInputComponent : Component {
  8. Transform2DComponent? transform;
  9. ArrowComponent? arrow;
  10. public ExampleShootingInputComponent() {
  11. }
  12. public override void OnAttached()
  13. {
  14. base.OnAttached();
  15. transform = owner.GetComponent<Transform2DComponent>();
  16. arrow = owner.GetComponent<ArrowComponent>();
  17. }
  18. public override void Update(float deltaTimeSeconds)
  19. {
  20. transform ??= owner.GetComponent<Transform2DComponent>();
  21. if(transform == null) throw new Exception("Example Input used on immovable object");
  22. arrow ??= owner.GetComponent<ArrowComponent>();
  23. if(arrow == null) throw new Exception("Example Shooter used on arrowless object");
  24. if(Raylib.IsKeyPressed(KeyboardKey.Space)) {
  25. var shoot = new Entity(owner.layers.First());
  26. shoot.zOrder = -5;
  27. var details = arrow.OriginAndVector();
  28. var selfTransform = transform.AbsoluteTransform();
  29. shoot.Attach(new Transform2DComponent((float)details.Item1.Real, (float)details.Item1.Imaginary, selfTransform.angle, selfTransform.scale));
  30. shoot.Attach(new TimeToLiveComponent(4f));
  31. shoot.Attach(new SpriteComponent("Beam.png"));
  32. shoot.Attach(new InertiaComponent(1.0f, (float)details.Item2.Real, (float)details.Item2.Imaginary));
  33. }
  34. }
  35. }
  36. }