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


C++ Star::isVisible方法代码示例

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


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

示例1: clearStarAt

void GameLayer::clearStarAt(CCPoint point) {
    int col = (int) point.x / TILE;
	int row  = (int) (_screenSize.height - point.y) / TILE;
    
	if (row < 0 || col < 0 || row >= _manager->getRows() || col >= _manager->getColumns() ||
        row * _manager->getColumns() + col >= STARS_IN_POOL) {
		return;
	}
    
	//identify cell in array
	Star * star = _manager->starFromPool(row * _manager->getColumns() + col);
    //CCLOG ("COL: %i  ROW: %i", col, row);
    
    if (star->isVisible()) {
        
        float diffx = _moon->getPositionX() - star->getPositionX();
        float diffy = _moon->getPositionY() - star->getPositionY();

        
        if ((diffx * diffx + diffy * diffy) <= _moon->getSquaredRadius()) {
            
            int starsCollected = _manager->getCollectedStars();
            int totalStarsCollected = _manager->getTotalCollectedStars();
            
            starsCollected++;
            totalStarsCollected++;
            
            _manager->setCollectedStars(starsCollected);
            _manager->setTotalCollectedStars(totalStarsCollected);
            
            star->setVisible(false);
            
            
            int totalStars = _manager->getTotalStars();
            
            //did we hit a boost?
            if (star->getIsBoost()) {
                
                _manager->setBoosting(true);
                
                if (starsCollected != totalStars) {
                    _boostHitParticles->setPosition(star->getPosition());
                    _boostHitParticles->resetSystem();
                }
            }
            
            //if last star on screen, show particles, show Moon Perch...
            if (starsCollected == totalStars) {
                SimpleAudioEngine::sharedEngine()->playEffect("last_star_hit.wav");
                _starHitParticles->setPosition(star->getPosition());
                _starHitParticles->resetSystem();
                _starsCollected = true;

                if (_sun->isVisible()) {
                    _moonPerch->setOpacity(100);
                } else {
                    _moonPerch->setOpacity(200);
                }
            } else {
                if (star->getIsBoost()) {
                    SimpleAudioEngine::sharedEngine()->playEffect("boost_hit.wav");
                } else {
                    SimpleAudioEngine::sharedEngine()->playEffect("star_hit.wav");
                }
            }
            
        }
	}
}
开发者ID:Ratel13,项目名称:moon-herder-cocos2d-x,代码行数:69,代码来源:GameLayer.cpp

示例2: update

void GameLayer::update (float dt) {
    
    if (_gameState == kGameStatePlay) {
        
		//if running game logic
		if (_running) {
            
            
            _manager->update(dt);
            dt *= DT_RATE;
            
			//update elements
            _moon->update(dt);
            if (_sun->isVisible()) {
                _sun->update(dt);
                if (_sun->checkCollisionWithMoon(_moon)) {
                    SimpleAudioEngine::sharedEngine()->playEffect("sun_hit.wav");
                }
            }
            
			
			//check collision with lines, update, draw
			Line * line;
            int len = _manager->getLines()->count();
            bool collisionDetected = false;
			
			for (int i = len-1; i >= 0; i--) {
                
				line = (Line *) _manager->getLines()->objectAtIndex(i);
                
				if (!collisionDetected && line->getActive()) {
					if (line->collidesWithMoon(_moon)) {
						collisionDetected = true;
                        SimpleAudioEngine::sharedEngine()->playEffect("line_hit.wav");
                        _lineHitParticles->setPosition(line->getCollisionPoint());
                        _lineHitParticles->resetSystem();
					}
				}
                
				if (line->getTrashme()) {
                    _manager->getLines()->removeObjectAtIndex(i);
				} else {
                    line->update(dt);
                }
			}
            _moon->place();
            
            //if moon off screen to the top, make screen darker as moons gets farther and farther away
            if (_moon->getPositionY() > _screenSize.height) {
                if (!_sun->isVisible()) {
                    float opacity = fabs((255 * (_moon->getPositionY() - _screenSize.height))/_screenSize.height);
                    if (opacity > 200) opacity = 200;
                    if (!_sun->isVisible()) _bgDark->setOpacity ( 255 - opacity );
                }
            } else {
                if (!_sun->isVisible()) {
                    if (_bgDark->getOpacity() != 255) _bgDark->setOpacity ( 255 );
                }
            }
        
            
			//track collision with MOON and STAR (usign grid logic)
            float range = _moon->getRadius();
            float posX = _moon->getPositionX();
            float posY = _moon->getPositionY();
            
			//I decided to check 9 cells for precision sake
            clearStarAt(ccp(posX, posY));
            clearStarAt(ccp(posX, posY + range));
            clearStarAt(ccp(posX, posY - range));
            clearStarAt(ccp(posX + range, posY));
            clearStarAt(ccp(posX + range, posY + range));
            clearStarAt(ccp(posX + range, posY - range));
            clearStarAt(ccp(posX - range, posY));
            clearStarAt(ccp(posX - range, posY - range));
            clearStarAt(ccp(posX - range, posY + range));
            
            
            //update bars
            
            
            
			//check timer
			if (_manager->getTime()  <= 0.65f && !_sun->isVisible()) {
				SimpleAudioEngine::sharedEngine()->playEffect("sun_rise.wav");
                _sun->setVisible(true);
				_sun->setHasRisen(false);
			} else if (_manager->getTime() <= 0.25f && _sun->isVisible() && !_sun->getHasGrown()) {
                SimpleAudioEngine::sharedEngine()->playEffect("sun_grow.wav");
                _sun->highNoon();
            } else if (_manager->getTime() <= 0.0f) {
                //if you want game over once time runs out.
                //game;
            }
            
            if (_sun->isVisible()) {
                if (!_bgLight->isVisible()) {
                    _bgLight->setVisible(true);
                }
                //when sun is added to screen, fade out dark bg
//.........这里部分代码省略.........
开发者ID:Ratel13,项目名称:moon-herder-cocos2d-x,代码行数:101,代码来源:GameLayer.cpp


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