The game objects

Like it was stated earlier, CometCrusher will feature a few game objects. Most of them won't be stationary and all behave differently in the game.

Each object will be created via a call to the CreateLayer, CreateImage, LoadSound, or LoadFont methods of fantomEngine.

So let's talk about them one by one.

Layers

The game will feature a few layers (groups). Each layer groups several objects. Thus, it makes sense to group objects that need to be handled together. The collision detection of fantomEngine will only work with objects that are in the same layer.

All layers are rendered in the order of their creation. The same goes for the corresponding objects in each layer, unless they are a child of an object.

For the game, we will have a few layers, as follows:

  • Background
  • Game
  • ParticleFX
  • UI
  • Title
  • High score list

Not every layer is visible at all times. For example, the high score list and the title are visible only when needed.

Background stars

The background of the game is composed of a two-digit number of star images, which are scaled down and then spin around their own center. This spinning animation is automatically done by fantomEngine during the updating of events for the game. So basically, you set the start up in the OnCreate phase of the game and then forget about them.

To set up the spinning, we will use a call to the SetSpin method of each star object.

Background stars

Comets

In CometCrusher, you will find three sizes of comets. When a comet is created, it will have the biggest size. Once you shoot at it, it will be cracked (destroyed) into several medium-sized comets. And if these are cracked, they will spawn several small comets. The small comets will be destroyed without spawning new comets once they get hit by a shot.

New big comets will be created at random positions. Medium and small comets will be spawned from the center of the previously destroyed comet. Every comet will spin around its center at a random speed. The direction and speed of their movement is also randomly determined, and set with the call of the SetSpeed method. Once a comet reaches the border of the screen (canvas), it will be automatically wrapped to the opposite side of the screen by fantomEngine. We will need to set this behavior with a call to the SetWrapScreen method.

Comets

The player ship

This is your vessel, your tool to get the job done. Controlling it is a little bit difficult and will be handled inside the OnObjectUpdate method. Hey, we are in space, so what do you expect? There is no grip of some tires here and if you turn your ship it isn't automatically flying into its new direction.

The following illustration will show you what that means:

The player ship

The vessel was flying upwards, and then turned to the right by 90 degrees. Then, its engine tried to push it into the new direction. The outcome was that the vessel was still heading at 90 degrees, but the ship was flying at a speed vector of 45 degrees. It was basically sliding through space.

So you have to push the ship with your engine. Directing the ship is a mix of turning the ship and adding speed to its new direction. As we don't want to go wild with the ship's speed, it will have a maximum speed. The SetMaxSpeed method will do that for us.

Even though we are in space, there is a little friction set for the ship. So if you don't speed up, it will stop after a while. The friction is set with the SetFriction method.

Turning your ship is done via a simple SetAngle method from fantomEngine. Increasing the speed and calculating its movement, via the AddSpeed method, is also supported by fantomEngine, so you don't need to worry about all the math that is done behind the scenes. Just like the comets, the player ship will wrap around the screen when it hits the edges of the screen canvas.

Be careful not to hit a comet with your ship without having your shield up. You will lose a life and when all your lives are gone, the game is over. Of course, the impact will crack that comet too.

The player ship

The shield

Just like every good spaceship, your vessel has a protection shield. It can be activated at will and will be active for a given amount of time. While being active, a collision with a comet will not harm your ship. Some players could use a "Shield up and hit" tactic.

The shield will be a child of the player ship. That means that fantomEngine will move it automatically with the player ship. Once set up correctly, you won't need to worry about its movement anymore. You only need to activate it and deactivate it after a certain amount of time. For setting up timer events, you can use the CreateObjTimer method. Once a timer fires, you can react to it in the OnObjectTimer method.

The shield

Shots

Besides breaking the comets into pieces, your ship carries a deadly cannon that fires some nice fast bullets which can blast a comet with one hit.

Each bullet will travel at a given speed at the angle which the player ship was facing when the bullet was shot. Each bullet will also wrap around the screen once it hits the borders. fantomEngine will also check for collisions with comets, and let you know about them in the OnObjectCollision method, so you can act accordingly. That means remove the bullet, add points to the score, destroy the comet that was hit, and maybe spawn new smaller comets. When a shot is fired, a corresponding sound effect will be played via a call of the Play method of the sound object.

Shots

Particles

When shots hit a comet or a player runs viciously into one of these huge rocks, an explosion will appear. This is just for visual kicks, so-called eye-candy. For an explosion, several particles will be spawned at the center of the explosion with a random speed and angle of movement. After a random time, they will be removed from the game. Also, an explosion sound effect will be played.

Particles

Game info text

Inside the game, we will inform the player about different statistics such as the game score. Each text object will be created with the CreateText method and then later updated with the SetText method.

Game info text
..................Content has been hidden....................

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