bool GameOverScene::init()
{
	bool bRet = false;
    do
    {
        CCDirector * pDirector;
        CC_BREAK_IF( ! (pDirector = CCDirector::sharedDirector()) );
        this->setContentSize(pDirector->getWinSize());
        
        CCSprite* bg = CCSprite::create("gameover.png");
        bg->setPosition(ccp(pDirector->getWinSize().width * 0.5,pDirector->getWinSize().height * 0.5));
        this->addChild(bg);
        
        CCMenuItemFont* mainMenu = CCMenuItemFont::create("Back To Menu",
			this,menu_selector(GameScene::menuPopSceneCallback));
        CCMenuItemFont* close = CCMenuItemFont::create("Exit Game",
			this,menu_selector(GameOverScene::menuCloseCallback));
        CCMenu* menu = CCMenu::create(mainMenu,close,NULL);
        menu->setPosition(ccp(pDirector->getWinSize().width * 0.5,pDirector->getWinSize().height * 0.3));
        menu->alignItemsVertically();
        this->addChild(menu,1);
        // success
        bRet = true;
    } while (0);
    return bRet;
}
Example #2
0
bool ShaderRetroEffect::init()
{
    if( ShaderTestDemo::init() ) {

        GLchar * fragSource = (GLchar*) CCString::createWithContentsOfFile(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("Shaders/example_HorizontalColor.fsh"))->getCString();
        CCGLProgram *p = new CCGLProgram();
        p->initWithVertexShaderByteArray(ccPositionTexture_vert, fragSource);

        p->addAttribute(kCCAttributeNamePosition, kCCVertexAttrib_Position);
        p->addAttribute(kCCAttributeNameTexCoord, kCCVertexAttrib_TexCoords);

        p->link();
        p->updateUniforms();


        CCDirector *director = CCDirector::sharedDirector();
        CCSize s = director->getWinSize();

        m_pLabel = CCLabelBMFont::create("RETRO EFFECT", "fonts/west_england-64.fnt");

        m_pLabel->setShaderProgram(p);

        p->release();


        m_pLabel->setPosition(ccp(s.width/2,s.height/2));

        addChild(m_pLabel);

        scheduleUpdate();
        return true;
    }

    return false;
}
void GameLayer::doGameEnd(CCNode* pSender){
	CCDirector* pDirector = CCDirector::sharedDirector();
	CCSize winSize = pDirector->getWinSize();

	//stop all acitons
	isGameEnded = true;
	heroLayer->unscheduleUpdate();
	heroLayer->unscheduleAllSelectors();
	_enemyAI->unscheduleUpdate();
	_enemyAI->unscheduleAllSelectors();

	//check game win or not
	CCSprite* resultPad = NULL;
	if (my_hero->getLife() <= 0){
		//game lose
		resultPad = CCSprite::create("ui/lose.png");
	}
	else{
		//game win
		resultPad = CCSprite::create("ui/win.png");
		MapLayer* thisMap = MapLayer::getMap();
		thisMap->unlockNextLevel();
		thisMap->setLevelAccomp();
	}
	this->addChild(resultPad, 101);
	resultPad->setPosition(ccp(winSize.width / 2, 
		winSize.height / 2 + resultPad->getContentSize().height / 3));

	//disable touches except back to menu
	CCLayerColor* maskLayer = CCLayerColor::create(ccc4(255, 255, 255, 160), winSize.width, winSize.height);
	this->setZOrder(1);
	this->addChild(maskLayer, 100);
	backIcon->setZOrder(101);
	backIcon->setPosition(ccp(winSize.width / 2, winSize.height / 2 - backIcon->getContentSize().height));
}
void GameLayer::ccTouchesBegan(CCSet* pTouch, CCEvent* pEvent){
	
	//check if the backIcon is pressed
	CCTouch *touch = (CCTouch*)pTouch->anyObject();
	CCPoint location = touch->getLocation();
	CCDirector* pDirector = CCDirector::sharedDirector();
	CCSize winSize = pDirector->getWinSize();
	float icon_radius = backIcon->getContentSize().height / 2;
	//distance from icon target to center of the sprite
	float distanceSQ = ccpDistanceSQ(location, backIcon->getPosition());
	if (distanceSQ <= icon_radius * icon_radius){
		//change the icon to pressed
		//MapLayer::getMap()->unlockNextLevel();
		pDirector->popScene();
		return;
	}
	//back button checking ended
	
	
	//gesture detection initiate
	ccp_last = touch->getLocationInView();
	ccp_last = pDirector->convertToGL(ccp_last);

	b_click = true;
	b_rect = false;
	b_circle = false;
	count_order = 0;
	gd_direction = kGDirectionNo;

	for (int i = 0; i < 4; i++){
		cache_deirectionshape[i] = false;
	}
	//gesture detection ended
}
Example #5
0
void AccelerometerTest::didAccelerate(CCAcceleration* pAccelerationValue)
{
//     double fNow = pAccelerationValue->timestamp;
// 
//     if (m_fLastTime > 0.0)
//     {
//         CCPoint ptNow = convertToUI
//     }
// 
//     m_fLastTime = fNow;

    CCDirector* pDir = CCDirector::sharedDirector();
    CCSize winSize   = pDir->getWinSize();

    /*FIXME: Testing on the Nexus S sometimes m_pBall is NULL */
    if ( m_pBall == NULL ) {
        return;
    }

    CCSize ballSize  = m_pBall->getContentSize();

    CCPoint ptNow  = m_pBall->getPosition();
    CCPoint ptTemp = pDir->convertToUI(ptNow);

    ptTemp.x += pAccelerationValue->x * 9.81f;
    ptTemp.y -= pAccelerationValue->y * 9.81f;

    CCPoint ptNext = pDir->convertToGL(ptTemp);
    FIX_POS(ptNext.x, (ballSize.width / 2.0), (winSize.width - ballSize.width / 2.0));
    FIX_POS(ptNext.y, (ballSize.height / 2.0), (winSize.height - ballSize.height / 2.0));
    m_pBall->setPosition(ptNext);
}
Example #6
0
void StartLayer::update(float dt)
{
    CCSprite* title = (CCSprite*)this->getChildByTag(10000);
    CCDirector* pDir = CCDirector::sharedDirector();
    CCSize winSize   = pDir->getWinSize();
    
    //判断小球精灵是否有效。
    if ( title == NULL ) {
        return;
    }
    //取得小球的图像区域大小。
    CCSize ballSize  = title->getContentSize();
    //取得小球的当前位置。
    CCPoint ptNow  = title->getPosition();
    //将当前位置转换成界面坐标系的位置。
    CCPoint ptTemp = pDir->convertToUI(ptNow);
    //由收到的速度乘以一个系数后来影响位置。
    ptTemp.x += posChange.x;
    ptTemp.y -= posChange.y;
    //再转换为OPENGL坐标系的位置。貌似有点麻烦,其实直接在上面X,Y的加减上做上正确的方向即可。
    CCPoint ptNext = pDir->convertToGL(ptTemp);
    //限定位置的X,Y的有效范围,等于小球边缘始终在窗口内。
    FIX_POS(ptNext.x, (ballSize.width / 2.0), (winSize.width - ballSize.width / 2.0));
    FIX_POS(ptNext.y, (ballSize.height / 2.0), (winSize.height - ballSize.height / 2.0));
    //将位置传给小球。
    title->setPosition(ptNext);
    

}
Example #7
0
void PauseLayer::buildUI() {
  this->removeAllChildrenWithCleanup(true);
  _state = PauseLayerStateTop;
  
  this->setTouchEnabled(true);
  
  CCDirector* director = CCDirector::sharedDirector();
  
  CCLayerColor* background = CCLayerColor::create(ccc4(0, 0, 0, 128), director->getWinSize().width, director->getWinSize().height);
  this->addChild(background);
  
  CCSprite* pause = CCSprite::create("pause_label.png");
  pause->setPosition(ccp(director->getWinSize().width / 2.0, 250));
  this->addChild(pause);
  
  _topMenu = CCMenu::create(CCMenuItemImage::create("resume.png", "resume_pressed.png", this, menu_selector(PauseLayer::onCancelPressed)),
                            CCMenuItemImage::create("replay.png", "replay_pressed.png", this, menu_selector(PauseLayer::onReplayPressed)),
                            CCMenuItemImage::create("title.png", "title_pressed.png", this, menu_selector(PauseLayer::onTitlePressed)),
                            NULL);
  
  _confirmMenu = CCMenu::create(CCMenuItemImage::create("yes.png", "yes_pressed.png",
                                                        this, menu_selector(PauseLayer::onYesPressed)),
                                CCMenuItemImage::create("no.png", "no_pressed.png",
                                                        this, menu_selector(PauseLayer::onNoPressed)),
                                NULL);
  _topMenu->setPosition(ccp(director->getWinSize().width / 2.0, 140));
  _confirmMenu->setPosition(ccp(director->getWinSize().width / 2.0, 140));
  _topMenu->alignItemsVerticallyWithPadding(20);
  _topMenu->setAnchorPoint(ccp(0.5, 0.5));
  _confirmMenu->setAnchorPoint(ccp(0.5, 0.5));
  _confirmMenu->alignItemsVerticallyWithPadding(20);
  
  _descriptionLabel = CCLabelTTF::create("ゲームを中断します。よろしいですか?", FONT_NAME, 16);
  _descriptionLabel->setPosition(ccp(director->getWinSize().width / 2.0, 200));
  _descriptionLabel->setVisible(false);
  this->addChild(_descriptionLabel);
  
  _topMenu->retain();
  _confirmMenu->retain();
  _descriptionLabel->retain();
  
  _pausedTargets = new CCSet();
  
  this->addChild(_topMenu);
}
bool AppDelegate::applicationDidFinishLaunching()
{
	// As an example, load config file
	// XXX: This should be loaded before the Director is initialized,
	// XXX: but at this point, the director is already initialized
	CCConfiguration::sharedConfiguration()->loadConfigFile("configs/config-example.plist");

    // initialize director
    CCDirector *pDirector = CCDirector::sharedDirector();
    pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());

//    CCSize screenSize = CCEGLView::sharedOpenGLView()->getFrameSize();

    CCSize designSize = CCSizeMake(720, 540);
    
    CCLog("winSize: %f  %f", pDirector->getWinSize().width, pDirector->getWinSize().height );


//    if (screenSize.height > 320)
//    {
//        CCSize resourceSize = CCSizeMake(960, 640);
//        std::vector<std::string> searchPaths;
//        searchPaths.push_back("hd");
//        pFileUtils->setSearchPaths(searchPaths);
//        pDirector->setContentScaleFactor(resourceSize.height/designSize.height);
//    }

    CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionNoBorder);

//    CCScene * pScene = CCScene::create();
//    CCLayer * pLayer = new TestController();
    
//    pLayer->autorelease();

//    pScene->addChild(pLayer);
    
//    CCScene* pScene = CCScene::create();
    CCScene* pScene = SceneEditorTestLayer::scene();
    pDirector->runWithScene(pScene);

    pDirector->setDisplayStats(false);
    return true;
}
Example #9
0
//---------------------------------------------------------------
//
//
void CLetterMoveLayer::preVisitWithClippingRect(CCRect clipRect)
{
    if (!this->getIsVisible())
        return;
	
    glEnable(GL_SCISSOR_TEST);
	
    CCDirector *director = CCDirector::sharedDirector();
    CCSize size =director->getWinSize();
    CCPoint origin = this->convertToWorldSpaceAR(clipRect.origin);
    CCPoint topRight =this->convertToWorldSpaceAR(ccpAdd(clipRect.origin, ccp(clipRect.size.width, clipRect.size.height)));
    CCRect scissorRect = CCRectMake(origin.x, origin.y, topRight.x-origin.x, topRight.y-origin.y);
	
    // transform the clipping rectangle to adjust to the current screen
    // orientation: the rectangle that has to be passed into glScissor is
    // always based on the coordinate system as if the device was held with the
    // home button at the bottom. the transformations account for different
    // device orientations and adjust the clipping rectangle to what the user
    // expects to happen.
    ccDeviceOrientation orientation =director->getDeviceOrientation();
    switch (orientation) {
        case kCCDeviceOrientationPortrait:
            break;
        case kCCDeviceOrientationPortraitUpsideDown:
            scissorRect.origin.x = size.width-scissorRect.size.width-scissorRect.origin.x;
            scissorRect.origin.y = size.height-scissorRect.size.height-scissorRect.origin.y;
            break;
        case kCCDeviceOrientationLandscapeLeft:
        {
            float tmp = scissorRect.origin.x;
            scissorRect.origin.x = scissorRect.origin.y;
            scissorRect.origin.y = size.width-scissorRect.size.width-tmp;
            tmp = scissorRect.size.width;
            scissorRect.size.width = scissorRect.size.height; 
            scissorRect.size.height = tmp;
        }
            break;
        case kCCDeviceOrientationLandscapeRight:
        {
            float tmp = scissorRect.origin.y;
            scissorRect.origin.y = scissorRect.origin.x;
            scissorRect.origin.x = size.height-scissorRect.size.height-tmp;
            tmp = scissorRect.size.width;
            scissorRect.size.width = scissorRect.size.height;
            scissorRect.size.height = tmp;
        }
            break;
    }
	
    // Handle Retina
    scissorRect = CC_RECT_POINTS_TO_PIXELS(scissorRect);
	
    glScissor((GLint) scissorRect.origin.x, (GLint) scissorRect.origin.y,
              (GLint) scissorRect.size.width, (GLint) scissorRect.size.height);
}
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    CCDirector* pDirector = CCDirector::sharedDirector();
    CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();

    pDirector->setOpenGLView(pEGLView);
	CCSize frameSize = pEGLView->getFrameSize();
    
    // enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices.
    TargetPlatform target = getTargetPlatform();
    if(target == kTargetIpad)
    {
        // ipad
        if(pDirector->enableRetinaDisplay(true))
        {
            // ipad hd
            CCFileUtils::sharedFileUtils()->setResourceDirectory("ipadhd");
        }
        else
        {
            CCFileUtils::sharedFileUtils()->setResourceDirectory("ipad");
        }
    }
    else if(target == kTargetIphone)
    {
        // iphone
        if(pDirector->enableRetinaDisplay(true))
        {
            if(pDirector->getWinSize().width > 480)
            {
                // iphone hd 4'
                CCFileUtils::sharedFileUtils()->setResourceDirectory("iphone");
            }
            else
            {
                // iphone hd 3'
                CCFileUtils::sharedFileUtils()->setResourceDirectory("iphone");
            }
        }
    }
	
    // turn on display FPS
    pDirector->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);

    // create a scene. it's an autorelease object
    CCScene *pScene = HelloWorld::scene();

    // run
    pDirector->runWithScene(pScene);

    return true;
}
Example #11
0
void CCScene::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent) {
    if(!mEnableSlideBack)
        return;
    CCPoint start = pTouch->getStartLocation();
    CCPoint end = pTouch->getLocation();
    CCDirector *d = CCDirector::sharedDirector();
    float w = d->getWinSize().width;
    if (start.x - end.x < -w/3.0f){
        scheduleOnce(schedule_selector(CCScene::delayBack), 0.0f);
    }
}
Example #12
0
bool CCScene::init()
{
    bool bRet = false;
     do 
     {
         CCDirector * pDirector;
         CC_BREAK_IF( ! (pDirector = CCDirector::sharedDirector()) );
         this->setContentSize(pDirector->getWinSize());
         // success
         bRet = true;
     } while (0);
     return bRet;
}
Example #13
0
bool MapScene::init()
{
	bool inited = false;
	do 
	{
		CCDirector * pDirector;
		CC_BREAK_IF(! (pDirector = CCDirector::sharedDirector()) );
		this->setContentSize(pDirector->getWinSize());

		inited = true;
	} while (0);
	return inited;
}
Example #14
0
void MapTileLayer::draw()
{
	if (map)
	{
		CHECK_GL_ERROR_DEBUG();
		CCDirector* direct = CCDirector::sharedDirector();
		int i = 0;
		CCSize mapTotalSize;
		mapTotalSize.width = map->nodeData->matrix->col * map->nodeSize->width;
		mapTotalSize.height = map->nodeData->matrix->row * map->nodeSize->height;
		for (i = 0; i <= map->nodeData->matrix->col; i ++)
		{
			MSPoint3D startP(i * map->nodeSize->width, 0, 0);
			MSPoint3D endP(i * map->nodeSize->width, 0, mapTotalSize.height);
			CCPoint sp = MapUtils::convertScreen(startP);
			CCPoint ep = MapUtils::convertScreen(endP);
			sp.y = CoordinateUtils::calculateCoordinateSystem(sp.y, direct->getWinSize());
			ep.y = CoordinateUtils::calculateCoordinateSystem(ep.y, direct->getWinSize());
			ccDrawLine(sp, ep);	
		}
		for (i = 0; i <= map->nodeData->matrix->row; i ++)
		{
			MSPoint3D startQ(0, 0, i * map->nodeSize->height);
			MSPoint3D endQ(mapTotalSize.width, 0, i * map->nodeSize->height);
			CCPoint sq = MapUtils::convertScreen(startQ);
			CCPoint eq = MapUtils::convertScreen(endQ);
			sq.y = CoordinateUtils::calculateCoordinateSystem(sq.y, direct->getWinSize());
			eq.y = CoordinateUtils::calculateCoordinateSystem(eq.y, direct->getWinSize());
			ccDrawLine(sq, eq);
		}
		CHECK_GL_ERROR_DEBUG();
	}
	else
	{
		CCLayer::draw();
	}

}
Example #15
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayerColor::initWithColor(ccc4(255, 255, 255, 255)))
    {
        return false;
    }

    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    // add a "close" icon to exit the progress. it's an autorelease object
    CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
                                        "CloseNormal.png",
                                        "CloseSelected.png",
                                        this,
                                        menu_selector(HelloWorld::menuCloseCallback) );
    pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20) );

    // create menu, it's an autorelease object
    CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
    pMenu->setPosition( CCPointZero );
    this->addChild(pMenu, 1);

    /////////////////////////////
    // 3. add your codes below...

    // add a label shows "Hello World"
    // create and initialize a label
    CCDirector* dir = CCDirector::sharedDirector();
    CCSize winsize = dir->getWinSize();
    
    CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Thonburi", 34);
    pLabel->setPosition(ccp(winsize.width/2, winsize.height - 30));
    this->addChild(pLabel);
    
    CCSprite* player = CCSprite::create("Player.png");
    player->setPosition(ccp(player->getContentSize().width/2, winsize.height/2));
    this->addChild(player);
    
    this->schedule(schedule_selector(HelloWorld::Update_CreatedEnemy), 1.0f);
    this->scheduleUpdate();
    this->setTouchEnabled(true);
    
    CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("background-music-aac.wav", true);
    
    return true;
}
Example #16
0
bool ConfigMenu::init(){
	if(!CCLayer::init()){
		return false;
	}
	CCDirector* director = CCDirector::sharedDirector();
	this->setContentSize(director->getWinSize());

	MaskLayer* _mask = MaskLayer::create();
	this->addChild(_mask);
	_mask->setOpacity(200);

	makeMenu();
	return true;
}
bool GameLayer::init(){
	bool bRet = false;

	do{
		CC_BREAK_IF(!CCLayer::init());
		CCDirector* pDirector = CCDirector::sharedDirector();
		CCSize winSize = pDirector->getWinSize();
		thisGame = this;
		isGameEnded = false;

		//add background
		background = CCSprite::create("ui/scene_clean.png");
		//float scaleRatio = winSize.height / background->getContentSize().height;
		//background->setScale(scaleRatio);
		background->setAnchorPoint(ccp(0, 0));
		background->setPosition(ccp(0, 0));
		this->addChild(background);


		//add decoration
		CCSprite* wall = CCSprite::create("ui/wall.png");
		wall->setPosition(ccp(wall->getContentSize().width / 2, 
			105 + wall->getContentSize().height / 2));
		//wall->setOpacity(50);
		this->addChild(wall);

		CCSprite* bamboo = CCSprite::create("ui/bamboo.png");
		bamboo->setPosition(ccp(winSize.width - bamboo->getContentSize().width / 2,
			105 + bamboo->getContentSize().height / 2));
		this->addChild(bamboo);
		
		
		//add back to menu icon
		backIcon = CCSprite::create("ui/back.png");
		backIcon->setPosition(ccp(winSize.width / 2,	//winSize.width - backIcon->getContentSize().width / 2,
			winSize.height - backIcon->getContentSize().height / 2));
		this->addChild(backIcon);

		//add HeroLayer (add hero and enemy on the hero layer)
		this->heroLayer = HeroLayer::create();
		this->addChild(heroLayer);
		my_hero = this->heroLayer->getPlayerHero();
		enemy = this->heroLayer->getOpponentHero();

		bRet = true;
	} while (0);

	return bRet;
}
bool PMSGameScene::init()
{
    if( super::init() )
    {
        CCDirector* director = CCDirector::sharedDirector();
        ControlDualEngine* controls = ControlDualEngine::create( "engine_background.png", "engine_bar.png", "shot-c.png" );
        this->addChild( controls, PMSGameScene::Child::Z::controls, PMSGameScene::Child::ControlDualEngine_controls );
        
        PMSGameLayer* game = PMSGameLayer::create( director->getWinSize() );
        this->addChild( game, PMSGameScene::Child::Z::game, PMSGameScene::Child::CCPhysicsSpriteLayer_game );
        
        return true;
    }
    return false;
}
Example #19
0
bool CCLayer::init()
{
    bool bRet = false;
    do
    {
        CCDirector * pDirector;
        CC_BREAK_IF(!(pDirector = CCDirector::sharedDirector()));
        this->setContentSize(pDirector->getWinSize());
        m_bIsTouchEnabled = false;
        m_bIsAccelerometerEnabled = false;
        // success
        bRet = true;
    } while(0);
    return bRet;
}
Example #20
0
bool CCLobbyView::initTopMenu()
{
    CCDirector* director = CCDirector::sharedDirector();
    const CCSize winSize = director->getWinSize();
    const CCSize mySize = this->getContentSize();
    const CCPoint center = ccpMult( ccpFromSize( mySize ), 0.5f );
    
    CCLabelTTF* consoleLabel = CCLabelTTF::create( "disconnected", "Arial", FONT_SIZE(24), CCSizeMake( winSize.width, FONT_SIZE(24) ), kCCTextAlignmentCenter );
    consoleLabel->setColor( ccc3(255, 255, 255) );
    CCMenuItemLabel* consoleItem = CCMenuItemLabel::create( consoleLabel );
    
    // bottom
    const CCSize editSize = CCSizeMake( winSize.width, FONT_SIZE(48) );
    CCMenuItem* editItem = CCMenuItem::create();
    editItem->setContentSize( editSize );
    
    CCMenu* topMenu = CCMenu::create( consoleItem, editItem, NULL );
    if( topMenu )
    {
        this->setConsole( consoleLabel );
        
        topMenu->alignItemsVertically();
        topMenu->setPosition( CCPointMake( center.x, winSize.height - (editItem->getContentSize().height + consoleItem->getContentSize().height)/2 ) );
        this->addChild( topMenu, 0, Child::CCMenu_topMenu );
        
        const CCPoint editItemPosition = editItem->getParent()->convertToWorldSpace( editItem->getPosition() );
        editItem->setContentSize( winSize );
        editItem->ignoreAnchorPointForPosition( false );
        editItem->setAnchorPoint( ccp( 0.5f, (winSize.height / (editItemPosition.y - winSize.height)) * 0.5f ) );
        
        CCScale9Sprite* editSprite = CCScale9Sprite::create("extensions/yellow_edit.png");
        CCEditBox* edit = CCEditBox::create( editSize, editSprite );
        edit->setPlaceHolder("PlayerName");
        edit->setReturnType(kKeyboardReturnTypeDone);
        edit->setFontColor(ccGRAY);
        edit->setMaxLength( 20 );
        edit->setDelegate(this);
        edit->setTouchEnabled( true );
        edit->setPosition( editItemPosition );
        CocosNetworkLogic* network = CocosNetworkLogic::getInstance();
        JString userName = network->getUserName();
        edit->setText(userName.UTF8Representation().cstr());
        this->addChild( edit );
        this->setEditName(edit);
    }
    
    return topMenu;
}
Example #21
0
bool CCScene::init()
{
    bool bRet = false;
     do 
     {
         CCDirector * pDirector;
         CC_BREAK_IF( ! (pDirector = CCDirector::sharedDirector()) );
         this->setContentSize(pDirector->getWinSize());
         // success
         //bRet = true;
         // #HLP_BEGIN
         bRet = CCLayer::init();
         setTouchEnabled(true);
         // #HLP_END
     } while (0);
     return bRet;
}
bool MainMenu::init()
{
    if( CCMenu::init() && this->initPassAndPlay() && this->initQuit() )
    {
        CCDirector* director = CCDirector::sharedDirector();
        CCSize winSize = director->getWinSize();
        CCPoint winSizePoint = ccpFromSize( winSize );
        CCPoint center = ccpMult( winSizePoint, 0.5f );
        /*char str[128] = { '\0' };
        sprintf( str, "width %lf, height %lf", winSize.width, winSize.height );
        CCLabelTTF* label = CCLabelTTF::create( str, "American Typewriter.ttf",  16 );
        label->setPosition( center );
        this->getChildByTag( Child::CCMenuItem_playOnline )->addChild( label );*/
        this->alignItemsVertically();
        return true;
    }
    return false;        
}
bool ControlDualEngine::init( const char* background, const char* progressIndicator, const char* demandIndicator )
{
    if( super::init() )
    {
        this->setBackgroundName( background );
        this->setProgressIndicatorName( progressIndicator );
        this->setDemandIndicatorName( demandIndicator );
        
        CCDirector* director = CCDirector::sharedDirector();
        CCSize winSize = director->getWinSize();
        CCPoint winSizePoint = ccpFromSize( winSize );
        CCPoint center = ccpMult( winSizePoint, 0.5f );
        this->setContentSize( winSize );
        
        this->initEngine( Child::ControlEngine_left, ccp( 0, center.y ), ccp( 0, 0.5f ) );
        this->initEngine( Child::ControlEngine_right, ccp( winSize.width, center.y ), ccp( 1, 0.5f ) );
        return true;
    }
    return false;
}
Example #24
0
bool GameScene::init(int stage)
{
	bool bRet = false;
    do
    {
	    CCDirector * pDirector;
        CC_BREAK_IF( ! (pDirector = CCDirector::sharedDirector()) );
        this->setContentSize(pDirector->getWinSize());

        //add stage by stage number
        if(stage == 1)
        {
            this->addChild(StageOne::create());
        }
        else this->addChild(StageTwo::create());
        // success
        bRet = true;
    } while (0);
    return bRet;
}
Example #25
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    CCDirector* pDirector = CCDirector::sharedDirector();
    CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();

    pDirector->setOpenGLView(pEGLView);

    CCSize screenSize = pDirector->getWinSize();

    //set design screen size to the iPad and ExactFit (image is stretched to fill screen
    CCEGLView::sharedOpenGLView()->setDesignResolutionSize(768, 1024, kResolutionShowAll);
    //if device's screen width is greater than 768, use high definition images
    if (screenSize.width > 768) {
        cocos2d::CCFileUtils::sharedFileUtils()->addSearchPath("hd");
//        CCFileUtils::sharedFileUtils()->setResourceDirectory("hd");
        pDirector->setContentScaleFactor(2);
        //or else, use standard definition
    } else {
        cocos2d::CCFileUtils::sharedFileUtils()->addSearchPath("sd");
//        CCFileUtils::sharedFileUtils()->setResourceDirectory("sd");
        pDirector->setContentScaleFactor(1);
    }
    
    //preload sound effects
    SimpleAudioEngine::sharedEngine()->preloadEffect( (CCFileUtils::sharedFileUtils()->fullPathForFilename("hit.wav")).c_str() );
    SimpleAudioEngine::sharedEngine()->preloadEffect( (CCFileUtils::sharedFileUtils()->fullPathForFilename("score.wav")).c_str() );
    // turn on display FPS
    pDirector->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);

    // create a scene. it's an autorelease object
//    CCScene *pScene = HelloWorld::scene();
    CCScene *pScene = CCLobbyView::scene();

    // run
    pDirector->runWithScene(pScene);

    return true;
}
Example #26
0
bool StartLayer::init()
{
    bool ret = CCLayer::init();
    if (ret == false) {
        return false;
    }
    
    CCDirector *d = CCDirector::sharedDirector();
    CCSize size = d->getWinSize();
    
    CCSprite *bgSprite = new CCSprite();
    bgSprite->initWithFile("loading-hd.png");
    bgSprite->setPosition(ccp(0, 0));
    bgSprite->setAnchorPoint(ccp(0, 0));//有点意思...
    this->addChild(bgSprite);
    
    this->addMenu();
    
    return true;
    
}
Example #27
0
void GameLayer::ccTouchesEnded(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent)
{
    CCLog("touches --------------------");
    
    CCTouch *oneTouch = (CCTouch *)pTouches->anyObject();
    //获取当前触摸
    CCPoint touchPoint = oneTouch->getLocation();
    
    CCDirector *dc = CCDirector::sharedDirector();
    CCSize size = dc->getWinSize();
    CCLog("x is %f,y is %f",touchPoint.x,touchPoint.y);
    
    CCPoint beginPoint = CCPoint(size.width/2,0);//发射位置在中间
//    CCPoint beginPoint = CCPoint(touchPoint.x,0);//发射位置不在中间
    bullet = CCSprite::create("bullet010_2.png");
    bullet->setPosition(beginPoint);
  

    if (touchPoint.x<size.width/2) {
        bullet->setRotation(-45);
    }
    else{
        bullet->setRotation(45);
    }
    addChild(bullet);
    
    CCMoveTo *move = CCMoveTo::create(1.0f, touchPoint);
    
    CCCallFuncN *removeAction = CCCallFuncN::create(this, callfuncN_selector(GameLayer::removeFish));
    CCFiniteTimeAction *allAction = CCSequence::create(move,removeAction);
    bullet->runAction(allAction);
    


    //起一个计时器
//    schedule(schedule_selector(GameLayer::checkHit),1.0f);//1s添加一个小鱼
    checkHit(0.0f);
    
    
}
Example #28
0
bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    CCDirector *pDirector = CCDirector::sharedDirector();
    //pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
    
    pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
    
    CCSize screenSize = pDirector->getWinSize();
    CCLOG("%f %f", screenSize.width, screenSize.height);
    //CCSize screenSize = pEGLView->getFrameSize();
    //CCEGLView::sharedOpenGLView() -> setDesignResolutionSize(768, 1024, kResolutionExactFit);
    if (screenSize.width > 768) {
        CCLOG("hd");
        CCFileUtils::sharedFileUtils()->addSearchPath("hd");
        pDirector->setContentScaleFactor(2);
    } else {
        CCLOG("SD");
        //or else, use standard definition
        CCFileUtils::sharedFileUtils()->addSearchPath("sd");
        pDirector->setContentScaleFactor(1);
    }

    SimpleAudioEngine::sharedEngine()->preloadEffect(CCFileUtils::sharedFileUtils()->fullPathForFilename("hit.wav").c_str());
    SimpleAudioEngine::sharedEngine()->preloadEffect(CCFileUtils::sharedFileUtils()->fullPathForFilename("score.wav").c_str());
AVAudioSession
    // turn on display FPS
    pDirector->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);

    // create a scene. it's an autorelease object
    CCScene *pScene = GameLayer::scene();

    // run
    pDirector->runWithScene(pScene);

    return true;
}
Example #29
0
bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    CCDirector *pDirector = CCDirector::sharedDirector();
    pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
    
    CCEGLView::sharedOpenGLView()->setDesignResolutionSize(g_nScreenWidth, g_nScreenHeight, kResolutionShowAll);

    // turn on display FPS
    pDirector->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);
	

    // register lua engine
    CCLuaEngine* pEngine = CCLuaEngine::defaultEngine();
    CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine);
	
	lua_State * pLuaState = ScutDataLogic::LuaHost::Instance()->GetLuaState();

	//CDataRequest::Instance()->RegisterLUACallBack((LUA_DATAHANDLE_CALLBACK)&ScutCxControl::netDataDispatch);
	//CFrameManager::Instance(); 
	char tempPath[MAX_PATH + 1];
	::GetModuleFileNameA(NULL,tempPath, _MAX_PATH + 1);
	string ret((char*)tempPath);
	ret = ret.substr(0,ret.rfind("\\") +  1);

    //std::string path = CCFileUtils::sharedFileUtils()->fullPathForFilename("E:/ND/openSourceEngine/Scutgame/Release.win32/lua/mainapp.lua");
	std::string path =ret +  "lua/mainapp.lua";
	//CFileHelper::executeScriptFile(NdDataLogic::CFileHelper::getPath("lua/mainapp.lua").c_str());
     pEngine->executeScriptFile(path.c_str());

	 CCSize szWin = pDirector->getWinSize();
	 CFileHelper::setWinSize(szWin.width, szWin.height);

    return true;
}
Example #30
0
bool VictoryScene::init()
{
	bool bRet = false;
    do
    {
        CCDirector * pDirector;
        CC_BREAK_IF( ! (pDirector = CCDirector::sharedDirector()) );
        this->setContentSize(pDirector->getWinSize());
        CCSprite* pSprite = CCSprite::create("victory.png");
        
        // position the sprite on the center of the screen
        pSprite->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width * 0.5 , CCDirector::sharedDirector()->getVisibleSize().height * 0.5));
        // add the sprite as a child to this layer
        addChild(pSprite, -1);
        
		//create menu for game victory
		CCMenuItemFont* backMenu = CCMenuItemFont::create("Back To Menu",this,menu_selector(GameScene::menuPopSceneCallback));
		CCMenuItemFont* exit = CCMenuItemFont::create("Exit",this,menu_selector(GameOverScene::menuCloseCallback));

		CCMenu* menu;
       /* if (pItem!= NULL)
        {
            menu = CCMenu::create(pItem,backMenu,exit,NULL);
        }
		else
		{*/
			menu = CCMenu::create(backMenu,exit,NULL);
		//}
		menu->alignItemsVertically();
		menu->setColor(ccc3(0,0,0));
		addChild(menu,3);

        
        // success
        bRet = true;
    } while (0);
    return bRet;
}