Building the Game The construction of the Space Out game is similar to that of the other games you’ve developed throughout the book. However, Space Out is slightly more involved simply because it is a more complete game. The next few sections guide you through the development of the game’s code and resources. Writing the Game Code Although the development of all the previous games in the book began with the header file for the game, Space Out is a little different in that it relies on a custom sprite class. For this reason, the code for the Space Out game begins with the header for this custom sprite class, AlienSprite, which is shown in Listing 21.1. Listing 21.1 The AlienSprite.h Header File Declares the AlienSprite Class, Which Is Derived from Sprite 1: #pragma once 2: 3: //—————————————————————-4: // Include Files 5: //—————————————————————-6: #include 7: #include “Sprite.h” 8: 9: //—————————————————————-10: // AlienSprite Class 11: //—————————————————————-12: class AlienSprite : public Sprite 13: { 14: public: 15: // Constructor(s)/Destructor 16: AlienSprite(Bitmap* pBitmap, RECT& rcBounds, 17: BOUNDSACTION baBoundsAction = BA_STOP); 18: virtual ~AlienSprite(); 19: 20: // General Methods 21: virtual SPRITEACTION Update(); 22: virtual Sprite* AddSprite(); 23: }; The AlienSprite class is not very complex at all, as the listing hopefully reveals. It’s important to notice that AlienSprite derives from Sprite (line 12), and declares a constructor and destructor (lines 16 18). More importantly, however, are the two methods in the Sprite class that AlienSprite overrides, Update() and AddSprite() (lines 21 and 22). These two methods are critical to providing the AlienSprite class with its own unique functionality separate from the Sprite class. In case you’re wondering exactly what this functionality is, let me explain. If you recall from earlier in the hour, one of the problems in the game engine was that it didn’t allow a sprite to create another sprite on its own. You added code to the game engine, including a method called AddSprite() in the Sprite class, to allow for this task to be carried out by sprites. However, the version of the AddSprite() method in the Sprite class doesn’t do anything it’s up to derived Sprite classes to create their own sprites. The AlienSprite class is an example of one of these derived classes that overrides the AddSprite() method to do something useful. Before you get to the AlienSprite::AddSprite() method, however, let’s take a quick look at some external global variables that are required of the AlienSprite class: extern Bitmap* _pBlobboBitmap; extern Bitmap* _pBMissileBitmap; extern Bitmap* _pJellyBitmap; extern Bitmap* _pJMissileBitmap; extern Bitmap* _pTimmyBitmap; extern Bitmap* _pTMissileBitmap; extern int _iDifficulty;
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Cheap Web Hosting services
No comments yet.
Sorry, the comment form is closed at this time.