Rendering Engine

How does the game's logic come onto the screen? That's one big question every beginning (game) developer had at one point, probably several times for each project. It is hard to say that there is one right way, as the solution often changes with the desired target deployment or other aspects. It was hard for me to find a library that fitted my needs. I just couldn't find one that I could trust. Libtcod was very close, but due to it's lack of documentation I thought it was the best way to get stuck in development again. In a swell of inner fervor and prone to test my newly acquired programming skills, I decided to implement my own solution. I wanted to display the tiles on the screen, something which couldn't possibly be that hard, wouldn't it?

Swing and Screen

I use Java's Swing framework, using a JFrame with a JPanel. I use an own class named Screen, which controls the type of output and processes input. Each screen represents an active and visible part of the interface, such as a help screen, a main menu. Every screen stands on its own and cannot be combined with another, like in a splitscreen. The JFrame is really just a naked base that gets initialized in the main class, to use a system window and to forward user input towards the screens. Every output gets collected in the RoguePanel, an extended JPanel. It outputs an array of some 30*60 tiles. The screens decide what it outputs and can write to a number of two-dimensional arrays.

Layers

These arrays really just contain simple (int) numbers. What they do is simple: the renderer works in several layers, one for each array. Each layer stands for a type of entity, such as creature, structure, terrain etc and is assigned a static source image file. The number really is an index that is now looked up on the source image. A 32*32 px section of the source is copied and printed to the current frame. The renderer doesn't even care about anything outside it's possible display range. That makes it really simple. Furthermore, changing the graphic style of Bronze and Faith is just a matter of exchanging these source images and knowing the indexes. If I wanted, I could exchange the graphical tileset for a set of characters. But I really like the tileset that is being prepared for BaF, so I'll stick with it.

Now some might think that I am restricted to using the tile's coordinates for everything. That's what I thought when I created the help screen with some text, as I have never worked with Java Swing before. It turned out I was wrong: RoguePanel (being an extension of JPanel) can be easily decorated with other Swing classes, such as JTextArea and other interface elements. If I ever choose to make a more fancy UI, I will know how to do it.

Leave a Reply

Your email address will not be published. Required fields are marked *