Exemple #1
0
void PlayLayer::upgradeTower(int tt,int lv)
{
	Point matrixCoord = convertToMatrixCoord(towerPos);
	int MatrixIndex = static_cast<int>( matrixCoord.y * MAP_WIDTH + matrixCoord.x );
	TowerBase* tower;
	// 先移除低等级塔,移除前线获得金币信息
	tower = towerMatrix[MatrixIndex];
	int m= tower->getTowerValue();
	
	if ( tt == 0 )//表示第一个塔
	{


		if( money < m )
			return;
		money=money-m;
		tower->removeFromParent();
		towerMatrix[MatrixIndex]=NULL;
		instance->setMoney(money);
		char countBuf8[16] = "";
		sprintf(countBuf8, "%d", money);
		auto moneyText = countBuf8;
		moneyLabel->setString(moneyText);

		//升级塔,造个新塔
		if( lv == 0 )
		{
			tower = ArrowTower1::create();	
			tower->setLevel(1);		
		}
		else if ( lv == 1)
		{
			tower = ArrowTower2::create();	
			tower->setLevel(2);	
		}
		else 
		{
			tower = ArrowTower3::create();	
			tower->setLevel(3);	
		}

		if(tower != NULL)
		{
			tower->setTowerPos(towerPos);
			//tower->runAction(Sequence::create(FadeIn::create(1.0f),NULL));
			this->addChild(tower);
			towerMatrix[MatrixIndex] =  tower;
			tower->setPosition(towerPos);
		}
		auto type =  TowerUpgrade::OTHER;
		chooseUpgradepanel->setChooseTowerUpgrade(type);
		//异常升级面板并设置为NULL,攻击范围
		chooseUpgradepanel->removeFromParent();
		draw->clear();
		chooseUpgradepanel=NULL;
		return;




	}
	else if (tt == 1)//表示第二个塔
	{

		//int m= currTower->getTowerValue();
		if( money < m )
			return;
		money=money-m;
		tower->removeFromParent();
		towerMatrix[MatrixIndex]=NULL;
		//currTower = NULL;
		instance->setMoney(money);
		char countBuf8[16] = "";
		sprintf(countBuf8, "%d", money);
		auto moneyText = countBuf8;
		//auto moneyText = std::to_string(money);
		moneyLabel->setString(moneyText);
		//升级塔,造个新塔
		if( lv == 0 )
		{
			tower = AttackTower1::create();	
			tower->setLevel(1);		
		}
		else if ( lv == 1)
		{
			tower = AttackTower2::create();	
			tower->setLevel(2);	
		}
		else 
		{
			tower = AttackTower3::create();	
			tower->setLevel(3);	
		}

		if(tower != NULL)
		{
			tower->setTowerPos(towerPos);
			//tower->runAction(Sequence::create(FadeIn::create(1.0f),NULL));
			this->addChild(tower);
			towerMatrix[MatrixIndex] =  tower;
			tower->setPosition(towerPos);

		}


		auto type =  TowerUpgrade::OTHER;
		chooseUpgradepanel->setChooseTowerUpgrade(type);
		//异常升级面板并设置为NULL,攻击范围
		chooseUpgradepanel->removeFromParent();
		draw->clear();
		chooseUpgradepanel=NULL;

		return;
	}
	else //表示第三个塔
	{

		//int m= currTower->getTowerValue();
		if( money < m )
			return;
		money=money-m;
		tower->removeFromParent();
		towerMatrix[MatrixIndex]=NULL;
		//currTower = NULL;

		instance->setMoney(money);
		char countBuf8[16] = "";
		sprintf(countBuf8, "%d", money);
		auto moneyText = countBuf8;
		//auto moneyText = std::to_string(money);
		moneyLabel->setString(moneyText);
		//升级塔,造个新塔
		if( lv == 0 )
		{
			tower = MultiDirTower1::create();	
			tower->setLevel(1);		
		}
		else if ( lv == 1)
		{
			tower = MultiDirTower2::create();	
			tower->setLevel(2);	
		}
		else 
		{
			tower = MultiDirTower3::create();	
			tower->setLevel(3);	
		}

		if(tower != NULL)
		{
			tower->setTowerPos(towerPos);
			//tower->runAction(Sequence::create(FadeIn::create(1.0f),NULL));
			this->addChild(tower);
			towerMatrix[MatrixIndex] =  tower;
			tower->setPosition(towerPos);

		}


		auto type =  TowerUpgrade::OTHER;
		chooseUpgradepanel->setChooseTowerUpgrade(type);
		//异常升级面板并设置为NULL,攻击范围
		chooseUpgradepanel->removeFromParent();
		draw->clear();
		chooseUpgradepanel=NULL;

		return;
	}

}
Exemple #2
0
void PlayLayer::addTower()
{
	if(chooseTowerpanel)
	{
		auto type = chooseTowerpanel->getChooseTowerType();
		if(type == TowerType::ANOTHER)
		{
			return;
		}
		Point matrixCoord = convertToMatrixCoord(towerPos);
		int MatrixIndex = static_cast<int>( matrixCoord.y * MAP_WIDTH + matrixCoord.x );
		bool noMoneyTips = false;
		TowerBase* tower = NULL;
		if( type == TowerType::ARROW_TOWER )
		{
			if( money >= 120 )
			{
				tower = ArrowTower::create();
				money -= 120;
			}
			else
				noMoneyTips = true;
		}
		else if( type == TowerType::ATTACK_TOWER )
		{
			if( money >= 150 )
			{
				tower = AttackTower::create();
				money -= 150;
			}
			else
				noMoneyTips = true;
		}
		else if( type == TowerType::MULTIDIR_TOWER )
		{
			if( money >= 400 )
			{
				tower = MultiDirTower::create();
				money -= 400;
			}else
				noMoneyTips = true;
		}
		if(tower != NULL)
		{
			tower->setPosition(towerPos);
			tower->runAction(Sequence::create(FadeIn::create(1.0f),NULL));
			this->addChild(tower);
			towerMatrix[MatrixIndex] =  tower;
			//add by  设置tower位置
			tower->setTowerPos(towerPos);
		}
		type =  TowerType::ANOTHER;
		chooseTowerpanel->setChooseTowerType(type);
		this->removeChild(chooseTowerpanel);
		chooseTowerpanel = NULL;

		//add by 
		instance->setMoney(money);


		//by 
		char countBuf8[16] = "";
		sprintf(countBuf8, "%d", money);
		auto moneyText = countBuf8;
		//auto moneyText = std::to_string(money);
		moneyLabel->setString(moneyText);



		if( noMoneyTips == true )
		{
			SimpleAudioEngine::getInstance()->playEffect(FileUtils::getInstance()->fullPathForFilename("sound/tip.wav").c_str(), false);
			//auto tips = Sprite::createWithSpriteFrameName("nomoney_mark.png");
			//add by 
			auto tips = Sprite::createWithSpriteFrameName("tip.png");
			tips->setPosition(towerPos);
			this->addChild(tips);
			tips->runAction(Sequence::create(DelayTime::create(0.5f),
				CallFunc::create(CC_CALLBACK_0(Sprite::removeFromParent, tips)),
				NULL));
		}
	}
}