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


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

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


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

示例1: ccpDistance

Creeps *Towers::getClosestTarget()
{
	Creeps *closestCreep = NULL;
	double maxDistant = 99999;

	DataModel *m = DataModel::getModel();

	for (int i=0;i<m->getTargets()->count();i++) {
		Creeps *creep=(Creeps *)m->getTargets()->objectAtIndex(i);
		double curDistance = ccpDistance(getPosition(), creep->getPosition());

		if (curDistance < maxDistant) {
			closestCreep = creep;
			maxDistant = curDistance;
		}

	}

	if (maxDistant < _range)
		return closestCreep;

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

示例2: 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

示例3: addTarget

void HelloWorld::addTarget() {
    
	DataModel *m = DataModel::getModel();
	Wave * wave = getCurrentWave();
    int tc=wave->getRedCreeps();
    int gn=wave->getGreenCreeps();
	if (tc <= 0&&gn<=0) {
		return; //[self getNextWave];
	}
	
//	wave->setTotalCreeps(--tc);
	
    Creeps *target = NULL;
//    if ((arc4random() % 2) == 0) {
//        target = FastRedCreep::creep();
//    } else {
//        target = StrongGreenCreep::creep();
//    }
	int random=CCRANDOM_0_1()*100;
    if ((random % 2) == 0) {
        if (wave->getRedCreeps()>0) {
           target =Creeps::create(ENERMY_NAME[0].c_str(),0,Info::getInfo()->creepInfo->value[0]);
            wave->setRedCreeps(--tc);
        }
        else if (wave->getGreenCreeps()>0){
           target = Creeps::create(ENERMY_NAME[1].c_str(),1,Info::getInfo()->creepInfo->value[1]);
            wave->setGreenCreeps(--gn);
            // NSLog(@"no more red");
        }
    }
    else {
        if (wave->getGreenCreeps()>0) {
          target = Creeps::create(ENERMY_NAME[1].c_str(),1,Info::getInfo()->creepInfo->value[1]);
            wave->setGreenCreeps(--gn);
        }
        else if (wave->getRedCreeps()>0){
            target = Creeps::create(ENERMY_NAME[0].c_str(),0,Info::getInfo()->creepInfo->value[0]);
            wave->setRedCreeps(--tc);
            //NSLog(@"no more green");
        }
        
    }
	WayPoint *waypoint = target->getCurrentWaypoint();
	target->setPosition( waypoint->getPosition());
	waypoint = target->getNextWaypoint();
	target->setVisible(true);
	addChild(target,1);
    
    target->setHealthBar(CCProgressTimer::create(CCSprite::create("health_bar_red.png")));
    target->getHealthBar()->setType(kCCProgressTimerTypeBar);
    target->getHealthBar()->setPercentage(100);
    target->getHealthBar()->setScale(0.1);
    target->getHealthBar()->setPosition(ccp(target->getPosition().x,(target->getPosition().y+20)));
    addChild(target->getHealthBar(),3);
    
	int moveDuration = target->getMoveDuration();
	CCMoveTo* actionMove = CCMoveTo::create(moveDuration,waypoint->getPosition());
	CCCallFuncN* actionMoveDone =CCCallFuncN::create(this,callfuncN_selector(HelloWorld::FollowPath));
	target->runAction(CCSequence::create(actionMove, actionMoveDone, NULL));
	
	// Add to targets array
	target->setTag(1);
	m->getTargets()->addObject(target);
	
}
开发者ID:pototao,项目名称:DefenseTest,代码行数:65,代码来源:HelloWorldScene.cpp


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