public static void TryToAddEnemy(GameTime gameTime) { CleanHouse(); ActorEnemy.AddEnemyCoolDown -= gameTime.ElapsedGameTime.TotalSeconds; if (ActorEnemy.AddEnemyCoolDown <= 0) { var enemy = new ActorEnemy(); enemy.SrcRect = new Rectangle(258, 115, 98, 50); enemy.ShotCoolDown = _rand.NextDouble() * 3.0 + 1.0; if (_rand.Next(2) == 1) { // from the left enemy.Speed.X = (float)_rand.NextDouble() * 25.0f + 10.0f; enemy.Location.Y = (float)_rand.NextDouble() * 150.0f; } else { // from the right enemy.Speed.X = -((float)_rand.NextDouble() * 25.0f + 10.0f); enemy.Location.X = ActorPlayer.Bounds.Right; enemy.Location.Y = (float)_rand.NextDouble() * 150.0f; } _enemies.Add(enemy); ActorEnemy.AddEnemyCoolDown = _rand.NextDouble() * 3.0 + 3.0; } }
private static void AddBullet(ActorEnemy enemy) { if (enemy != null && enemy.ShotCoolDown <= 0) { var shot = new ActorBullet(); shot.SrcRect = new Rectangle(497, 2, 9, 33); shot.Location.X = enemy.Location.X + enemy.SrcRect.Width / 2 - shot.SrcRect.Width / 2; shot.Location.Y = enemy.Location.Y + enemy.SrcRect.Height - shot.SrcRect.Height; shot.Speed.Y = 200.0f; _bullets.Add(shot); enemy.ShotCoolDown = enemy.SecondsBetweenShots; } }