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


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

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


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

示例1: checkCollision

void GameScene::checkCollision(){
    std::vector<int> catched;
    
    for (int i = 0; i < _fish.size(); i++) {
        Fish *fish = _fish.at(i);
        if (!fish->getIsCatched()) {
            Point fishPoint = fish->getPosition();
            Size fishSize = Size(fish->getContentSize().width * fabs(fish->getScaleX()), fish->getContentSize().height * fabs(fish->getScaleY()));
            Point hookpoint = _fisherman->getHookWorldPoint();
            
            bool x = false;
            bool y = false;
            
            if (((fishPoint.x - (fishSize.width/2)) < hookpoint.x) &&
                ((fishPoint.x + (fishSize.width/2)) > hookpoint.x)) {
                x = true;
            }
            
            if (((fishPoint.y - (fishSize.height/2)) < hookpoint.y) &&
                ((fishPoint.y + (fishSize.height/2)) > hookpoint.y)) {
                y = true;
            }
            
            if (x && y) {
                catched.push_back(i);
            }
        }
    }
    
    for (int i = 0; i < catched.size(); i++) {
        int x = catched.at(i);
        Fish *f = _fish.at(x);
        if(f != _catchedFish) {
            f->setIsCatched(true);
            if (!_catchedFish) {
                CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("new_pick_up.wav");
                _catchedFish = f;
                _catchedFish->setPreventAnimations(true);
                _catchedFish->setRotation(_catchedFish->getScaleX() > 0 ? 90 : 270);
                _scoreMultiplier = 1;
                
                _currentScore = _catchedFish->getScore();
                
            } else {
                if (!dynamic_cast<Turtle*>(f)) {
                    CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("new_pick_up.wav");
                    _scoreMultiplier ++;
                    
                    if (f->getScore() > _catchedFish->getScore()) {
                        //                f->setScore(f->getScore());
                        _fish.erase(std::remove(_fish.begin(), _fish.end(), _catchedFish), _fish.end());
                        _catchedFish->removeFromParent();
                        _catchedFish = NULL;
                        
                        
                        _catchedFish = f;
                        _currentScore += _catchedFish->getScore();
                        _catchedFish->setPreventAnimations(true);
                        _catchedFish->setRotation(_catchedFish->getScaleX() > 0 ? 90 : 270);
                        
                    } else {
                        _currentScore += f->getScore();
                        _fish.erase(std::remove(_fish.begin(), _fish.end(), f), _fish.end());
                        f->removeFromParent();
                        f = NULL;
                        
                    }

                }
                
                
            }

        }
        
        
    }
    
    if (_currentScore > 0) {
        char buff[100];
        sprintf(buff, "%dX%i", (int)roundf(_currentScore),(int)_scoreMultiplier);
        std::string buffAsStdStr = buff;
        _currentLabel->setString(buffAsStdStr);
        
    }
    
}
开发者ID:areschoug,项目名称:LD29,代码行数:87,代码来源:GameScene.cpp


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