KDbool Ch7_GridPathfinding::init ( KDvoid )
{	
	// Superclass initialization and message
	if ( !Recipe::init ( ) )
	{
		return KD_FALSE;
	}

	this->showMessage ( "Tap and hold to draw walls.\nPress 'Find Path' to run the simulation." );

	//Initial variables
	m_tGridSize			= ccp ( 25, 15 );
	m_fNodeSpace		= 16.0f;
	m_tTouchedNode		= ccp ( 0, 0 );
	m_tStartCoord		= ccp ( 2, 2 );
	m_tEndCoord			= ccp ( m_tGridSize.x - 3, m_tGridSize.y - 3 );
	m_bTouchedNodeIsNew = KD_FALSE;
	m_pFoundPath		= new CCArray ( );
	m_bAddMode			= KD_TRUE;
	
	// Seperate grid node
	m_pGridNode = CCNode::create ( );
	m_pGridNode->setPosition ( ccp ( 35, 15 ) );
	this->addChild ( m_pGridNode, 3 ); 

	// Create 2D array (grid)
	m_pGrid = new CCArray ( (KDint) m_tGridSize.x ); 
	for ( KDint x = 0; x < (KDint) m_tGridSize.x; x++ )
	{
		m_pGrid->addObject ( CCArray::createWithCapacity ( (KDint) (KDint) m_tGridSize.y ) );
	}

	// Create AStar nodes and place them in the grid
	for ( KDint x = 0; x < (KDint) m_tGridSize.x; x++ )
	{
		for ( KDint y = 0; y < (KDint) m_tGridSize.y; y++ )
		{
			// Add a node
			AStarNode*	pNode = AStarNode::create ( );
			pNode->setPosition ( ccp ( x * m_fNodeSpace + m_fNodeSpace / 2, y * m_fNodeSpace + m_fNodeSpace / 2 ) );
			( (CCArray*) m_pGrid->objectAtIndex ( x ) )->addObject ( pNode );
		}
	}
	
	// Add neighbor nodes
	for ( KDint x = 0; x < (KDint) m_tGridSize.x; x++ )
	{
		for ( KDint y = 0; y < (KDint) m_tGridSize.y; y++ )
		{			
			// Add a node
			AStarNode*	pNode = (AStarNode*) ( (CCArray*) m_pGrid->objectAtIndex ( x ) )->objectAtIndex ( y );
			
			// Add self as neighbor to neighboring nodes
			this->addNeighbor ( pNode, x - 1, y - 1 );		// Top-Left
			this->addNeighbor ( pNode, x - 1, y     );		// Left
			this->addNeighbor ( pNode, x - 1, y + 1 );		// Bottom-Left
			this->addNeighbor ( pNode, x    , y - 1 );		// Top
			
			this->addNeighbor ( pNode, x    , y + 1 );		// Bottom
			this->addNeighbor ( pNode, x + 1, y - 1 );		// Top-Right
			this->addNeighbor ( pNode, x + 1, y     );		// Right
			this->addNeighbor ( pNode, x + 1, y + 1 );		// Bottom-Right		
		}
	}

	// Add visual represenation of nodes
	this->addGridArt ( );
	
	// Menu items 
	CCMenuItemFont::setFontSize ( 30 );

	CCMenuItemFont*		pFindPathItem = CCMenuItemFont::create ( "Find Path", this, menu_selector ( Ch7_GridPathfinding::findPath ) );
	pFindPathItem->setScale ( 0.65f );
	
	CCMenuItemToggle*	pSwitchModeItem = CCMenuItemToggle::createWithTarget 
	(
		this, 
		menu_selector ( Ch7_GridPathfinding::switchMode ), 
		CCMenuItemFont::create ( "Switch Mode: Remove Wall" ),
		CCMenuItemFont::create ( "Switch Mode: Add Wall" ), 
		KD_NULL 
	);
	pSwitchModeItem->setScale ( 0.65f );
	
	CCMenu*				pMenu = CCMenu::create ( pFindPathItem, pSwitchModeItem, KD_NULL );
	pMenu->alignItemsVertically ( 0 );
	pMenu->setPosition ( ccp ( 350, 290 ) );
	this->addChild ( pMenu, Z_HUD );

	// Add draw layer
	this->addDrawLayer ( );
	
	// Schedule step method
	this->schedule ( schedule_selector ( Ch7_GridPathfinding::step ) );

	return KD_TRUE;
}
Ejemplo n.º 2
0
bool FriendList::init()
{
    if ( !CCLayer::init())
    {
        return false;
    }
    
    mEnableHighScoreDisplay = false;
    mEnableInstalledDisplay = false;
    mReadyForNextDownload   = false;
    mPhotoLoadIndex         = 0;
    
    EziSocialObject::sharedObject()->setFacebookDelegate(this);
    
    CCSize winSize = CCDirector::sharedDirector()->getVisibleSize();
    SCREEN_WIDTH  = winSize.width;
    SCREEN_HEIGHT = winSize.height;
    
    CCLayerColor *backgroundLayer = CCLayerColor::create(ccc4(20, 100, 100, 255), SCREEN_WIDTH, SCREEN_HEIGHT);
    
    this->addChild(backgroundLayer);
    
    
    MENU_FONT_SCALE = SCREEN_HEIGHT/320;
    
    
    // Back Menu
    
    CCMenuItemFont *itemBack = CCMenuItemFont::create("Back", this, menu_selector(FriendList::showHomePage));
	itemBack->setPosition(ccp(SCREEN_WIDTH/2, (itemBack->getContentSize().height/2 + 2) * MENU_FONT_SCALE));
	
    CCMenuItemFont *itemHighScore = CCMenuItemFont::create("High Scores", this, menu_selector(FriendList::showHighScoreList));
    itemHighScore->setAnchorPoint(ccp(1, 0.5));
    itemHighScore->setPosition(ccp((SCREEN_WIDTH-10), itemBack->getPositionY()));
    
    CCMenuItemFont *allFriends = CCMenuItemFont::create("All Friends", this, menu_selector(FriendList::showAllFriendsList));
    allFriends->setAnchorPoint(ccp(0, 0.5));
    allFriends->setPosition(ccp((10), itemBack->getPositionY()));
    
    CCMenuItemFont *installedOnly = CCMenuItemFont::create("Installed Only", this, menu_selector(FriendList::showInstalledList));
    installedOnly->setAnchorPoint(ccp(0, 1));
    installedOnly->setPosition(ccp((10), SCREEN_HEIGHT - 2));
    
    CCMenuItemFont *notPlaying = CCMenuItemFont::create("Friends Not Playing", this, menu_selector(FriendList::showNotInstalledList));
    notPlaying->setAnchorPoint(ccp(1, 1));
    notPlaying->setPosition(ccp((SCREEN_WIDTH-10), SCREEN_HEIGHT - 2));
    
    
    
    
    itemBack->setScale(MENU_FONT_SCALE);
    itemHighScore->setScale(MENU_FONT_SCALE);
    allFriends->setScale(MENU_FONT_SCALE);
    installedOnly->setScale(MENU_FONT_SCALE);
    notPlaying->setScale(MENU_FONT_SCALE);
    
    CCMenu *menuBack = CCMenu::create(itemBack, itemHighScore, allFriends, installedOnly, notPlaying, NULL);
	menuBack->setPosition(CCPointZero);
	addChild(menuBack);
    
    float gap = itemBack->getContentSize().height * 2 * MENU_FONT_SCALE + (10 * MENU_FONT_SCALE);
    
    mFriendList = NULL;
    
    PHOTO_SCALE = SCREEN_HEIGHT/1536;
    
    if (PHOTO_SCALE <= 0.5 && PHOTO_SCALE > 0.25)
    {
        FB_DEFAULT_PHOTO = "fb_user_icon_half.jpg";
    }
    else if (PHOTO_SCALE < 0.25)
    {
        FB_DEFAULT_PHOTO = "fb_user_icon_quater.jpg";
    }
    
    
    CCSprite *sprite = CCSprite::create(FB_DEFAULT_PHOTO);
    CELL_HEIGHT = (sprite->getContentSize().height) + (40 * PHOTO_SCALE);
    
    
    mTableView = CCTableView::create(this, CCSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT - gap));
    mTableView->setDirection(kCCScrollViewDirectionVertical);
    mTableView->setPosition(ccp(0, gap/2));
    
    mTableView->setDelegate(this);
    this->addChild(mTableView);
    
    mTableView->reloadData();
    
    ALL_DOWNLOAD_COMPLETE = true;
    
    mLoadingImage = CCSprite::create("ball.png");
    mLoadingImage->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT/2));
    mLoadingImage->retain();
    
    this->addChild(mLoadingImage);
    this->hideLoadingAction();
    
    return true;
}
Ejemplo n.º 3
0
bool RequestList::init()
{
    if ( !CCLayer::init())
    {
        return false;
    }
    
    mPhotoLoadIndex         = 0;
    
    EziSocialObject::sharedObject()->setFacebookDelegate(this);
    
    CCSize winSize = CCDirector::sharedDirector()->getVisibleSize();
    SCREEN_WIDTH  = winSize.width;
    SCREEN_HEIGHT = winSize.height;
    
    CCLayerColor *backgroundLayer = CCLayerColor::create(ccc4(20, 100, 100, 255), SCREEN_WIDTH, SCREEN_HEIGHT);
    
    this->addChild(backgroundLayer);
    
    
    MENU_FONT_SCALE = SCREEN_HEIGHT/320;
    
    
    // Back Menu
    
    CCMenuItemFont *itemBack = CCMenuItemFont::create("Back", this, menu_selector(RequestList::showHomePage));
    itemBack->setAnchorPoint(ccp(1, 0.5));
	itemBack->setPosition(ccp(SCREEN_WIDTH - 10, (itemBack->getContentSize().height/2 + 2) * MENU_FONT_SCALE));
	
    CCMenuItemFont *purgeItems = CCMenuItemFont::create("Clear Completed Requests",
                                                           this,
                                                           menu_selector(RequestList::clearCompletedRequest));
    purgeItems->setAnchorPoint(ccp(0, 0.5));
    purgeItems->setPosition(ccp(10, (itemBack->getContentSize().height/2 + 2) * MENU_FONT_SCALE));
    
    
    itemBack->setScale(MENU_FONT_SCALE);
    purgeItems->setScale(MENU_FONT_SCALE);
    
    CCMenu *menuBack = CCMenu::create(itemBack, purgeItems, NULL);
	menuBack->setPosition(CCPointZero);
	addChild(menuBack);
    
    float gap = itemBack->getContentSize().height * 2 * MENU_FONT_SCALE + (10 * MENU_FONT_SCALE);
    
    _fbIncomingRequestList = NULL;
    
    refreshList();

    SCALE_FACTOR  = SCREEN_HEIGHT / 768.0f;
    SCALE_FACTOR = MAX(0.5, SCALE_FACTOR);
    
    PHOTO_SCALE = SCREEN_HEIGHT/1536;
    
    if (PHOTO_SCALE <= 0.5 && PHOTO_SCALE > 0.25)
    {
        FB_DEFAULT_PHOTO = "fb_user_icon_half.jpg";
    }
    else if (PHOTO_SCALE < 0.25)
    {
        FB_DEFAULT_PHOTO = "fb_user_icon_quater.jpg";
    }
    
    
    CCSprite *sprite = CCSprite::create(FB_DEFAULT_PHOTO);
    CELL_HEIGHT = (sprite->getContentSize().height) + (40 * PHOTO_SCALE);
    
    
    mTableView = CCTableView::create(this, CCSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT - gap));
    mTableView->setDirection(kCCScrollViewDirectionVertical);
    mTableView->setPosition(ccp(0, gap/2));
    
    mTableView->setDelegate(this);
    this->addChild(mTableView);
    
    mTableView->reloadData();
    
    ALL_DOWNLOAD_COMPLETE = true;
    
    mLoadingImage = CCSprite::create("ball.png");
    mLoadingImage->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT/2));
    mLoadingImage->retain();
    
    this->addChild(mLoadingImage);
    this->hideLoadingAction();
    
    return true;
}
Ejemplo n.º 4
0
bool S411FeedBack::setUpSubClass2()
{
	bool bRet = false;
	do
	{
        refreshItemImage->setOpacity(0);
        refreshItemImage->setEnabled(false);
        isMale = true;
        AppDelegate::S51TextViewStr = "";
        
        feedBackSp = CCSprite::create("S41FeedBack.png");
        feedBackSp->setPosition(ccp(530,330));
        this->addChild(feedBackSp, zNum, 10);
        
        float pox = 487;
        float poy = 477;
        
        male = CCSprite::create("S49RadioSelected.png");
        male->setPosition(ccp(pox,poy));
        this->addChild(male,zNum);
        
        CCSprite * sprite1 = CCSprite::create();
        CCSprite * sprite2 = CCSprite::create();
        CCMenuItemSprite * maleItem = CCMenuItemSprite::create(
                                                               sprite1,
                                                               sprite2,
                                                               this,
                                                               menu_selector(S411FeedBack::changeSex));
        maleItem->setPosition(male->getPosition());
        maleItem->setContentSize(CCSizeMake(male->getContentSize().width*3, male->getContentSize().height*3));
        _menu->addChild(maleItem,zNum);
        
        
        
        
        famale =CCSprite::create("S49RadioSelected.png");
        famale->setPosition(ccp(pox+45,poy));
        this->addChild(famale,zNum);
        famale->setOpacity(0);
        
        CCSprite * sprite3 = CCSprite::create();
        CCSprite * sprite4 = CCSprite::create();
        CCMenuItemSprite * faMaleItem = CCMenuItemSprite::create(sprite3, sprite4,this,menu_selector(S411FeedBack::changeSex));
        faMaleItem->setPosition(famale->getPosition());
        faMaleItem->setContentSize(CCSizeMake(famale->getContentSize().width*3, famale->getContentSize().height*3));
        _menu->addChild(faMaleItem,zNum);
        
        
        float editFontSize = 10;
        float addWidth = 128.0;
        float addHeight = 45;
        const char * input = "";
        
        CCScale9Sprite *sacel9SprG1=CCScale9Sprite::create("S49Submit.png");
        sacel9SprG1->setOpacity(1);
        nameBox=CCEditBox::create(CCSizeMake(sacel9SprG1->getContentSize().width*2.8, sacel9SprG1->getContentSize().height), sacel9SprG1);
        nameBox->setFontName(s1FontName_macro);
        nameBox->setFontSize(editFontSize);
        nameBox->setFontColor(ccBLACK);
        nameBox->setInputMode(kEditBoxInputModeAny);
        nameBox->setPlaceHolder(input);
        nameBox->setPosition(ccp(240+addWidth,430+addHeight));
        this->addChild(nameBox,zNum);
        nameBox->setDelegate(this);
        
        
        
        
        CCScale9Sprite *sacel9SprG2=CCScale9Sprite::create("S49Submit.png");
        sacel9SprG2->setOpacity(1);
        telBox=CCEditBox::create(CCSizeMake(sacel9SprG2->getContentSize().width*2.8, sacel9SprG2->getContentSize().height), sacel9SprG2);
        telBox->setFontSize(editFontSize);
        telBox->setFontColor(ccBLACK);
        telBox->setPlaceHolder(input);
        telBox->setPosition(ccp(240+addWidth,400+addHeight));
        this->addChild(telBox,zNum);
        telBox->setDelegate(this);
        
        
        CCScale9Sprite *sacel9SprG3=CCScale9Sprite::create("S49Submit.png");
        sacel9SprG3->setOpacity(1);
        mobilePhoneBox=CCEditBox::create(CCSizeMake(sacel9SprG3->getContentSize().width*2.8, sacel9SprG3->getContentSize().height), sacel9SprG3);
        mobilePhoneBox->setFontSize(editFontSize);
        mobilePhoneBox->setFontColor(ccBLACK);
        mobilePhoneBox->setPlaceHolder(input);
        mobilePhoneBox->setPosition(ccp(240+addWidth,365+addHeight));
        this->addChild(mobilePhoneBox,zNum);
        mobilePhoneBox->setDelegate(this);
        
        
        
        CCScale9Sprite *sacel9SprG4=CCScale9Sprite::create("S49Submit.png");
        sacel9SprG4->setOpacity(1);
        mailBox=CCEditBox::create(CCSizeMake(sacel9SprG4->getContentSize().width*2.8, sacel9SprG4->getContentSize().height), sacel9SprG4);
        mailBox->setFontSize(editFontSize);
        mailBox->setFontColor(ccBLACK);
        mailBox->setPlaceHolder(input);
        mailBox->setPosition(ccp(240+addWidth,335+addHeight));
        this->addChild(mailBox,zNum);
        mailBox->setDelegate(this);
        
        
        CCScale9Sprite *sacel9SprG5=CCScale9Sprite::create("S49Submit.png");
        sacel9SprG5->setOpacity(1);
        msnBox=CCEditBox::create(CCSizeMake(sacel9SprG5->getContentSize().width*2.8, sacel9SprG5->getContentSize().height), sacel9SprG5);
        msnBox->setFontSize(editFontSize);
        msnBox->setFontColor(ccBLACK);
        msnBox->setPlaceHolder(input);
        msnBox->setPosition(ccp(240+addWidth,305+addHeight));
        this->addChild(msnBox,zNum);
        msnBox->setDelegate(this);
        
        
        CCScale9Sprite *sacel9SprG6=CCScale9Sprite::create("S49Submit.png");
        sacel9SprG6->setOpacity(1);
        addressBox=CCEditBox::create(CCSizeMake(sacel9SprG6->getContentSize().width*4, sacel9SprG6->getContentSize().height), sacel9SprG6);
        addressBox->setFontSize(editFontSize);
        addressBox->setFontColor(ccBLACK);
        addressBox->setPlaceHolder(input);
        addressBox->setPosition(ccp(270+addWidth,269+addHeight));
        this->addChild(addressBox,zNum);
        addressBox->setDelegate(this);
        
        CCScale9Sprite *sacel9SprG7=CCScale9Sprite::create("S49Submit.png");
        sacel9SprG7->setOpacity(1);
        submitBox=CCEditBox::create(CCSizeMake(sacel9SprG7->getContentSize().width*1.5, sacel9SprG7->getContentSize().height), sacel9SprG7);
        submitBox->setFontSize(editFontSize);
        submitBox->setFontColor(ccBLACK);
       // submitBox->setPlaceHolder("asdhjashdkjansda\nasdjgkjahdkjas");//input);
        submitBox->setPosition(ccp(210+addWidth,140+addHeight));
        this->addChild(submitBox,zNum);
        submitBox->setDelegate(this);
        
        textView = CCUIKit::create();
        CCRect aRect = CCRectMake(295, 480, 500, 100);
        textView->creatWithRect(aRect,this);
        addChild(textView);
        AppDelegate::isTextViewExist = false;
        
        CCScale9Sprite *sacel9SprG8=CCScale9Sprite::create("S49Submit.png");
        sacel9SprG8->setOpacity(1);
        yanzhengBox=CCEditBox::create(CCSizeMake(sacel9SprG8->getContentSize().width*1.5, sacel9SprG8->getContentSize().height), sacel9SprG8);
        yanzhengBox->setFontSize(editFontSize);
        yanzhengBox->setFontColor(ccBLACK);
        yanzhengBox->setPlaceHolder(input);
        yanzhengBox->setPosition(ccp(210+addWidth,110+addHeight));
        this->addChild(yanzhengBox,zNum);
        yanzhengBox->setDelegate(this);
        
        
        
        CCMenuItemFont *aItem = CCMenuItemFont::create("提交留言",this,menu_selector(S411FeedBack::submit));
        aItem->setOpacity(1);
        aItem->setColor(ccBLACK);
        aItem->setScale(1.2);
        aItem->setPosition(ccp(550,165));
        aItem->setContentSize(CCSizeMake(100,100));
        _menu ->addChild(aItem,zNum);
    
        CCLabelTTF * titlelabel = CCLabelTTF::create("我要加盟", s1FontName_macro, 15);
        titlelabel->setPosition(ccp(visibleSize.width/2,visibleSize.height/2+155));
        titlelabel->setColor(ccWHITE);
        this->addChild(titlelabel,zNum+1000);
        
		bRet = true;
	} while (0);
    
	return bRet;
}