Ejemplo n.º 1
0
void TakasuPoppo::swipeSetup() {
    CCSwipeGestureRecognizer *swipe = CCSwipeGestureRecognizer::create();
    swipe->setTarget(this, callfuncO_selector(TakasuPoppo::didSwipe));
    
    swipe->setDirection(kSwipeGestureRecognizerDirectionDown | kSwipeGestureRecognizerDirectionLeft |
                        kSwipeGestureRecognizerDirectionRight | kSwipeGestureRecognizerDirectionUp);
    swipe->setCancelsTouchesInView(true);
    this->addChild(swipe);
}
Ejemplo n.º 2
0
// on "init" you need to initialize your instance
bool MainGame::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    
    
    //creating and initialising swipe gesture recogniser
    CCSwipeGestureRecognizer * swipe = CCSwipeGestureRecognizer::create();
    swipe->setTarget(this, callfuncO_selector(MainGame::didSwipe));
    swipe->setDirection(kSwipeGestureRecognizerDirectionRight | kSwipeGestureRecognizerDirectionLeft| kSwipeGestureRecognizerDirectionUp| kSwipeGestureRecognizerDirectionDown);
    swipe->setCancelsTouchesInView(true);
    this->addChild(swipe);
    
    size = CCDirector::sharedDirector()->getWinSize();
    
    CCLog("size");
    std::cout<<size.width;
    
    
    //setting background
    std::string s1 = "background-iphone5.png";
    pSprite = CCSprite::create(s1.c_str());
    pSprite->setPosition(ccp(size.width/2, size.height/2) );
    this->addChild(pSprite, 0);
    
    
    
    
    
    //ntPopUp->setOpacity(255);
    
    
    
    //back button
    CCMenuItemImage* back = CCMenuItemImage::create(
                                                    "backtomenu.png",
                                                    "backtomenu.png",
                                                    this,
                                                    menu_selector(MainGame::backToChosen));
    back->setPosition(ccp(0,360));

    
    //new tile pop up image, pop up that appears when a new tile is reached
    ntPopUp = CCMenuItemImage::create(
                                      "newTilePopUp.png",
                                      "newTilePopUp.png",
                                      this,
                                      menu_selector(MainGame::closePopUp));
    ntPopUp->setPosition(ccp(0,0));
    ntPopUp->setOpacity(0);
    
    
    
    //game over pop up that appears when the game is over
    gameOver = CCMenuItemImage::create(
                                      "gameOver.png",
                                      "gameOver.png",
                                      this,
                                      menu_selector(MainGame::replay));
    gameOver->setPosition(ccp(0,0));
    gameOver->setOpacity(0);
    gameOver->setEnabled(false);
    
  
    
    
    CCMenu* menu = CCMenu::create();
    menu->addChild(back,100);
    menu->addChild(ntPopUp,1100);
    menu->addChild(gameOver,1000);

    this->addChild(menu,1000);
    
    
    //tile image at the bottom which shows your highest tile for the current game
    NewTopTileSprite = CCSprite::create("2.png");
    NewTopTileSprite->setScale(2.5);
    NewTopTileSprite->setOpacity(0);
    NewTopTileSprite->setPosition(ccp(size.width/2, size.height/2) );
    this->addChild(NewTopTileSprite, 1001);
    
    
    /*int hscore = CCUserDefault::sharedUserDefault()->getIntegerForKey("highscore");
    
    if(!hscore){
        hscore = 0;
    }
    
    std::stringstream ss;
    ss << hscore;
    std::string str = ss.str();
    
    
    //timeholder.insert(2,":");
    
    std::string s = "hello";*/
    
   
    
    
    
   
    
    
    
    
    
    
    
    
    //initialising the tile array
    tiles = new CCArray;
    
    
    //creates a 4*4 matrix or a 2d array.
    
	for(int i=0; i<4; i++)    //This loops on the rows.
	{
		for(int j=0; j<4; j++) //This loops on the columns
		{
			//board[i][j] = false; //you can also connect to the file
			//and place the name of your ifstream in the input after opening the file will
			//let you read from the file.
            tilesOnBoard[i][j] = NULL;
            NewTilesOnBoard[i][j] = NULL;
		}
	}
    
    //start with 2 tiles
    newTile();
    newTile();
    
    
    fiveTwelve = CCSprite::create("2.png");
    fiveTwelve->setPosition(ccp(size.width/2, size.height/2-409) );
    this->addChild(fiveTwelve, 1);
    
    
    
    
        CCLog("size");
    std::cout<<size.width;


    return true;
}
Ejemplo n.º 3
0
void homeLayer::animationcompleted(CCNode* sender)
{
    goes_next=false;
    CCNodeLoaderLibrary * ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
    /* Create an autorelease CCBReader. */
    cocos2d::extension::CCBReader * ccbReader=NULL;
    CCNode * node =NULL;
    if(game_click==11)
    {
        
        Scene_common* pScene = new Scene_common();
        if (pScene)
        {
            pScene->ReplaceScene("SelectPlayerLayer.ccbi","SelectPlayerLayer", SelectPlayerLayerLoader::loader(),this,true,callfuncO_selector(SelectPlayerLayer::onDidSwipe));
            pScene->release();
        }
        return;

        ccNodeLoaderLibrary->registerCCNodeLoader("CountNumberLayer", CountNumberLayerLoader::loader());
        ccbReader = new cocos2d::extension::CCBReader(ccNodeLoaderLibrary);
        /* Read a ccbi file. */
        // from each of the test scenes.
        node = ccbReader->readNodeGraphFromFile("CountGameLayer.ccbi", this);
        ((CountNumberLayer*)node)->setAnimationManager(ccbReader->getAnimationManager());
    }
    else if(game_click==12)
    {
        
        Scene_common* pScene = new Scene_common();
        if (pScene)
        {
          pScene->ReplaceScene("MainLayer.ccbi","MainLayer", MainLayerLoader::loader(),this,true,callfuncO_selector(homeLayer::onDidSwipe));
            pScene->release();
        }
        return;
//       ccNodeLoaderLibrary->registerCCNodeLoader("IdentifyNumberLayer", IdentifyNumberLayerLoader::loader());
//       ccbReader = new cocos2d::extension::CCBReader(ccNodeLoaderLibrary);
//       /* Read a ccbi file. */
//       // from each of the test scenes.
//       node = ccbReader->readNodeGraphFromFile("ClickGameLayer.ccbi", this);
    }
    else
    {
      ccNodeLoaderLibrary->registerCCNodeLoader("GamePlayLayer", GamePlayLayerLoader::loader());
      ccbReader = new cocos2d::extension::CCBReader(ccNodeLoaderLibrary);
      /* Read a ccbi file. */
      // from each of the test scenes.
      node = ccbReader->readNodeGraphFromFile("GamePlayLayer.ccbi", this);
      ((GamePlayLayer*)node)->setAnimationManager(ccbReader->getAnimationManager());
        
    }
    CCScene * scene = CCScene::create();
    ccbReader->autorelease();
    if(node != NULL)
    {
        CCSwipeGestureRecognizer * swipe = CCSwipeGestureRecognizer::create();
        swipe->setTarget(node,callfuncO_selector(GamePlayLayer::onDidSwipe));
        swipe->setDirection(kSwipeGestureRecognizerDirectionRight | kSwipeGestureRecognizerDirectionLeft|kSwipeGestureRecognizerDirectionUp|kSwipeGestureRecognizerDirectionDown);
        swipe->setCancelsTouchesInView(true);
        scene->addChild(swipe);

        scene->addChild(node);
        
    }
    //CCLog("moved to next scene");
    /* Push the new scene with a fancy transition. */
    CCDirector::sharedDirector()->pushScene(scene);
}