Based on the Cocos2d-x-1.0.1 aircraft war game development instance (on), cocos2dx aircraft war

Source: Internet
Author: User

Based on the Cocos2d-x-1.0.1 aircraft war game development instance (on), cocos2dx aircraft war

I have recently come across several versions of cocos2dx and decided to try every major version change. This instance imitates the aircraft war game in version 5.0,

 

I. Tools

1. Materials: materials (images, sounds, etc.) from the network

2. Engine: cocos2d-1.0.1-x-0.9.2

3. Environment: vs2010

Ii. Classes used

1. game menu interface class: PlaneWarMenu -- derived from the CCLayer class.

1 // game menu interface class 2 class PlaneWarMenu: public CCLayer 3 {4 public: 5 virtual bool init (); 6 static cocos2d: CCScene * scene (); 7 8 virtual void menuStartCallback (CCObject * pSender); 9 virtual void menuManualCallback (CCObject * pSender); 10 virtual void menuAboutCallback (CCObject * pSender ); 11 virtual void menuBackCallback (CCObject * pSender); 12 13 LAYER_NODE_FUNC (PlaneWarMenu); 14 };

 

2. game category: PlaneWarGame -- derived from the CCLayer class.

1 // game category 2 class PlaneWarGame: public CCLayer 3 {4 public: 5 PlaneWarGame (); 6 ~ PlaneWarGame (); 7 static CCScene * scene (); 8 virtual bool init (); 9 10 // game interface initialization 11 bool initBackground (); 12 void bg1roll (); 13 void bg2roll (); 14 bool initMenu1 (); 15 bool initMenu2 (); 16 bool initMenu3 (); 17 18 // call back the menu items in the game interface 19 void menuPauseCallback (CCObject * pSender); 20 void callback (CCObject * pSender); 21 void menuBombCallback (CCObject * pSender ); 22 void menuResumeCallback (CCObject * pSender); 23 void menuRestartCallback (CCObject * pSender); 24 void menuBackCallback (CCObject * pSender); 25 26 scheduler (PlaneWarGame ); 27 28 // generate 29 void addEnemy (float dt) for enemy planes; 30 // 31 void shoot (float dt) for gamer bullets ); 32 // loop of game logic 33 void gameLoop (float dt); 34 void addBullet (CCSprite * bullet, CCPoint pt ); 35 // generate 36 void addProp (float dt); 37 // game collision detection 38 void updateGame (float dt); 39 // data display 40 void show (); 41 // game end 42 void gameover (bool isWin); 43 44 void spriteMoveFinished (CCNode * sender); 45 void killAllEnemys (); 46 void releaseEnemys (); 47 48 // Keyboard message Processing 49 void processWin32KeyPress (UINT message, WPARAM wParam, LPARAM lParam); 50 // touch operation 51 void registerWithTouchDispatcher (); 52 virtual bool ccTouchBegan (CCTouch * pTouch, CCEvent * pEvent); 53 virtual void ccTouchMoved (CCTouch * pTouch, CCEvent * pEvent); 54 virtual void ccTouchEnded (CCTouch * pTouch, CCEvent * pEvent); 55 protected: 56 57 // game member 58 PlaySprite * _ player; // player plane 59 CCArray * _ enemys; // enemy aircraft array 60 CCArray * _ bullets; // array of bullets 61 int _ bulletsDestroyed; // number of bullets hitting the target 62 63 // game control 64 CCLabelBMFont * _ label; // score tag 65 CCMenuItemSprite * _ pause; // pause button 66 CCMenu * _ menu; // menu in the game interface (pause/sound/bomb) 67 68 // main game attributes 69 bool _ issound; // the background music switch 70 CCSize _ size; // game interface size (screen size) 71 int _ score; // 72 bool _ isOver; // game end mark 73 };

 

 

3. Game Introduction Class: PlaneWarInfoboard -- derived from the CCLayer class.

1 // game Introduction class 2 class PlaneWarInfoboard: public CCLayer 3 {4 public: 5 virtual bool init (); 6 static cocos2d: CCScene * scene (); 7 8 virtual void menuBackCallback (CCObject * pSender); 9 10 LAYER_NODE_FUNC (PlaneWarInfoboard); 11 };

 

4. Player role class: PlaySprite-because it is inconvenient to directly inherit the CCSprite class, it is derived from the CCNode class and used in combination.

1 // player airplane motion mode 2 enum moveMode {3 MM_NONE = 0, 4 MM_UP, 5 MM_DOWN, 6 MM_LEFT, 7 MM_RIGHT 8 }; 9 // bullet type 10 enum bulletKind {11 BK_SINGLE = 0, 12 BK_DOUBLE13}; 14 15 // player Angle class 16 PlaySprite: public CCNode17 {18 public: 19 virtual void onEnter (); 20 21 PlaySprite (); 22 ~ PlaySprite (); 23 24 CCRect getRect (); 25 CCPoint getPlayerPt (); 26 void setPlayerPt (CCPoint pt); 27 28 void setMoveMode (UINT message, WPARAM wParam ); 29 void move (float dt); 30 void die (); 31 void destroy (); 32 33 public: 34 // attribute 35 moveMode _ mode; // sports mode (Direction Press) 36 bool _ isDragEnabled; // can be dragged by the mouse (move the mouse) 37 38 bulletKind _ bulletKind; // bullet type (Variable double hair) 39 int _ bombCount; // number of bombs (obtained from item eating) 40 41 protected: 42 CCSprite * _ sprite; // representing genie 43 };

 

 

5. Enemies: EnemySprite-because it is inconvenient to directly inherit the CCSprite class, it is derived from the CCNode class and used in combination to use the CCSprite class.

1 enum EnemyKind {2 EK_SMALL = 0, 3 EK_MIDDLE, 4 EK_BIG 5}; 6 7 // eight enemy class EnemySprite: public CCNode 9 {// three types of enemy aircraft 10 public: 11 EnemySprite (); 12 ~ EnemySprite (); 13 14 virtual void onEnter (); 15 16 CCRect getRect (); 17 18 void spriteMoveFinished (CCNode * sender); 19 20 void die (); 21 void destroy (); 22 23 bool isNull (); 24 public: 25 // attribute 26 int _ hp; // Blood Volume 27 EnemyKind _ enemyKind; // 28 bool _ die for enemy aircraft types; // 29 bool _ destroy dead; // 30 31 released protected: 32 CCSprite * _ sprite; // representing the genie 33 };


Aircraft war game development example based on Cocos2d-x-1.0.1 (medium) aircraft war game development example based on Cocos2d-x-1.0.1 (lower)
 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.