CircleEntity.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Numerics;
  4. using System.Text.Json;
  5. using BubbleSocketCore.Input;
  6. namespace BubbleSocketCore.Simulation.Entity
  7. {
  8. class CircleEntity : IEntity
  9. {
  10. private int Id;
  11. private Vector2 Position;
  12. private Vector2 Center;
  13. private float Radius;
  14. private float Speed;
  15. public CircleEntity()
  16. {
  17. Center = new Vector2(150, 75);
  18. Radius = 70.0f;
  19. Speed = 2;
  20. }
  21. public IEntity ApplyInputs(int elapsedTick, List<PlayerInput> inputs)
  22. {
  23. long millis = elapsedTick * TickService.simulationTickRateInMs;
  24. Position.X = Radius * (float)Math.Cos(millis / (Speed * 1000.0)) + Center.X;
  25. Position.Y = Radius * (float)Math.Sin(millis / (Speed * 1000.0)) + Center.Y;
  26. return this;
  27. }
  28. public IEntity Clone()
  29. {
  30. return new CircleEntity();
  31. }
  32. public int GetId()
  33. {
  34. return Id;
  35. }
  36. public Dictionary<string, object> Serialize()
  37. {
  38. return new Dictionary<string, object>{
  39. { "id", Id },
  40. {"position", new List<object> {
  41. Position.X,
  42. Position.Y
  43. }
  44. },
  45. };
  46. }
  47. public void SetId(int entityId)
  48. {
  49. Id = entityId;
  50. }
  51. public override string ToString()
  52. {
  53. return JsonSerializer.Serialize(Serialize());
  54. }
  55. }
  56. }