Ejemplo n.º 1
0
//////////////////////////////////////////////////////////////////////////
//get kind objects
//////////////////////////////////////////////////////////////////////////
std::vector<CCNode*> LevelLayer::getChildrenByTag(int tag)
{
	std::vector<CCNode*> result;

	CCArray* children = this->getChildren();
	for (size_t i = 0; i < children->count(); ++i)
	{
		CCNode* node = (CCNode*)children->objectAtIndex(i);
		if(node && node->getTag() == tag)
		{
			result.push_back(node);
		}
	}

	if(m_pObjectsLayer != NULL)
	{
		children = m_pObjectsLayer->getChildren();
		for (size_t i = 0; children && i < children->count(); ++i)
		{
			CCNode* node = (CCNode*)children->objectAtIndex(i);
			if(node && node->getTag() == tag)
			{
				result.push_back(node);
			}
		}
	
	}
	return result;
}
// 物理構造を持つふたつのオブジェクトが衝突した時に呼ばれる関数
void GamePhysicsContactListener::BeginContact(b2Contact* contact) {
	// 衝突した2つのオブジェクトのデータを取得
	CCNode* actorA = (CCNode*)contact->GetFixtureA()->GetBody()->GetUserData();
	CCNode* actorB = (CCNode*)contact->GetFixtureB()->GetBody()->GetUserData();

	// 衝突した2つのオブジェクトに値するタグを取得
	int tagA = actorA->getTag();
	int tagB = actorB->getTag();

	if (!actorA || !actorB){										// データが2つ揃っていない場合はそのまま戻る
		return;
	} else if ((tagA == TAG_PLAYER_UNIT && tagB == TAG_DESTROYER_UNIT) || (tagA == TAG_DESTROYER_UNIT && tagB == TAG_PLAYER_UNIT)
			|| (tagB == TAG_PLAYER_UNIT && tagA == TAG_DESTROYER_UNIT) || (tagB == TAG_DESTROYER_UNIT && tagA == TAG_PLAYER_UNIT)) {
		// ゲームオーバー
        actorA->setTag(TAG_COLLISION);
	} else if(tagA == TAG_PLAYER_UNIT && tagB == TAG_MISSILE) {
		// 自機のライフが1減る
        actorA->setTag(TAG_PLAYER_UNIT);
	} else if ((tagA == TAG_DESTROYER_UNIT && tagB == TAG_MISSILE) || (tagA == TAG_MISSILE && tagB == TAG_DESTROYER_UNIT)) {
		//
        actorA->setTag(TAG_DESTROYER_UNIT);
	} else if ((tagA == TAG_SUBMARINE_UNIT && tagB == TAG_MISSILE) || (tagA == TAG_MISSILE && tagB == TAG_SUBMARINE_UNIT)) {
		//
        actorA->setTag(TAG_SUBMARINE_UNIT);
	}
}
Ejemplo n.º 3
0
//////////////////////////////////////////////////////////////////////////
//get kind objects count
//////////////////////////////////////////////////////////////////////////
int LevelLayer::getObjectCount(int tag)
{
	//std::vector<CCNode*> result;
	int count = 0;

	CCArray* children = this->getChildren();
	for (size_t i = 0; i < children->count(); ++i)
	{
		CCNode* node = (CCNode*)children->objectAtIndex(i);
		if(node && node->getTag() == tag)
		{
			//result.push_back(node);
			count++;
		}
	}

	if(m_pObjectsLayer != NULL)
	{
		children = m_pObjectsLayer->getChildren();
		for (size_t i = 0; i < children->count(); ++i)
		{
			CCNode* node = (CCNode*)children->objectAtIndex(i);
			if(node && node->getTag() == tag)
			{
				//result.push_back(node);
				count++;
			}
		}
	}

	return count;
	//return result.size();
}
Ejemplo n.º 4
0
void CSharpTollgate::addTableCell(unsigned int uIdx, CTableViewCell * pCell)
{
	const vector<StageWidget> *data = DataCenter::sharedData()->getStageData()
		->getStageWidgets(m_chapter);
	CStage &stage = m_stageList.at(uIdx);

	for (int i = 0; i < 2; i++)
	{
		CCNode * node = (CCNode*)m_cell->getChildren()->objectAtIndex(i);

		if (node->getTag()==1)
		{
			const StageWidget *widget = nullptr;			
			CCString *strId = CCString::createWithFormat("hero%d",uIdx+1);
			for (int j=0; j<data->size();++j)
			{
				widget = &data->at(j);
				if (widget->widgetId!=""&&widget->widgetId.compare(strId->getCString())==0)
				{				
					CButton *btn =  CButton::create(widget->normalImage.c_str());
					btn->setScaleX(widget->scaleX);
					btn->setScaleY(widget->scaleY);
					btn->setPosition(ccp(100, 80/*btn->boundingBox().size.height*/));  
					btn->setAnchorPoint(ccp(0.5, 0.0));
					btn->setUserData(&m_stageList.at(uIdx));
					btn->setOnClickListener(this,ccw_click_selector(CSharpTollgate::onBattle));
					btn->setTag(1);
					pCell->addChild(btn);
					if (!stage.isOpen)
					{
						btn->getNormalImage()->setShaderProgram(ShaderDataMgr->getShaderByType(ShaderStone));
// 						btn->getSelectedImage()->setShaderProgram(ShaderDataMgr->getShaderByType(ShaderStone));
					}
					break;
				}
			}
		}
		else if (node->getTag()==2)
		{
			CImageView *image = UICloneMgr::cloneImageView((CImageView*)node);
			if (stage.star>0)
			{		
				image->setTexture(CCTextureCache::sharedTextureCache()->addImage(CCString::createWithFormat("tollgate/star_%d.png",stage.star)->getCString()));
			}
			else
			{
				image->setTexture(CCTextureCache::sharedTextureCache()->addImage("tollgate/star_3.png"));
				image->setShaderProgram(ShaderDataMgr->getShaderByType(ShaderStone));
			}
			image->setAnchorPoint(ccp(0.5f,0));

			pCell->addChild(image);
		}
	}
	pCell->setVisible(false);
	pCell->setScale(1.15f);
	pCell->runAction(CCSequence::create(CCDelayTime::create(0.1f+0.15f*uIdx),CCShow::create(),CCScaleTo::create(0.05f,1.0f),CCCallFuncN::create(this,callfuncN_selector(CSharpTollgate::heroCall)),nullptr));
}
Ejemplo n.º 5
0
//////////////////////////////////////////////////////////////////////////
//called when level active
//////////////////////////////////////////////////////////////////////////
void LevelLayer::onActiveLayer(sActiveLevelConfig& config)
{
	//
	this->setTouchEnabled(true);
	//
	CCDirector::sharedDirector()->setLevelRenderCameraOffset(ccp(0,0));

	//send active event to children
	CCArray* children = this->getChildren();
	if (children)
	{
		int childrenCount = children->count();
		for (int i = 0; i < childrenCount; ++i)
		{
			CCNode* child = (CCNode* )children->objectAtIndex(i);
			ASSERT(child != NULL, "child is NULL");

			BaseListener* listener = LevelLayer::sGetListenerByTag(child->getTag());
			if (listener)
			{
				listener->HandleLayerActiveEvent(child, &config);
			}			
		}
	}

	if(m_pObjectsLayer != NULL)
	{
		/*CCNode* pNode = getSpriteSeer();
		if(pNode != NULL)
		{
		BaseListener* listener = LevelLayer::sGetListenerByTag(pNode->getTag());
		listener->HandleLayerActiveEvent(pNode, &config);
		}*/

		CCArray* children = m_pObjectsLayer->getChildren();
		if (children)
		{
			int childrenCount = children->count();
			for (int i = 0; i < childrenCount; ++i)
			{
				CCNode* child = (CCNode* )children->objectAtIndex(i);
				ASSERT(child != NULL, "child is NULL");

				BaseListener* listener = LevelLayer::sGetListenerByTag(child->getTag());
				if (listener)
				{
					listener->HandleLayerActiveEvent(child, &config);
				}				
			}
		}

	}

	//get other players
	//OnlineNetworkManager::sShareInstance()->sendGetOtherPlayersMessage();
}
Ejemplo n.º 6
0
void BasicInfoView::basicViewBtnCallback(CCObject *pSender){
    CCNode *node = (CCNode*)pSender;
    cout << "tag = " << node->getTag() << endl;
    switch (node->getTag()) {
        case 0:
            //m_playerInfoView = PlayerInfoView::create(this);
            ((m_pMenuTarget)->*(m_MenuSelector))(this,NULL);
            //m_playerInfoView->showPlayerInfo();
            break;
            
        default:
            break;
    }
}
void GamePhysicsContactListener::BeginContact(b2Contact* contact)
{
    // 衝突した双方の物体を取得
    b2Body* bodyA = contact->GetFixtureA()->GetBody();
    b2Body* bodyB = contact->GetFixtureB()->GetBody();

    CCNode* nodeA = (CCNode*)bodyA->GetUserData();
    CCNode* nodeB = (CCNode*)bodyB->GetUserData();

    if( nodeA != NULL && nodeB != NULL ){
        //
        if( nodeA->getTag() == NODE_TAG_BALL ){
            Ball* pBall = (Ball*)nodeA;
            pBall->contactWith(nodeB);
        }
        else if( nodeB->getTag() == NODE_TAG_BALL ){
            Ball* pBall = (Ball*)nodeB;
            pBall->contactWith(nodeA);
        }
    }

#if 0
    // 物体にひもづくSpriteを取得
    PhysicsSprite* spriteA = (PhysicsSprite*)bodyA->GetUserData();
    PhysicsSprite* spriteB = (PhysicsSprite*)bodyB->GetUserData();

    // 地面との衝突は無視する
    if (spriteA->getTag() == Config::kTag_Ground ||
        spriteB->getTag() == Config::kTag_Ground)
    {
        return;
    }

    // 衝突時の加速度を取得
    b2Vec2 velocityA = bodyA->GetLinearVelocity();
    b2Vec2 velocityB = bodyB->GetLinearVelocity();
    CCLOG("[BeginContact] A(%f, %f) B(%f, %f)", velocityA.x, velocityA.y, velocityB.x, velocityB.y);

    // 加速度が一定上の大きさだったら、ぶつかられた方を削除する
    float threshold = 3;
    if (pow(velocityA.x, 2) + pow(velocityA.y, 2) > pow(threshold, 2)) {
        spriteB->setDeleteFlag(true);
    }
    if (pow(velocityB.x, 2) + pow(velocityB.y, 2) > pow(threshold, 2)) {
        spriteA->setDeleteFlag(true);
    }
#endif
}
Ejemplo n.º 8
0
void GUISpinView::scrollTo(int rowIndex)
{
    
    m_targetRow = rowIndex;
    if (m_targetRow >= m_itemCount || m_targetRow < 0) {
        return;
    }
    CCNode * node = m_mainNode->getChildByTag(m_targetRow);
    float h = node->getPosition().y;
    float dis = -h - (kMoveRound * m_itemCount * m_itemHeight);
    int th = m_itemHeight;
    float r = rand()% (th-10);
    r -= (th-10) * 0.5f;
    CCArray * array = m_mainNode->getChildren();
    if (array) {
        for (int i = 0; i < array->count(); i++) {
            CCNode * node = (CCNode *)array->objectAtIndex(i);
            CCMoveBy * move = CCMoveBy::create(kMoveTime, CCPoint(0, dis + r));
            CCEaseSineOut * easeout = CCEaseSineOut::create(move);
            CCDelayTime * delay = CCDelayTime::create(0.2f);
            CCMoveBy * move2 = CCMoveBy::create(0.2f, ccp(0, -r));
            CCSequence * seq = CCSequence::create(easeout,delay,move2,NULL);
            if (node->getTag() == m_targetRow) {
                node->runAction(CCSequence::create(seq,CCDelayTime::create(0.2f),CCCallFunc::create(this, callfunc_selector(GUISpinView::scrollFinish)), NULL));
            }else{
                node->runAction(seq);
            }
        }
    }
    scheduleUpdate();
}
Ejemplo n.º 9
0
//////////////////////////////////////////////////////////////////////////
//called when touch end
//////////////////////////////////////////////////////////////////////////
void LevelLayer::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent)
{

	CCTouch* touch = (CCTouch*)pTouches->anyObject();
	CCPoint oldPT = touch->getLocationInView();
	oldPT = CCDirector::sharedDirector()->convertToGL(oldPT);	

	CCPoint newPT = LevelMultiResolution::sTransformWindowPointToMap(oldPT);

	//send touch end event to children
	CCArray* children = this->getChildren();
	if (children)
	{
		int childrenCount = children->count();
		for (int i = 0; i < childrenCount; ++i)
		{
			CCNode* child = (CCNode* )children->objectAtIndex(i);
			ASSERT(child != NULL, "child is NULL");

			BaseListener* listener = LevelLayer::sGetListenerByTag(child->getTag());
			if (listener)
			{
				listener->HandleLayerTouchEndEvent(child, newPT);
			}			
		}
	}

	//reset touch point
	m_touchWinPoint = ccp(0, 0);
}
Ejemplo n.º 10
0
	CCNode* SceneReader::nodeByTag(CCNode *pParent, int nTag)
	{		
		if (pParent == NULL)
		{
			return NULL;
		}
		CCNode *_retNode = NULL;
		CCArray *pChildren = pParent->getChildren();
		if(pChildren && pChildren->count() > 0)
		{
			CCObject* child;
			CCARRAY_FOREACH(pChildren, child)
			{
				CCNode* pNode = (CCNode*)child;
				if(pNode && pNode->getTag() == nTag)
				{
					_retNode =  pNode;
					break;
				}
				else
				{
					_retNode = nodeByTag(pNode, nTag);
					if (_retNode != NULL)
					{
						break;
					}
					
				}
			}
Ejemplo n.º 11
0
void PopupLayer::buttonCallback(cocos2d::CCObject *pSender){
	CCNode* node = dynamic_cast<CCNode*>(pSender);
	CCLog("touch tag: %d", node->getTag());
	if (m_callback && m_callbackListener){
		(m_callbackListener->*m_callback)(node);
	}
	this->removeFromParent();
}
Ejemplo n.º 12
0
void ModelDialog::buttonCallback(cocos2d::CCObject *pSender){
    CCNode* node = dynamic_cast<CCNode*>(pSender);
    CCLog("touch tag: %d", node->getTag());
    if (m_callback && m_callbackListener){
        (m_callbackListener->*m_callback)(node,NULL);
    }
    close();
}
Ejemplo n.º 13
0
//////////////////////////////////////////////////////////////////////////
//called when level de-active
//////////////////////////////////////////////////////////////////////////
void LevelLayer::onDeactiveLayer()
{
	this->setTouchEnabled(false);	

	//send de-active event to children
	CCArray* children = this->getChildren();
	if (children)
	{
		int childrenCount = children->count();
		for (int i = 0; i < childrenCount; ++i)
		{
			CCNode* child = (CCNode* )children->objectAtIndex(i);
			ASSERT(child != NULL, "child is NULL");

			BaseListener* listener = LevelLayer::sGetListenerByTag(child->getTag());
			if (listener)
			{
				listener->HandleLayerDeactiveEvent(child);
			}			
		}
	}	

	//send de-active event to children
	if(getObjectLayer())
	{
		CCArray* children = this->getObjectLayer()->getChildren();
		if (children)
		{
			int childrenCount = children->count();
			for (int i = 0; i < childrenCount; ++i)
			{
				CCNode* child = (CCNode* )children->objectAtIndex(i);
				ASSERT(child != NULL, "child is NULL");

				BaseListener* listener = LevelLayer::sGetListenerByTag(child->getTag());
				if (listener)
				{
					listener->HandleLayerDeactiveEvent(child);
				}				
			}
		}	
	}
	
}
Ejemplo n.º 14
0
//用于完成下层的数据通信
void PoptipLayer::buttonCallback(cocos2d::CCObject *pSender){
	CCNode* node = dynamic_cast<CCNode*>(pSender);
	CCLog("touch tag: %d", node->getTag());


	switch(node->getTag())
	{
	case 1:          //sure
		{
			this->removeFromParent();
			break;
		}
	case 2:        //cancel
		{ 
			this->removeFromParent();   
			break;
		}
	default:
		break;
	}
}
Ejemplo n.º 15
0
//////////////////////////////////////////////////////////////////////////
//called when touch layer
//////////////////////////////////////////////////////////////////////////
void LevelLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{
	CCTouch* touch = (CCTouch*)pTouches->anyObject();
	CCPoint oldPT = touch->getLocationInView();
	oldPT = CCDirector::sharedDirector()->convertToGL(oldPT);	

	m_touchWinPoint = oldPT;

    float deviceScale = CCDirector::sharedDirector()->getContentScaleFactor();
    oldPT = CCPoint(oldPT.x * deviceScale, oldPT.y * deviceScale);
    
	CCPoint newPT = LevelMultiResolution::sTransformWindowPointToMap(oldPT);

	// Note: 打断自动寻路到副本显示感叹号
	TaskManager::getInstance()->InterruptAutoGoToInstanceEvent();
    
	//by benyang: deal with npc first
	if(!NPCManager::sharedManager()->processTouch(newPT))
	{
		//send touch begin event to children
		CCArray* children = this->getChildren();
		if (children)
		{
			int childrenCount = children->count();
			for (int i = 0; i < childrenCount; ++i)
			{
				CCNode* child = (CCNode* )children->objectAtIndex(i);
				ASSERT(child != NULL, "child is NULL");

				BaseListener* listener = LevelLayer::sGetListenerByTag(child->getTag());
				if (listener)
				{
					listener->HandleLayerTouchBeginEvent(child, newPT);
				}				
			}
		}
	}

	//上面的listener未命中,直接调用SpriteSeerListener
	SpriteSeer * seer = GameManager::Get()->getHero();
	if (seer)
	{
		BaseListener* listener = LevelLayer::sGetListenerByTag(seer->getTag());
		if (listener)
		{
			listener->HandleLayerTouchBeginEvent(seer, newPT);
		}		
	}

	//record touch point in map
	m_touchWinPoint = oldPT;		
}
Ejemplo n.º 16
0
CCNode* Widget::getChildByTag(int aTag)
{
    CCAssert( aTag != kCCNodeTagInvalid, "Invalid tag");
    
    if(_widgetChildren && _widgetChildren->count() > 0)
    {
        CCObject* child;
        CCARRAY_FOREACH(_widgetChildren, child)
        {
            CCNode* pNode = (CCNode*) child;
            if(pNode && pNode->getTag() == aTag)
                return pNode;
        }
Ejemplo n.º 17
0
void MapMenu1Layer::controlButtonTest(CCObject* pObject, CCControlEvent event)
{
//	CCLog( "CGStartGameLayer::controlButtonEventhandle" );
//    m_TestLabel->setString("chenee is pig");
    CocosDenshion::SimpleAudioEngine::sharedEngine()->stopAllEffects();
    CCNode* node = (CCNode*)pObject;
    int tag = node->getTag();
    if (1 == tag) {
        CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("wkszMapMenu/1/sound1.mp3", false);
    }else if(2 == tag){
        CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("wkszMapMenu/1/sound2.mp3", false);
    }
    
}
Ejemplo n.º 18
0
void PopupLayer::buttonCallback(cocos2d::CCObject *pSender){
    CCNode* node = dynamic_cast<CCNode*>(pSender);
	int tag = node->getTag();
	//quit
	if(tag == 40)
	{
		#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
			MessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert");
			return;
		#endif

			Director::getInstance()->end();

		#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
			exit(0);
		#endif
	}
	//resume
	else if (tag == 41)
	{
		node->getParent()->getParent()->getParent()->resume();
	}
	//restart
	else if(tag == 42)
	{
		GameMain::score = 0;
		GameMain::gravity = 0;
		ui::TextAtlas* score_lbl = (ui::TextAtlas*)(node->getParent()->getParent()->getParent()->getChildByTag(1)->getChildByTag(5)->getChildByTag(2));
		String* s = String::createWithFormat("%d", GameMain::score*5);
		score_lbl->setStringValue(s->getCString());
		ui::LoadingBar* score_bar = (ui::LoadingBar* )(node->getParent()->getParent()->getParent()->getChildByTag(1)->getChildByTag(5)->getChildByTag(1));
		score_bar->setPercent(GameMain::score*5);
		node->getParent()->getParent()->getParent()->resume();
	}
	//next
	else if (tag == 43)
	{
		GameMain::score = 0;
		GameMain::gravity = 0;
		ui::TextAtlas* score_lbl = (ui::TextAtlas*)(node->getParent()->getParent()->getParent()->getChildByTag(1)->getChildByTag(5)->getChildByTag(2));
		String* s = String::createWithFormat("%d", GameMain::score*5);
		score_lbl->setStringValue(s->getCString());
		GameMain::page+=2;
		ui::LoadingBar* score_bar = (ui::LoadingBar* )(node->getParent()->getParent()->getParent()->getChildByTag(1)->getChildByTag(5)->getChildByTag(1));
		score_bar->setPercent(GameMain::score*5);
		node->getParent()->getParent()->getParent()->resume();
	}
    this->removeFromParent();
}
Ejemplo n.º 19
0
void MultiPriceMatch::btnPriceCallback(Ref* pSender, ui::Widget::TouchEventType eEventType){
	/*if (eEventType != ui::Widget::TouchEventType::BEGAN)*/

	CCNode* node = (CCNode*) pSender;
	int tag = node->getTag();
	bool bSel = false;

	for (int i = 0; i < 3;i++){
		if (tag == (BTN_PRICE_1 + i)) bSel = true;
	}

	if (bSel == false) return;

	cocos2d::log("button's tag is %d",tag);
	auto button = (Button*) _SORT_UINode->getChildByTag(tag);
	AppDelegate *app = (AppDelegate*)Application::getInstance();


	switch (eEventType) {
		case ui::Widget::TouchEventType::BEGAN:
			cocos2d::log("btnPriceCallback Began");
			button->getTouchBeganPosition();
			button->setZOrder(99);
			break;
		case ui::Widget::TouchEventType::ENDED:
			cocos2d::log("btnPriceCallback Ended");
			if (app->getBGMstatus() == BGMusic_flag::ON){
				app->PlayEffect(SOUND_BUTTON_CLICK);

			}	
			button->setZOrder(1);
			MovetoPriceLabel(button);
			break;
		case ui::Widget::TouchEventType::MOVED:
			button->setPosition(button->getTouchMovePosition());
			cocos2d::log("btnPriceCallback Moving");
			break;
		case ui::Widget::TouchEventType::CANCELED:
			cocos2d::log("touch Cancel");
			button->setZOrder(1);
			break;
		default:
			cocos2d::log("touch Default");
			break;
	}
	return;

}
Ejemplo n.º 20
0
void MapMenu1Layer::gameCB( CCObject* pObject )
{
    CCNode *node = (CCNode*)pObject;
    int tag = node->getTag();
    switch (tag) {
        case 1:
            loadCCBFile(1);
            break;
        case 2:
            CCLOG("no yet finished!!");
            break;
        default:
            break;
    }
 

}
Ejemplo n.º 21
0
//------------------------------------------------------------------------------
CCArray*    LHLayer::layersWithTag(int tag){
    
#if COCOS2D_VERSION >= 0x00020000
    CCArray* array = CCArray::create();
#else
    CCArray* array = CCArray::array();
#endif
    
    CCArray* children = getChildren();
    for(int i = 0; i < children->count(); ++i){
        CCNode* node = (CCNode*)children->objectAtIndex(i);

        if(LHLayer::isLHLayer(node)){
            if(node->getTag() == tag)
                array->addObject(node);
        }
    }
    return array;   
}
Ejemplo n.º 22
0
void MainMenuBtnLayer::menucallback(CCObject *_sender)
{
    CCNode *node = (CCNode*) _sender;
    int tag = node->getTag();

    switch (tag)
    {
    case MAINMENU_ID_START:
        GameManager::SharedGameManager().runSceneWithID(SCENE_ID_PLAY, TRANSITION_ID_CROSSFADE, TRANSITION_DURATION);
        break;
    case MAINMENU_ID_SETTING:
        GameManager::SharedGameManager().runSceneWithID(SCENE_ID_SETTINGS);
        break;
    case MAINMENU_ID_ABOUT:
        GameManager::SharedGameManager().runSceneWithID(SCENE_ID_ABOUT);
        break;
    case MAINMENU_ID_QUIT:
        GameManager::SharedGameManager().runSceneWithID(SCENE_ID_QUIT);
        break;
    }
}
Ejemplo n.º 23
0
void DaFeiJi::removeInactiveUnit(float dt) {
        CCNode* selChild = NULL;
		CCArray*  layerChildren = getChildren();
		for (unsigned int i =0 ;i< layerChildren->count();i++) {
            selChild = (CCNode*)layerChildren->objectAtIndex(i);
            if (selChild) {
 //              if( typeof selChild.update == 'function' ) {
					selChild->update(dt);
                    int tag = selChild->getTag();
					printf("tag  = %d \n",tag);
                    if ((tag == PLAYER_TAG) || (tag == PLAYER_BULLET_TAG) ||
                        (tag == ENEMY_TAG) || (tag == ENMEY_BULLET_TAG)) {
						DaFeiJiObjectInterface* selChildInterface = dynamic_cast<DaFeiJiObjectInterface*>(selChild);
                        if (!selChildInterface->isActive()) {
                            selChildInterface->destroy();
                        }
//                  }
                }
            }
        }
    }
Ejemplo n.º 24
0
void PrepareLayer::menuTouch(CCObject *pSender)
{ToolsFun::sharedTools()->playEffect(BUTTON);
CCNode *node = (CCNode*)pSender;
int tag = node->getTag() - 100;
switch(tag)
{
case 0:
	back(pSender);
	break;
case 1:
	showShopLayer(pSender);
	break;
case 2:
	showHeroLayer(pSender);
	break;
case 3:
	heroUp(pSender);
	break;
case 4:
case 5:
	showPetLayer(pSender);
	break;
case 6:
	{
		showShopLayer(pSender);
	}
	break;
case 7:
	//	showShopLayer(pSender);
	startGame(pSender);
	break;
case 8:
	startGame(pSender);
	break;
default:
	break;
}
}
Ejemplo n.º 25
0
//------------------------------------------------------------------------------
CCArray*    LHLayer::spritesWithTag(int tag){
#if COCOS2D_VERSION >= 0x00020000
    CCArray* array = CCArray::create();
#else
    CCArray* array = CCArray::array();
#endif
    
    CCArray* children = getChildren();
    for(int i = 0; i < children->count(); ++i){
        CCNode* node = (CCNode*)children->objectAtIndex(i);
        
        if(LHSprite::isLHSprite(node)){
            if(node->getTag() == tag)
                array->addObject(node);
        }
        else if(LHBatch::isLHBatch(node)){
            array->addObjectsFromArray(((LHBatch*)node)->spritesWithTag(tag));
        }
        else if(LHLayer::isLHLayer(node)){
            array->addObjectsFromArray(((LHLayer*)node)->spritesWithTag(tag));
        }
    }
    return array;       
}
Ejemplo n.º 26
0
void RigidBlock::interationWithOther(b2Body* otherBody)
{
	CCNode *otherNode =(CCNode*) (otherBody->GetUserData());
	CCLog("Interation with %d", otherNode->getTag());
}
Ejemplo n.º 27
0
void ControlLayer::menuCallBackMove(CCObject *pSender)
{
	CCNode *node = (CCNode *)pSender;
	int targetDirection = node->getTag();
	sGlobal->hero->move((HeroDirection)targetDirection);
}
Ejemplo n.º 28
0
//////////////////////////////////////////////////////////////////////////
//update movable objects z order 
//////////////////////////////////////////////////////////////////////////
void LevelLayer::update(float dt)
{
	//m_cameraController.Update(dt);
    CameraController::sharedCameraController()->Update(dt);
    

	for(std::map<unsigned int, WAKL_INFO>::iterator iter = m_walkInfo.begin(); iter != m_walkInfo.end(); iter++)
	{
		if(iter->second.idleTime.time <= iter->second.idleTime.curTime && !iter->second.walk.bUsed)
		{
			iter->second.walk.bUsed = true;
			updateOtherPlayer(iter->second.walk.uid, iter->second.walk.pt, iter->second.walk.animID, iter->second.walk.bFlip);
		}
		else
		{
			iter->second.idleTime.curTime += dt;
			
		}
	}

	while(!LevelManager::sShareInstance()->m_otherPlayerInfo.empty())
	{
		const LevelManager::OTHER_PLAYER_INFO& info = LevelManager::sShareInstance()->m_otherPlayerInfo.top();

		m_levelBuilder->addOtherPlayer(info.uid, info.userName.c_str(), info.type, info.pos, info.orient, info.battleSide);
		LevelManager::sShareInstance()->m_otherPlayerInfo.pop();
	}

	CCArray* children = this->getChildren();
	if (children)
	{
		int childrenCount = children->count();
		for (int i = 0; i < childrenCount; ++i)
		{
			CCNode* child = (CCNode* )children->objectAtIndex(i);
			ASSERT(child != NULL, "child is NULL");

			BaseListener* listener = LevelLayer::sGetListenerByTag(child->getTag());
			if (listener)
			{
				listener->HandleLayerUpdateEvent(child, dt);
			}			
		}
	}

	if(m_pObjectsLayer != NULL)
	{
		children = m_pObjectsLayer->getChildren();
		if (children)
		{
			int childrenCount = children->count();
			for (int i = 0; i < childrenCount; ++i)
			{
				CCNode* child = (CCNode* )children->objectAtIndex(i);
				ASSERT(child != NULL, "child is NULL");

				BaseListener* listener = LevelLayer::sGetListenerByTag(child->getTag());
				if (listener)
				{
					listener->HandleLayerUpdateEvent(child, dt);
				}				
			}
		}
	}

	// update Hero 
	SpriteSeer* hero = GameManager::Get()->getHero();
	if (hero)
	{
		hero->Update(dt);
	}

	//更新其他玩家
	std::map<uint32_t, OthersPlayerInfo>::iterator itor = m_othersPlayerInfo.begin();
	while (itor != m_othersPlayerInfo.end())
	{
		OthersPlayerInfo playerInfo = (*itor).second;

		SpriteSeer * seer = playerInfo.seer;
		if (seer)
		{
			seer->Update(dt);
		}		

		itor++;
	}

	// update ItemUpdatManager
	ItemUpdateManager::Get()->Update(dt);

	// update monster
	SpriteMonsterMgr::Get()->Update(dt);

	// update actor
	EnginePlayerManager::getInstance()->update(dt);

	// Note: Update SpriteElf
	SpriteElfManager::Get()->Update(dt);

	// Note: 剧情Update
	StoryInstanceDirector::Get()->Update(dt);

	//按住屏幕移动持续寻路
	if (pressTime < 0.1f)
	{
		pressTime += dt;
	}
	else if (m_touchWinPoint.x != 0 && m_touchWinPoint.y != 0)
	{
		float deviceScale = CCDirector::sharedDirector()->getContentScaleFactor();
		m_touchWinPoint = CCPoint(m_touchWinPoint.x * deviceScale, m_touchWinPoint.y * deviceScale);
    
		CCPoint newPT = LevelMultiResolution::sTransformWindowPointToMap(m_touchWinPoint);

		SpriteSeer * hero = GameManager::Get()->getHero();
		if (hero)
		{
			BaseListener* listener = LevelLayer::sGetListenerByTag(hero->getTag());
			if (listener)
			{
				listener->HandleLayerTouchBeginEvent(hero, newPT);
			}			
		}
		pressTime = 0.0f;
	}

	SkillDispMgr::Get()->Update(dt);

	PvAIManager::Get()->Update(dt);

}