Blocks Game

Popularized by classic games such as Breakout and Arkanoid, the ball-and-paddle block-bashing game genre is a fun exercise in game programming because it requires fast-paced input, sprite control, animation, and collision detection—all the nutrients you need for a healthy game in a little package. This is what I consider the marquee demo game for the Advanced2D engine because it provides a good overview of the engine’s core features.

The source code is about as tight as I could make it without resorting to complex algorithms, and yet it is still 870 lines—or 30 pages of laid-out text (which is why I’m not listing the code here). And yet, this is a tiny game by most standards. (In contrast, most commercial games have more than 800 lines of code just for the title screen.) Figure 13.3 shows a screenshot of the Blocks game.

Figure 13.3. The Blocks game.


From this figure, you can see that this is no ordinary Breakout-style game. First of all, the ball is a light source that casts a shadow when it nears the paddle. Or is this just a rendering trick? You can explore the source code to find out! Second, the ball leaves a trail behind it as it moves. In addition, the blocks themselves are rendered in varying levels of alpha, and you must hit them repeatedly to eliminate them. The ball’s power level increases as long as you don’t let it hit the floor.

Unlike most games of this genre, this game doesn’t have “lives” in the normal sense; instead, if you let the ball hit the floor, the power level drops back down to one, and you have to build it back up again! The status information on top is highlighted with smoky particles!

You may add new levels to the game by modifying the levels.h file. Here’s a challenge: Modify the game so it uses Lua script to define the levels. By doing this, anyone will be able to custom-design new block layouts and try them out without recompiling the game.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset