Time for action – updating the WeaponManager class
Add a property to the
Player
module to create a shortcut to the square the player is currently located in:#Region "Properties" Public ReadOnly Property PathingNodePosition As Vector2 Get Return TileMap.GetSquareAtPixel(BaseSprite.WorldCenter) End Get End Property #End Region
Modify the
tryToSpawnPowerup()
method of theWeaponManager
module and replace theIf
statement that checks to see if the square the power-up is being placed on contains a wall tile (it currently reads "If Not TileMap.IsWallTile(x,y) Then
") with the following code:If Not IsNothing(PathFinder.FindPath( New Vector2(x,y), Player.PathingNodePosition)) Then
Execute Robot Rampage and explore the map, looking for the power-ups.
What just happened?
Since the FindPath()
method returns Nothing
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...