本文整理汇总了C++中DataModel::getTowers方法的典型用法代码示例。如果您正苦于以下问题:C++ DataModel::getTowers方法的具体用法?C++ DataModel::getTowers怎么用?C++ DataModel::getTowers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataModel
的用法示例。
在下文中一共展示了DataModel::getTowers方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: canBuildOnTilePosition
bool HelloWorld::canBuildOnTilePosition(CCPoint pos)
{
// pos=ccpAdd(pos, ccp(0, 50));
CCPoint towerLoc = tileCoordForPosition(pos);
int tileGid =_background->tileGIDAt(towerLoc);
CCDictionary *props = _tileMap->propertiesForGID(tileGid);
const CCString *type = props->valueForKey("buildable");
CCString* str=CCString::create("1");
DataModel *m = DataModel::getModel();
bool occupied = false;
for (int i=0;i< m->getTowers()->count();i++) {
Towers *tower=(Towers*)m->getTowers()->objectAtIndex(i);
CCRect towerRect = CCRectMake(tower->getPosition().x - (tower->getContentSize().width/2),
tower->getPosition().y - (tower->getContentSize().height/2),
tower->getContentSize().width, tower->getContentSize().height);
if (towerRect.containsPoint(pos)) {
occupied = true;
}
}
if(str->isEqual(type)&&!occupied) {
return true;
}
return false;
}
示例2: addTower
void HelloWorld::addTower(CCPoint pos,int towerTag) {
// pos = ccpAdd(pos, ccp(0, 50));
CCLog("towerTag--------------- %d ",towerTag);
DataModel *m = DataModel::getModel();
Towers *target = NULL;
CCPoint towerLoc =tileCoordForPosition(pos);
int tileGid =_background->tileGIDAt(towerLoc);
CCDictionary *props =_tileMap->propertiesForGID(tileGid);
const CCString *type = props->valueForKey("buildable");
bool occupied = false;
CCString *str=CCString::create("1");
for (int i=0;i< m->getTowers()->count();i++) {
Towers *tower=(Towers*)m->getTowers()->objectAtIndex(i);
CCRect towerRect = CCRectMake(tower->getPosition().x - (tower->getContentSize().width/2),
tower->getPosition().y - (tower->getContentSize().height/2),
tower->getContentSize().width, tower->getContentSize().height);
if (towerRect.containsPoint(pos)) {
occupied = true;
}
}
if(str->isEqual(type)&&!occupied) {
// return true;
// }
// if(str->isEqual(type)) {
int money= gameHUD->getResources();
switch (towerTag) {
case 1:
if(money>=25){
target = Towers::create(TOWER_NAME[0].c_str(),0,Info::getInfo()->towerInfo->value[0]);
gameHUD->setResources(money-25);
}else{
return;
}
break;
case 2:
if(money>=25){
target = Towers::create(TOWER_NAME[1].c_str(),1,Info::getInfo()->towerInfo->value[1]);
gameHUD->setResources(money-35);
}else{
return;
}
break;
case 3:
if(money>=25){
target =Towers::create(TOWER_NAME[0].c_str(),0,Info::getInfo()->towerInfo->value[0]);
gameHUD->setResources(money-25);
}else{
return;
}
break;
case 4:
if(money>=25){
target = Towers::create(TOWER_NAME[0].c_str(),0,Info::getInfo()->towerInfo->value[0]);
gameHUD->setResources(money-25);
}else{
return;
}
break;
default:
break;
}
target->setPosition(ccp((towerLoc.x * 32) + 16, _tileMap->getContentSize().height - (towerLoc.y * 32) - 16));
addChild(target,1);
target->setTag(1);
m->getTowers()->addObject(target);
// target->release();
} else {
// CCLog("Tile Not Buildable");
}
}