public Bullet Add(Vector2 position, Vector2 velocity, Ship ship) { Bullet newBullet = new Bullet(position, velocity, ship); newBullet.Id = Interlocked.Increment(ref idCounter); Bullets.Add(newBullet); return newBullet; }
object[] Serialize(Bullet bullet) { object[] serializedBullet = new object[5]; serializedBullet[0] = bullet.Id; serializedBullet[1] = bullet.Movement.Position.X; serializedBullet[2] = bullet.Movement.Position.Y; serializedBullet[3] = bullet.Movement.Velocity.X; serializedBullet[4] = bullet.Movement.Velocity.Y; return serializedBullet; }
Bullet DeserializeBullet(JToken token) { Bullet bullet = null; if (token.Count<object>() != 0) { bullet = new Bullet(Vector2.Zero, Vector2.Zero, null); bullet.Id = (int)token[0]; bullet.Movement.Position.X = (float)token[1]; bullet.Movement.Position.Y = (float)token[2]; bullet.Movement.Velocity.X = (float)token[3]; bullet.Movement.Velocity.Y = (float)token[4]; } return bullet; }