Ejemplo n.º 1
0
void GameLayer::updateFish(float dt)
{
    
    vector< int >::iterator it = m_currentFish.begin();
    
    while(it != m_currentFish.end()) {
        Fish * fish = (Fish *)this->getFishes()->getObjectAtIndex(*it);
        
        if(fish->getDeleted()){
            fish->setDeleted(false);
            fish->setVisible(false);
            it = m_currentFish.erase(it);
        }
        else ++it;
    }
    
    _timeStampAddFish += dt * 20;
    
    if(_timeStampAddFish > _nextTimeStampAddFish){
        int _time = _timeStampAddFish / DELTA_ADDFISH;
        
        // Check current avaible Fish Generation Time
        
         this->setCrtTime(_time);
        
        this->addFish();
        
        _nextTimeStampAddFish = _timeStampAddFish + DELTA_ADDFISH;
        
        if(this->getCrtTime() > 180){
            int randomScript = (int)(CCRANDOM_0_1() * 100) % MAX_SCRIPT_SIZE;
          
            this->setCrtScript(randomScript + 1);
            this->setCrtTime(0);
            _nextTimeStampAddFish = _timeStampAddFish = 0;
        }
    }
}
Ejemplo n.º 2
0
void GameLayer::updateBullet(float dt)
{
    fireBullet(dt);
   
    
    Ref *pBulletObj = NULL;
    
    
    
    CCARRAY_FOREACH(m_pBullets, pBulletObj)
    {
        Bullet *pBullet = (Bullet *)pBulletObj;
        if (pBullet->getCaught())
            continue;
        bool caught = false;
        bool hit = false;
        
        for(std::vector<int>::iterator it = m_currentFish.begin();it != m_currentFish.end();it++){
            int index = *it;
            Fish * fish = (Fish *)this->getFishes()->getObjectAtIndex(index);
            
            if(!fish->getVisible() && !fish->getDeleted()){
                continue;
            }
            
            Rect hittestRect = shrinkRect(fish->getBounding(), 0.65f, 0.8f);
            
            if (hittestRect.containsPoint(pBullet->getSpriteBullet()->getPosition()))
            {
                fish->hit(pBullet->getPower());
                
                hit = true;
                
                if (fish->getHP() <= 0){
                    
                    caught = true;
                    
                    // Add animation coin
                    
                    this->addCoin(fish->getSprite()->getPositionX(),fish->getSprite()->getPositionY(),fish->getCoin(),"COMBO");
                    
                    auto label = Label::create();
                    if(fish->getIsInstance()){
                        label->setTextColor(Color4B::ORANGE);
                        label->enableOutline(Color4B::WHITE,4);
                        label->setPosition(fish->getSprite()->getPosition());
                        label->setString(StringUtils::format("Perfect \n+ %d",fish->getCoin()));
                        label->setSystemFontSize(26);
                    }
                    else{
                        label->setTextColor(Color4B::YELLOW);
                        label->enableOutline(Color4B::WHITE,3);
                        label->setPosition(fish->getSprite()->getPosition());
                        label->setString(StringUtils::format("+ %d",fish->getCoin()));
                        label->setSystemFontSize(20);
                    }
                    
                    label->setHorizontalAlignment(TextHAlignment::CENTER);
                    label->setVerticalAlignment(TextVAlignment::CENTER);
                    
                    label->runAction(Sequence::create(
                                                      MoveBy::create(0.5f,Vec2(0,10)),
                                                      FadeOut::create(0.5f),
                                                      RemoveSelf::create(true),
                                                      NULL));
                    
                    this->addChild(label);
                    
                    
                    int crtXP = User::Instance().getXP();
                    crtXP ++ ;
                    User::Instance().setXP(crtXP);
                    User::Instance().save();
                    this->updateXP();
                    
                    fish->showCaught();
                    
                }
                
                break;
                
            }
            
        }
        
        
        if (caught)
        {
            pBullet->showNet();
        }
        else
        {
            if (hit)
            {
                pBullet->showSmoke();
            }
        }
    }