A look at structures and game objects for our tactical RPG on the Sega Genesis and Mega Drive.
Last time we announced our new upcoming game for the Sega Genesis, We Got Dungeons.
This time we'll delve into the technical details of the game, so strap in for some tech talk!
First off let's talk about the levels.
We are planning on having several different tiers of levels, each of them comprised of several floors of increasing difficulty. The levels are broken down into separate discrete rooms that are filled with randomly generated encounters.
In order to maximize the number of different rooms that we have to work with, and make each room as interesting and varied as possible, we have an elegant yet simple system in place.
First, we create a room template that is a plain old matrix of numbers. Looks something like this:
Now that we have these templates we can easily generate a floor map by stitching multiple rooms together.
You can notice that in that example we have 6 as a decorative object that is 3 tiles wide. When the room is generated a random object will be picked and placed there.
This approach gives us the ability to quickly create lots of room templates and have them appear random but at the same time have enough control to give each and every single room that handcrafted feel that many procedurally generated levels lack.
But this is ROM memory, so how do we use this in the game. Well, we have a matrix of pointers to game objects (we will talk about those structures in a later post so stay tuned) that point to whatever is loaded in at that particular square. After that, we can finally draw those objects on the screen. Right?
Unfortunately, there is one last catch. The internal data structures are normal matrices that represent 32x32 pixel squares on the screen. But We Got Dungeons uses an isometric perspective. This means that we have to transform the Cartesian coordinates of a square grid matrix into isometric coordinates.
Due to the isometric perspective, the art is "squished" and the grid runs at an angle of 26.565°. That number is very specific for a reason, and this is where a little bit of maths comes in very handy.
A slope of a line is defined as the ratio between the change of the y coordinate and the change of the x coordinate or:
With a little bit of geometry we get the following:
Looking at this picture it is clear that the slope is:
Which in our case is tan(26.565). Google tells us that the tangent of 26.565 degrees is 0.49999888349. Which is close enough to 0.5 which in turn gives us a nice ratio of 2:1.
Now we can use this simple ratio to convert the square coordinates into isometric coordinates and draw the art at the proper coordinates on the screen.
Thus, we are able to generate good looking, unique dungeons for each and every playthrough of the game. Check out part 3 in our series to talk about the game objects and how they interact with each other!