当前位置: 首页>>代码示例>>C++>>正文


C++ Fish::hit方法代码示例

本文整理汇总了C++中Fish::hit方法的典型用法代码示例。如果您正苦于以下问题:C++ Fish::hit方法的具体用法?C++ Fish::hit怎么用?C++ Fish::hit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Fish的用法示例。


在下文中一共展示了Fish::hit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: updateBullet

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();
            }
        }
    }
开发者ID:ch1301028,项目名称:tienca,代码行数:98,代码来源:GameLayer.cpp


注:本文中的Fish::hit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。