Chapter 4. Game #3, CometCrusher

Asteroids was a classic arcade game in the 80s. You could find it in every arcade hall. You had to control a little spaceship and blast asteroids which were flying around into pieces. Sometimes an enemy spaceship flew by and you had to avoid its deadly shots and try to shoot it down for additional points. If you don't know about this game, then have a look at the following: http://en.wikipedia.org/wiki/Asteroids_%28video_game%29.

In this chapter, we will create the game CometCrusher, a game similar to Asteroids.

In the game, you are trapped inside a huge asteroid field, and you have to make sure that your little spaceship is not crushed by these huge rocks of heavy material. Three hits and your ship is gone! So blast your cannon at them and smash them into pieces. Once you are done, you can be sure that there is more work for you to do because space is full of rocks.

During this chapter, we make heavy use of a game framework called fantomEngine. We will do the following:

  • Create, load, and display images via the fantomEngine game framework
  • Save and load a high score list via SaveState
  • Load and play sound effects
  • Learn where to store the game resources
  • Install Flex, and a command-line compiler to create FLASH games

Since almost every game stores at least a high score list, you will learn how to create a high score list, save it, and also load it back into the game the next time the game loads.

Besides the actual game code, we will learn how to export to FLASH.

Using a game framework—the fantomEngine

In Chapter 3, Game #2, Rocket commander we have created every single class and function required for our game. Sometimes we also created duplicate functionality. For example, every object had its render method. This bloats up the code of the game but it was also good to understand the concept of a whole game.

To avoid redundant coding and make your life easier, you can and will use the fantomEngine game framework for this game.

The source code file, fantomEngine.monkey is included with this book, but for the most recent version visit: http://code.google.com/p/fantomengine/.

The fantomEngine features some classes (objects) for different functionalities, which are described as follows:

  • ftEngine: This is the main engine class
  • ftObject: An object that can be an image, text, circle, or a box
  • ftSound: This is to handle sound files
  • ftLayer: A layer groups several objects together to update, render, and check collisions
  • ftFont: This is a bitmap font object which can load EZGui compatible font files
  • ftTimer: Using this, a timer will be called at will and you can automate processes with it

In this chapter, we won't go into every feature of the fantomEngine. For a detailed reference please visit its website.

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

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