O'Reilly logo

XNA 4.0 Game Development by Example Beginner's Guide by Kurt Jaegers

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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)) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required