Time for action – updating the WeaponManager class

  1. Add a property to the Player class to create a shortcut to the square the player is currently located in:
    #region Properties
    public static Vector2 PathingNodePosition
    {
        get
        {
            return TileMap.GetSquareAtPixel(BaseSprite.WorldCenter);
        }
    }
    #endregion
  2. Modify the tryToSpawnPowerup() method of the WeaponManager class and replace the if statement that checks to see if the tile the power-up is being placed on is a wall (it currently reads if (!TileMap.IsWallTile(x,y))) with the following:
    if (!(PathFinder.FindPath(
        new Vector2(x,y),
        Player.PathingNodePosition)==null))
  3. Execute Robot Rampage and explore the map, looking for the power-ups.

What just happened?

Since the FindPath() method returns null immediately ...

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.