Additions to the Game


If I were developing Invasion of the Slugwroths for commercial release, the next thing I'd add would be Captain Chloride's salt shooterso he can kill the Slugwroths himself instead of running them into doors. Of course, this would require a salt_shooter class. I would add a data member of type salt_shooter to the chloride class.

The salt_shooter class would need to contain member data for storing how many shots were left. It could have a variable indicating its maximum range. That way, I could add SuperPower SaltTabs in later levels. If Captain Chloride finds and picks up SuperPower SaltTabs, his salt shooter fires a greater distance for a specific number of shots.

To enable the Captain to carry his salt shooter as he walks, I would need to add two animations of him carrying it while walkingone animation for walking left and the other for walking right. Firing the salt shooter requires two more animations: firing left and firing right.

Adding all of these animations requires techniques that you know alreadythe same techniques I used to make him walk. Selecting the correct animation means adding more states to the chloride class. Recall that the chloride class contains an enumeration called state. The constants in that enumeration tell what state the Captain is in. If you look in the file Chloride.h in the folder Source\Chapter18\Prog_18_01 on the CD, you'll see that there are constants for walking left and right. I would need to add constants for walking left with the salt shooter out, walking right with the salt shooter out, firing to the left, and firing to the right.

Tip

When you simulate a projectile being fired over a short distance, like bullets or the salt blast from the salt shooter, you usually do not add the effects of gravity. Gravity does not change the course much of bullets and similar projectiles over short distances. Therefore, the effect can be ignored.


When the salt shooter fires, it works very much like the cannon example you first saw in chapter 9, "Floating Point Math in C++." Instead of a cannonball, I would create a class to represent a blast of salt. Unlike the cannonball class, the salt_blast class would not model the effects of gravity. The blast of salt would always continue in a straight line until it hit something. When it did, it would explode in a white poof. If it hit a Slugwroth, the salt_blast object would call the slug::Kill() function.

As you can see, adding the salt shooter is just a matter of applying the techniques you've already seen in the example programs in this book.

What about Captain Chloride's powerups? How would those work?

Factoid

When a character in a game jumps, he behaves very much like a projectile that has just been launched in a gravity field. Therefore, the code for plotting his course is very similar to the code used for the cannonball in the cannon examples.


I think you've probably guessed that adding powerups is just a variation on the techniques we used to implement the door key. Your game characters can pick up virtually anything that way.

How about jumping? Wouldn't it be great if the Captain could jump?

Not a problem: That's just a matter of adding another pair of animations to his animated_sprite, adding a state constant for jumping left and one for jumping right, and writing a function to make him jump. Interestingly, the code in the Captain's Jump() function would be extremely similar to the code that made the cannonball move in the cannon examples. Any time you're modeling a projectile in a gravity field, it moves the way the cannonball did.

Another feature that might be nice is to have a hole for Captain Chloride to fall into. To do so, I would add the hole as a special type of nonmoving sprite. When the Captain's bounding rectangle bumps the bounding rectangle of the hole, the game plays an animation of him falling in.

Likewise, many games contain elevators and moving platforms. I could add that to Invasion of the Slugwroths by creating the elevator or platform as a type of sprite or animated sprite. As long as Captain Chloride is standing on top of the elevator or platform, he moves with it. How can the game tell? It uses the bounding rectangles.

As you can see, now that you have the programming basics down there are a number of additions that you can make to this gameor to a new game that you develop yourself. Of course, there are still aspects of game programming left to learn. And that's what we'll discuss next.



Creating Games in C++(c) A Step-by-Step Guide
Creating Games in C++: A Step-by-Step Guide
ISBN: 0735714347
EAN: 2147483647
Year: N/A
Pages: 148

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net