高仿打飞机代码实现

cocos2d-x实现高仿微信打飞机游戏

  (2013-10-10 19:29:03)
标签: 

微信打飞机

 

cocos2d-x

 

it

分类: Cocos2d-X
cocos2d-x实现高仿微信打飞机游戏


核心代码
1游戏界面

#ifndef __HELLOWORLD_SCENE_H__

#define __HELLOWORLD_SCENE_H__


#include "cocos2d.h"

#include "ChangeBullet.h"

#include "FoePlane.h"

using namespace cocos2d;


class HelloWorld : public cocos2d::CCLayer

{

public:

    // Method 'init' in cocos2d-x returns bool, instead of 'id' in cocos2d-iphone (an object pointer)

    virtual bool init();


    // there's no 'id' in cpp, so we recommend to return the class instance pointer

    static cocos2d::CCScene* scene();

    

    // a selector callback

    void menuCloseCallback(CCObject* pSender);


    // preprocessor macro for "static create()" constructor ( node() deprecated )

    CREATE_FUNC(HelloWorld);

    

    // 背景 -- 滚动

    CCSprite *BG1;

    CCSprite *BG2;

    int adjustmentBG;

    

    // 判断游戏是否结束

    bool isGameOver;

    

    // 玩家飞机

    CCSprite *player;


    // 飞机的子弹

    CCSprite *bullet;

    int bulletSpeed;//子弹速度

    

    //敌人飞机

    CCArray *foePlanes;

    int smallPlaneTime;//25毫秒出现一个敌人小飞机

    int mediumPlaneTime;//400毫秒出现一个敌人的中等飞机

    int bigPlaneTime;//每个1秒中出现一个敌人的打飞机

    

    //空降物品时间计数

    int propTime;

    //空降物品

    //ChangeBullet *prop;

    //判断空间物品是否出去了

    bool isVisible;

    

    //得分

    CCLabelTTF *scoreLabel;

    int scoreInt;//得分

    

    //开始

    CCMenu *restart;

    

    //更换子弹

    bool isBigBullet;

    bool isChangeBullet;

    int bulletLastTime;//更换子弹持续的时间

    

    //游戏结束提示

    CCLabelTTF *gameOverLabel;

    

    

    //初始化数据

    void initData();

    //背景

    void loadBackground();

    void scrollBackground();

    

    

    //重写触屏回调函数

    virtual bool ccTouchBegan(CCTouch* touch, CCEvent* event);

    virtual void ccTouchMoved(CCTouch* touch, CCEvent* event);

    virtual void ccTouchEnded(CCTouch* touch, CCEvent* event);

    

    //重写生命周期函数

    virtual void onEnter();

    virtual void onExit();


    //更新函数

    void update(float dt);

    

    //载入玩家

    void loadPlayer();

    

    

    //制造子弹 开火 移动

    void madeBullet();

    void firingBullet();

    void resetBullet();

    

    //添加敌机

    void addFoePlane();

    //移动敌机

    void moveFoePlane();

    


    //子弹持续时间

    void bulletLast();

    

    //制造小飞机

    FoePlane *makeSmallFoePlane();

    

    //制造中等飞机

    FoePlane *makemediumFoePlane();

    

    //制造大飞机

    FoePlane *makeBigFoePlane();

    

    

    //碰撞检测

    void collisionDetection();

    

    void foePlaneBlowup(FoePlane *foePlane);

    

    void blowupEnd(FoePlane *foePlane);

    

    

    //游戏结束

    void GameOver();

    //游戏暂停

    void GamePause();

    //游戏开始

    void GameStart();

    //游戏重新开始

    void GameRestart();

    //玩家飞机爆炸动画

    void playerPlaneBlowup();

    //飞机的小尾巴

    void getBoom(CCPoint pt);

    void getLine(CCPoint pt);

    

    CCMotionStreak* strike;

};


#endif // __HELLOWORLD_SCENE_H__



#include "HelloWorldScene.h"

#include "SimpleAudioEngine.h"


using namespace cocos2d;

using namespace CocosDenshion;


CCScene* HelloWorld::scene()

{

    // 'scene' is an autorelease object

    CCScene *scene = CCScene::create();

    

    // 'layer' is an autorelease object

    HelloWorld *layer = HelloWorld::create();


    // add layer as a child to scene

    scene->addChild(layer);


    // return the scene

    return scene;

}


// on "init" you need to initialize your instance

bool HelloWorld::init()

{

    //

    // 1. super init first

    if ( !CCLayer::init() )

    {

        return false;

    }


     //初始化数据

    initData();

    //载入背景

    

    loadBackground();

    loadPlayer();

    madeBullet();

    resetBullet();

    //系统更新函数

    scheduleUpdate();

    return true;

}



void HelloWorld::initData()

{

    adjustmentBG = 568;

    isGameOver = false;

    //子弹初速度是25

    bulletSpeed = 25;

    

    //各种类型飞机出现的时间间隔

    smallPlaneTime = 0;

    mediumPlaneTime = 0;

    bigPlaneTime = 0;

    

    bulletLastTime = 1200;

    

    //空降物品计数

    propTime = 0;

    

    //得分计数

    scoreInt = 0;

    

    isBigBullet = false;

    isChangeBullet = false;

    

    foePlanes = CCArray::create();

    foePlanes->retain();

    

    

}



void HelloWorld::loadBackground()

{

    

    //下雪拉

    CCParticleSystem* particleSyetem = CCParticleSnow::create();

    particleSyetem->setTexture( CCTextureCache::sharedTextureCache()->addImage("snow.png"));

    addChild(particleSyetem,1);

    

    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("gameArts.plist");

    CCSpriteBatchNode *spriteSheet =CCSpriteBatchNode::batchNodeWithFile("gameArts.png");

    addChild(spriteSheet);


    BG1= CCSprite::spriteWithSpriteFrameName("background_2.png");

    BG2= CCSprite::spriteWithSpriteFrameName("background_2.png");

    BG1->setPosition(ccp(0,0));

    BG2->setPosition(ccp(0,566));

    BG1->setAnchorPoint(ccp(0,0));

    BG2->setAnchorPoint(ccp(0,0));

    addChild(BG1,0,888);

    addChild(BG2,0,999);

    

    //显示分数的Label

    scoreLabel = CCLabelTTF::create("Score:0000", "Zapfino", 20);

    scoreLabel->setPosition(ccp(170,450));

    addChild(scoreLabel,4,333);

    

    //显示暂停按钮

    


    strike=CCMotionStreak::streakWithFade(1.0f,//尾巴持续的时间

                                          16.0f,//尾巴大小

                                          16.0f,//图片的大小

                                          ccc3(0,0,255),//颜色

                                          "fire.png"//使用的图片

                                          );

    addChild(strike,1);

    strike->setPosition(ccp(240,160));

    

    CCMenuItemImage *pCloseItem = CCMenuItemImage::create(

                                                          "BurstAircraftPause.png",

                                                          "BurstAircraftPause.png",

                                                          this,

                                                          menu_selector(HelloWorld::GamePause) );

    pCloseItem->setPositionccp(CCDirector::sharedDirector()->getWinSize().width -300460) );

    

    // create menu, it's an autorelease object

    CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);

    pMenu->setPositionCCPointZero );

    this->addChild(pMenu, 1);

    

}


void HelloWorld::scrollBackground()

{

    CCSprite *bg1 = CCSprite::create();

    bg1 = (CCSprite *)this->getChildByTag(888);

    CCSprite *bg2 = CCSprite::create();

    bg2 = (CCSprite *)this->getChildByTag(999);

    

    bg1->setPositionY(bg1->getPositionY()-2);//背景1向下移动

    bg2->setPositionY(bg1->getPositionY()+566);//背景2跟随背景1向下移动

    if(bg2->getPositionY() == 0)

    {

        bg1->setPositionY(0);

    }


}


void HelloWorld::loadPlayer()

{

    //gameArts.png上面截取一个小图片

    player = CCSprite::create("gameArts.png", CCRectMake(432, 0, 66, 82));

    

    //锚点

    player->setAnchorPoint(ccp(0.5, 0.5));

    addChild(player,2,555);

    

    //创建动画

    CCAnimation *animation = CCAnimation::create();

    animation->setDelayPerUnit(0.1f);

    

    //添加每个zhen

    animation->addSpriteFrame(CCSpriteFrame::create("gameArts.png",CCRectMake(43206682)));

    animation->addSpriteFrame(CCSpriteFrame::create("gameArts.png",CCRectMake(4323326680)));

    

    CCAnimate *anim = CCAnimate::create(animation);

    player->runAction(::cocos2d::CCRepeatForever::create(anim));

    

    player->setAnchorPoint(ccp(0.5, 0.5));

    player->setPosition(ccp(160,50));

}


void HelloWorld::madeBullet()

{

    bullet = CCSprite::spriteWithSpriteFrameName((!isBigBullet)?"bullet1.png":"bullet2.png");

    bullet->setAnchorPoint(ccp(0.5, 0.5));

    addChild(bullet);

}


void HelloWorld::resetBullet()

{

    if ((isBigBullet&&isChangeBullet) || (!isBigBullet&&isChangeBullet))

    {

        bullet->removeFromParentAndCleanup(false);

        madeBullet();

        isChangeBullet = false;

    }

    bulletSpeed = (480 - (player->getPositionY() + 50))/15;

    

    if (bulletSpeed<</span>5)

    {

        bulletSpeed=5;

    }

    

    bullet->setPosition(ccp(player->getPositionX(), player->getPositionY()+50));

}


void HelloWorld::firingBullet()

{

    bullet->setPosition(ccp(bullet->getPositionX(), bullet->getPositionY()+bulletSpeed));

    if (bullet->getPositionY()>460) {

        resetBullet();

    }

}


void HelloWorld::onEnter(){

    

    CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,0,false);

    CCLayer::onEnter();

}


void HelloWorld::onExit(){

    

    CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);

    CCLayer::onExit();

}


bool HelloWorld::ccTouchBegan(CCTouch* touch, CCEvent* event){

    CCLOG("ccTouchBegan");

    return true;

}


void HelloWorld::ccTouchMoved(CCTouch* touch, CCEvent* event){

    //CCLOG("ccTouchMoved");

    //飞机烟花么?

    getLine(touch->getLocation());

    strike->setPosition(touch->getLocation());


    

    CCSprite *nowSprite = (CCSprite *)this->getChildByTag(555);

    

    if(

       (

        (nowSprite->getPosition().x-touch->getLocation().x)<<span style="color: #272ad8">50

        &&(nowSprite->getPosition().x-touch->getLocation().x)>-50

        )

       &&

       (

        (nowSprite->getPosition().y-touch->getLocation().y)<<span style="color: #272ad8">30

        &&(nowSprite->getPosition().y-touch->getLocation().y)>-30

        )

       )

        

        

    {

        nowSprite->setPosition(touch->getLocation());

    }

    

    //CCLOG("nowSprite   %f  %f ",nowSprite->getPosition().x,nowSprite->getPosition().y);

    

    //CCLOG("touch      %f  %f ",touch->getLocation().x,touch->getLocation().y);

}


void HelloWorld::ccTouchEnded(CCTouch* touch, CCEvent* event){

    //CCLOG("ccTouchEnded");

     getBoom(touch->getLocation());

    

}



void HelloWorld::update(float dt)

{

    if(!isGameOver)

    {

        scrollBackground();

        

        firingBullet();

        

        addFoePlane();

        moveFoePlane();

        

        bulletLast();

        

        collisionDetection();

    }

}

void HelloWorld::bulletLast()

{

    if (isBigBullet)

    {

        if (bulletLastTime > 0)

        {

            bulletLastTime --;

        }

        else

        {

            bulletLastTime = 1200;

            isBigBullet = false;

            isChangeBullet = true;

        }

    }

}


void HelloWorld::collisionDetection()

{

    

    //检测子弹和敌方飞机是否碰撞

    for (int i = 0;i<<span style="color: #4f8187">foePlanes->count();i++)

    {

        FoePlane *tmpPlane =(FoePlane *) foePlanes->objectAtIndex(i);

        if (tmpPlane->boundingBox().intersectsRect(bullet->boundingBox()))

        {

            //CCLOG("子弹和敌方飞机相撞");

            

            //子弹重设

            resetBullet();

            

            //判读敌人飞机是否还有血

            tmpPlane->hp = tmpPlane->hp - (isBigBullet?2:1);//一个子弹一滴血

            

            if (tmpPlane->hp <= 0)

            {

                //运行爆炸动画

                //CCLOG("运行爆炸动画");

                //各种类型的飞机爆炸的效果

                foePlaneBlowup(tmpPlane);

                

                foePlanes->removeObject(tmpPlane);

            }

            else

            {

                //CCLOG("每个子弹都有打击效果 主要是中等飞机和大飞机");

                //每个子弹都有打击效果 主要是中等飞机和大飞机

                //[self hitAnimationToFoePlane:tmpPlane];

            }

            

            

            

        }


    }


    //检测敌方飞机和我方飞机是否相撞

    for (int i = 0;i<<span style="color: #4f8187">foePlanes->count();i++)

    {

        FoePlane *tmpPlane =(FoePlane *) foePlanes->objectAtIndex(i);

        if (tmpPlane->boundingBox().intersectsRect(player->boundingBox()))

        {

            CCLOG("玩家飞机和敌方飞机相撞");

            

            //游戏结束

            GameOver();

            //玩家飞机爆炸

            playerPlaneBlowup();

            //敌方飞机爆炸

            foePlaneBlowup(tmpPlane);

            //敌方飞机移出数组

            

        }

    }

    

    

    

}


void HelloWorld::GameOver()

{

    isGameOver = true;

    GamePause();

    gameOverLabel = CCLabelTTF::create("GAME OVER", "Zapfino", 20);

    gameOverLabel->setPosition(ccp(160300));


    addChild(gameOverLabel,4);

    CCMenuItemFont *gameOverItem = CCMenuItemFont::create("Restart",this,menu_selector(HelloWorld::GameRestart));


    restart = CCMenu::create(gameOverItem,NULL);

    restart->setPosition(ccp(160200));

    addChild(restart,4);

}

void HelloWorld::GamePause()

{

    if (isGameOver == false) {

        CCMenuItemFont *gameOverItem = CCMenuItemFont::create("Start Game"this,menu_selector(HelloWorld::GameStart));

        gameOverItem->setFontName("Zapfino");

        gameOverItem->setFontSize(20);

        restart = CCMenu::create(gameOverItem,NULL);

        addChild(restart,4);

        isGameOver = true;

   

    }

    else

    {

        //prop->stopAllActions;

    }

}

void HelloWorld::GameStart()

{

    if (isGameOver) {

        removeChild(restarttrue);

        isGameOver = false;

    }

}

void HelloWorld::GameRestart()

{

    removeAllChildrenWithCleanup(true);

    foePlanes->removeAllObjects();

    initData();

    loadBackground();

    loadPlayer();

    madeBullet();

    resetBullet();

    

}


void HelloWorld::playerPlaneBlowup()

{

    //首先飞机停止所有动画

    player->stopAllActions();

    //创建动画

    CCAnimation *animation = CCAnimation::create();

    animation->setDelayPerUnit(0.1f);

    

    //添加每个zhen

    animation->addSpriteFrame(CCSpriteFrame::create("gameArts.png",CCRectMake(4322496682)));

    animation->addSpriteFrame(CCSpriteFrame::create("gameArts.png",CCRectMake(432836682)));

    animation->addSpriteFrame(CCSpriteFrame::create("gameArts.png",CCRectMake(4321666682)));

    animation->addSpriteFrame(CCSpriteFrame::create("gameArts.png",CCRectMake(475694452)));


    CCAnimate *anim = CCAnimate::create(animation);

    

    player->runAction(CCSequence::actions(anim,NULL));

    

}

void HelloWorld::foePlaneBlowup(FoePlane *foePlane)

{

    int animationNum = 0;

    

    if (foePlane->planeType == 1)

    {

        animationNum = 4;

        scoreInt += 2000;

        //首先飞机停止所有动画

        foePlane->stopAllActions();

        //创建动画

        CCAnimation *animation = CCAnimation::create();

        animation->setDelayPerUnit(0.1f);

        

        //添加每个zhen

        animation->addSpriteFrame(CCSpriteFrame::create("gameArts.png",CCRectMake(476573424)));

        animation->addSpriteFrame(CCSpriteFrame::create("gameArts.png",CCRectMake(4207293432)));

        animation->addSpriteFrame(CCSpriteFrame::create("gameArts.png",CCRectMake(4727193834)));

        animation->addSpriteFrame(CCSpriteFrame::create("gameArts.png",CCRectMake(4794133232)));

        CCAnimate *anim = CCAnimate::create(animation);

        CCCallFuncN *end = CCCallFuncN::actionWithTarget(this,callfuncN_selector(HelloWorld::blowupEnd));

        foePlane->runAction(CCSequence::actions(anim,end,NULL));

        

        

        

        

    }

    

    if (foePlane->planeType == 3)

    {

        animationNum = 4;

        scoreInt += 10000;

        

        

        //首先飞机停止所有动画

        foePlane->stopAllActions();

        //创建动画

        CCAnimation *animation = CCAnimation::create();

        animation->setDelayPerUnit(0.1f);

        

        //添加每个zhen

        animation->addSpriteFrame(CCSpriteFrame::create("gameArts.png",CCRectMake(4325384660)));

        animation->addSpriteFrame(CCSpriteFrame::create("gameArts.png",CCRectMake(4325994660)));

        animation->addSpriteFrame(CCSpriteFrame::create("gameArts.png",CCRectMake(4324764662)));

        animation->addSpriteFrame(CCSpriteFrame::create("gameArts.png",CCRectMake(06284652)));

        CCAnimate *anim = CCAnimate::create(animation);

        CCCallFuncN *end = CCCallFuncN::actionWithTarget(this,callfuncN_selector(HelloWorld::blowupEnd));

        foePlane->runAction(CCSequence::actions(anim,end,NULL));


    }

    

    if (foePlane->planeType == 2)

    {

        animationNum = 7;

        scoreInt += 40000;

        

        

        //首先飞机停止所有动画

        foePlane->stopAllActions();

        //创建动画

        CCAnimation *animation = CCAnimation::create();

        animation->setDelayPerUnit(0.1f);

        

        //添加每个zhen

        animation->addSpriteFrame(CCSpriteFrame::create("gameArts.png",CCRectMake(0754110169)));

        animation->addSpriteFrame(CCSpriteFrame::create("gameArts.png",CCRectMake(321171110169)));

        animation->addSpriteFrame(CCSpriteFrame::create("gameArts.png",CCRectMake(321514110169)));

        animation->addSpriteFrame(CCSpriteFrame::create("gameArts.png",CCRectMake(321343110169)));

        animation->addSpriteFrame(CCSpriteFrame::create("gameArts.png",CCRectMake(3210110169)));

        animation->addSpriteFrame(CCSpriteFrame::create("gameArts.png",CCRectMake(21356994133)));

        animation->addSpriteFrame(CCSpriteFrame::create("gameArts.png",CCRectMake(11756994133)));

        CCAnimate *anim = CCAnimate::create(animation);

        CCCallFuncN *end = CCCallFuncN::actionWithTarget(this,callfuncN_selector(HelloWorld::blowupEnd));

        foePlane->runAction(CCSequence::actions(anim,end,NULL));

    }

    

    

    CCString *scoreString = CCString::createWithFormat("Score:%d",scoreInt);

    scoreLabel->setString(scoreString->getCString());


    


    

    

}

void HelloWorld::blowupEnd(FoePlane *foePlane)

{

    FoePlane *tmpPlane = (FoePlane *)foePlane;

    tmpPlane->removeFromParentAndCleanup(false);

}

void HelloWorld::addFoePlane()

{

    smallPlaneTime ++;

    mediumPlaneTime ++;

    bigPlaneTime ++;

    

    if (smallPlaneTime > 25)

    {

        //CCLOG("制造小飞机");

        FoePlane *smallPlane = HelloWorld::makeSmallFoePlane();

        addChild(smallPlane,3);

        foePlanes->addObject(smallPlane);

        

        smallPlaneTime = 0;

    }

    

    if (mediumPlaneTime > 400)

    {

        //CCLOG("制造中飞机");

        FoePlane *mediumPlane = HelloWorld::makemediumFoePlane();

        addChild(mediumPlane,3);

        foePlanes->addObject(mediumPlane);

        

        mediumPlaneTime = 0;

    }

    

    if (bigPlaneTime > 700

    {

        //CCLOG("制造大飞机");

        FoePlane *bigPlane = HelloWorld::makeBigFoePlane();

        addChild(bigPlane,3);

        foePlanes->addObject(bigPlane);

        

       // [self performSelector:@selector(bigPlaneOutSount) withObject:nil afterDelay:0.5];

        

        bigPlaneTime = 0;

    }

    

    //CCLOG("foePlanes === %d",foePlanes->count());

}


FoePlane * HelloWorld::makeSmallFoePlane()

{

    

    FoePlane *smallPlane =(FoePlane *) FoePlane::spriteWithSpriteFrameName("enemy1_fly_1.png");

    smallPlane->setAnchorPoint(ccp(00));

    smallPlane->setPosition(ccp(arc4random()%290+17468));

    smallPlane->planeType = 1;


    smallPlane->hp = 1;

    

    smallPlane->speed = arc4random()%4 + 2;

    //CCLOG(" smallPlane    x= %d     y = %d ",smallPlane->getPositionX(),smallPlane->getPositionY());

    return smallPlane;

    

}


FoePlane * HelloWorld::makemediumFoePlane()

{

    FoePlane *mediumPlane =(FoePlane *) FoePlane::spriteWithSpriteFrameName("enemy3_fly_1.png");

    mediumPlane->setAnchorPoint(ccp(00));

    mediumPlane->setPosition(ccp(arc4random()%280+23468));

    mediumPlane->planeType = 3;

    

    mediumPlane->hp = 15;

    

    mediumPlane->speed = arc4random()%3 + 2;

    //CCLOG(" mediumPlane    x= %d     y = %d ",mediumPlane->getPositionX(),mediumPlane->getPositionY());

    return mediumPlane;

    

}




FoePlane * HelloWorld::makeBigFoePlane()

{

    FoePlane *bigPlane =(FoePlane *) FoePlane::spriteWithSpriteFrameName("enemy2_fly_1.png");

    bigPlane->setAnchorPoint(ccp(00));

    bigPlane->setPosition(ccp(arc4random()%210+55500));

    bigPlane->planeType = 2;

    

    bigPlane->hp = 25;

    

    bigPlane->speed = arc4random()%2 + 2;

    //CCLOG(" bigPlane    x= %d     y = %d ",bigPlane->getPositionX(),bigPlane->getPositionY());

    return bigPlane;

    

}

void HelloWorld::moveFoePlane()

{

    for (int i = 0 ; i<<span style="color: #4f8187">foePlanes->count(); i++)

    {

        FoePlane* temPlane =  (FoePlane*)foePlanes->objectAtIndex(i);

        

        //CCLog(" temPlane    x= %d     y = %d ",temPlane->getPositionX(),temPlane->getPositionY());

        temPlane->setPosition(ccp(temPlane->getPositionX(), temPlane->getPositionY()-temPlane->speed));

        if (temPlane->getPositionY() < (-75))

        {

            foePlanes->removeObject(temPlane);

            temPlane->removeFromParentAndCleanup(false);

        }

    }

}


void HelloWorld::getLine(CCPoint pt)

{

    

    

    cocos2d::CCParticleSystemQuad*mSystem=CCParticleSystemQuad::particleWithFile("himiParticle.plist");

    //mSystem->initWithFile("Particle.plist");//plist文件可以通过例子编辑器获得

    mSystem->setTextureWithRect(CCTextureCache::sharedTextureCache()->addImage("fire.png")

                                ,CCRectMake(0,0,32,32));//加载图片,第一个参数是纹理,第二个参数是选择图片上的位置

    //    mSystem->setBlendAdditive(true);//这个调用必不可少

    mSystem->setPosition(pt);//设置位置

    mSystem->setDuration(0.000003f);

    mSystem->setLife(0.000005f);

    addChild(mSystem);

    //mSystem->release();

    //delete mSystem;

    //CC_SAFE_DELETE(mSystem);

    mSystem->setAutoRemoveOnFinish(true);

}

void HelloWorld::getBoom(CCPoint pt)

{

    

    cocos2d::CCParticleSystemQuad   *mSystem2 =CCParticleSystemQuad::particleWithFile("himiParticle.plist");

    //mSystem2->initWithFile("Boom.plist");//plist文件可以通过例子编辑器获得

    mSystem2->setTextureWithRect(CCTextureCache::sharedTextureCache()->addImage("stars.png")

                                 ,CCRectMake(0,0,32,32));//加载图片,第一个参数是纹理,第二个参数是选择图片上的位置

    mSystem2->setBlendAdditive(true);//这个调用必不可少

    mSystem2->setPosition(pt);//设置位置

    mSystem2->setDuration(0.05f);

    addChild(mSystem2);

    //mSystem2->release();

    //CC_SAFE_DELETE(mSystem2);

    mSystem2->setAutoRemoveOnFinish(true);

    

    

}


void HelloWorld::menuCloseCallback(CCObject* pSender)

{

    CCDirector::sharedDirector()->end();


#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)

    exit(0);

#endif

}



2飞机类


 

//

//  FoePlane.h

//  xiaoguodongAttackPlane

//

//  Created by Dong on 13-10-9.

//

//


#ifndef __xiaoguodongAttackPlane__FoePlane__

#define __xiaoguodongAttackPlane__FoePlane__



#include

#include "cocos2d.h"

#include "cocos-ext.h"

using namespace cocos2d::extension;

class FoePlane:public cocos2d::CCSprite

{

public:

    virtual bool init();

    static cocos2d::CCScene* scene();

    CREATE_FUNC(FoePlane);

    

    int planeType;

    

    int hp;

    

    int speed;

    

    

};

#endif


直接运行肯定会崩溃的   需要加入游戏的一些资源文件


cocos2d-x实现高仿微信打飞机游戏


自己还添加了一些粒子效果   虽然风格和原来的黑白画面不太协调而且很花哨但是自己很喜欢。。。

cocos2d-x实现高仿微信打飞机游戏

没有加道具和音效,期待3.0版本吧,嘻嘻




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值