Time for action – power-ups

  1. 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();
  2. 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)) ...

Get XNA 4.0 Game Development by Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.