Time for action – updating the WeaponManager class
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
Modify the
tryToSpawnPowerup()
method of the WeaponManager class and replace theif
statement that checks to see if the tile the power-up is being placed on is a wall (it currently readsif (!TileMap.IsWallTile(x,y))
) with the following:if (!(PathFinder.FindPath( new Vector2(x,y), Player.PathingNodePosition)==null))
Execute Robot Rampage and explore the map, looking for the power-ups.
What just happened?
Since the FindPath()
method returns null immediately if either the starting or ending square is a wall, this new condition will cover trying to place a power-up on a wall tile as well as accounting for unreachable tiles on the map.
We talked in the power-ups section about...