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


C++ DataModel::getProjectiles方法代码示例

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


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

示例1: finishFiring

void Towers::finishFiring() {
	if (!_target) {
		return;
	}
	DataModel *m = DataModel::getModel();

	setNextBullet(Bullet::create(BULLET_NAME[bulletTag].c_str(),bulletTag,Info::getInfo()->bulletInfo->value[bulletTag]));
	getNextBullet()->setPosition(getPosition());

	this->getParent()->addChild(getNextBullet(),1);
	m->getProjectiles()->addObject(getNextBullet());

	float delta = 1.0;
	CCPoint shootVector = ccpSub(_target->getPosition(),getPosition());
	CCPoint normalizedShootVector = ccpNormalize(shootVector);
	CCPoint overshotVector = ccpMult(normalizedShootVector, 320);
	CCPoint offscreenPoint = ccpAdd(getPosition(), overshotVector);

	getNextBullet()->runAction(CCSequence::create(CCMoveTo::create(delta,offscreenPoint),
		CCCallFuncN::create(this,callfuncN_selector( Towers::creepMoveFinished)),NULL));

	getNextBullet()->setTag(bulletTag);

	setNextBullet(NULL);

}
开发者ID:pototao,项目名称:DefenseTest,代码行数:26,代码来源:Towers.cpp

示例2: creepMoveFinished

void Towers::creepMoveFinished(CCNode* sender) {

	DataModel * m = DataModel::getModel();

	CCSprite *sprite =(CCSprite*)sender;
	this->getParent()->removeChild(sprite,true);
	m->getProjectiles()->removeObject(sprite);

}
开发者ID:pototao,项目名称:DefenseTest,代码行数:9,代码来源:Towers.cpp

示例3: update

void HelloWorld::update(float dt) {
    
    
    DataModel *m =DataModel:: getModel();
    CCArray *projectilesToDelete =new CCArray();
    
    Bullet *projectile =NULL;
	/*CCLog("projectileRect count %d",  m->getProjectiles()->count());*/
    for (int i=0;i<m->getProjectiles()->count();i++) {
        projectile=(Bullet *)m->getProjectiles()->objectAtIndex(i);
        
        CCRect projectileRect = CCRectMake(projectile->getPosition().x - (projectile->getContentSize().width/2),
                                           projectile->getPosition().y - (projectile->getContentSize().height/2),
                                           projectile->getContentSize().width,
                                           projectile->getContentSize().height);
       /* CCLog("projectileRect width %f height %f ",  projectile->getContentSize().width,  projectile->getContentSize().height);*/
        CCArray *targetsToDelete = new CCArray();
        for (int j=0;j<m->getTargets()->count();j++) {
            CCSprite *target=(CCSprite *)m->getTargets()->objectAtIndex(j);
            CCRect targetRect = CCRectMake(target->getPosition().x - (target->getContentSize().width/2),
                                           target->getPosition().y - (target->getContentSize().height/2),
                                           target->getContentSize().width,
                                           target->getContentSize().height);
            
            //                if (CGRectIntersectsRect(projectileRect, targetRect)) {
            if(projectileRect.intersectsRect(targetRect)){
                projectilesToDelete->addObject(projectile);
                
                 Creeps *creep = (Creeps *)target;
                int bulletType=projectile->getTag();
				/*CCLog("hellocpp update bullettype %d",bulletType);*/
                if (bulletType ==0){//MachineGun Projectile
                   
                    int hp=creep->getHp();
                    creep->setHp(--hp);
                    //               
                    if (creep->getHp() <= 0) {
                        targetsToDelete->addObject(target);
                        gameHUD->updateResources(1);
                         removeChild(creep->getHealthBar(),true);
                    }
                    break;
                }
                else if (bulletType ==1){//Freeze projectile
                    CCMoveTo*actionFreeze = CCMoveTo::create(1,creep->getPosition());
                    CCCallFuncN* actionMoveResume = CCCallFuncN::create(this, callfuncN_selector(HelloWorld::ResumePath));
                    creep->stopAllActions();
                    creep->runAction(CCSequence:: create(actionFreeze, actionMoveResume, NULL));
                    break;
                }
                break;
                
            }
        }
        for (int k=0; k<targetsToDelete->count(); k++) {
            CCSprite* target=(CCSprite*)targetsToDelete->objectAtIndex(k);
            m->getTargets()->removeObject(target);
            removeChild(target, true);
        }
        targetsToDelete->release();
    }
    
    for (int k=0; k<projectilesToDelete->count(); k++) {
        CCSprite *projectile=(CCSprite *)projectilesToDelete->objectAtIndex(k);
        m->getProjectiles()->removeObject(projectile);
        removeChild(projectile,true);
    }
    projectilesToDelete->release();
    
    Wave *wave =getCurrentWave();
    
    if (wave!=NULL&&m->getTargets()->count() ==0 && wave->getRedCreeps()<=0&&wave->getGreenCreeps()<=0){
        
//        getNextWave();
//         gameHUD->updateWaveCount();
        schedule(schedule_selector(HelloWorld::waveWait),3.0);
         gameHUD->newWaveApproaching();
        }
    
}
开发者ID:pototao,项目名称:DefenseTest,代码行数:80,代码来源:HelloWorldScene.cpp


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