Пример #1
0
//-----------------------------
//
//
void CMiniGameCatchLayer::UpDataTime( ccTime dt )
{
    m_iTime--;
    if( m_iTime <= 0 )
    {
        m_iTime = 0;
    }
    int height = m_pTimeSprite->getTextureRect().size.height;
    CCRect rect( 0, 0, ( (float)m_iTime / (float)m_iMaxTime ) * m_iTimeBar, height );
    if( NULL != m_pTimeSprite )
    {
        m_pTimeSprite->setTextureRect( rect );
    }
    
    if( m_iTime <= 0 && !m_bIsFinish)
    {
		m_bIsFinish = true;
		if( CCUserDefault::sharedUserDefault()->getBoolForKey( "sound" ) )
		{
			CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("data/audio/time_up.mp3", false);
		}

		AdvanceSprite *pAdv = new AdvanceSprite();
		pAdv->addFramesFromiT2D( "time_up.plist" );
		pAdv->autorelease();
		addChild( pAdv, 100 );

		int timeup[] = { 0,3,2 };
		pAdv->PlayAnimation( timeup, 1, NULL, this, false, true );
		CCSize size = CCDirector::sharedDirector()->getWinSize();
		pAdv->setPosition( ccp( size.width/2, size.height/2 ) );

		schedule( schedule_selector( CMiniGameCatchLayer::Finsh ), 3.0f ); 
    }
    
}
Пример #2
0
//------------------------------------------------------------------------
//
//
void CFightGroundLayer::CreatPlayer()
{
	//CBaseDataPet *pBaseDataPet = g_pClientLoader->GetBaseDataPetFromId(1);

	CBaseDataAnimation *pAnimationData = g_pClientLoader->GetBaseDataAnimationFromId(g_pPetDataBlock->ResId);

	if( NULL != pAnimationData )
	{
		CBaseDataPet *pPetBaseData = g_pClientLoader->GetBaseDataPetFromId( g_pPetDataBlock->petid );

		m_pPetLeft = new CPet();
		m_pPetLeft->init();
		m_pPetLeft->autorelease();
		m_pPetLeft->setSitId( FIGHT_LEFT_PLAYER_POS );
		m_pPetLeft->setFlipX( true );
		
		//PetDatablock *petdata = new PetDatablock();    
		//petdata->petName		= "petName1";
		//petdata->Agility		= 10;
		//petdata->hp			= 100;
		//petdata->MaxHp		= 100;
		//petdata->Damage		= 10;
		//petdata->ResId		= g_pPetDataBlock->ResId;

		m_pPetLeft->setPetDataBlock(g_pPetDataBlock);
		m_pPetLeft->addFramesFromiT2D( pAnimationData->m_strPlist.c_str(), pAnimationData->m_iPlistType );
		m_pPetLeft->PlayAnimation( pAnimationData->m_stand, -1,NULL,this, false, false );

		m_pPetLeft->setTurnEndCallBack( this, callfuncND_selector( CFightGroundLayer::FightTurnOverCallBack ), NULL );

		CCNode* pNode = GetXMLNodeFromKey( "t2dSceneObject_player1_pos" );
		m_pPetLeft->setPosition( pNode->getPosition() );
		pNode = GetXMLNodeFromKey( "t2dSceneObject_player1_attack" );
		m_pPetLeft->setTargetPosition( pNode->getPosition() );
		addChild( m_pPetLeft, MAXTORQUELAYERNUM );
	}

    CBaseDataPet* pPetBaseData = g_pClientLoader->GetBaseDataPetFromId( CSelectEnemyScene::s_pPetDataBlock->petid );
	CBaseDataAnimation *pAnimationData2 = g_pClientLoader->GetBaseDataAnimationFromId(pPetBaseData->animationid);

	if( NULL != pAnimationData2 )
	{
		m_pPetRight = new CPet();
		m_pPetRight->init();
		m_pPetRight->autorelease();
		m_pPetRight->setSitId( FIGHT_RIFHT_PLAYER_POS );

		m_pPetRight->setPetDataBlock(CSelectEnemyScene::s_pPetDataBlock);
    
		m_pPetRight->addFramesFromiT2D( pAnimationData2->m_strPlist.c_str(), pAnimationData2->m_iPlistType );
		m_pPetRight->PlayAnimation( pAnimationData2->m_stand, -1,NULL,this, false, false );

		m_pPetRight->setTurnEndCallBack( this, callfuncND_selector( CFightGroundLayer::FightTurnOverCallBack ), NULL );

		m_pPetRight->setFlipX( false );

		CCNode* pNode = GetXMLNodeFromKey( "t2dSceneObject_player2_pos" );
		m_pPetRight->setPosition( pNode->getPosition() );

		pNode = GetXMLNodeFromKey( "t2dSceneObject_player2_attack" );
		m_pPetRight->setTargetPosition( pNode->getPosition() );

		addChild( m_pPetRight, MAXTORQUELAYERNUM );
	}
	schedule(schedule_selector(CFightGroundLayer::upData),0.1f);

	m_pPetLeft->setLockTarget( m_pPetRight );
	m_pPetRight->setLockTarget( m_pPetLeft );

/*************************************player1Hp&Mp****************************************/
	m_pPlayer1Hp = new CCSprite();
	m_pPlayer1Hp->init();
    
    string path = GetGameImagesPath();
    path = path + "fight_lefthp.png";
    m_pPlayer1Hp->initWithFile(path.c_str());
	//ccColor3B ccRED={255,0,0};
    //m_pPlayer1Hp->setColor( ccRED );
	m_pPlayer1Hp->autorelease();
	m_pPlayer1Hp->setAnchorPoint( ccp( 0,0 ) );
	addChild( m_pPlayer1Hp, MAXTORQUELAYERNUM );

	CCNode* pNode = GetXMLNodeFromKey( "t2dSceneObject_player1hpbar" );

	m_iMaxHpBar = m_pPlayer1Hp->getTextureRect().size.width;
	m_iMaxHpHeight = m_pPlayer1Hp->getTextureRect().size.height;
	m_pPlayer1Hp->setPosition( ccp( pNode->getPosition().x - m_iMaxHpBar / 2, pNode->getPosition().y - m_iMaxHpHeight / 2 ) );
	m_pPlayer1Hp->setTextureRect( CCRectMake(0, 0, m_iMaxHpBar,m_iMaxHpHeight) );
	m_iHpInitPos = m_pPlayer1Hp->getPosition().x;
	
	m_pPlayer1Mp = new CCSprite();
	m_pPlayer1Mp->init();
	//ccColor3B ccBlue={0,0,255};
	//m_pPlayer1Mp->setColor( ccBlue );
    path = GetGameImagesPath();
    path = path + "fight_leftmp.png";
    m_pPlayer1Mp->initWithFile(path.c_str());
    
	m_pPlayer1Mp->autorelease();
	m_pPlayer1Mp->setAnchorPoint( ccp( 0,0 ) );
	addChild( m_pPlayer1Mp, MAXTORQUELAYERNUM );

	pNode = GetXMLNodeFromKey( "t2dSceneObject_player1MpBar" );

	m_iMaxMpBar		= m_pPlayer1Mp->getTextureRect().size.width;
	m_iMaxMpHeight	= m_pPlayer1Mp->getTextureRect().size.height;
	m_pPlayer1Mp->setPosition( ccp( pNode->getPosition().x - m_iMaxMpBar / 2, pNode->getPosition().y - m_iMaxMpHeight / 2 ) );
	m_pPlayer1Mp->setTextureRect( CCRectMake(0, 0, m_iMaxMpBar,m_iMaxMpHeight) );

	m_iMpInitPos = m_pPlayer1Mp->getPosition().x;

/*************************************player2Hp&Mp****************************************/
	m_pPlayer2Hp = new CCSprite();
	m_pPlayer2Hp->init();
    
    path = GetGameImagesPath();
    path = path + "fight_righthp.png";
    m_pPlayer2Hp->initWithFile(path.c_str());
    
	m_pPlayer2Hp->autorelease();
	m_pPlayer2Hp->setAnchorPoint( ccp( 0,0 ) );
	addChild( m_pPlayer2Hp, MAXTORQUELAYERNUM );

	pNode = GetXMLNodeFromKey( "t2dSceneObject_player2hpbar" );

	m_iMaxHpBar =  m_pPlayer2Hp->getTextureRect().size.width;
	m_iMaxHpHeight = m_pPlayer2Hp->getTextureRect().size.height;
	m_pPlayer2Hp->setPosition( ccp( pNode->getPosition().x - m_iMaxHpBar / 2, pNode->getPosition().y - m_iMaxHpHeight / 2 ) );
	m_pPlayer2Hp->setTextureRect( CCRectMake(0, 0, m_iMaxHpBar,m_iMaxHpHeight) );

	m_pPlayer2Mp = new CCSprite();
	m_pPlayer2Mp->init();
    path = GetGameImagesPath();
    path = path + "fight_rightmp.png";
    m_pPlayer2Mp->initWithFile(path.c_str());
	m_pPlayer2Mp->setAnchorPoint( ccp( 0,0 ) );
	addChild( m_pPlayer2Mp, MAXTORQUELAYERNUM );

	pNode = GetXMLNodeFromKey( "t2dSceneObject_player2MpBar" );

	m_iMaxMpBar		=  m_pPlayer2Mp->getTextureRect().size.width;
	m_iMaxMpHeight	=  m_pPlayer2Mp->getTextureRect().size.height;
	m_pPlayer2Mp->setPosition( ccp( pNode->getPosition().x - m_iMaxMpBar / 2, pNode->getPosition().y - m_iMaxMpHeight / 2 ) );
	m_pPlayer2Mp->setTextureRect( CCRectMake(0, 0, m_iMaxMpBar,m_iMaxMpHeight) );
/****************************************************************************************/
   
	pNode = GetXMLNodeFromKey( "player1NameBg" );

	m_pLeftPetName  = CCLabelTTF::labelWithString( "10000",kFontSystem[FONT_TINY].fontName,kFontSystem[FONT_TINY].fontSize);
	m_pLeftPetName->setColor( ccWhite );
    
	m_pLeftPetName->setString( m_pPetLeft->GetPetData()->petName.c_str() );
	m_pLeftPetName->setPosition( pNode->getPosition());
    addChild( m_pLeftPetName,MAXTORQUELAYERNUM );

	pNode = GetXMLNodeFromKey( "player2NameBG" );

	m_pRightPetName = CCLabelTTF::labelWithString( "10000",kFontSystem[FONT_SMALL].fontName,kFontSystem[FONT_TINY].fontSize);
	m_pRightPetName->setColor( ccWhite );
	m_pRightPetName->setString( m_pPetRight->GetPetData()->petName.c_str() );
	m_pRightPetName->setPosition( pNode->getPosition());
	addChild( m_pRightPetName,MAXTORQUELAYERNUM );
    
    CCSprite *pSprite= (CCSprite*)GetXMLNodeFromKey( "button_back" );
    CCMenu *pMenu = CreatGameUIWithSprite( pSprite, menu_selector(CFightGroundLayer::menuCallback), 0, this, pSprite->getPosition() );
    removeChild( pSprite, true );
    addChild( pMenu, pSprite->getZOrder() );
    
    std::string effectpath = GetGameParticlePath();
    std::string filename = effectpath + "Glitter.plist";
    CCParticleSystemQuad *pEmitter = CCParticleSystemQuad::particleWithFile( filename.c_str() );
    //m_emitter->setPositionType( kCCPositionTypeRelative );
    pEmitter->setPosition( getPosition() );
    CCPoint pos = getPosition();
    addChild( pEmitter, 100 );
    
    AdvanceSprite *pAdv = new AdvanceSprite();
    pAdv->addFramesFromiT2D( "battlenow.plist" );
    pAdv->autorelease();
    addChild( pAdv, 100 );
    
    m_pBattlenow = pAdv;
    
    int battleNow[] = { 0,2,1 };
    pAdv->PlayAnimation( battleNow, 1, callfunc_selector(CFightGroundLayer::FightBegin), this, false, true );
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    pAdv->setPosition( ccp( size.width/2, size.height/2 ) );

	if( CCUserDefault::sharedUserDefault()->getBoolForKey( "sound" ) )
	{
		CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("data/audio/Battlenow.mp3", false);
	}
}