Time for action – power-ups
Add the following declarations to the WeaponManager class:
static public List<Sprite> PowerUps = new List<Sprite>(); static private int maxActivePowerups = 5; static private float timeSinceLastPowerup = 0.0f; static private float timeBetweenPowerups = 2.0f; static private Random rand = new Random();
Add the
tryToSpawnPowerup()
method to the Weapons Management Methods region of the WeaponManager class:private static void tryToSpawnPowerup(int x, int y, WeaponType type) { if (PowerUps.Count >= maxActivePowerups) { return; } Rectangle thisDestination = TileMap.SquareWorldRectangle(new Vector2(x,y)); foreach (Sprite powerup in PowerUps) { if (powerup.WorldRectangle == thisDestination) { return; } } if (!TileMap.IsWallTile(x,y)) { Sprite newPowerup = new Sprite( new Vector2(thisDestination.X, thisDestination.Y), Texture, ...