12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- using System;
- using System.Collections.Generic;
- using System.Numerics;
- using System.Text.Json;
- using BubbleSocketCore.Input;
- namespace BubbleSocketCore.Simulation.Entity
- {
- class CircleEntity : IEntity
- {
- private int Id;
- private Vector2 Position;
- private Vector2 Center;
- private float Radius;
- private float Speed;
- public CircleEntity()
- {
- Center = new Vector2(150, 75);
- Radius = 70.0f;
- Speed = 2;
- }
- public IEntity ApplyInputs(int elapsedTick, List<PlayerInput> inputs)
- {
- long millis = elapsedTick * TickService.simulationTickRateInMs;
- Position.X = Radius * (float)Math.Cos(millis / (Speed * 1000.0)) + Center.X;
- Position.Y = Radius * (float)Math.Sin(millis / (Speed * 1000.0)) + Center.Y;
- return this;
- }
- public IEntity Clone()
- {
- return new CircleEntity();
- }
- public int GetId()
- {
- return Id;
- }
- public Dictionary<string, object> Serialize()
- {
- return new Dictionary<string, object>{
- { "id", Id },
- {"position", new List<object> {
- Position.X,
- Position.Y
- }
- },
- };
- }
- public void SetId(int entityId)
- {
- Id = entityId;
- }
- public override string ToString()
- {
- return JsonSerializer.Serialize(Serialize());
- }
- }
- }
|