コード例 #1
0
ファイル: MonsterBuilder.cpp プロジェクト: joyfish/TowerTD
void MonsterBuilder::MonsterFactoryController()
{
    SoundUtil::getInstance()->playEffect(BUILDMONSTER);
	if (_iNumber == 10)_iNumber = 0;
	int number = 10 - (_iBatch - 1) * 2;
	MonsterBase * pMonster;
	if (_iBatch == _iReadFileMonsterCount && _iNumber == 5)
	{
		pMonster = MonsterFactory::createMonster(en_Boss_Big);
	}
	else
	{
		if (_iNumber < number)
		{
			pMonster = MonsterFactory::createMonster(MonsterType(1 + int(_iBatch / 5)));
		}
		else
		{
			pMonster = MonsterFactory::createMonster(MonsterType(4 + int(_iBatch / 5)));
		}
	}
	pMonster->setIHp(pMonster->getIHp() + (_iBatch - 1) / 5 * pMonster->getIHp());
	pMonster->setMaxSpeed(pMonster->getISpeed() + int(_iBatch / 5) * 10);
	pMonster->getSprite()->runAction(Animate::create(_createMonsterAnimation));
	_iNumber++;
}
コード例 #2
0
void CCLayerParent::quirkButtonTapped(CCObject* obj) {    
   //CCLog("Quirk button tapped!");
	 CCMenuItemSprite * item = ( CCMenuItemSprite * )obj;
	 
 	int index = item->getTag();
	CCLog("%d button tapped!",index);
    if(!decks[index].cooldown) return;
   PlayerComponent* humanPlayer = _humanPlayer->player();
	if(!_playerSystem->handleEconomic(humanPlayer,&decks[index])) return;

   if(decks[index].cooldown)
   {
	   decks[index].cooldown = false;
	   decks[index].potentio->setValue(0.1f);
	   decks[index].potentio->setVisible(true);
   }


       CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("spawn.wav");
	Entity* entity = _entityFactory->createMonsterWithTeam(MonsterType(index),1);
	RenderComponent* render =entity->render();
	if (render) {        
	    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
	    float randomOffset = CCRANDOM_X_Y(-winSize.height * 0.25, winSize.height * 0.25);
	    render->node->setPosition ( ccp(winSize.width * 0.25, winSize.height * 0.5 + randomOffset));
			
	}
}
コード例 #3
0
 void AIStateMass::updateEntity(Entity *entity,AISystem *system) {
    
    TeamComponent* team = entity->team();
    PlayerComponent* player = entity->player();
    AIComponent* ai = entity->ai();
    if (!team || !player || !ai) return;
    
    CCArray* enemies = entity->entitiesWithinRange(decks[0].fight.Range,OPPOSITE_TEAM(team->team));
    if (enemies->count() > 0) {
        system->changeStateForEntity(entity,AIStateDefend::create());
        //CCLog("Defend State");
        return;
    }
	int total = 0;
	for(int i = BUILDING_NUM; i<BUILDING_NUM+SPRITE_NUM;i++)
	{
		if(decks[i].selection)
			total += decks[i].price;
	}
	if (player->coins > total) {
		//AIState *state = AIStateCounter::create();
		//state->retain();
        //system->changeStateForEntity(entity,AIStateCounter::create());
        //CCLog("Counter State");
		for(int i = BUILDING_NUM; i<BUILDING_NUM+SPRITE_NUM;i++)
		{
			if(decks[i].selection)
				system->spawnMonsterForEntity(MonsterType(i),entity);
		}
        return;
    }
    
    player->attacking = false;
    
}
コード例 #4
0
void AIStateRush::updateEntity(Entity *entity,AISystem *system) {
    
    TeamComponent* team = entity->team();
    PlayerComponent* player = entity->player();
    AIComponent* ai = entity->ai();
    if (!team || !player || !ai) return;
    
	int aitotal = 0;
	int playertotal = 0;
	for(int i = BUILDING_NUM; i<BUILDING_NUM+SPRITE_NUM;i++)
	{
		playertotal += values[0][i];
		aitotal += values[1][i];
	}
    CCArray* enemies = entity->entitiesWithinRange(decks[0].fight.Range,OPPOSITE_TEAM(team->team));
    if (enemies->count() > 0 &&playertotal>aitotal) {
		AIState *state =  AIStateDefend::create();
		//state->retain();
        system->changeStateForEntity(entity, state);
        return;
    }
	//int total = 0;
	//for(int i = BUILDING_NUM; i<BUILDING_NUM+SPRITE_NUM;i++)
	//{
	//	if(decks[i].selection)
	//		total += decks[i].price;
	//}
	//if (total == 0) {
	////AIState *state =  AIStateMass::create();
 //       //state->retain();
 //       system->changeStateForEntity(entity, AIStateMass::create());
 //       //CCLog("Mass State");
 //       return;
 //   }
    
    player->attacking = true;

    if (aitotal > playertotal) {
		for(int i = BUILDING_NUM; i<BUILDING_NUM+SPRITE_NUM;i++)
		{
			if(decks[i].selection)
			{
				system->spawnMonsterForEntity(MonsterType(i),entity);
				break;
			}
		}
    }    
}