Chapter 3. Game #2, Rocket Commander

Every game developer should know about Missile Command. You don't? Well, the game we will create in this chapter Rocket Commander, is based on the classic ATARI hit game Missile Command. It is a single player arcade game. In Rocket Commander, you are in control of the AEDS (Arial Earth Defence Squadron) and so have two powerful rocket launchers at your command. The enemy will try to destroy our beloved cities with their bombs and rockets, which will fall from the sky. You have to use your missiles and destroy the incoming weapons before they destroy the cities and cause total mayhem.

First, have a look at the original game at http://en.wikipedia.org/wiki/Missile_Command.

Missile Command was a huge hit. It was mainly controlled with three buttons for the missile launching bases and a trackball for aiming your shots. Using the mouse to control this game is perfect. But, under HTML5, you can only use the left mouse button, you might say. That is right, but we can still use keys to shoot the rockets.

In this chapter, we will learn the following:

  • How to draw more primitives, such as lines and dots
  • How to print text on the screen
  • How to make use of functions
  • Reading the coordinates and button clicks of a mouse
  • Randomly generating numbers
  • Basic circle-collision detection

Again, we will use the primitives that Monkey provides, since there is no need to create any media for this game. We will create the basic structure of the game at first. Next, we will create the data structures to hold the game data, such as game score, numbers of rockets left, and so on.

As a first test, you will build the game interface. This means drawing the cities and rockets. The next step will be to implement the ability to read the mouse state.

To actually fire the rockets, we have to implement the rocket data and handle updating it in every frame.

As we need something to shoot at, we need the enemy to throw down some bombs. You will create their data structures and spawn these deadly things on the screen!

Finally, we need to check if our rockets have destroyed something, or worse, the enemy has hit the cities. So, we will learn how to check for a collision.

When the game is completed, it will resemble the following screenshot:

Game #2, Rocket Commander

Are you ready to rumble? Ok! Let's get rolling!

The game objects

Each game is made of some objects. These can be images, or sounds, but also complex structures, such as a game character and its abilities. In our game, we have a few objects, as follows:

  • The cities we have to defend
  • The rocket launchers that will fire our rockets
  • The rockets themselves
  • The bombs that will fall down on our precious cities and try to destroy them
  • Explosions that will show up once a rocket bursts into pieces (the particle clouds from these explosions will be the real harm to the bombs; if they collide with an explosion cloud, the bombs will be destroyed)

There are few more elements/objects to the game, such as the game UI (score, background, and so on), but we will concentrate on the ones just listed. Each object will be built with a separate class.

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

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