public UserCommand(Ship.Action action, bool active, TimeSpan elapsedTime) { Id = Interlocked.Increment(ref idCounter); Action = action; Active = active; ElapsedTime = elapsedTime; }
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; }
/// <summary> /// Creates a new ship and adds it to the world (should only be called by the server) /// </summary> /// <returns></returns> public Ship Create() { Ship newShip = new Ship(world); newShip.Id = Interlocked.Increment(ref idCounter); Ships.Add(newShip.Id, newShip); return newShip; }
/// <summary> /// Adds a ship to the world (should be called by the client when sync'ing from the server) /// </summary> public Ship Add(int id) { Ship newShip = new Ship(world); newShip.Id = id; Ships.Add(newShip.Id, newShip); return newShip; }
object[] Serialize(Ship ship) { object[] serializedShip = new object[10]; serializedShip[0] = ship.Id; serializedShip[1] = ship.Movement.Position.X; serializedShip[2] = ship.Movement.Position.Y; serializedShip[3] = ship.Movement.Velocity.X; serializedShip[4] = ship.Movement.Velocity.Y; serializedShip[5] = ship.Movement.Acceleration.X; serializedShip[6] = ship.Movement.Acceleration.Y; serializedShip[7] = ship.Movement.Rotation; serializedShip[8] = ship.Health.Alive; serializedShip[9] = ship.Health.Health; return serializedShip; }
public void Draw(Ship ship, LineBatch lineBatch, PointBatch pointBatch, Camera camera) { // Draw the ship Matrix rotation = Matrix.CreateRotationZ(ship.Movement.Rotation); Matrix translation = Matrix.CreateTranslation(new Vector3(ship.Movement.Position.X, ship.Movement.Position.Y, 0.0f)); lineBatch.Begin(rotation * translation, camera); for (int v = 0; v < vertices.Count; v++) { lineBatch.Draw(vertices[v], vertices[(v + 1) % vertices.Count], lineWidth, color); } lineBatch.End(); pointBatch.Begin(translation, camera); pointBatch.Draw(Vector3.Zero, lightRadius, lightColor); pointBatch.End(); }
Ship Deserialize(JToken token) { Ship ship = null; if (token.Count<object>() != 0) { ship = new Ship(null); ship.Id = (int)token[0]; ship.Movement.Position.X = (float)token[1]; ship.Movement.Position.Y = (float)token[2]; ship.Movement.Velocity.X = (float)token[3]; ship.Movement.Velocity.Y = (float)token[4]; ship.Movement.Acceleration.X = (float)token[5]; ship.Movement.Acceleration.Y = (float)token[6]; ship.Movement.Rotation = (float)token[7]; ship.Health.Alive = (bool)token[8]; ship.Health.Health = (int)token[9]; } return ship; }
public User() { ShipId = -1; Ship = null; }
public ShipWeapons(Ship ship, World world) { this.ship = ship; this.world = world; lastBulletFired = DateTime.Now; }
public Bullet(Vector2 position, Vector2 velocity, Ship ship) { Movement = new BulletMovement(position, velocity); this.ship = ship; }
public ShipMovement(Ship ship) : base() { this.ship = ship; }