static Tuple <int, int> DrawEnemyShip() { EnemyShip match = null; var random = new Random(); var x = random.Next(0, _windowWidth); var y = random.Next(0, _windowHeight - 20); // make sure that no two enemy ships are in the same location for (int i = 0; i < _enemies.Length; i++) { if (_enemies[i]?.X == x && _enemies[i]?.Y == y) { match = _enemies[i]; break; } } while (x == match?.X && y == match?.Y) { x = random.Next(0, _windowWidth); y = random.Next(0, _windowHeight - 20); } WriteAt(ENEMY_SHIP, x, y, ENEMY_SHIP_FOREGROUND_COLOR, ENEMY_SHIP_BACKGROUND_COLOR); return(new Tuple <int, int>(x, y)); }
static void DrawEnemyShips() { for (int i = 0; i < _numberOfEnemyShips; i++) { var coordinates = DrawEnemyShip(); _enemies[i] = new EnemyShip(coordinates.Item1, coordinates.Item2); } }
private void SpawnEnemyShip() { int value = random.Next(1, screen.Width - 2); var enemyShip = new EnemyShip(this, ENEMY, value, 1, ENEMY_LIVES); enemyShip.Draw(); enemyShips.Add(enemyShip); lastSpawn = DateTime.Now; }
public Fleet(int _x, int _y, int _Rows, int _Columns) : base() { Direction = 1; Alive = true; ObjectType = eType.Enemy; x = _x; y = _y; Rows = _Rows; Columns = _Columns; EnemyShips = new EnemyShip[Columns][]; for (int i = 0; i < Columns; i++) { EnemyShips[i] = new EnemyShip[Rows]; for (int j = 0; j < Rows; j++) { EnemyShips[i][j] = new EnemyShip(x + Engine.Width / 25 * i, y + Engine.Width / 25 * j, Engine.Width / 50, Engine.Width / 50); } } for (int i = 0; i < Columns; i++) { EnemyShips[i][Rows - 1].CanFire = true; } }
public void Spawn(GameMessage message) { int index = message.index; int p = BitConverter.ToInt32(message.Message, 16); if (entities.Keys.Contains<int>(index)) { if (entities[index].typeID == -1) { entities.Remove(index); } else { return; } } if (idCounter <= index) idCounter = index + 1; switch (p) { case 0: var ship = new PlayerShip(); ship.HandleSpawnMessage(message); AddEntity(index, ship); break; case 1: var enemyShip = new EnemyShip(); enemyShip.HandleSpawnMessage(message); AddEntity(index, enemyShip); break; case 2: var bullet = new Bullet(); bullet.HandleSpawnMessage(message); AddEntity(index, bullet); break; case 3: var chunk = new BuildingChunk(); chunk.HandleSpawnMessage(message); AddEntity(index, chunk); break; } }
private void UpdateClients() { if (updateCounter > (1000.0d / Game1.updatesPerSecond)) { if (numShips < maxNumShips) { var ship = new EnemyShip(); ship.Place(new Vector2(rand.Next(Game1.width), -100)); createdEntities.Add(ship); ++numShips; } foreach (IEntity entity in entities.Values) { if (entity.RequiresUpdate) { entity.RequiresUpdate = false; broadcastMessages.Add(entity.GetStateMessage()); } } foreach (KeyValuePair<int, List<GameMessage>> messageList in messages) { messageList.Value.AddRange(broadcastMessages); if (messageList.Value.Count > 0) { if (messageList.Value.Count == 1) { _server.Connections[messageList.Key].Send(messageList.Value[0]); messageList.Value.Clear(); } else if (messageList.Value.Count < 100) { Connection conn; if (_server.Connections.TryGetValue(messageList.Key, out conn)) conn.Send(GameMessage.MessageBundle(messageList.Value)); else { } messageList.Value.Clear(); } else { List<GameMessage> updateMessages = new List<GameMessage>(); for (int i = 0; i < 100; ++i) { updateMessages.Add(messageList.Value[0]); messageList.Value.Remove(messageList.Value[0]); } Connection conn; if (_server.Connections.TryGetValue(messageList.Key, out conn)) { conn.Send(GameMessage.MessageBundle(updateMessages)); } else { } } } } broadcastMessages.Clear(); updateCounter = 0.0d; } }