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


C++ Enemy::getBoundingBox方法代码示例

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


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

示例1: addSmallEnemy

void LayerEnemy::addSmallEnemy(float dt)
{
	Enemy *smallPlane = Enemy::create();
	smallPlane->bindEnemySprite(CCSprite::createWithSpriteFrameName("enemy1.png"), SMALL_MAXLIFE);
	m_psmallArray->addObject(smallPlane);
	addChild(smallPlane);

	//! 随机产生0.0~1.0的数
	float x = CCRANDOM_0_1()*(winSize.width - smallPlane->getBoundingBox().size.width) + smallPlane->getBoundingBox().size.width /2;
	float y = winSize.height + smallPlane->boundingBox().size.height / 2;

	CCPoint smallBirth = ccp(x, y);
	smallPlane->setPosition(smallBirth);
	CCMoveTo *to = CCMoveTo::create(3, ccp(
			smallBirth.x, 
			smallBirth.y - winSize.height - smallPlane->getBoundingBox().size.height /2
		));

	CCCallFuncN *actionDone = CCCallFuncN::create(this, callfuncN_selector(LayerEnemy::smallEnemyMoveFinishedFCallBack));
	CCSequence *sequence = CCSequence::create(to, actionDone, NULL);

	smallPlane->runAction(sequence);
//CCLog("%p", smallPlane);
//CCLog("before count  = %d", m_psmallArray->count());
}
开发者ID:dalechngame,项目名称:mygame,代码行数:25,代码来源:LayerEnemy.cpp

示例2: checkCollisionsWithEnemies

void RaiseTheDeadSpell::checkCollisionsWithEnemies(const sf::FloatRect* boundingBox) {
	// this method is overridden to guarantee that the spell only hits once
	// and that the iterator is not invalidated (we change the enemy vector size on the fly)
	for (auto& go : *m_enemies) {
		if (!go->isViewable()) continue;
		Enemy* enemy = dynamic_cast<Enemy*>(go);
		if (enemy != nullptr && (enemy->getBoundingBox()->intersects(*boundingBox))) {
			enemy->onHit(this);
			break;
		}
	}
}
开发者ID:MORTAL2000,项目名称:Cendric2,代码行数:12,代码来源:RaiseTheDeadSpell.cpp

示例3: CheckEnemyHits

void CheckEnemyHits(){
	for(int i=0;i < enemies.size(); i++){
		hgeRect* enemyBox;
		Enemy* enemy = enemies.at(i);
		enemyBox = enemy->getBoundingBox();
		for(int j=0; j < players.size(); j++){
			hgeRect* playerBox;
			Player* player = players.at(j);
				if (!player->getInvulnerable()) {
				playerBox = player->getBoundingBox();
				if (enemyBox->Intersect(playerBox)){
					gameActive = false;
				}
			}
		}
	}
}
开发者ID:Hammers,项目名称:SeePlusPlus,代码行数:17,代码来源:Main.cpp

示例4: update

void FightingLayer::update(float dt) {
    
    _playDuration += dt;
    
    Rect rect = Rect(0, 0, _ground->getContentSize().width, _ground->getContentSize().height);
    // Update bullets
    for (std::vector<Bullet *>::size_type i = 0; i != _bullets->size(); i++) {
        Bullet *bullet = _bullets->at(i);
        bullet->update(dt);
        
        if (!rect.containsPoint(bullet->getPosition())) {
            bullet->kill();
            _bullets->erase(_bullets->begin() + i);
            i--;
            continue;
        }
        
        for (std::vector<Enemy *>::size_type j = 0; j != _enemies->size(); j++) {
            Enemy *enemy = _enemies->at(j);
            
            // Check if bullet hits
            if (enemy->getBoundingBox().containsPoint(bullet->getPosition())) {
                _score += 10;
                // Remove enemy
                //enemy->removeFromParent();
                enemy->kill();
                _enemies->erase(_enemies->begin() + j);
                j--;
                
                // REmove bullet
                bullet->kill();
                _bullets->erase(_bullets->begin() + i);
                i--;
                
                updateScore();
                
                break;
            }
        }
    }
    
    
    for (std::vector<Smoke *>::size_type i = 0; i != _smokes->size(); i++) {
        Smoke *smoke = _smokes->at(i);
        Point position = smoke->getPosition();
        if (position.x < 0) {
            position.x = 0;
            smoke->reverse();
        }
        else if (position.x > rect.size.width) {
            position.x = rect.size.width;
            smoke->reverse();
        }
    }
    
    
    for (std::vector<Enemy *>::size_type i = 0; i != _enemies->size(); i++) {
        Enemy *enemy = _enemies->at(i);
        
        // Check if outside
        bool isOutside = (enemy->getDirection() == -1 && enemy->getPosition().x < 0) || (enemy->getDirection() == 1 && enemy->getPosition().x > _ground->getContentSize().width);
        if (isOutside) {
            enemy->removeFromParent();
            _enemies->erase(_enemies->begin() + i);
            i--;
            continue;
        }
        
        // Check if hits player
        
        if (_player->getBoundingBox().intersectsRect(enemy->getBoundingBox()) && _player->isAlive()) {
            _player->kill();
            CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("die_sound.wav");
            this->gameDidEnd();
            break;
        }
    }
    if (_player->isAlive()) {
        Point playerPosition = _player->getPosition();
        if (playerPosition.x < _player->getContentSize().width) {
            playerPosition.x = _player->getContentSize().width;
            _player->setPosition(playerPosition);
        }
        else if (playerPosition.x > _ground->getContentSize().width -_player->getContentSize().width) {
            _player->setPositionX(_ground->getContentSize().width -_player->getContentSize().width);
        }
    }
}
开发者ID:hellozimi,项目名称:Disco-Apocalypse,代码行数:88,代码来源:FightingLayer.cpp


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