Thursday, July 09, 2009
A* and Dungeon Generation
Over-engineering dungeon generation
Until today, I used to have a massive ConnectRooms function that connected different rooms. It would enter and leave rooms differently based on their type, and would kink around and bend in random locations. After reading this post I realized that my approach was horrible, and the results weren't that great. So I implemented A* and now I just make a call to A* to connect rooms. That's it ... one call ... well, mostly.
Edited on: Thursday, July 09, 2009 3:51 PM
Categories: General Programming
Friday, August 22, 2008
Rendering in OpenGL
My last post brought up an important issue - rendering. Most Roguelikes use ascii to represent everything. Those that use tile graphics.....I'm not sure what they use for rendering. Like the title says, RogueRunner uses OpenGL. It's platform independent, clean and easy to use, and easy to learn. For those who might consider OpenGL there are excellent tutorials by Nehe that are a great kick start.
The biggest advantage of using OpenGL, at least in my mind, is the use of alpha blending. For those who don't know, alpha blending allows for images to use transparency so that when 1 image is painted on top of another, it doesn't completely cover the underlying image. For example, a sword tile is drawn on top of a floor tile. This can be done any number of times, and so facilitates layering.
RogueRunner makes extensive use of this. Most notably when rendering doors, stairs, and decorations. More specifically, the doors and stairs themselves are different tiles to be blended on top of whatever you want. This means that instead of having a set of tiles that have a common door but different background, you just have 1 door and as many background tiles as you want. Example:
Using this method means I don't have to store every combination of every type of door with every type of background. Just combine any door with any background!
Another of the big advantages of OpenGL is lighting. I'm using the Angband tileset made by David Gervais, and many of the tiles are dedicated to drawing the same texture at different light levels. OpenGL elliminates the need for this. Textures can be colored in any way you want. For example, the tiles around the player can be tinted slightly yellow to simulate torch light, or the cells around a fireball can be lit red as it travels towards its target, or the player's color can change when they're poisoned or petrified. All this and more with no changes at all to the tiles themselves.
The last thing I'll mention is the square grid. I'm not bound to it in any way with OpenGL, though I stick to it when rendering most things. Without adhering to the grid arrows can fly straight at their target, explosions can look better, creatures can be scaled to be bigger or smaller, and magic in general can be made to look better. None of this is done yet, but it's all planned for.
The bottom line is, OpenGL simplifies the task of rendering and adds certain abilities that a pure tile based approach couldn't produce.
Edited on: Friday, August 22, 2008 12:34 PM
Categories: General Programming