Chapter 9. Game #8, Treasure Chest

Wow! You've almost made it through this book. This is the last game we will develop together, and after we are done, you can proudly say that you have at least created eight games. That makes you definitely a game developer!

After all these action-packed games, it is time for another brain teaser. For this, we will create Game #8, Treasure Chest. It is a game in the likeness of the famous Bejewled (http://en.wikipedia.org/wiki/Bejewled).

In Treasure Chest, you have to line up at least three gems with the same color in a row by switching pieces that lie next to each other. To do this, you click on the first gem with your mouse and then on a neighboring gem. The position of these two gems is exchanged. If their new position results in valid line ups, the game will allow the exchange and you will be rewarded with some points. Also, the gems will vanish and the empty space will be filled by the gems from above. Empty spaces on the top will be filled randomly with new gems.

In this chapter, you won't learn many new things. You will learn what a tile map is, but we will mostly include techniques we have learned in previous chapters. Take it as your final exam. If you manage to develop this game, you are ready to go and make lots of money! Or at least some great games! And that is what it is all about, right?

Anyway, in this chapter we will cover the following:

  • How to store a tile map
  • Iterating through the tile map to find matching gems
  • Dealing with 2D arrays
  • Connecting the tile map to objects on the canvas

We will create an HTML5 game again, but you can definitely create one for GLFW, XNA, or the supported mobile platforms, too.

OK, it is time to get started. Let's go... one more time!

Frameworks and modules used

Again, we will utilize the fantomEngine framework/module. It helps to shorten the code tremendously. Believe it or not, the code for this game would easily have spanned two chapters if we had not used a framework like this.

We need to use at least Version 1.40 of fantomEngine, and you can get the newest version at its website, http://code.google.com/p/fantomengine.

Please get familiar with its API, as this book does not explain the API in detail. It just shows you how to use it in Monkey.

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

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