Thursday, 29 January 2015

Procedural Generation - Part Four - Doors, Diamonds and Sound

Last time we set our Hero free to roam the dungeon but there wasn't much to do there. This time we will set a diamond that he can collect and we will mark this momentous find with a sound effect!

The code's layout is largely unchanged. If this was being developed into a full game, I'd seriously recommend splitting into several packages before it gets any larger! The slider controls are gone this time and instead of drawing the entire map at once, just a smaller view port is drawn centered round the hero character. One button - Refresh - is kept so that the dungeon can be rebuilt.

map_render.dart - Loading sounds is very similar to loading images. This is done in an async fashion and we wait for all to load up. The function drawMap has become a little more complicated too as we keep track of the section of the map to be drawn.

PGMap has a new method createDoor which goes through the room and adds a door to the room furthest to the top of the map. Our hero can now take a walk outside. The trees are rendered off their grid points. If the hero walks behind trees you will see a layered effect and it also helps break up the grid appearance of the map. Each block object that makes up the map now has a list of items for the Hero to interact with.

Code is available on Github and a live demo is available here. Use arrow keys to move!

Next time we will finish our dungeon adventures by putting some other characters in the dungeon.