void HelloWorld::update(float delta)
{
	if(m_bStart)
	{
		CCArmature *pHero = (CCArmature*)(m_pGameScene->getChildByTag(10005)->getComponent("CCArmature")->getNode());
		pHero->getParent()->setPositionX(pHero->getParent()->getPositionX() + m_fSpeed);
		CCArmature *pEnemy = (CCArmature*)(m_pGameScene->getChildByTag(10006)->getComponent("CCArmature")->getNode());

		if(ccpDistance(ccp(pHero->getParent()->getPositionX(), 0), ccp(pEnemy->getParent()->getPositionX(), 0)) < m_fAttackDis)
		{	
			pHero->getAnimation()->play("attack");
			pHero->getAnimation()->setMovementEventCallFunc(this,
                                                        movementEvent_selector(HelloWorld::animationEvent));
			m_bStart = false;
		}
	}

	if(m_bDead)
	{
		CCComRender *pUIRender = static_cast<CCComRender*>(m_pGameScene->getChildByTag(10007)->getComponent("GUIComponent"));
		UILayer *pUILayer = static_cast<UILayer*>(pUIRender->getNode());
		UILoadingBar *pHPLoadingBar = static_cast<UILoadingBar*>(pUILayer->getWidgetByName("hp02_LoadingBar"));
		UILoadingBar *pMPLoadingBar = static_cast<UILoadingBar*>(pUILayer->getWidgetByName("mp02_LoadingBar"));

		pHPLoadingBar->setPercent(m_fPercentage);
		pMPLoadingBar->setPercent(m_fPercentage);

		m_fPercentage -= 2.0f;
        if (m_fPercentage < 0.0f) {
            unscheduleUpdate();
        }
	}
	
}
bool UILoadingBarTest_Left_Scale9::init()
{
    if (UIScene::init())
    {
        scheduleUpdate();
        
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("LoadingBar left scale9 render");
        alert->setFontName("Marker Felt");
        alert->setFontSize(20);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.7));
        m_pUiLayer->addWidget(alert);
        
        // Create the loading bar
        UILoadingBar* loadingBar = UILoadingBar::create();
        loadingBar->setName("LoadingBar");
        loadingBar->loadTexture("cocosui/slider_bar_active_9patch.png");
        loadingBar->setScale9Enabled(true);
        loadingBar->setCapInsets(CCRectMake(0, 0, 0, 0));
        /*===*/
        loadingBar->setSize(CCSizeMake(300, loadingBar->getContentSize().height));
        /*=*/
        loadingBar->setPercent(0);
        
        loadingBar->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f));
        m_pUiLayer->addWidget(loadingBar);
        
        return true;
    }
    return false;
}
bool UILoadingBarTest_Left::init()
{
    if (UIScene::init())
    {
        scheduleUpdate();
        
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("LoadingBar left");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75));
        m_pUiLayer->addWidget(alert);
        
        // Create the loading bar
        UILoadingBar* loadingBar = UILoadingBar::create();
        loadingBar->setName("LoadingBar");
        loadingBar->loadTexture("cocosui/sliderProgress.png");        
        loadingBar->setPercent(0);
        
        loadingBar->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f));
        m_pUiLayer->addWidget(loadingBar);
        
        return true;
    }
    return false;
}
void UILoadingBarTest_Left::update(float delta)
{
    m_nCount++;
    if (m_nCount > 100)
    {
        m_nCount = 0;
    }
        
    UILoadingBar* loadingBar = dynamic_cast<UILoadingBar*>(m_pUiLayer->getWidgetByName("LoadingBar"));
    loadingBar->setPercent(m_nCount);
}
Пример #5
0
bool FightingScene::init()
{
	if (!CCLayer::init())
	{
		return false;
	}

	visibleSize = CCDirector::sharedDirector()->getVisibleSize();

	fightingMap = new FightingMap();
	fightingMap->tiledMap->setPosition(ccp(0, 0));
	addChild(fightingMap->tiledMap);

	// 将领
	CCPoint formationGeneralPositions[3][3] = 
	{
		{ccp(417, 426), ccp(288, 426), ccp(156, 426)},
		{ccp(417, 296), ccp(288, 296), ccp(156, 296)},
		{ccp(417, 164), ccp(288, 164), ccp(156, 164)}
	};

	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			if (formationGeneral[j][i] == false)
			{
				continue;
			}

			GeneralSprite gs = formationManager->generalSpriteArray[j][i];

			if (gs.general == NULL)
			{
				continue;
			}

			if (gs.general->isFormation == false)
			{
				continue;
			}

			Monster* monster = gs.general;
			gs.general->creatArmature();
			monster->setPosition(ccp(formationGeneralPositions[j][i].x, formationGeneralPositions[j][i].y));
			monster->setOriginalPosition(monster->position);
			monster->armature->setPosition(monster->position);
			monster->setDirectionEXT(RIGHT, DIRECTION_NONE);
			monster->setAction(STAND);
			addChild(monster->armature);

			// 血量条
			monster->uiBloodLayer = UILayer::create();
			UILayout* bloodRoot = dynamic_cast<UILayout*>(GUIReader::shareReader()->widgetFromJsonFile("ui/UIBlood.ExportJson"));
			monster->uiBloodLayer->addWidget(bloodRoot);

			UILoadingBar* bloodLoadingBar = dynamic_cast<UILoadingBar*>(monster->uiBloodLayer->getWidgetByName("BloodLoadingBar"));
			UILoadingBar* angerLoadingBar = dynamic_cast<UILoadingBar*>(monster->uiBloodLayer->getWidgetByName("AngerLoadingBar"));

			angerLoadingBar->setPercent(0);
			monster->uiBloodLayer->setPosition(ccp(-50, 80));
			monster->armature->addChild(monster->uiBloodLayer);

			monster->setFightingMap(fightingMap);
			monster->setIsAi(true);
			monster->setIsFriend(true);

			monsterFriendVector.push_back(monster);
			monsterFriendArray[j][i] = monster;

			StateMachine* stateMachine = new StateMachine(monster);
			monster->setStateMachine(stateMachine);
		}
	}

	// 小兵
	CCPoint formationSoldierPositions[3][3] = 
	{
		{ccp(742, 426), ccp(874, 426), ccp(1003, 426)},
		{ccp(742, 296), ccp(874, 296), ccp(1003, 296)},
		{ccp(742, 164), ccp(874, 164), ccp(1003, 164)}
	};

	vector<string> armyVector = chapterManager->getArmyVector();

	int k = 0;

	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			if (formationSoldier[j][i] == false)
			{
				continue;
			}

			if (armyVector.size() == k)
			{
				continue;
			}

			Solider* solider = new Solider(atoi(armyVector[k++].c_str()));;
			solider->creatArmature();
			Monster* monster = solider;
			monster->setPosition(ccp(formationSoldierPositions[j][i].x, formationSoldierPositions[j][i].y));
			monster->armature->setPosition(monster->position);
			monster->setOriginalPosition(monster->position);
			monster->setDirectionEXT(RIGHT, DIRECTION_NONE);
			monster->setAction(STAND);
			monster->armature->setScaleX(-1);
			addChild(monster->armature);

			// 血量条
			monster->uiBloodLayer = UILayer::create();
			UILayout* bloodRoot = dynamic_cast<UILayout*>(GUIReader::shareReader()->widgetFromJsonFile("ui/UIBlood.ExportJson"));
			monster->uiBloodLayer->addWidget(bloodRoot);

			UILoadingBar* bloodLoadingBar = dynamic_cast<UILoadingBar*>(monster->uiBloodLayer->getWidgetByName("BloodLoadingBar"));
			UILoadingBar* angerLoadingBar = dynamic_cast<UILoadingBar*>(monster->uiBloodLayer->getWidgetByName("AngerLoadingBar"));
			bloodLoadingBar->setDirection(LoadingBarTypeRight);
			angerLoadingBar->setDirection(LoadingBarTypeRight);

			angerLoadingBar->setPercent(0);
			monster->uiBloodLayer->setPosition(ccp(-50, 80));
			monster->armature->addChild(monster->uiBloodLayer);

			monster->setFightingMap(fightingMap);
			monster->setIsAi(true);
			monster->setIsFriend(false);

			monsterEnemyVector.push_back(monster);
			monsterEnemyArray[j][i] = monster;

			StateMachine* stateMachine = new StateMachine(monster);
			monster->setStateMachine(stateMachine);
		}
	}

	qianJunPoZhanEffect = new Effect(QIAN_JUN_PO);
	qianJunPoZhanEffect->armature->setVisible(false);
	addChild(qianJunPoZhanEffect->armature);

	fenNuYiJiEffect = new Effect(FEN_NU_YI_JI);
	fenNuYiJiEffect->armature->setVisible(false);
	addChild(fenNuYiJiEffect->armature);

	liZhanEffect = new Effect(LI_ZHAN);
	liZhanEffect->armature->setVisible(false);
	addChild(liZhanEffect->armature);

	// 敏捷值排序[占位点排序]
	for (int i = 0; i < monsterEnemyVector.size(); i++)
	{
		monsterAgilityVector.push_back(monsterEnemyVector[i]);
	}

	for (int i = 0; i < monsterFriendVector.size(); i++)
	{
		monsterAgilityVector.push_back(monsterFriendVector[i]);
	}

	for (int i = 0; i < monsterAgilityVector.size(); i++)
	{
		for (int j = 0; j < monsterAgilityVector.size(); j++)
		{
			if (monsterAgilityVector[i]->minJie > monsterAgilityVector[j]->minJie)
			{
				Monster* sprite = monsterAgilityVector[i];
				monsterAgilityVector[i] = monsterAgilityVector[j];
				monsterAgilityVector[j] = sprite;
			}
		}
	}

	setKeypadEnabled(true);

	return true;
}