本文整理汇总了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);
}
示例2: creepMoveFinished
void Towers::creepMoveFinished(CCNode* sender) {
DataModel * m = DataModel::getModel();
CCSprite *sprite =(CCSprite*)sender;
this->getParent()->removeChild(sprite,true);
m->getProjectiles()->removeObject(sprite);
}
示例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();
}
}