• 大小: 13.73MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-08-01
  • 语言: 其他
  • 标签: cocos2d-x  源码  

资源简介

自己写了一个简单的小程序,其中有不足之处,望谅解,本程序只供对cocos2d-x游戏开发者学习使用;开发环境xcode4.5 coco2d-x

资源截图

代码片段和文件信息

//
//  Bullet.cpp
//  PlantsVSZombies
//
//  Created by user on 13-6-5.
//
//

#include “Bullet.h“

extern CCArray* bulletArray;

Bullet::Bullet(Plants *aplantsCCPoint pCClayer *layer)
{
    plants = new Plants(aplants->plantsName);
    switch (aplants->plantsName)
    {
        case Sunflower:
        {
            this->creatSunflowerBullet(player);
            break;
        }
        case SmallPea:
        case MiddlePea:
        case ThreeBulletPea:
        {
            this->creatPeaBullet(p layer);
            break;
        }
        default:
            break;
    }
}

Bullet::~Bullet()
{
    delete plants;
}

void Bullet::creatSunflowerBullet(CCPoint pCClayer *layer)
{
    CCSpriteframeCache *cache = CCSpriteframeCache::sharedSpriteframeCache();
    cache->addSpriteframesWithFile(“Sun_default.plist“);
    this->initWithSpriteframeName(“Sun-1(被拖移).tiff“);
    this->setScale(0.5);
    
    char temp[50];
    CCArray *plistArray = CCArray::createWithCapacity(10);
    for(int i=1;i<22;i++)
    {
        sprintf(temp “Sun-%i(被拖移).tiff“i);
        CCSpriteframe *frame = cache->spriteframeByName(temp);
        plistArray->addobject(frame);
    }
    CCAnimation *animation = CCAnimation::createWithSpriteframes(plistArray0.15);
    CCAnimate *animate = CCAnimate::create(animation);
    this->runAction(CCRepeatForever::create(animate));
    
    CCMenuItemSprite *m = CCMenuItemSprite::create(this this this menu_selector(Bullet::collectSunshine));
    m->setTag(4002);
    CCMenu *menu = CCMenu::create(mNULL);
    menu->setPosition(ccp(p.x+20 p.y+30));
    menu->setEnabled(true);
    menu->setTag(4001);
    layer->addChild(menu);
    CCJumpTo *jumpTo = CCJumpTo::create(1.0 ccp(menu->getPosition().x-40menu->getPosition().y-25) 30 1);
    menu->runAction(jumpTo);
    menu->setZOrder(1000);
}

void Bullet::moveSunshine(CCNode *senderCCMenu *m)
{
    extern int SunNumber;
    SunNumber = SunNumber + 50;
    m->removeFromParent();
}

void Bullet::collectSunshine(CCNode *sender)
{
    sender->stopAllActions();
    CCMoveTo *moveTo = CCMoveTo::create(1.0 ccp(60 320));
    CCCallFuncND *funcND = CCCallFuncND::create(this callfuncND_selector(Bullet::moveSunshine) sender->getParent());
    CCSequence *seq = CCSequence::create(moveTofuncNDNULL);
    sender->getParent()->runAction(seq);
}

void Bullet::creatPeaBullet(CCPoint pCClayer *layer)
{

    bulletArray->retain();
    position = p;
    
    CCSpriteframeCache *cache = CCSpriteframeCache::sharedSpriteframeCache();
    cache->addSpriteframesWithFile(“PeashooterBullet_default.plist“);
    this->initWithSpriteframeName(“PeashooterBullet-1(被拖移).tiff“);
    this->setPosition(ccp(p.x+10 p.y+10));
    this->setScale(0.5);
    bulletArray->addobject(this);//把子弹添加到数组里边
    layer->addChild(this);
    float distance = 500-this->getPosition().x;
    float time = distance/BulletSpeedRatio;
    CCMoveTo *moveTo = CCMoveTo::create(time ccp(500this->getPosition().y));
    this->runAction(mov

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-11-16 14:29  PlantsVSZombies\
     文件        6148  2013-11-16 14:29  PlantsVSZombies\.DS_Store
     目录           0  2013-11-21 08:42  __MACOSX\
     目录           0  2013-11-21 08:42  __MACOSX\PlantsVSZombies\
     文件          82  2013-11-16 14:29  __MACOSX\PlantsVSZombies\._.DS_Store
     目录           0  2013-11-21 08:40  PlantsVSZombies\PlantsVSZombies\
     文件        6148  2013-11-14 09:03  PlantsVSZombies\PlantsVSZombies\.DS_Store
     目录           0  2013-11-21 08:42  __MACOSX\PlantsVSZombies\PlantsVSZombies\
     文件          82  2013-11-14 09:03  __MACOSX\PlantsVSZombies\PlantsVSZombies\._.DS_Store
     文件        4732  2013-11-19 09:45  PlantsVSZombies\PlantsVSZombies\Bullet.cpp
     文件         171  2013-11-19 09:45  __MACOSX\PlantsVSZombies\PlantsVSZombies\._Bullet.cpp
     文件         898  2013-11-15 20:00  PlantsVSZombies\PlantsVSZombies\Bullet.h
     文件         171  2013-11-15 20:00  __MACOSX\PlantsVSZombies\PlantsVSZombies\._Bullet.h
     目录           0  2013-11-19 20:03  PlantsVSZombies\PlantsVSZombies\Classes\
     文件        4994  2013-11-19 20:03  PlantsVSZombies\PlantsVSZombies\Classes\AppDelegate.cpp
     目录           0  2013-11-21 08:42  __MACOSX\PlantsVSZombies\PlantsVSZombies\Classes\
     文件         171  2013-11-19 20:03  __MACOSX\PlantsVSZombies\PlantsVSZombies\Classes\._AppDelegate.cpp
     文件        1183  2013-11-12 12:00  PlantsVSZombies\PlantsVSZombies\Classes\AppDelegate.h
     文件         171  2013-11-12 12:00  __MACOSX\PlantsVSZombies\PlantsVSZombies\Classes\._AppDelegate.h
     文件         331  2013-11-20 11:15  PlantsVSZombies\PlantsVSZombies\Data.h
     文件         171  2013-11-20 11:15  __MACOSX\PlantsVSZombies\PlantsVSZombies\._Data.h
     文件        1747  2013-11-19 19:42  PlantsVSZombies\PlantsVSZombies\FailScene.cpp
     文件         171  2013-11-19 19:42  __MACOSX\PlantsVSZombies\PlantsVSZombies\._FailScene.cpp
     文件         442  2013-11-19 19:41  PlantsVSZombies\PlantsVSZombies\FailScene.h
     文件         171  2013-11-19 19:41  __MACOSX\PlantsVSZombies\PlantsVSZombies\._FailScene.h
     文件       12453  2013-11-19 09:36  PlantsVSZombies\PlantsVSZombies\failscene.png
     文件         177  2013-11-19 09:36  __MACOSX\PlantsVSZombies\PlantsVSZombies\._failscene.png
     文件        4507  2013-11-16 13:34  PlantsVSZombies\PlantsVSZombies\FinalWave.png
     文件         177  2013-11-16 13:34  __MACOSX\PlantsVSZombies\PlantsVSZombies\._FinalWave.png
     文件         229  2013-11-08 08:26  PlantsVSZombies\PlantsVSZombies\FlagMeterLevelProgress.png
     文件         172  2013-11-08 08:26  __MACOSX\PlantsVSZombies\PlantsVSZombies\._FlagMeterLevelProgress.png
............此处省略1846个文件信息

评论

共有 条评论