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


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

本文整理汇总了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;
}
开发者ID:pototao,项目名称:DefenseTest,代码行数:28,代码来源:HelloWorldScene.cpp

示例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");
	}
	
}
开发者ID:pototao,项目名称:DefenseTest,代码行数:80,代码来源:HelloWorldScene.cpp


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