示例#1
0
bool Background::Init()
{
    do
    {
        CCNodeLoaderLibrary * ccNodeLoaderLibraryLeft = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
        CCBReader * ccbReaderLeft = new CCBReader(ccNodeLoaderLibraryLeft);
        CCNode * bgLeft = ccbReaderLeft->readNodeGraphFromFile("ccb/background.ccbi", this);
        CCBAnimationManager* animationManagerLeft = ccbReaderLeft->getAnimationManager();
        animationManagerLeft->runAnimationsForSequenceNamed("left");
        ccbReaderLeft->release();
        
        CCNodeLoaderLibrary * ccNodeLoaderLibraryRight = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
        CCBReader * ccbReaderRight = new CCBReader(ccNodeLoaderLibraryRight);
        CCNode * bgRight = ccbReaderRight->readNodeGraphFromFile("ccb/background.ccbi", this);
        CCBAnimationManager* animationManagerRight = ccbReaderRight->getAnimationManager();
        animationManagerRight->runAnimationsForSequenceNamed("right");
        ccbReaderRight->release();
        
        CCClippingNode * clippingNodeLeft = CCClippingNode::create();
        addChild(clippingNodeLeft);
        clippingNodeLeft->addChild(bgLeft,enZOrderBack,enTagBgLeft);
        CCDrawNode *shapeLeft = CCDrawNode::create();
        static CCPoint triangleLeft[3];
        triangleLeft[0] = ccp(0, 0);
        triangleLeft[1] = ccp(SCREEN_WIDTH,0);
        triangleLeft[2] = ccp(0,SCREEN_HEIGHT);
        static ccColor4F green = {0, 1, 0, 1};
        shapeLeft->drawPolygon(triangleLeft, 3, green, 0, green);
        clippingNodeLeft->setStencil(shapeLeft);
        clippingNodeLeft->setInverted(false);
        
        CCClippingNode * clippingNodeRight = CCClippingNode::create();
        addChild(clippingNodeRight);
        clippingNodeRight->addChild(bgRight,enZOrderBack,enTagBgRight);
        CCDrawNode *shapeRight = CCDrawNode::create();
        static CCPoint triangleRight[3];
        triangleRight[0] = ccp(SCREEN_WIDTH, SCREEN_HEIGHT);
        triangleRight[1] = ccp(SCREEN_WIDTH,0);
        triangleRight[2] = ccp(0,SCREEN_HEIGHT);
//        static ccColor4F green = {0, 1, 0, 1};
        shapeRight->drawPolygon(triangleRight, 3, green, 0, green);
        clippingNodeRight->setStencil(shapeRight);
        clippingNodeRight->setInverted(false);
        
        m_CraterArrayLeft = CCArray::create();
        m_CraterArrayLeft->retain();
        m_CraterArrayRight = CCArray::create();
        m_CraterArrayRight->retain();
        m_CraterArrayLeftDeleted = CCArray::create();
        m_CraterArrayLeftDeleted->retain();
        m_CraterArrayRightDeleted = CCArray::create();
        m_CraterArrayRightDeleted->retain();
        
        
        return true;
    } while (false);
    CCLog("Function Background::Init Error!");
    return false;
}
示例#2
0
void Background::OnDead(enUnitIndex target, CCPoint targetPos)
{
    enUnitType eType = GlobalData::sharedDirector()->getUnitTypeByIndex(target);
    unitDataMap unitData = GlobalData::sharedDirector()->getUnitDefaultData();
//    unitPosMap unitsPos = GlobalData::sharedDirector()->getUnitPos();
    
    if(eType==enUnitTypeTroopMine ||
       eType==enUnitTypeTroopEnemy)
    {
        CCNodeLoaderLibrary * ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
        CCBReader * ccbReader = new CCBReader(ccNodeLoaderLibrary);
        CCNode * ccbNode = ccbReader->readNodeGraphFromFile(unitData[eType].strCCBI.c_str(), this);
        CCBAnimationManager* animationManager = ccbReader->getAnimationManager();
        animationManager->runAnimationsForSequenceNamed("dead");
        ccbReader->release();
        ccbNode->setScaleX(0.5);//the bg sprite in ccb is scale.
        
        if(target<enUnitIndexEnemy1)
        {
            m_backgroundLeft->addChild(ccbNode);
            ccbNode->setPosition(m_backgroundLeft->convertToNodeSpace(targetPos));
            m_CraterArrayLeft->addObject(ccbNode);
        }
        else
        {
            m_backgroundRight->addChild(ccbNode);
            ccbNode->setPosition(m_backgroundRight->convertToNodeSpace(targetPos));
            m_CraterArrayRight->addObject(ccbNode);
        }
    }
    else if(eType==enUnitTypeCarMine ||
            eType==enUnitTypeCarEnemy)
    {
        CCNodeLoaderLibrary * ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
        CCBReader * ccbReader = new CCBReader(ccNodeLoaderLibrary);
        CCNode * ccbNode = ccbReader->readNodeGraphFromFile("ccb/boom.ccbi", this);
        CCBAnimationManager* animationManager = ccbReader->getAnimationManager();
        animationManager->runAnimationsForSequenceNamed("boom");
        ccbReader->release();
        ccbNode->setScaleX(0.5);//the bg sprite in ccb is scale.
        
        if(target<enUnitIndexEnemy1)
        {
            m_backgroundLeft->addChild(ccbNode);
            ccbNode->setPosition(m_backgroundLeft->convertToNodeSpace(targetPos));
            m_CraterArrayLeft->addObject(ccbNode);
        }
        else
        {
            m_backgroundRight->addChild(ccbNode);
            ccbNode->setPosition(m_backgroundRight->convertToNodeSpace(targetPos));
            m_CraterArrayRight->addObject(ccbNode);
        }
    }
}
示例#3
0
void Enemy::handleCollisionWith(GameObject* gameObject)
{
//    if (this->hp<=0) {
//        this->isScheduledForRemove = true;
//    }
//    
//    bloodBar->setScaleX(0.3f*hp/maxHp);
//    
    if (gameObject != NULL)
    {
        if (gameObject->getTag() < 200)
        {
            if (stopAction())
            {
                return;
            }
            if (checkIsCollision(gameObject))
            {
                isCollision = true;
                stop();
                CCBAnimationManager* animationManager = dynamic_cast<CCBAnimationManager*>(this->getUserObject());
                
                if (animationManager->getRunningSequenceName() == NULL or strcmp(animationManager->getRunningSequenceName(), "attack") != false)
                {
                    animationManager->runAnimationsForSequenceNamed("attack");
                    CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(effectSoundFileName);
                    gameObject->atkHandler(atk, this);
                }
                curActionCount++;
            }
        }
        
    }    
}
FMMapAvatarNode * FMMapAvatarNode::creatAvatarNode(bool includeSelf, CCDictionary * dic)
{
    FMMapAvatarNode * node = new FMMapAvatarNode();
    if (node) {
        FMDataManager * manager = FMDataManager::sharedManager();
        
        node->m_includeSelf = includeSelf;
        node->m_dicList->addObject(dic);
        
        if (includeSelf) {
            CCBAnimationManager * anim = (CCBAnimationManager *)node->m_mainAvatarNode->getUserObject();
            anim->runAnimationsForSequenceNamed("2");
            node->m_mainAvatarNode->setPosition(ccp(avatarDiffx, avatarDiffy));
        }
        
        CCString * uid = (CCString *)dic->objectForKey("uid");
        const char * iconpath = SNSFunction_getFacebookIcon(uid->getCString());

        CCSprite * icon = (CCSprite*)node->m_mainAvatarNode->getChildByTag(1);
        
        if (iconpath && manager->isFileExist(iconpath)) {
            CCSprite * spr = CCSprite::create(iconpath);
            float size = 26.f;
            spr->setScale(size / MAX(spr->getContentSize().width, size));
            icon->addChild(spr);
            spr->setPosition(ccp(icon->getContentSize().width/2, icon->getContentSize().height/2));
        }
        
        node->autorelease();
        return node;
    }
    CC_SAFE_DELETE(node);
    return NULL;
}
示例#5
0
void Enemy::resetSpeed()
{
    xSpeed = kCJStartSpeed;
    CCBAnimationManager* animationManager = dynamic_cast<CCBAnimationManager*>(this->getUserObject());
    if (animationManager->getRunningSequenceName() == NULL or strcmp(animationManager->getRunningSequenceName(), "walk") != false)
    {
        animationManager->runAnimationsForSequenceNamed("walk");
    }
}
示例#6
0
void  Soldier::normalAtkHandler(GameObject* gameObject)
{
    CCBAnimationManager* animationManager = dynamic_cast<CCBAnimationManager*>(this->getUserObject());
    if (animationManager->getRunningSequenceName() == NULL or strcmp(animationManager->getRunningSequenceName(), "attack1") != false)
    {
        animationManager->runAnimationsForSequenceNamed("attack1");
        CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(effectSoundFileName);
        gameObject->atkHandler(atk, this);
    }
}
示例#7
0
void Zombie::handleCollisionWith(GameObject* gameObject)
{
    if (this->hp<=0) {
        this->isScheduledForRemove = true;
    }
    S1* rabit = dynamic_cast<S1*>(gameObject);


    if (rabit != NULL) {
        xSpeed = 0;
        rabit->setHp(rabit->getHp()-this->atk);
        CCBAnimationManager* animationManager = dynamic_cast<CCBAnimationManager*>(this->getUserObject());
        animationManager->runAnimationsForSequenceNamed("attack");
    }
}
bool FMMapAvatarNode::addAvatarNode(CCDictionary * dic)
{
    if (m_avatarList->count() >= 4) {
        return false;
    }
    FMDataManager * manager = FMDataManager::sharedManager();
    
    FMMainScene * mainScene = (FMMainScene *)FMDataManager::sharedManager()->getUI(kUI_MainScene);
    FMWorldMapNode* wd = (FMWorldMapNode*)mainScene->getNode(kWorldMapNode);
    CCNode * n = manager->createNode("UI/FMUIAvatar.ccbi", wd);
    addChild(n,10-m_avatarList->count(),m_avatarList->count());
    m_avatarList->addObject(n);
    
    CCString * uid = (CCString *)dic->objectForKey("uid");
    const char * iconpath = SNSFunction_getFacebookIcon(uid->getCString());
    
    CCSprite * icon = (CCSprite*)n->getChildByTag(1);
    
    if (iconpath && manager->isFileExist(iconpath)) {
        CCSprite * spr = CCSprite::create(iconpath);
        float size = 26.f;
        spr->setScale(size / MAX(spr->getContentSize().width, size));
        icon->addChild(spr);
        spr->setPosition(ccp(icon->getContentSize().width/2, icon->getContentSize().height/2));
    }
    
    int cnt = m_avatarList->count()-1;
    if (m_includeSelf) {
        cnt++;
    }
    n->setPosition(ccp(cnt * avatarDiffx, cnt * avatarDiffy));
    
    CCBAnimationManager * anim = (CCBAnimationManager *)n->getUserObject();
    anim->runAnimationsForSequenceNamed("2");

    m_dicList->addObject(dic);
    
    return true;
}
示例#9
0
void Dragon::handleCollisionWith(GameObject* gameObject)
{
  Coin *coin = dynamic_cast<Coin*>(gameObject);
  Bomb *bomb = dynamic_cast<Bomb*>(gameObject);
  if (coin)
  {
    // Took a coin
    ySpeed_ = kCJCoinSpeed;
    
    GameScene::sharedScene()->setScore(GameScene::sharedScene()->getScore()+1);
  }
  else if (bomb)
  {
    // Hit a bomb
    if (ySpeed_ > 0) ySpeed_ = 0;
    
    CCBAnimationManager* animationManager = dynamic_cast<CCBAnimationManager*>(this->getUserObject());
    if (animationManager) {
      animationManager->runAnimationsForSequenceNamed("Hit");
    }
  }
  
}
示例#10
0
文件: Hero.cpp 项目: JuhnXu/joker
void Hero::handleCollisionWith(GameObject *gameObject)
{
    CCBAnimationManager* animationManager = dynamic_cast<CCBAnimationManager*>(this->getUserObject());
    animationManager->runAnimationsForSequenceNamed("attack");
}