Exemplo n.º 1
0
void GameLayer::showTutorialLayer()
{
    CCArray *stringArray = CCArray::create(
                                           ccs("test1.png"),
                                           ccs("test2.png"),
                                           NULL);
    TutorialLayer* tutotialLayer = new TutorialLayer(stringArray, this);
    tutotialLayer->setPosition(Point(0, 0));
    this->addChild(tutotialLayer);
}
void MessageWindowSprite::setLabelString(CCString LabelStr)
{
    std::string MessageStr = LabelStr.getCString();
    
    int     pos;
    unsigned char   lead;
    int     charSize = 0;
   
    CCString*   MessageCCString;
    CCArray*    MessageCCArrary = new CCArray;
    
    for (pos=0; pos < MessageStr.size() ; pos += charSize) {
        
        //UTF-8の文字サイズ判別
        lead = MessageStr[pos];
        if (lead < 0x80) {
            charSize = 1;
        } else if (lead < 0xE0) {
            charSize = 2;
        } else if (lead < 0xF0) {
            charSize = 3;
        } else {
            charSize = 4;
        }
       
        //UTF-8の文字を一文字づつ切り出してCCArrayに格納
        MessageCCString = ccs(MessageStr.substr(pos,charSize).c_str());
        MessageCCArrary->addObject(MessageCCString);
    
    }
    //メンバ変数にセット
    MessageStrCCArray = MessageCCArrary;
}
Exemplo n.º 3
0
KDbool AppDelegate::applicationDidFinishLaunching ( KDvoid )
{
	CCSize		tDesignSize = CCEGLView::sharedOpenGLView ( )->getFrameSize ( );

	tDesignSize = ccs ( 480, 320 );

	// Initialize Resolution
	CCEGLView::sharedOpenGLView ( )->setDesignResolutionSize ( tDesignSize, kResolutionExactFit );

	// Initalize Frame rate and debug display
	CCDirector::sharedDirector ( )->setAnimationInterval ( 1 / 60.0 );
//	CCDirector::sharedDirector ( )->setDisplayStats ( KD_TRUE );

    std::vector<std::string>	aPaths;
	aPaths.push_back ( "Fonts" );
	aPaths.push_back ( "Images" );
	aPaths.push_back ( "Sounds" );
	
	CCFileUtils::sharedFileUtils ( )->setSearchPaths ( aPaths );

	// Initialize Scene
	CCDirector::sharedDirector ( )->runWithScene ( IntroLayer::scene ( ) );

	return KD_TRUE;
}
Exemplo n.º 4
0
KDbool AppDelegate::applicationDidFinishLaunching ( KDvoid )
{
	// Initialize Resolution
	CCEGLView::sharedOpenGLView ( )->setDesignResolutionSize ( ccs ( 480, 320 ), kResolutionExactFit );

	// Initalize Frame rate and debug display
	CCDirector::sharedDirector ( )->setAnimationInterval ( 1 / 60.0 );
	CCDirector::sharedDirector ( )->setDisplayStats ( KD_TRUE );

    std::vector<std::string>	aPaths;
	aPaths.push_back ( "Data" );
	aPaths.push_back ( "Data Model" );
	aPaths.push_back ( "Images" );	
	aPaths.push_back ( "Fonts" );
	aPaths.push_back ( "Etc" );
	aPaths.push_back ( "Tilemaps" );
	aPaths.push_back ( "CocosBuilder" );
	aPaths.push_back ( "Music" );
	aPaths.push_back ( "Sounds" );
	
	CCFileUtils::sharedFileUtils ( )->setSearchPaths ( aPaths );

	// Initialize Scene
	CCDirector::sharedDirector ( )->runWithScene ( RecipeList::scene ( ) );

	return KD_TRUE;
}
Exemplo n.º 5
0
void LotteryRotateView::playAnimation(int useMoney,int rotateType/* = 0*/)
{
    m_rewardsContainer->removeAllChildren();
    //设置转动类型 0-普通,1-连转10次
    LotteryController::shared()->rotateType = rotateType;
    m_startAddCnt1 = 0;
    m_startAddCnt2 = 0;

//    CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(LOTTERYACTVIEW_SEND, CCString::createWithFormat("%d", useMoney));
    CCDictionary* dict = CCDictionary::create();
    dict->setObject(ccs(LOTTERYACTVIEW_SEND), "key");
    dict->setObject(CCString::createWithFormat("%d", useMoney), "value");
    int direction = 0;//0为顺时针
    if (m_tScrollAngel > 0)
    {
        direction = 1;
    }
    dict->setObject(CCString::createWithFormat("%d", direction), "value1");
    CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(LOTTERYROTATEVIEW, dict);
    
    m_hasGetReward = false;
    m_rotating = true;
    
    //    setRotationAngle(0);
    m_rotateAngle = 0;
    m_ftimeGap4 = 0.0f;
    m_fTimeGap3 = 1.0f/24.0f;
    m_isSendNotify0 = false;
    m_isSendNotify1 = false;
    this->schedule(schedule_selector(LotteryRotateView::rotatingHandler), m_fTimeGap3);
}
Exemplo n.º 6
0
bool CCControlButtonTest_HelloVariableSize::init()
{
    if (CCControlScene::init())
    {
        CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
        
        // Defines an array of title to create buttons dynamically
        CCArray *stringArray = CCArray::create(
            ccs("Hello"),
            ccs("Variable"),
            ccs("Size"),
            ccs("!"),
            NULL);
        
        CCNode *layer = CCNode::create();
        addChild(layer, 1);
        
        double total_width = 0, height = 0;
        
        // For each title in the array
        CCObject* pObj = NULL;
        CCARRAY_FOREACH(stringArray, pObj)
        {
            CCString* title = (CCString*)pObj;
            // Creates a button with this string as title
            CCControlButton *button = standardButtonWithTitle(title->getCString());
            button->setPosition(ccp (total_width + button->getContentSize().width / 2, button->getContentSize().height / 2));
            layer->addChild(button);
            
            // Compute the size of the layer
            height = button->getContentSize().height;
            total_width += button->getContentSize().width;
        }

        layer->setAnchorPoint(ccp (0.5, 0.5));
        layer->setContentSize(CCSizeMake(total_width, height));
        layer->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f));
        
        // Add the black background
        CCScale9Sprite *background = CCScale9Sprite::create("extensions/buttonBackground.png");
        background->setContentSize(CCSizeMake(total_width + 14, height + 14));
        background->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f));
        addChild(background);
        return true;
    }
KDvoid CCTransitionPageTurn::onEnter ( KDvoid )
{
	CCTransitionScene::onEnter ( );

	const CCSize&   tSize = CCDirector::sharedDirector ( )->getWinSize ( );
	KDint			x, y;

	if ( tSize.cx > tSize.cy )
	{
		x = 16;
        y = 12;
	}
	else
	{
		x = 12;
        y = 16;
	}

	CCActionInterval*  pAction = this->actionWithSize ( ccs ( x, y ) );

	if ( !m_bBackwards )
	{
		m_pOutScene->runAction
		(
			CCSequence::create
			(
				pAction,
				CCCallFunc::create ( this, callfunc_selector ( CCTransitionScene::finish ) ),
				CCStopGrid::create ( ),
				KD_NULL
			)
		);
	}
	else
	{
		// to prevent initial flicker
		m_pInScene->setVisible ( KD_FALSE );
		m_pInScene->runAction
		(
			CCSequence::create
			(
			    CCShow::create ( ),
				pAction,
				CCCallFunc::create ( this, callfunc_selector ( CCTransitionScene::finish ) ),
				CCStopGrid::create ( ),
				KD_NULL
			)
		);
	}
}
Exemplo n.º 8
0
KDbool TestList::init ( KDvoid )
{
	if ( !CCLayer::initWithVisibleViewport ( ) )
	{
		return KD_FALSE;
	}

	const CCSize&  tLyrSize = this->getContentSize ( );

	CCLayerGradient*  pBG = CCLayerGradient::create ( ccc4 ( 52, 84, 236, 200 ), ccc4 ( 149, 0, 202, 200 ) );
	pBG->setContentSize ( tLyrSize );
	this->addChild ( pBG, -10 );

	CCSprite*  pBottomLeft = CCSprite::create ( "ccb/jungle-left.png" );
	this->addChild ( pBottomLeft, 10 );
	pBottomLeft->setScale ( 1.5f );
	pBottomLeft->setOpacity ( 210 );
	pBottomLeft->setPositionWithParent ( kCCAlignmentBottomLeft );

	CCSprite*  pBottomRight = CCSprite::create ( "ccb/jungle-right.png" );
	this->addChild ( pBottomRight, 10 );
	pBottomRight->setScale ( 1.5f );
	pBottomRight->setOpacity ( 210 );
	pBottomRight->setPositionWithParent ( kCCAlignmentBottomRight );

	CCMenuItemImage*  pQuit = CCMenuItemImage::create
	(
		"xm_supports/CloseNormal.png", "xm_supports/CloseSelected.png", this, menu_selector ( TestList::onQuit ) 
	);
	pQuit->setScale ( 1.2f );
	pQuit->setPosition ( this, kCCAlignmentTopRight, ccp ( 10, 10 ) );
	this->addChild ( CCMenu::createWithItem ( pQuit ), 10 ); 

	CCTableView*  pTableView = CCTableView::create ( this, ccs ( tLyrSize.cx, tLyrSize.cy - 20.f ) );
	this->addChild ( pTableView );
	pTableView->setDelegate   ( this );	
	pTableView->setDataSource ( this );
	pTableView->setPosition   ( ccp ( 0, 10 ) );

	if ( s_tPrevPosition.x != -1 )
	{
		pTableView->setContentOffset ( s_tPrevPosition );
	}
	
	CCMenuItemFont::setFontSize ( 30 );
	CCMenuItemFont::setFontName ( "fonts/ThonburiBold.ttf" );

	return KD_TRUE;
}
Exemplo n.º 9
0
void TestFeedBackView::onOkClick(cocos2d::CCObject *pSender, CCControlEvent event)
{
//    if (TESTFEEDBACK_CONTROL->getServerId().length() == 0 || TESTFEEDBACK_CONTROL->getName().length() == 0 ||  TESTFEEDBACK_CONTROL->getServerId() == "0")
//    {
//        CCCommonUtils::flyHint("", "", "请输入服务器号和名字");//todocfb
//        return;
//    }
    //////////点确认按钮单独传递玩家的服务器号和名字,反馈内容在每次填写完面板后已经向后台传递完成
    CCObject* obj = NULL;
    CCDictionary* pelem = NULL;
    CCARRAY_FOREACH(m_data, obj)
    {
        pelem = (CCDictionary*)obj;
        pelem->setObject(ccs("1"), "fixFlag");
        break;//所以只需要每其中一项理性“fixFlag”即可
    }
Exemplo n.º 10
0
void CommonNotify::registerNotify()
{
	CCArray* nameList = CCArray::create(
		ccs(kVCLevelUp),
		ccs(kVCBuyMoney),
		ccs(kNCVersionError),
		ccs(kVCSellEquip),
		ccs(kNCNetError),
		ccs(kNCSellEquipage),
		NULL);
	RegisterObservers(this, nameList, callfuncO_selector(CommonNotify::_onNotification)); 
}
Exemplo n.º 11
0
KDbool AppDelegate::applicationDidFinishLaunching ( KDvoid )
{
	// Initialize Resolution
	CCEGLView::sharedOpenGLView ( )->setDesignResolutionSize ( ccs ( 768, 1024 ), kResolutionExactFit );

	// Initalize Frame rate and debug display
	CCDirector::sharedDirector ( )->setAnimationInterval ( 1 / 60.0 );
//	CCDirector::sharedDirector ( )->setDisplayStats ( KD_TRUE );

    std::vector<std::string>	aPaths;
	aPaths.push_back ( "Graphics" );
	aPaths.push_back ( "Fonts" );
	aPaths.push_back ( "Audio" );
	aPaths.push_back ( "Levels" );
	
	CCFileUtils::sharedFileUtils ( )->setSearchPaths ( aPaths );

	// Initialize Scene
	CCDirector::sharedDirector ( )->runWithScene ( Intro::scene ( ) );

	return KD_TRUE;
}
Exemplo n.º 12
0
void LotteryRotateView::rotateFinished()
{
    if (m_rotating == false || m_targetCell == NULL)
    {
        m_rotating = false;
        this->unschedule(schedule_selector(LotteryRotateView::rotatingHandler));
        return;
    }
    this->unschedule(schedule_selector(LotteryRotateView::rotatingHandler));
    m_rotating = false;
    m_rotateAngle = m_fEndAngle;
    if (m_rotateAngle>0)
    {
        m_rotateAngle = fmodf(m_rotateAngle, 360.0f);
    }
    else
    {
        m_rotateAngle = fmodf(m_rotateAngle, -360.0f);
    }
    CCDictionary* dict = CCDictionary::create();
    dict->setObject(ccs(LOTTERYACTVIEW_COM), "key");
    CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(LOTTERYROTATEVIEW, dict);
}
Exemplo n.º 13
0
void Datagram_Handshake_IO::retransmit_flight(size_t flight_idx)
   {
   const std::vector<uint16_t>& flight = m_flights.at(flight_idx);

   BOTAN_ASSERT(flight.size() > 0, "Nonempty flight to retransmit");

   uint16_t epoch = m_flight_data[flight[0]].epoch;

   for(auto msg_seq : flight)
      {
      auto& msg = m_flight_data[msg_seq];

      if(msg.epoch != epoch)
         {
         // Epoch gap: insert the CCS
         std::vector<uint8_t> ccs(1, 1);
         m_send_hs(epoch, CHANGE_CIPHER_SPEC, ccs);
         }

      send_message(msg_seq, msg.epoch, msg.msg_type, msg.msg_bits);
      epoch = msg.epoch;
      }
   }
Exemplo n.º 14
0
void IllegalWord::init(string name /*= "cfg/illegalWords.xml"*/)
{
	if (!isInit)
	{
		unsigned char* pBuffer = NULL;
		unsigned long bufferSize = 0;
		//先将xml读入buffer
		pBuffer = CCFileUtils::sharedFileUtils()->getFileData(name.c_str(), "r", &bufferSize);
		wordArr = CCArray::create();
		wordArr->retain();
		doc = new tinyxml2::XMLDocument();
		doc->Parse((const char*)pBuffer);
		rootElement = doc->RootElement();
		XMLElement *element = rootElement->FirstChildElement();
		while (element)
		{
			CCString* node = ccs(element->Attribute("name"));
			wordArr->addObject(node);
			element = element->NextSiblingElement();
		}
		isInit = true;
		delete doc;
	}
}
KDbool Ch1_ColoringSprites::init ( KDvoid )
{	
	if ( !Recipe::init ( ) )
	{
		return KD_FALSE;
	}

	this->initButtons ( );

	// The Fade Scene Sprite
	CCSprite*	pFadeSprite = CCSprite::create ( "blank.png" );
	pFadeSprite->setOpacity ( 0 );
	pFadeSprite->setPosition ( ccp ( 240, 160 ) );
	pFadeSprite->setTextureRect ( CCRect ( 0, 0, 480, 320 ) );
	this->addChild ( pFadeSprite, 3, TAG_FADE_SPRITE );
	
	// Draw the sky using blank.png
	this->drawColoredSpriteAt ( ccp ( 240, 190 ), CCRect ( 0, 0, 480, 260 ), ccc3 ( 150, 200, 200 ), 0 );

	// Draw the sun
	CCSprite*	pSun = CCSprite::create ( "fire.png" );
	pSun->setPosition ( ccp ( 50, 230 ) );
	pSun->setScale ( 3.0f );
	pSun->setColor ( ccc3 ( 255, 255, 0 ) );
	this->addChild ( pSun, 0, TAG_SUN_BG );	

	// Draw some mountains in the background
	CCSprite*	pMountains = CCSprite::create ( "mountains.png" );
	pMountains->setPosition ( ccp ( 250, 200 ) );
	pMountains->setScale ( 0.6f );
	this->addChild ( pMountains, 0, TAG_MOUNTAIN_BG );

	// Add a gradient below the mountains
	CCLayerGradient*	pGroundGradient = CCLayerGradient::create ( ccc4 ( 61, 33, 62, 255 ), ccc4 ( 65, 89, 54, 255 ), ccp ( 0, -1 ) );
	pGroundGradient->setContentSize ( ccs ( 480, 100 ) );
	pGroundGradient->setPosition ( ccp ( 0, 50 ) );
	this->addChild ( pGroundGradient, 0, TAG_GROUND_GRADIENT );

	// Add a sinister red glow gradient behind the evil samurai
	CCLayerGradient*	pRedGradient = CCLayerGradient::create ( ccc4 ( 0, 0, 0, 0 ), ccc4 ( 255, 0, 0, 100 ), ccp ( 1, 0 ) );
	pRedGradient->setContentSize ( ccs ( 200, 200 ) );
	pRedGradient->setPosition ( ccp ( 280, 60 ) );
	this->addChild ( pRedGradient, 0, TAG_RED_GRADIENT );
	
	// Draw dramatic movie bars
	this->drawColoredSpriteAt ( ccp ( 240, 290 ), CCRect ( 0, 0, 480, 60 ), ccc3 ( 0, 0, 0 ), 2 ); 
	this->drawColoredSpriteAt ( ccp ( 240,  30 ), CCRect ( 0, 0, 480, 60 ), ccc3 ( 0, 0, 0 ), 2 ); 

	// Draw the good samurai
	CCSprite*	pGoodSamurai = CCSprite::create ( "samurai_good.png" );
	pGoodSamurai->setAnchorPoint ( ccp ( 0.5f, 0 ) );
	pGoodSamurai->setPosition ( ccp ( 100, 70) );
	pGoodSamurai->setScale ( 0.5f );
	this->addChild ( pGoodSamurai, 1, TAG_GOOD_SAMURAI );

	// Draw the evil samurai
	CCSprite*	pEvilSamurai = CCSprite::create ( "samurai_evil.png" );
	pEvilSamurai->setAnchorPoint ( ccp ( 0.5f, 0 ) );
	pEvilSamurai->setPosition ( ccp ( 370, 70) );
	pEvilSamurai->setFlipX ( KD_TRUE );
	pEvilSamurai->setScale ( 0.5f );
	this->addChild ( pEvilSamurai, 1, TAG_BAD_SAMURAI );

	// Make the swords glow
	this->glowAt ( ccp ( 230, 280 ), CCSize ( 3.0f, 11.0f ), ccc3 ( 0, 230, 255 ),  45.0f, pGoodSamurai );
	this->glowAt ( ccp (  70, 280 ), CCSize ( 3.0f, 11.0f ), ccc3 ( 255, 200, 2 ), -45.0f, pEvilSamurai );	

	return KD_TRUE;
}
Exemplo n.º 16
0
CppSQLite3DB* StoreDatabase::prepare()
{
    return StoreDatabase::prepare(ccs(""));
}
//--------------------------------------------------------
ccColor3B CListControllerLayer::_GetColorByName(std::string p_szName)
{
	CCArray a;
	a.addObjectsFromArray( &FKCW_Base_Utils::ComponentOfString(p_szName, '_') );
	if( a.count() >= 3 )
	{
		CCString* FKCWHead = (CCString*)a.objectAtIndex(0);
		CCString* SmallType = (CCString*)a.objectAtIndex(1);
		if(! FKCWHead->isEqual(ccs("FKCW")) )
			return ccc3(225,238,210);

		if(SmallType->isEqual(ccs("UI")))
			return ccc3(230, 155, 3);
		else if(SmallType->isEqual(ccs("Action")))
			return ccc3(209, 73, 78);
		else if(SmallType->isEqual(ccs("UIWidget")))
			return ccc3(131, 175, 155);
		else if(SmallType->isEqual(ccs("Base")))
			return ccc3(249, 205, 173);
		else if(SmallType->isEqual(ccs("EffectNode")))
			return ccc3(175, 215, 237);
		else if(SmallType->isEqual(ccs("RenderEx")))
			return ccc3(175, 18, 88);
		else if(SmallType->isEqual(ccs("GR")))
			return ccc3(130, 57, 53);
		else if(SmallType->isEqual(ccs("Database")))
			return ccc3(160, 191, 124);
		else if(SmallType->isEqual(ccs("Network")))
			return ccc3(255, 252, 153);
		else if(SmallType->isEqual(ccs("Json")))
			return ccc3(87, 105, 60);
		else if(SmallType->isEqual(ccs("Font")))
			return ccc3(230, 155, 3);
		else if(SmallType->isEqual(ccs("SimpleNet")))
			return ccc3(209, 73, 78);
		else if(SmallType->isEqual(ccs("SceneEx")))
			return ccc3(175, 215, 237);
		else if(SmallType->isEqual(ccs("3D")))
			return ccc3(64, 116, 52);
		else if(SmallType->isEqual(ccs("RichHtml")))
			return ccc3(249, 205, 173);
		else if(SmallType->isEqual(ccs("Story")))
			return ccc3(131, 175, 155);
		else if(SmallType->isEqual(ccs("Pixel")))
			return ccc3(175, 18, 88);
	}
	return ccc3(225,238,210);
}
KDbool Ch4_TopDownIsometric::init ( KDvoid )
{	
	if ( !GameArea2D::init ( ) )
	{
		return KD_FALSE;
	}

	m_tGameAreaSize = ccs ( 2000, 1200 );

	m_pMessage->setString ( "Press A to jump. \nPress B to fire bouncy balls. \nPinch to zoom." );
			
	// Initialization
	m_pBalls = new CCArray ( );
	m_pTrees = new CCArray ( );
	m_fAnimCount = 0;
	
	m_fCameraZoom = 1.0f;
	m_fLastMultiTouchZoomDistance = 0.0f;
	m_tLastPressedVector = ccp ( 1, 0 );
	m_fFireCount = 0;
	m_nGunmanDirection = RIGHT;
	m_pButtons = new CCArray ( );
	
	// Special isometric gravity and contact listener
	m_pWorld->SetGravity ( b2Vec2 ( 0, 0 ) );
	m_pWorld->SetContactListener ( new IsometricContactListener );

	// Iso debug drawing
	CC_SAFE_DELETE ( m_pDebugDraw );
	m_pDebugDraw = new CCBox2DDebugDraw ( PTM_RATIO, PERSPECTIVE_RATIO, m_tGameAreaSize );
	m_pWorld->SetDebugDraw ( m_pDebugDraw );

	// Initialize gunman
	CCSpriteFrameCache*		pCache = CCSpriteFrameCache::sharedSpriteFrameCache ( );
	pCache->addSpriteFramesWithFile ( "gunman.plist" );
	this->initGunman ( );

	//Initialize DPad
	pCache->addSpriteFramesWithFile ( "dpad_buttons.plist" );
	m_pDPad = DPad::create ( );
	m_pDPad->setPosition ( ccp ( 75, 75 ) );
	m_pDPad->setOpacity ( 100 );
	this->addChild ( m_pDPad, 5 );

	// Create buttons		
	this->createButtonWithPosition ( ccp ( 340, 75 ), "b_button_up.png", "b_button_down.png", "B" );
	this->createButtonWithPosition ( ccp ( 420, 75 ), "a_button_up.png", "a_button_down.png", "A" );

	// This sets off a chain reaction
	this->animateGunman ( );
	
	// Add ground texture
	this->addGroundTexture ( );
	
	// Add trees
	for ( KDint i = 0; i < 20; i++ )
	{
		this->addTreeAtPoint 
		(
			ccp ( kdRand ( ) % ( (KDint) m_tGameAreaSize.cx - 200 ) + 100, kdRand ( ) % ( (KDint) m_tGameAreaSize.cy - 200 ) + 100 ) 
		);
	}
	
	// Add walls 
	
	// Horizontal
	for ( KDint i = 0; i < 10; i++ )
	{
		KDfloat		fLength = kdRand ( ) % 50 + 50.f;
		KDfloat		x = kdRand ( ) % ( (KDint) ( m_tGameAreaSize.cx - fLength * 8 ) ) + fLength * 4;
		KDfloat		y = kdRand ( ) % ( (KDint) m_tGameAreaSize.cy - 400 ) + 200.f;
		KDfloat		fHeight = kdRand ( ) % 200 * 1.f;
		this->addBrickWallFrom ( ccp ( x - fLength, y ), ccp ( x + fLength, y ), fHeight );
	}
	
	// Vertical
	for ( KDint i = 0; i < 10; i++ )
	{
		KDfloat		fLength = kdRand ( ) % 100 * 1.f;
		KDfloat		y = kdRand ( ) % ( (KDint) ( m_tGameAreaSize.cy - fLength * 8 ) ) + fLength * 4;
		KDfloat		x = kdRand ( ) % ( (KDint) m_tGameAreaSize.cx - 400 ) + 200.f;
		KDfloat		fHeight = kdRand ( ) % 50 + 50.f;
		this->addBrickWallFrom ( ccp ( x, y - fLength ), ccp ( x, y + fLength ), fHeight );
	}
	
	// Level Boundaries
	this->addBrickWallFrom ( ccp ( 150, 150 ), ccp ( m_tGameAreaSize.cx - 150, 150 ), 100.0f );
	this->addBrickWallFrom ( ccp ( 150, 150 ), ccp ( 150, m_tGameAreaSize.cy - 150 ), 100.0f );
	this->addBrickWallFrom ( ccp ( 150, m_tGameAreaSize.cy - 150 ), ccp ( m_tGameAreaSize.cx - 150, m_tGameAreaSize.cy - 150 ), 100.0f );
	this->addBrickWallFrom ( ccp ( m_tGameAreaSize.cx - 150, 150 ), ccp ( m_tGameAreaSize.cx - 150, m_tGameAreaSize.cy - 150 ), 100.0f );

	return KD_TRUE;
}
KDbool Ch7_SideScrollingPathfinding::init ( KDvoid )
{	
	// Set game area size
	m_tGameAreaSize = ccp ( 1000 / PTM_RATIO, 600 / PTM_RATIO );		// Box2d units

	if ( !GameArea2D::init ( ) )
	{
		return KD_FALSE;
	}
	m_pMessage->setString ( "Tap the screen move the actor to that point.\nTap again to queue another waypoint." );

	// Set 2D side scrolling gravity
	m_pWorld->SetGravity ( b2Vec2 ( 0, -20.0f ) );
	
	// Add three platforms 
	this->addBoxAtPoint ( ccp ( 625, 200 ), ccs ( 200, 50 ) );
	this->addBoxAtPoint ( ccp (  75, 300 ), ccs ( 230, 50 ) );
	this->addBoxAtPoint ( ccp ( 125, 100 ), ccp ( 220, 50 ) );

	// Create Actor
	this->addActor ( );
	
	// Add draw layer
	this->addDrawLayer ( );
	
	// Create level boundaries
	this->addLevelBoundaries ( );
	
	// Initial variables
	m_fCameraZoom = 0.45f;
	
	// Create SSAStarNodes 
	m_pNodes = new CCArray ( );
	
	// distance between nodes that the actor can run between
	KDfloat		fNodeRunDistInterval = 100.0f;
	
	// How far to search for nodes the actor can jump to
	KDfloat		fMaxJumpSearchDist = 500.0f;
	
	// Add some nodes to the bottom of the level
	for ( KDfloat x = 20.0f; x <= m_tGameAreaSize.cx * PTM_RATIO - 20.0f; x += fNodeRunDistInterval )
	{
		SSAStarNode*	pNode = SSAStarNode::create ( );
		pNode->setPosition ( ccp ( x, 20.0f ) );
		pNode->setBody ( m_pLevelBoundary->getBody ( ) );
		pNode->setActor ( m_pActor );
		m_pNodes->addObject ( pNode );
	}
	
	// Link those nodes together as 'run neighbors'
	for ( KDuint i = 0; i < m_pNodes->count ( ) - 1; i++ )
	{
		SSAStarNode*	pN1 = (SSAStarNode*) m_pNodes->objectAtIndex ( i );
		SSAStarNode*	pN2 = (SSAStarNode*) m_pNodes->objectAtIndex ( i + 1 );
		
		this->linkRunNeighbor ( pN1, pN2 );
	}
	
	// Add nodes to all level platforms 
	for ( b2Body* pBody = m_pWorld->GetBodyList ( ); pBody; pBody = pBody->GetNext ( ) )
	{		
		if ( pBody->GetUserData ( ) != KD_NULL ) 
		{			
			GameObject*		pObject = (GameObject*) pBody->GetUserData ( );
			
			if ( pObject->getTag ( ) == GO_TAG_WALL && pObject->getPolygonShape ( ) )
			{				
				// Nodes on this body only
				CCArray*	pNodesThisBody = CCArray::create ( );
				
				// Process each polygon vertex
				b2PolygonShape*		pShape = pObject->getPolygonShape ( );
				for ( KDint i = 0; i < pShape->m_vertexCount; i++ )
				{					
					b2Vec2		tVertex = pShape->m_vertices [ i ];
					
					// All nodes are 1 unit above their corresponding platform
					b2Vec2		tNodePosition = b2Vec2 ( tVertex.x + pBody->GetPosition ( ).x, tVertex.y + pBody->GetPosition ( ).y + 1.0f );
					
					// Move nodes inward to lessen chance of missing a jump
					if ( pShape->m_centroid.x < tVertex.x )
					{
						tNodePosition = b2Vec2 ( tNodePosition.x - 0.5f, tNodePosition.y );
					}
					else
					{
						tNodePosition = b2Vec2 ( tNodePosition.x + 0.5f, tNodePosition.y );
					}
			
					// If this node position is not inside the polygon we create an SSAStarNode
					if ( !pShape->TestPoint ( pBody->GetTransform ( ), tNodePosition ) ) 
					{			
						SSAStarNode*	pNode = SSAStarNode::create ( );
						pNode->setPosition ( ccp ( tNodePosition.x * PTM_RATIO, tNodePosition.y * PTM_RATIO ) );
						pNode->setBody ( pBody );
						pNode->setActor ( m_pActor );
						m_pNodes->addObject ( pNode );
						pNodesThisBody->addObject ( pNode );
					}					
				}				
				
				// Add in-between nodes (for running)
				KDbool	bDone = KD_FALSE;
				while ( !bDone )
				{
					if ( pNodesThisBody->count ( ) == 0 )
					{
						break; 
					}
				
					bDone = KD_TRUE;
					for ( KDuint i = 0; i < pNodesThisBody->count ( ) - 1; i++ )
					{					
						SSAStarNode*	pNode1 = (SSAStarNode*) pNodesThisBody->objectAtIndex ( i );
						SSAStarNode*	pNode2 = (SSAStarNode*) pNodesThisBody->objectAtIndex ( i + 1 );
							
						if ( GameHelper::absoluteValue ( pNode1->getPosition ( ).y - pNode2->getPosition ( ).y ) > 0.1f )
						{
							// These are not side by side
							continue;
						}
						
						if ( GameHelper::distanceP1 ( pNode1->getPosition ( ), pNode2->getPosition ( ) ) > fNodeRunDistInterval )
						{
							
							CCPoint		tMidPoint = GameHelper::midPointP1 ( pNode1->getPosition ( ), pNode2->getPosition ( ) );
							b2Vec2		tMp = b2Vec2 ( tMidPoint.x / PTM_RATIO, tMidPoint.y / PTM_RATIO );
							
							//If node is not in the polygon, add it
							if ( !pShape->TestPoint ( pBody->GetTransform ( ), tMp ) )
							{
								SSAStarNode*	pNode = SSAStarNode::create ( );
								pNode->setPosition ( GameHelper::midPointP1 ( pNode1->getPosition ( ), pNode2->getPosition ( ) ) );
								pNode->setBody ( pBody );
								pNode->setActor ( m_pActor );
								pNodesThisBody->insertObject ( pNode, i + 1 );
								m_pNodes->insertObject ( pNode, m_pNodes->indexOfObject ( pNode2 ) );
								bDone = KD_FALSE;
								break;
							}		
						}						
					}							
				}
								
				// Link all of the neighboring nodes on this body
				for ( KDuint i = 0; i < pNodesThisBody->count ( ) - 1; i++ )
				{
					if ( pNodesThisBody->count ( ) == 0 )
					{
						break; 
					}
				
					SSAStarNode*	pNode1 = (SSAStarNode*) pNodesThisBody->objectAtIndex ( i );
					SSAStarNode*	pNode2 = (SSAStarNode*) pNodesThisBody->objectAtIndex ( i + 1 );
				
					if ( GameHelper::absoluteValue ( pNode1->getPosition ( ).y - pNode2->getPosition ( ) .y ) > 0.1f )
					{
						// These are not side by side
						continue;
					}
					
					// Two-way link
					this->linkRunNeighbor ( pNode1, pNode2 );
				}				
			}			
		}
	}
		
	// Neighbor all other nodes (for jumping)
	for ( KDuint i = 0; i < m_pNodes->count ( ); i++ )
	{
		for ( KDuint j = 0; j < m_pNodes->count ( ); j++ )
		{
			if ( i == j )
			{
				continue; 
			}
		
			SSAStarNode*	pNode1 = (SSAStarNode*) m_pNodes->objectAtIndex ( i );
			SSAStarNode*	pNode2 = (SSAStarNode*) m_pNodes->objectAtIndex ( j );
		
			if ( pNode1->getBody ( ) == pNode2->getBody ( ) )
			{
				continue; 
			}
		
			if ( GameHelper::distanceP1 ( pNode1->getPosition ( ), pNode2->getPosition ( ) ) <= fMaxJumpSearchDist )
			{
				CCPoint		tSrc = ccp ( pNode1->getPosition ( ).x / PTM_RATIO, pNode1->getPosition ( ).y / PTM_RATIO );
				CCPoint		tDst = ccp ( pNode2->getPosition ( ).x / PTM_RATIO, pNode2->getPosition ( ).y / PTM_RATIO );
				
				// Calculate our jump "launch" vector
				Vector3D*	pLaunchVector3D = SSGameActor::canJumpFrom ( tSrc, tDst, m_pActor->getCircleShape ( )->m_radius * 1.5f, m_pWorld, m_pActor->getMaxSpeed ( ) );
				
				if ( pLaunchVector3D )
				{
					// Only neighbor up if a jump can be made
					// 1-way link
					if ( !pNode1->containsNeighborForNode ( pNode2 ) )
					{
						SSNeighborNode*		pNeighbor = SSNeighborNode::create ( );
						pNeighbor->setLaunchVector ( ccp ( pLaunchVector3D->x, pLaunchVector3D->y ) );
						pNeighbor->setNode ( pNode2 );
						pNeighbor->setMoveType ( MOVE_TYPE_JUMP );
						pNeighbor->setCost ( pNode1->costToNeighbor ( pNeighbor ) );
						pNode1->getNeighbors ( )->addObject ( pNeighbor );
					}
				}
			}
		}
	}
	
	return KD_TRUE;
}
Exemplo n.º 20
0
CppSQLite3DB* StoreDatabase::prepare(const char *dbName)
{
    return StoreDatabase::prepare(ccs(dbName));
}
Exemplo n.º 21
0
void LotteryRotateView::rotatingHandler(float dt){
    m_ftimeGap4 += dt;
//    CCLOG("m_ftimeGap4:%f", m_ftimeGap4);
    float angleGap = 10.0f;
    if (m_hasGetReward)
    {
        angleGap = fabs(m_fEndAngle) * (((100.0f-m_fTimeIdx3*(100.0f/m_fTimeCnt3))*(100.0f-m_fTimeIdx3*(100.0f/m_fTimeCnt3)) - (100.0f-(m_fTimeIdx3+1)*(100.0f/m_fTimeCnt3))*(100.0f-(m_fTimeIdx3+1)*(100.0f/m_fTimeCnt3)))/(100.0f*100.0f));
    }
    
    float rotateToAngle = m_rotateAngle;
    float radians = CC_DEGREES_TO_RADIANS(angleGap);
    
//    CCLOG("cctouchEND:%f, m_fEndTime3:%f, m_fTimeCnt3:%d", m_fEndAngle, m_fEndTime3, m_fTimeCnt3);
//    CCLOG("rotatingHandler-angleGap:%f, rotateToAngle:%f, m_fEndAngle:%f,radians:%f", angleGap, m_rotateAngle, m_fEndAngle,radians);
    if (m_tScrollAngel > 0) {
        
        if (rotateToAngle >= m_fEndAngle && m_hasGetReward) {
            rotateFinished();
            return;
        }
    }
    else {
        angleGap = -angleGap;
        radians = CC_DEGREES_TO_RADIANS(angleGap);
        if (rotateToAngle <= m_fEndAngle && m_hasGetReward) {
            rotateFinished();
            return;
        }
    }
    
    if (m_ftimeGap4 > 2.2f && !m_isSendNotify0)
    {
        m_isSendNotify0 = true;
        CCDictionary* dict = CCDictionary::create();
        dict->setObject(ccs("REMOVEPARTICLE"), "key");
        dict->setObject(ccs("1"), "value");
        CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(LOTTERYROTATEVIEW, dict);
        
        m_startAddCnt2 = m_fTimeCnt3-m_fTimeIdx3;
    }
    if (abs(m_rotateAngle*2.0) > abs(m_fEndAngle) && !m_isSendNotify1)
    {
        m_isSendNotify1 = true;
        CCDictionary* dict = CCDictionary::create();
        dict->setObject(ccs("REMOVEPARTICLE"), "key");
        dict->setObject(ccs("0"), "value");
        CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(LOTTERYROTATEVIEW, dict);
        
        m_startAddCnt1 = m_fTimeCnt3-m_fTimeIdx3;
    }
    int startAddCnt;
    startAddCnt=(m_startAddCnt1>m_startAddCnt2?m_startAddCnt1:m_startAddCnt2);
    
    setRotationAngle(radians);
    m_rotateAngle += angleGap;
    
    if (m_fTimeCnt3 != 0 && startAddCnt > 0 && LotteryController::shared()->rotateType==1 && m_fTimeIdx3 >= (m_fTimeCnt3 - startAddCnt)) {//0-普通,1-连转10次
        for (int i=0; i<10; i++) {
            int idx = (m_fTimeCnt3 - startAddCnt)+(startAddCnt*(0.1*i));
            if(m_fTimeIdx3==idx){
                if(i==0){
                    addRewardsNodeBg();
                }
                addRewardsNodeByIndex(i);
            }
        }
    }
    m_fTimeIdx3 = m_fTimeIdx3 + 1;
    if (m_fTimeIdx3 >= m_fTimeCnt3 && m_hasGetReward)
    {
        rotateFinished();
        addShowItemListView();
        return;
    }
}
Exemplo n.º 22
0
void LotteryRotateView::onTouchEnded(CCTouch* touch, CCEvent* event)
{
    if (!this->isVisible())
    {
        return;
    }

    if (!m_enabled) {
        return;
    }
    
    long endTouchTime = clock() / 1000;
    
    if (m_pTouches->containsObject(touch))
    {
        if (m_pTouches->count() == 1 && m_bTouchMoved)
        {
        }
        m_pTouches->removeObject(touch);
    }

    if (m_pTouches->count() == 0)
    {
        m_bDragging = false;
        m_bTouchMoved = false;
    }

    CCPoint startPoint = m_pContainer->convertToNodeSpace(touch->getStartLocation());
//    CCPoint lastPoint = m_pContainer->convertToNodeSpace(touch->getPreviousLocation());
    CCPoint nowPoint = m_pContainer->convertToNodeSpace(touch->getLocation());
    CCPoint startLine = ccpSub(startPoint, ccp(0, 0));
    CCPoint nowLine = ccpSub(nowPoint, ccp(0, 0));
    
    float angle = CC_RADIANS_TO_DEGREES(ccpSub(nowLine, startPoint).getAngle());
    if (abs(angle) >= 60 && abs(angle) <= 120)
    {
        return;
    }
    
    float degreeGap = CC_RADIANS_TO_DEGREES(nowLine.getAngle(startLine));
    CCLOG("%f:", degreeGap);
    if (fabs(degreeGap) < 15)
    {
        m_rewardsContainer->removeAllChildren();
        return;
    }

    int spendTime = (int)(endTouchTime - m_lastTouchMoveTime) + 1;
    float speed = 100*fabs(m_tScrollAngel)/spendTime;
    m_speed3 = (fabs(degreeGap)) / ((endTouchTime - m_startTouchTime) / 1000.0f);

    CCLOG("speed:%f,speed3:%f",speed, m_speed3);
    if (speed < 6 || m_speed3 < 60.0f) {
        return;
    }
//    m_speed3 = m_speed3 * 2.0f;
    
    bool guide = CCUserDefault::sharedUserDefault()->getBoolForKey("LOTTERYGUIDE");
    if (!guide)
    {
        CCUserDefault::sharedUserDefault()->setBoolForKey("LOTTERYGUIDE", true);
        CCUserDefault::sharedUserDefault()->flush();
        CCDictionary* dict = CCDictionary::create();
        dict->setObject(ccs("HIDEGUIDENODE"), "key");
        CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(LOTTERYROTATEVIEW, dict);
    }
    
//    if (!isChipEnough())
//    {
//        return;
//    }
    SoundController::sharedSound()->playEffects(Music_Sfx_UI_roulette);
    playAnimation(0);
}
Exemplo n.º 23
0
void LotteryRotateView::getCmdData(CCObject *pObj)
{
    CCString* reward = CCString::create("");
    if (LotteryController::shared()->rotateType==1) {//0-普通,1-连转10次
        m_save10Arr = dynamic_cast<CCArray*>(pObj);
        LotteryController::shared()->m_save10Arr = dynamic_cast<CCArray*>(pObj);
        if(m_save10Arr && m_save10Arr->count()>0){
            CCDictionary* lastDict = dynamic_cast<CCDictionary*>(m_save10Arr->objectAtIndex(m_save10Arr->count()-1));
            int dictType = lastDict->valueForKey("type")->intValue();
            CCDictionary* rewardsDic = _dict(lastDict->objectForKey("result"));
            /*  里面的type 是
                RESOURCE, BOX_TIMES, REWARD 0 1 2*/
            if (dictType == 0) {//RESOURCE
                int resType = rewardsDic->valueForKey("type")->intValue();
                reward = CCString::create(CC_ITOA(resType));
            }else if (dictType == 1){//BOX_TIMES
                reward = CCString::create(CC_ITOA(100));
            }else if (dictType == 2){//REWARD
                int resType = rewardsDic->valueForKey("type")->intValue();
                if (resType == 7) {
                    CCDictionary* valueDic = _dict(rewardsDic->objectForKey("value"));
                    int itemId = valueDic->valueForKey("itemId")->intValue();
                    reward = CCString::create(CC_ITOA(itemId));
                }else{
                    reward = CCString::create(CC_ITOA(resType));
                }
            }
        }

    }else{
        reward = dynamic_cast<CCString*>(pObj);
    }
    CCLOG("reward:%s",reward->getCString());
    if (!reward || (reward && reward->compare("error")==0))
    {
        m_targetCell = NULL;
        CCDictionary* dict = CCDictionary::create();
        dict->setObject(ccs(LOTTERYACTVIEW_COM), "key");
        dict->setObject(ccs("error"), "value");
        CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(LOTTERYROTATEVIEW, dict);
//        rotateFinished();
        this->unschedule(schedule_selector(LotteryRotateView::rotatingHandler));
        m_rotating = false;
        return;
    }
    
    float rotateAngleArr[12] = {0, 30, 60,  90,   120,    150,     180,   -150,    -120,  -90, -60,   -30};
    float rotateAngle = 0.0f;
    LotteryActCell* cell2 = NULL;
    bool getTarget = false;
    for (int i = 0; i < m_pContainer->getChildrenCount(); i++)
    {
        cell2 = dynamic_cast<LotteryActCell*>(m_pContainer->getChildByTag(i));
        if (cell2)
        {
            rotateAngle = rotateAngleArr[i];
            cell2->setAngle(CC_DEGREES_TO_RADIANS(rotateAngle));
            if (!getTarget && reward->compare(cell2->getItemId().c_str())==0)
            {
                m_targetCell = cell2;
                getTarget = true;
            }
        }
    }
    doCellSort();
    if (m_targetCell == NULL)
    {
//        rotateFinished();
        this->unschedule(schedule_selector(LotteryRotateView::rotatingHandler));
        m_rotating = false;
        CCDictionary* dict = CCDictionary::create();
        dict->setObject(ccs(LOTTERYACTVIEW_COM), "key");
        dict->setObject(ccs("error"), "value");
        CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(LOTTERYROTATEVIEW, dict);
        return;
    }
    
    int index = m_targetCell->getTag();
    // 基准角度
    float addAngle = 0.0;
    if (LotteryController::shared()->rotateType==1) {//0-普通,1-连转10次
//        addAngle = 360;
    }
    if (m_tScrollAngel > 0) {
        m_fEndAngle = -(index+3)*30 + addAngle + (1 + ((int) m_speed3/360)) * 360.0f;//720
    }
    else {
        m_fEndAngle = -(index+3)*30.0f - addAngle - (1 + ((int) m_speed3/360)) * 360.0f;//360
    }
    
    m_fEndTime3 = fabs(m_fEndAngle)/m_speed3;// 一圈的时间
    m_fTimeCnt3 = (int) (m_fEndTime3/m_fTimeGap3)*1.3;
//    if (LotteryController::shared()->rotateType==1) {//0-普通,1-连转10次
//        addRewardsNodeBg();
//    }
//    if (m_fTimeCnt3 > 300)
//    {
//        m_fTimeCnt3 = m_fTimeCnt3/2;
//    }
    m_fTimeIdx3 = 0;
    m_rotateAngle = 0;
    m_hasGetReward = true;
}