When I last left off, I managed to get the trap placement mechanic working as designed. Of the core mechanics I needed to get working, the last one remaining was enemy platform pathfinding…
Platform Pathfinding Challenges
As previously stated, the game’s object is to ward off hoards of enemies trying to navigate their way to your treasure vault by placing traps and barriers in their way.
The player can navigate the environment by moving left, right, jumping, and falling. I wanted to give the enemy a similar capability:
In this scenario, an enemy character can walk left or right and can clear obstacles up to two squares (32x32px tiles) high and three across. Each scenario is numbered and represents the following:
- All possible ‘jump’/walk movements from a platform (1-3 across, 2 up)
- Walk left or right 1 square
- Drop down left or right
- Jump up left or right 1 square
- Jump up left or right 2 squares
- Jump up left or right 2 squares, illustrating that the platform might be floating (i.e. allows free movement beneath it)
- Jump across left or right 1 square and up 2 squares
- Jump across 2 squares (same height)
- Jump across 2 squares and up 1 square
- Jump across 2 squares and up 2 squares
- Dropdown 1 square left or right from any height to a platform below (this is implied in 3, but I wanted to illustrate it explicitly)
- Drop down to a platform of any height, 1 square left or right across
- Drop down to a platform of any height, 2 squares left or right across
While I found a couple of examples of this working/implemented in GML using a modified version of the A* Search Algorithm, I could never get them to work within my project. I discussed the problem with my friend Jason, who created a working prototype for me that met all of the design specifications. But not fully understanding how the code worked, I failed to integrate it.
Now that I have the time to troubleshoot it, I’m reluctant to do as I fear that I don’t understand it well enough to support it. Instead, it might be better to build something simpler…
Possible Solutions
Thinking through the problem, there are many other ways I could have solved this. Wrecking Crew for the NES comes to mind:
Enemies (and the player) in Wrecking Crew use ladders to navigate up and down platform levels. Why couldn’t I implement a similar feature?
Ladders
For example, instead of trying to make the enemy AI smart enough to navigate obstacles with a preset of constraints/scenarios, I could have them wander left and right across vertical planes, moving up or down when they reach a ladder, depending on whether the vault was above or below them.
Alternately, rather than placing ladders in fixed places, perhaps some enemy types could create erect them?
Stairs
Another option would be to use teleportation in the form of background staircases:
In this example, the enemies could access specific floors using “staircase” objects that would move them from point A to B and B to C, and vice versa.
Either scenario would necessitate creating two extra animation frames for each enemy sprite. Not a deal breaker, but something to consider…