
Lesson 8 Source Files
Resource Files
This is a very important lesson. We finally can have a title screen and render text. To accomplish this I’ve added a simple blitter that renders an entire texture to a rectangular area. I’ve also reorganized the code to clean some things up. The video buffer class now handles all the pixel plotting and blitting functions.
Along with title screens comes the notion of “states.” Each state has a loading process and an execution process. When the state changes all the resources for that state are loaded in. While the state continues the same we just process the logic for that state. Garbage collection takes care of clearing out the unneeded resources. The trick is keeping track of what states are what number and which state can go to what other states and how. To get from the title screen to the game hit enter. To get back to the title screen press escape. To halt the program, press esc from the title screen.
To simplify some things we really should be using constants. Java doesn’t have constants. We’ll take care of how to get around that in Lesson 9.
The major advance that this lesson brings is being able to write text to the screen. The font_gen class is currently quite simple. It finds all the fonts that the current system supports and then generates a bitmap containing all the printable characters rendered at 36 pixels in height using the color red and the font “Ariel.” Needless to say, in Lesson 9 we’ll be abstracting this class a little more so we can adjust the font properties at load time and maybe add in the ability to have more than one font. The really nice thing about letting the language handle rendering a bitmap font rather than doing it yourself with a paint program is that we can let the language tell us the location and size of each character. You don’t need to go one letter at a time and tell the program how large each character is.
For no particular reason the generated font map is saved to a PNG file so you can see what it looks like. Keep in mind that this font generator will only work with Java. Other languages have other ways of doing this task. I’ve personally done it with C++ using the Windows API.
Our video_buffer class now has a “Print” function which takes the font class, the text and the height (in pixels) of the text. It then takes care of everything else. We’ll be improving that later as well.
Believe it or not you now have all the basic tools you need to make a complete game. In lesson 9 we’ll finally turn this tutorial into a complete game. In Lesson 10 we’ll start to push the limits with some fancy rendering.