Cocos2d-x简单游戏<打飞机>代码实现|第四部分:主场景<Helloworld.h>

本文介绍使用Cocos2d-x开发一款简单的打飞机游戏的过程,涵盖游戏核心组件如飞机、子弹的设计与实现,以及触碰事件、碰撞检测等关键功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 第一部分:Cocos2d-x简单游戏<打飞机>代码实现|第一部分:飞机类

 第二部分:Cocos2d-x简单游戏<打飞机>代码实现|第二部分:子弹类

 第三部分:Cocos2d-x简单游戏<打飞机>代码实现|第三部分:引导层



#ifndef __HELLOWORLD_SCENE_H__

#define __HELLOWORLD_SCENE_H__


#include "commonHeader.h"

#include "CCPlane.h"

#include "CCProps.h"


class HelloWorld :public cocos2d::CCLayer{

    

private:

   //背景

   CCSprite *background1;

   CCSprite *background2;

    

   CCLabelTTF *scoreLabel;//分数标签

   int score;//分数值

    


   int adjustmentBg;//自适应背景

    

    /*我的飞机*/

   CCSprite *adminPlayer;//飞机

   CCSprite *bullets;//子弹

   int bulletsNum;//子弹数量

   int bulletSpeed;//子弹速度

   int bulletTiming;//特殊子弹时间

    //子弹样式

   bool bigBullets;//大子弹

   bool changeBullets;//变化子弹

    

    /*对方飞机*/

    //cocos2d::CCSprite *Plane;

    CC_SYNTHESIZE_RETAIN(CCArray *,__Planes, Planes);

    /*添加飞机的时间*/

   int bigPlane;

   int smallPlane;

   int mediumPlane;

    

   //道具

    CC_SYNTHESIZE_RETAIN(CCProps *,__props, Prop);

    //道具添加时间

   int isProps;

    //判断是否存在

   bool isExist;

    

    //游戏是否结束

   bool isGameFinish;


    

    

    

public:

    HelloWorld();

    ~HelloWorld();

    

    //初始化场景

   virtual bool init();

    //回调函数

   void menuCloseCallback(CCObject* pSender);

    CREATE_FUNC(HelloWorld);

    

   virtual void update(float delta);

    //添加触碰事件

   virtual bool ccTouchBegan(CCTouch *pTouch,CCEvent *pEvent);

   virtual void ccTouchMoved(CCTouch *pTouch,CCEvent *pEvent);

   virtual void ccTouchEnded(CCTouch *pTouch,CCEvent *pEvent);

   virtual void ccTouchCancelled(CCTouch *pTouch,CCEvent *pEvent);

   virtual void registerWithTouchDispatcher();

    

    SCENE_FUNC(HelloWorld);

    

protected:

    

   void initData();

   void loadBackground();

   void loadPlayer();

   void backgrouneScroll();

   void madeBullet();

   void resetBullet();

   void firingBullets();

   CCPoint boundLayerPos(CCPoint newPos);

   void panForTranslation(CCPoint translation);

   void moveFoePlane();

   void addFoePlane();

   CCPlane* makeBigFoePlane();

   CCPlane* makeMediumFoePlane();

   CCPlane* makeSmallFoePlane();

   void makeProps();

   void resetProps();

   void bulletTimingFn();

   void collisionDetection();

   void fowPlaneHitAnimation(CCPlane* foePlane);

   void fowPlaneBlowupAnimation(CCPlane*foePlane);

   void playerBlowupAnimation();

   void playerBlowupEnd(CCObject* sender);

   void blowupEnd(CCObject* sender);

   void gameOver();

   void restartFn();

    

};


#endif // __HELLOWORLD_SCENE_H__


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GFanStudio-LeeSir

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值