Exemple #1
0
void  Stage04::HitTest()
{
	auto mPlayer	= getChildByTag(1);
	if(mPlayer->getBoundingBox().containsPoint(grandma->getPosition()))
	{
		Director::getInstance()->replaceScene(TransitionSlideInL::create(1.0f,GameOverLayer::createScene()));
	}
	if(mPlayer->getBoundingBox().containsPoint(grandpa->getPosition()))
	{
		Director::getInstance()->replaceScene(TransitionSlideInL::create(1.0f,GameOverLayer::createScene()));
	}
	LeftCar* getLeftCar = NULL;
	for(int i = mLeftCarList.size() - 1;i >= 0;i--)
	{
		getLeftCar		=	mLeftCarList.at(i);
		if(mPlayer->getBoundingBox().containsPoint(getLeftCar->getPosition()))
		{
			if(!mIsGameOver)
			{
				mIsGameOver = true;
				Director::getInstance()->replaceScene(TransitionSlideInL::create(1.0f,GameOverLayer::createScene()));
		
			}
		}
	}
	RightCar* getRightCar = NULL;
	for(int i = mRightCarList.size() - 1;i >= 0;i--)
	{
		getRightCar		=	mRightCarList.at(i);
		if(mPlayer->getBoundingBox().containsPoint(getRightCar->getPosition()))
		{
			if(!mIsGameOver)
			{
				mIsGameOver = true;
				Director::getInstance()->replaceScene(TransitionSlideInL::create(1.0f,GameOverLayer::createScene()));
		
			}
		}
	}
}
void TMXLayer::removeTileAt(const Vector2& pos)
{
    CCASSERT(pos.x < _layerSize.width && pos.y < _layerSize.height && pos.x >=0 && pos.y >=0, "TMXLayer: invalid position");
    CCASSERT(_tiles && _atlasIndexArray, "TMXLayer: the tiles map has been released");

    int gid = getTileGIDAt(pos);

    if (gid) 
    {
        int z = pos.x + pos.y * _layerSize.width;
        ssize_t atlasIndex = atlasIndexForExistantZ(z);

        // remove tile from GID map
        _tiles[z] = 0;

        // remove tile from atlas position array
        ccCArrayRemoveValueAtIndex(_atlasIndexArray, atlasIndex);

        // remove it from sprites and/or texture atlas
        Sprite *sprite = (Sprite*)getChildByTag(z);
        if (sprite)
        {
            SpriteBatchNode::removeChild(sprite, true);
        }
        else 
        {
            _textureAtlas->removeQuadAtIndex(atlasIndex);

            // update possible children
            for(const auto &obj : _children) {
                Sprite* child = static_cast<Sprite*>(obj);
                ssize_t ai = child->getAtlasIndex();
                if ( ai >= atlasIndex )
                {
                    child->setAtlasIndex(ai-1);
                }
            }
        }
    }
}
Exemple #3
0
void MenuLayer2::alignMenusV()
{
    for(int i=0;i<2;i++) 
    {
        auto menu = static_cast<Menu*>( getChildByTag(100+i) );
        menu->setPosition( _centeredMenu );
        if(i==0) 
        {
            // TIP: if no padding, padding = 5
            menu->alignItemsVertically();            
            auto p = menu->getPosition();
            menu->setPosition(p + Vec2(100,0));
        } 
        else 
        {
            // TIP: but padding is configurable
            menu->alignItemsVerticallyWithPadding(40);    
            auto p = menu->getPosition();
            menu->setPosition(p - Vec2(100,0));
        }        
    }
}
Exemple #4
0
void Stage04::GameStep(float dt)
{
	moveAllCars();
	moveNPC();
	HitTest();
	//检测主角是否到了指定位置
	if(bus != NULL)
		if(bus->getPositionX() <= -300.0f)
		{
			bus->removeFromParent();
			bus = NULL;
		}
	
	if(mIsWin == true) return;
	auto s	= getChildByTag(1);
	float dis = ccpDistance(s->getPosition(),ccp(winSize.width / 2, winSize.height / 2 - 50));
	if(dis <= 15)
	{
		StagePass();
		mIsWin = true;
	}
}
Exemple #5
0
void MenuLayer2::alignMenusV()
{
	for(int i=0;i<2;i++) 
	{
		CCMenu *menu = (CCMenu*)getChildByTag(100+i);
		menu->setPosition( m_centeredMenu );
		if(i==0) 
		{
			// TIP: if no padding, padding = 5
			menu->alignItemsVertically();			
			CGPoint p = menu->getPosition();
			menu->setPosition( ccpAdd(p, CGPointMake(100,0)) );			
		} 
		else 
		{
			// TIP: but padding is configurable
			menu->alignItemsVerticallyWithPadding(40);	
			CGPoint p = menu->getPosition();
			menu->setPosition( ccpSub(p, CGPointMake(100,0)) );
		}		
	}
}
bool GameScene::ccTouchBegan(CCTouch* pTouch, CCEvent* pEvent) {
    if (isGameOver) {
        return true;
    }
    
    if (isShowingHint) {
        removeChildByTag(TAG_HINT, true);
        isShowingHint = false;
        
        CCSprite* bird = (CCSprite*)getChildByTag(TAG_BIRD);
        if (bird) {
            bird->stopAllActions();
            
            CCAnimation* animation = CCAnimation::create();
            for (int i = 0; i < 3; i++) {
                CCString* birdName = CCString::createWithFormat("bird%d_%d.png", birdID, i);
                CCSpriteFrame* frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(birdName->getCString());
                animation->addSpriteFrame(frame);
            }
            animation->setDelayPerUnit(0.08f);
            CCAnimate* animate = CCAnimate::create(animation);
            CCRepeatForever* repeat = CCRepeatForever::create(animate);
            bird->runAction(repeat);
        }
        CCLabelAtlas* score = CCLabelAtlas::create("0", "score_number.png", 30, 45, '0');
        score->setAnchorPoint(ccp(0.5f, 0.5f));
        score->setPosition(ccp(screenSize.width * 0.5f, screenSize.height * 0.85f));
        score->setScale(1.5f);
        addChild(score, 10, 999);
        
        schedule(schedule_selector(GameScene::pipeCreate), 1.5f, 99999, 2.0f);
        scheduleUpdate();
    }
    
    birdFlyLogic();
    
    return true;
}
Exemple #7
0
void Box2DTestLayer::addNewSpriteAtPosition(CCPoint p)
{
    CCLOG("Add sprite %0.2f x %02.f",p.x,p.y);
    CCNode* parent = getChildByTag(kTagParentNode);
    
    //We have a 64x64 sprite sheet with 4 different 32x32 images.  The following code is
    //just randomly picking one of the images
    int idx = (CCRANDOM_0_1() > .5 ? 0:1);
    int idy = (CCRANDOM_0_1() > .5 ? 0:1);
    PhysicsSprite *sprite = new PhysicsSprite();
    sprite->initWithTexture(m_pSpriteTexture, CCRectMake(32 * idx,32 * idy,32,32));
    sprite->autorelease();

    parent->addChild(sprite);
    
    sprite->setPosition( ccp( p.x, p.y) );
    
    // Define the dynamic body.
    //Set up a 1m squared box in the physics world
    b2BodyDef bodyDef;
    bodyDef.type = b2_dynamicBody;
    bodyDef.position.Set(p.x/PTM_RATIO, p.y/PTM_RATIO);

    b2Body *body = world->CreateBody(&bodyDef);
    
    // Define another box shape for our dynamic body.
    b2PolygonShape dynamicBox;
    dynamicBox.SetAsBox(.5f, .5f);//These are mid points for our 1m box
    
    // Define the dynamic body fixture.
    b2FixtureDef fixtureDef;
    fixtureDef.shape = &dynamicBox;    
    fixtureDef.density = 1.0f;
    fixtureDef.friction = 0.3f;
    body->CreateFixture(&fixtureDef);

    sprite->setPhysicsBody(body);
}
Exemple #8
0
void ChipmunkTestLayer::addNewSpriteAtPosition(Point pos)
{
#if CC_ENABLE_CHIPMUNK_INTEGRATION    
    int posx, posy;

    auto parent = getChildByTag(kTagParentNode);

    posx = CCRANDOM_0_1() * 200.0f;
    posy = CCRANDOM_0_1() * 200.0f;

    posx = (posx % 4) * 85;
    posy = (posy % 3) * 121;


    int num = 4;
    cpVect verts[] = {
        cpv(-24,-54),
        cpv(-24, 54),
        cpv( 24, 54),
        cpv( 24,-54),
    };

    cpBody *body = cpBodyNew(1.0f, cpMomentForPoly(1.0f, num, verts, cpvzero));

    body->p = cpv(pos.x, pos.y);
    cpSpaceAddBody(_space, body);

    cpShape* shape = cpPolyShapeNew(body, num, verts, cpvzero);
    shape->e = 0.5f; shape->u = 0.5f;
    cpSpaceAddShape(_space, shape);

    auto sprite = PhysicsSprite::createWithTexture(_spriteTexture, Rect(posx, posy, 85, 121));
    parent->addChild(sprite);

    sprite->setCPBody(body);
    sprite->setPosition(pos);
#endif
}
bool SJIndex::start(Touch*touch
                    , cocos2d::Event  *event)
{
    auto target = static_cast<Sprite*>(event->getCurrentTarget());

    cocos2d::Point locationInNode = target->convertToNodeSpace(touch->getLocation());
    cocos2d::Size s = target->getContentSize();
    cocos2d::Rect rect = cocos2d::Rect(0, 0, s.width, s.height);

    if (rect.containsPoint(locationInNode))
    {
    int tag=target->getTag();


    bool  isVeryHardUnLock = UserDefault::getInstance()->getBoolForKey("isVeryHardUnLock");

    if(tag==5&&!isVeryHardUnLock){
        auto move=MoveTo::create(0.3, Vec2(WIDTH/2, HEIGHT/3));
        auto jump=JumpTo::create(0.5, Vec2(WIDTH/2, HEIGHT/2), HEIGHT/6, 1);
        auto t=EaseIn::create(jump, 0.5);
        auto all=Sequence::create(move,t, NULL);
        alertBox->runAction(all);

        return false;
    }

    auto gameVC=SJGame::createScene();
    SJGame *g=(SJGame*)gameVC->getChildByTag(88);
    g->count=tag;

    TransitionScene *reScene=NULL;
    reScene=CCTransitionJumpZoom::create(0.5, gameVC);
//    gameVC:;
    Director::getInstance()->replaceScene(reScene);
        return true;
    }
    return false;
}
Exemple #10
0
void GameScene::onEnterTransitionDidFinish()
{
	Layer::onEnterTransitionDidFinish();
	auto UIComponent = (cocostudio::ComRender*) UINode->getComponent("gameSceneUI");
	auto UILayer = (Layer*)UIComponent->getNode();
	auto loadingBar = dynamic_cast<LoadingBar*>(UILayer->getChildByTag(GAMESCENE_LOADINGBAR));
	auto labelCombo = dynamic_cast<Text*>(UILayer->getChildByTag(GAMESCENE_LABEL_COMBO));
	auto labelInfo = dynamic_cast<Text*>(UILayer->getChildByTag(GAMESCENE_LABEL_INFO));
	auto labelLevel = dynamic_cast<Text*>(UILayer->getChildByTag(GAMESCENE_LABEL_LEVEL));
	auto labelDifficulty = dynamic_cast<Text*>(UILayer->getChildByTag(GAMESCENE_LABEL_DIFFICULTY));
	auto labelScore = dynamic_cast<Text*>(UILayer->getChildByTag(GAMESCENE_LABEL_PERCENT));
	/////////////////////////////////////////////////////	
	std::string musicname = FileUtils::getInstance()->fullPathForFilename("music/" + FileName + ".mp3");
	AudioEngine::getInstance()->create(musicname.c_str());
	auto title = AudioEngine::getInstance()->getName();
	if (title != "")
		labelInfo->setString(title);//显示ID3 TITLE
	else
		labelInfo->setString(FileName);//没获取到则显示文件名
	labelInfo->setColor(Color3B(64, 68, 72));
	MusicInfo info = MapUtils::loadMap(FileName.c_str());
	if (setting_difficulty == 0)
	{
		notenumber = info.NoteNumber_Easy;
		labelLevel->setString(info.Level_Easy);
		labelDifficulty->setString("Easy");
		labelLevel->setColor(Color3B(45, 65, 30));
		labelDifficulty->setColor(Color3B(45, 65, 30));
		labelScore->setColor(Color3B(45, 65, 30));
		preloadTime = 60;
	}
	else if (setting_difficulty == 1)
	{
		notenumber = info.NoteNumber_Hard;
		labelLevel->setString(info.Level_Hard);
		labelDifficulty->setString("Hard");
		labelLevel->setColor(Color3B(150, 15, 15));
		labelDifficulty->setColor(Color3B(150, 15, 15));
		labelScore->setColor(Color3B(150, 15, 15));
		preloadTime = 40;
	}
	labelCombo->setString("READY");
	loadingBar->setPercent(0);
	this->schedule(schedule_selector(GameScene::startGame), 0.02f);
}
void Sensors::closeAnalyticsDialog() {
  auto p_modal_mesurements_analytics =
      static_cast<scene::menu::MesurementsAnalytics *>(
          this->getChildByTag(Tag_Id_Mesurements_Analytics));

  // Slide Out Animation
  scene::layout::helper::Contents::SlideOut(
      p_modal_mesurements_analytics, 0.2f,
      scene::layout::helper::Contents::Forward_To_Right_e, true);

  // Update Select Record
  // read list view
  auto p_panel =
      this->_p_contents->getChildByName<ui::Layout *>("panelBackground");
  auto p_list_view = p_panel->getChildByName<ui::ListView *>("listSensors");
  auto p_widget = p_list_view->getItem(p_list_view->getCurSelectedIndex());
  lib::object::LocationItem location_item =
      lib::network::DataStoreSingleton::getInstance()->getLocationItem(
          p_modal_mesurements_analytics->getMSensorMainId());

  auto p_record = p_widget->getChildByTag(Tag_Id_Sensor_Record);
  this->setMesurementData(p_record, location_item);
}
Exemple #12
0
void LabelTTFOldNew::onDraw()
{
    kmMat4 oldMat;
    kmGLGetMatrix(KM_GL_MODELVIEW, &oldMat);
    kmGLLoadMatrix(&_modelViewTransform);
    
    auto label1 = (Label*)getChildByTag(kTagBitmapAtlas2);
    auto labelSize = label1->getContentSize();
    auto origin    = Director::getInstance()->getWinSize();
    
    origin.width = origin.width   / 2 - (labelSize.width / 2);
    origin.height = origin.height / 2 - (labelSize.height / 2);
    
    Point vertices[4]=
    {
        Point(origin.width, origin.height),
        Point(labelSize.width + origin.width, origin.height),
        Point(labelSize.width + origin.width, labelSize.height + origin.height),
        Point(origin.width, labelSize.height + origin.height)
    };
    DrawPrimitives::drawPoly(vertices, 4, true);
    
    kmGLLoadMatrix(&oldMat);
}
Exemple #13
0
void Load::LoadingBar(float dt)
{
    auto size = Director::getInstance()->getVisibleSize();
    auto lb = dynamic_cast<class LoadingBar*>(getChildByTag(1));
    float per = lb->getPercent() + 1.0f;
    lb->setPercent(per);
   //图片加载
    auto load = Sprite::create("load.png");
    load->setPosition(Vec2(size.width/2-150,size.height/2+60));
    auto moveTo = MoveTo::create(0.6,Vec2( size.width/2+130,size.height/2+60));
    auto seq = Sequence::create(moveTo, NULL);
    load->runAction(seq);
    addChild(load);
    
   if (per==100) {
       unschedule("LoadingBar");
       auto callf=CallFunc::create([this](){
           Director::getInstance()->replaceScene(GameScene::createScene());
       });
       auto seq=Sequence::create(DelayTime::create(1.1), callf,NULL);
       this->runAction(seq);
   }
    
}
Exemple #14
0
void GuideLayer::onTouchEnded(Touch* touch, Event  *event)
{
	log("onTouchEnded");
	Sprite* getObstacle = NULL;
	for(int i = mObstacleList.size() - 1;i >= 0;i--)
	{
		getObstacle			=	mObstacleList.at(i);
		if(mFootPrint->getBoundingBox().containsPoint(getObstacle->getPosition()))
		{
			
			MessageBox("路径上有障碍物","提示");
		}
		
	}
	mFootPrint = NULL;
	auto location = touch->getLocation();

	auto s	= getChildByTag(1);
	float dis = sqrt((s->getPositionX() - location.x)*(s->getPositionX() - location.x) + (s->getPositionY() - location.y)*(s->getPositionY() - location.y));
	float time = dis / 100;
	s->stopAllActions();
	s->runAction( MoveTo::create(time, Point(location.x, location.y) ) );
	float o = location.x - s->getPosition().x;
	float a = location.y - s->getPosition().y;
	float at = (float) CC_RADIANS_TO_DEGREES( atanf( o/a) );

	if( a < 0 ) 
	{
		if(  o < 0 )
			at = 180 + fabs(at);
		else
			at = 180 - fabs(at);    
	}
	s->runAction( RotateTo::create(0.2, at) );

}
Exemple #15
0
bool Landing::init()
{
    if ( !LayerColor ::initWithColor(Color4B(255, 255, 255, 255)) )
    {
        return false;
    }
    
    Size visiblesize=Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    thelogo=Sprite::create("ui/logo.png");
    thelogo->setScale(0.7);
    thelogo->setTag(101);
    thelogo->setPosition(Vec2(visiblesize.width/2, visiblesize.height/1.8));
    addChild(thelogo);
    
    auto touchme=Sprite::create("ui/touch.png");
    touchme->setScale(0.9);
    touchme->setPosition(Vec2(visiblesize.width/2, visiblesize.height/6));
    this->addChild(touchme);
    
    auto fadeout=FadeOut::create(1);
    auto fadein=FadeIn::create(1);
    auto seq=Sequence::create(fadeout,fadein, NULL);
    touchme->runAction(RepeatForever::create(seq));
    
    auto listener=EventListenerTouchOneByOne::create();
    listener->setSwallowTouches(true);
    listener->onTouchBegan=CC_CALLBACK_2(Landing::onTouchBegan, this);
    
    EventDispatcher * eventDispatcher=Director::getInstance()->getEventDispatcher();
    eventDispatcher->addEventListenerWithSceneGraphPriority(listener, getChildByTag(101));

   
    return true;
    
}
void GameScene::birdFlyLogic() {
    M3AudioManager::shareInstance()->playSound(SOUND_FLY);
    
    CCSprite* bird = (CCSprite*)getChildByTag(TAG_BIRD);
    bird->stopActionByTag(100);
    
    bird->setRotation(340);
    
    CCMoveBy* moveUp = CCMoveBy::create(0.2f, ccp(0, bird->getContentSize().height * 1.25f));
    CCEaseOut* upEout = CCEaseOut::create(moveUp, 2.25f);
    
    CCDelayTime* delay = CCDelayTime::create(0.2f);
    CCRotateBy* rotate = CCRotateBy::create(0.35f, 75);
    CCSequence* seq0 = CCSequence::create(delay, rotate, NULL);
    
    CCMoveBy* moveDown = CCMoveBy::create(1.5f, ccp(0, -screenSize.height * 1.5f));
    CCEaseIn* downIn = CCEaseIn::create(moveDown, 1.95f);
    
    CCSpawn* spawn = CCSpawn::create(seq0, downIn, NULL);
    
    CCSequence* seq = CCSequence::create(upEout, spawn, NULL);
    seq->setTag(100);
    bird->runAction(seq);
}
//------------------------------------------------------------------
//
// Effect1
//
//------------------------------------------------------------------
void Effect1::onEnter()
{
	EffectAdvanceTextLayer::onEnter();

	CCNode* target = getChildByTag(kTagBackground);
	
	// To reuse a grid the grid size and the grid type must be the same.
	// in this case:
	//     Lens3D is Grid3D and it's size is (15,10)
	//     Waves3D is Grid3D and it's size is (15,10)
	
	CGSize size = CCDirector::sharedDirector()->getWinSize();
	CCActionInterval* lens = CCLens3D::actionWithPosition(ccp(size.width/2,size.height/2), 240, ccg(15,10), 0.0f);
	CCActionInterval* waves = CCWaves3D::actionWithWaves(18, 15, ccg(15,10), 10);

	CCFiniteTimeAction* reuse = CCReuseGrid::actionWithTimes(1);
	CCActionInterval* delay = CCDelayTime::actionWithDuration(8);

	CCActionInterval* orbit = CCOrbitCamera::actionWithDuration(5, 1, 2, 0, 180, 0, -90);
	CCActionInterval* orbit_back = orbit->reverse();

	target->runAction( CCRepeatForever::actionWithAction( (CCActionInterval *)(CCSequence::actions( orbit, orbit_back, NULL) ) ) );
	target->runAction( CCSequence::actions(lens, delay, reuse, waves, NULL) );
}
void MainGameLayer::checkSwipe(float dt)
{
	MissionariesLayer* missionariesL = (MissionariesLayer*)getChildByTag(kTagLyrMissionaries);

	if( iSwipeStartY < iSwipeEndY 
		&& 20 < (iSwipeEndY - iSwipeStartY) )
	{
		log("Jump!");
		if(isLeftTouched)
		{
			//missionariesL->jump(true);
		}
		else
		{
			//missionariesL->jump(false);
		}

		// stop move
		unschedule(schedule_selector(MainGameLayer::checkTouchHold));

		// stop check swipe
		unschedule(schedule_selector(MainGameLayer::checkSwipe));
	}
}
void GridLayer::UpdateGridLabels()
{
   Viewport& viewport = Viewport::Instance();
   CCSize worldSize = viewport.GetWorldSizeMeters();
   float32 dx = (worldSize.width)/_subdivisions;
   float32 dy = (worldSize.height)/_subdivisions;
   uint32 tag = TAG_LABEL_GRID_BASE;
   float32 scale = viewport.GetScale();

   for(int idx = 0; idx <= _subdivisions; idx++)
   {
      for(int idy = 0; idy <= _subdivisions; idy++)
      {
         tag++;
         Vec2 pt(dx*idx-worldSize.width/2,dy*idy-worldSize.height/2);
         CCPoint pixel = viewport.Convert(pt);
         CCNode* label = (CCNode*)getChildByTag(tag);
         assert(label != NULL);
         label->setPosition(pixel);
         label->setScale(GRID_SCALE_FACTOR/scale);
      }
   }
   
}
//------------------------------------------------------------------
//
// Effect1
//
//------------------------------------------------------------------
void Effect1::onEnter()
{
    EffectAdvanceTextLayer::onEnter();

    auto target = getChildByTag(kTagBackground);
    
    // To reuse a grid the grid size and the grid type must be the same.
    // in this case:
    //     Lens3D is Grid3D and it's size is (15,10)
    //     Waves3D is Grid3D and it's size is (15,10)
    
    auto size = Director::getInstance()->getWinSize();
    auto lens = Lens3D::create(0.0f, Size(15,10), Point(size.width/2,size.height/2), 240);
    auto waves = Waves3D::create(10, Size(15,10), 18, 15);

    auto reuse = ReuseGrid::create(1);
    auto delay = DelayTime::create(8);

    auto orbit = OrbitCamera::create(5, 1, 2, 0, 180, 0, -90);
    auto orbit_back = orbit->reverse();

    target->runAction( RepeatForever::create( Sequence::create( orbit, orbit_back, NULL)  ) );
    target->runAction( Sequence::create(lens, delay, reuse, waves, NULL) );
}
Exemple #21
0
void TMXOrthoFlipRunTimeTestNew::flipIt(float dt)
{
    auto map = (cocos2d::experimental::TMXTiledMap*) getChildByTag(kTagTileMap);
    auto layer = map->getLayer("Layer 0");

    //blue diamond 
    auto tileCoord = Vec2(1,10);
    int flags;
    unsigned int GID = layer->getTileGIDAt(tileCoord, (TMXTileFlags*)&flags);
    // Vertical
    if( flags & kTMXTileVerticalFlag )
        flags &= ~kTMXTileVerticalFlag;
    else
        flags |= kTMXTileVerticalFlag;
    layer->setTileGID(GID ,tileCoord, (TMXTileFlags)flags);


    tileCoord = Vec2(1,8);    
    GID = layer->getTileGIDAt(tileCoord, (TMXTileFlags*)&flags);
    // Vertical
    if( flags & kTMXTileVerticalFlag )
        flags &= ~kTMXTileVerticalFlag;
    else
        flags |= kTMXTileVerticalFlag;    
    layer->setTileGID(GID ,tileCoord, (TMXTileFlags)flags);


    tileCoord = Vec2(2,8);
    GID = layer->getTileGIDAt(tileCoord, (TMXTileFlags*)&flags);
    // Horizontal
    if( flags & kTMXTileHorizontalFlag )
        flags &= ~kTMXTileHorizontalFlag;
    else
        flags |= kTMXTileHorizontalFlag;    
    layer->setTileGID(GID, tileCoord, (TMXTileFlags)flags);    
}
Exemple #22
0
bool GameScene::init()
{
	//super init
	if (!Layer::init())
	{
		return false;
	}
	Size visibleSize = Director::getInstance()->getVisibleSize();
	Point origin = Director::getInstance()->getVisibleOrigin();

	/////////////////////////////////////////////////////
	auto sceneNode = cocostudio::SceneReader::getInstance()->createNodeWithSceneFile("gameScene.json");
	addChild(sceneNode);
	UINode = sceneNode->getChildByTag(10004);
	MenuNode = sceneNode->getChildByTag(10005);
	auto UIComponent = (cocostudio::ComRender*) UINode->getComponent("gameSceneUI");
	auto PauseComponent = (cocostudio::ComRender*)MenuNode->getComponent("pauseSelectUI");
	auto UILayer = (Layer*)UIComponent->getNode();
	auto MenuLayer = (Layer*)PauseComponent->getNode();
	//////////
	auto buttonPause = dynamic_cast<Button*>(UILayer->getChildByTag(GAMESCENE_BUTTON_PAUSE));
	buttonPause->addTouchEventListener(this, toucheventselector(GameScene::touchEvent));
	buttonPause->setTouchEnabled(false);
	//////////
	auto bgPause = dynamic_cast<ImageView*>(MenuLayer->getChildByTag(GAMESCENE_MENU_BG));
	auto buttonRetry = dynamic_cast<Button*>(MenuLayer->getChildByTag(GAMESCENE_MENU_RETRY));
	auto buttonReturn = dynamic_cast<Button*>(MenuLayer->getChildByTag(GAMESCENE_MENU_RETURN));
	auto buttonResume = dynamic_cast<Button*>(MenuLayer->getChildByTag(GAMESCENE_MENU_RESUME));
	bgPause->addTouchEventListener(this, toucheventselector(GameScene::touchEvent));
	buttonRetry->addTouchEventListener(this, toucheventselector(GameScene::touchEvent));
	buttonReturn->addTouchEventListener(this, toucheventselector(GameScene::touchEvent));
	buttonResume->addTouchEventListener(this, toucheventselector(GameScene::touchEvent));
	bgPause->setEnabled(false);
	buttonRetry->setEnabled(false);
	buttonReturn->setEnabled(false);
	buttonResume->setEnabled(false);
	//////////
	return true;
}
Exemple #23
0
void MovedTile::doubleNumber()
{
	this->m_number = this->m_number*2;
	auto bk = static_cast<LayerColor*>(this->getChildByTag(110));
	auto label = static_cast<Label*>(bk->getChildByTag(10));
	label->setString(__String::createWithFormat("%d",m_number)->getCString());
	//动画
	bk->runAction(Sequence::create(
		ScaleTo::create(0.15f,0.8f),
		ScaleTo::create(0.15f,1.2f),
		ScaleTo::create(0.15f,1.0f),
		nullptr)
		);

	switch (this->m_number) {
	/*
	case 2:
		bk->setColor(Color3B(230,220,210));
		bk->setColor(Color3B(255,255,255));*///用不到
	case 4:
		bk->setColor(Color3B(230,210,190));
		break;
	case 8:
		bk->setColor(Color3B(230,150,100));
		label->setColor(Color3B(255,255,255));
		break;
	case 16:
		bk->setColor(Color3B(230,120,80));
		label->setColor(Color3B(255,255,255));
		break;
	case 32:
		bk->setColor(Color3B(230,100,90));
		label->setColor(Color3B(255,255,255));
		break;
	case 64:
		bk->setColor(Color3B(230,70,60));
		label->setColor(Color3B(255,255,255));
		break;
	case 128:
		label->setScale(0.8f);
		bk->setColor(Color3B(230,190,60));
		label->setColor(Color3B(255,255,255));
		break;
	case 256:
		bk->setColor(Color3B(230,190,60));
		label->setColor(Color3B(255,255,255));
		break;
	case 512:
		bk->setColor(Color3B(230,190,60));
		label->setColor(Color3B(255,255,255));
		break;
	case 1024:
		label->setScale(0.7f);
		break;
	case 2048:
		/*label->setScale(0.7);*///在1024已经放缩,再放缩就不合适了
		bk->setColor(Color3B(210,180,30));
		label->setColor(Color3B(255,255,255));
		UserDefault::getInstance()->setBoolForKey("On2048",true);
		break;
	default:
		break;
	}
}
void CJSScrollViewLayer::ccTouchEnded(CCTouch* touch, CCEvent* event)
{
	CCPoint ptTouch = touch->getLocationInView();
	ptTouch = CCDirector::sharedDirector()->convertToGL(ptTouch);

	CCLog("CJSScrollViewLayer::ccTouchEnded() x:%f , y:%f",ptTouch.x,ptTouch.y);

	CCPoint ptDif = ccpSub(ptTouch, mPtTouchBegan);

	if ( abs(ptDif.x) < 10) {
		CCScrollView *sv = (CCScrollView *)getChildByTag(TAG_JSSEL_SCROLLVIEW);
		CCRect rcScrollView = sv->boundingBox();

		CCPoint ptOffset = sv->getContentOffset();

		for (unsigned int i=0 ; i<m_arrThumb.count(); i++) {

			int nTag = TAG_JSSEL_SCROLLVIEW_SPRITE+i;
			CCSprite *sprite = (CCSprite *) m_arrThumb.objectAtIndex(i);
			CCRect rcSprite = sprite->boundingBox();

			CCRect rcTouch = rcSprite;
			rcTouch.origin.x += ptOffset.x + rcScrollView.origin.x;
			rcTouch.origin.y = rcScrollView.origin.y;

			if (true == rcTouch.containsPoint(ptTouch)) {

				//CCScene *pScene = CCScene::create();

				// sound 중지
				if ( CocosDenshion::SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying() )
					CocosDenshion::SimpleAudioEngine::sharedEngine()->stopBackgroundMusic();

				CocosDenshion::SimpleAudioEngine::sharedEngine()->stopAllEffects();

				//CCLog(">>>>>>>>>>>>>>>>> scrollview tag : %d",nTag-TAG_EBOOK_SCROLLVIEW_SPRITE+1);
		/*		CEbookLayer *layer = new CEbookLayer(nTag-TAG_JSSEL_SCROLLVIEW_SPRITE);	// 이미지 인덱스

				if (pScene && layer) {
					layer->autorelease();
					pScene->addChild(layer);
					CCDirector::sharedDirector()->replaceScene(pScene);
				}
		*/
				SELECT_GAME game;
				game.nLevel = m_nGameLevel;
				game.nImgIndex = nTag-TAG_JSSEL_SCROLLVIEW_SPRITE;

				CCUserDefault::sharedUserDefault()->setIntegerForKey("JS_GAME_LEVEL", m_nGameLevel);

/*	// 마지막 촬영 이미지 선택 시 Jni로 Android 카메라 앱 불러 촬영 후 이미지 획득 후 게임 실행
				if ( 12 == game.nImgIndex )
				{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
					m_strImgPath = (char*)getImagePathToPlatform();
					CCLog ("CJSScrollViewLayer m_strImgPath =  %s", m_strImgPath);
#else
					break;
#endif
				}
				else
				{
					pScene = JS_Main::scene(game);
					CCDirector::sharedDirector()->replaceScene(CCTransitionFade::create( 0.3f, pScene ) );
				}
*/
				break;
			}
		}
	}
}
Exemple #25
0
CCSprite* CCTubeGridTile::getChildForStartErasingAt(int direction)
{
	CCSprite*prtSprite = NULL;
	if (DIRECTION_TOP == direction)
	{
		prtSprite = (CCSprite*)getChildByTag(TAG_CURVE_TOPLEFT);
		if (NULL == prtSprite)
		{
			prtSprite = (CCSprite*)getChildByTag(TAG_CURVE_TOPRIGHT);
		}
		if (NULL == prtSprite)
		{
			prtSprite = (CCSprite*)getChildByTag(TAG_LINE_VERTICAL);
		}
	}
	else if (DIRECTION_LEFT == direction)
	{
		prtSprite = (CCSprite*)getChildByTag(TAG_CURVE_TOPLEFT);
		if (NULL == prtSprite)
		{
			prtSprite = (CCSprite*)getChildByTag(TAG_CURVE_BOTTONLEFT);
		}
		if (NULL == prtSprite)
		{
			prtSprite = (CCSprite*)getChildByTag(TAG_LINE_HORIZONTAL);
		}
	}
	else if (DIRECTION_BOTTON == direction)
	{
		prtSprite = (CCSprite*)getChildByTag(TAG_CURVE_BOTTONLEFT);
		if (NULL == prtSprite)
		{
			prtSprite = (CCSprite*)getChildByTag(TAG_CURVE_BOTTONRIGHT);
		}
		if (NULL == prtSprite)
		{
			prtSprite = (CCSprite*)getChildByTag(TAG_LINE_VERTICAL);
		}
	}
	else if (DIRECTION_RIGHT == direction)
	{
		prtSprite = (CCSprite*)getChildByTag(TAG_CURVE_BOTTONRIGHT);
		if (NULL == prtSprite)
		{
			prtSprite = (CCSprite*)getChildByTag(TAG_CURVE_TOPRIGHT);
		}
		if (NULL == prtSprite)
		{
			prtSprite = (CCSprite*)getChildByTag(TAG_LINE_HORIZONTAL);
		}
	}

	return prtSprite;
}
void 
GamePlaying::onTouchEnded(Touch* t,Event* ev){
	if(_slushLimit==0){
		return;
	}

	auto stigma = getChildByName("stigma");
	stigma->setName("");
	stigma->runAction(Sequence::createWithTwoActions(FadeOut::create(0.5f),RemoveSelf::create()));

	//CreateSlushParticle(_touchedPos,t->getLocation());

	bool flg=false;
	///カットチェック
	for(MyPolygon& p : _polygons){
		auto nnode = getChildByTag(p.tag);
		if(nnode==nullptr){
			continue;
		}
		auto psp=(MyPhysicsShape*)(nnode->getPhysicsBody()->getFirstShape());
		auto cps=(cpPolyShape*)(psp->getPolyShape());
		
		auto& polyPos = getChildByTag(p.tag)->getPosition();
		for(int j=0;j<cps->numVerts;++j){
			if(j==cps->numVerts-1){
				flg=IsIntersected(_touchedPos,
					t->getLocation(),
					Vec2(cps->tVerts[j].x,cps->tVerts[j].y),
					Vec2(cps->tVerts[0].x,cps->tVerts[0].y));
				if(flg){
					PosUv posuv;
					posuv.pos = IntersectedPoint(_touchedPos,
								t->getLocation(),
								Vec2(cps->tVerts[j].x,cps->tVerts[j].y),
								Vec2(cps->tVerts[0].x,cps->tVerts[0].y));
					//とりあえずvertsのインデックスとp.vertices,p.uvsのインデクスが同一であると仮定する。
					posuv.uv = GetMidUV(Vec2(cps->verts[j].x,cps->verts[j].y)+polyPos,
						p.uvs[j],
						Vec2(cps->tVerts[0].x,cps->tVerts[0].y),
						p.uvs[0],
						posuv.pos);
					p.cutEdges.push_back(std::make_pair(j,posuv));//インデックスとuv&posのペア
					p.wasCut=true;
					
				}
			}else{
				flg=IsIntersected(_touchedPos,
					t->getLocation(),
					Vec2(cps->tVerts[j].x,cps->tVerts[j].y),
					Vec2(cps->tVerts[j+1].x,cps->tVerts[j+1].y));
				if(flg){
					PosUv posuv;
					posuv.pos =IntersectedPoint(_touchedPos,
								t->getLocation(),
								Vec2(cps->tVerts[j].x,cps->tVerts[j].y),
								Vec2(cps->tVerts[j+1].x,cps->tVerts[j+1].y));
					//とりあえずvertsのインデックスとp.vertices,p.uvsのインデクスが同一であると仮定する。
					posuv.uv = GetMidUV(Vec2(cps->tVerts[j].x,cps->tVerts[j].y),
						p.uvs[j],
						Vec2(cps->tVerts[j+1].x,cps->tVerts[j+1].y),
						p.uvs[j+1],
						posuv.pos);
					p.cutEdges.push_back(std::make_pair(j,posuv));
					p.wasCut=true;

				}
			}
		}
	}

	std::vector<Vec2> cuttingEdges;

	///一時的…追加用ベクタ作成
	std::vector<MyPolygon> addedpolygons(0);
	int cutcount=0;
	///分離処理(頂点の生成)
	for(MyPolygon& p : _polygons){
		if(p.cutEdges.empty() || p.cutEdges.size()==1){//カットできてない場合は次へ
			p.wasCut=false;
			p.cutEdges.clear();
			continue;
		}
		++cutcount;
		//n番目がカットされている場合、nとn+1の間をカットしている
		//カットされている場合は2つのカットポイントが存在する

		Vec2& fpos=p.cutEdges[0].second.pos;
		Vec2& spos=p.cutEdges[1].second.pos;

		if((_touchedPos-fpos).length()>(_touchedPos-spos).length()){
			//切るエフェクトの発生
			CreateSlushParticle(spos,fpos);
		}else{
			//切るエフェクトの発生
			CreateSlushParticle(fpos,spos);
		}

		//とりあえず複製を一つ用意する

		//頂点数も変わる。エッジ番号の差が1なら残りの頂点数は1つまり差=残り頂点数となる

		//↑2つが新たな頂点となる(ソートが必要)
		if(p.cutEdges[0].first > p.cutEdges[1].first){
			std::swap(p.cutEdges[0],p.cutEdges[1]);
		}

		auto nnode = getChildByTag(p.tag);
		auto& polyPos = nnode->getPosition();
		auto psp=(MyPhysicsShape*)(nnode->getPhysicsBody()->getFirstShape());
		auto cps=(cpPolyShape*)(psp->getPolyShape());

		//sort完了
		//差を算出
		int diff = p.cutEdges[1].first-p.cutEdges[0].first;
		Vec2 pos=p.position;
		MyPolygon poly;
		std::vector<Vec2>& tmpUvs=p.uvs;

		poly.vertices.clear();
		poly.uvs.clear();
		
		poly.tag = p.tag;
		poly.texId = p.texId;
		poly.wasCut=p.wasCut;

		Vec2 newpos = p.cutEdges[0].second.pos-polyPos;
		poly.vertices.push_back(newpos);
		poly.uvs.push_back(p.cutEdges[0].second.uv);//切断端点
		for(int i=1;i<=diff;++i){
			int idx=p.cutEdges[0].first+i;
			cpVect& ve=cps->tVerts[idx];//元の座標を利用
			newpos = Vec2(ve.x,ve.y)-polyPos;
			poly.vertices.push_back(newpos);
			poly.uvs.push_back(tmpUvs[idx]);
		}
		newpos = p.cutEdges[1].second.pos-polyPos;
		poly.vertices.push_back(newpos);
		poly.uvs.push_back(p.cutEdges[1].second.uv);//切断端点
		poly.position = polyPos;
		addedpolygons.push_back(poly);

		poly.vertices.clear();
		poly.uvs.clear();

		//もうひとつのポリゴン
		diff=p.vertices.size()-diff;
		poly.texId = p.texId;
		poly.wasCut=p.wasCut;
		newpos = p.cutEdges[1].second.pos-polyPos;
		poly.vertices.push_back(newpos);
		poly.uvs.push_back(p.cutEdges[1].second.uv);//切断端点
		for(int i=1;i<=diff;++i){
			int idx = (p.cutEdges[1].first+i)%p.vertices.size();
			cpVect& ve=cps->tVerts[idx];//元の座標を利用
			newpos = Vec2(ve.x,ve.y)-polyPos;
			poly.vertices.push_back(newpos);
			poly.uvs.push_back(tmpUvs[idx]);
		}
		newpos = p.cutEdges[0].second.pos-polyPos;
		poly.vertices.push_back(newpos);
		poly.uvs.push_back(p.cutEdges[0].second.uv);//切断端点
		poly.position = polyPos;
		addedpolygons.push_back(poly);
	}

	//切れてなければリターンする
	if(cutcount==0){
		removeChild(stigma);
		return;
	}

	for(auto& p : _polygons){
		auto node = getChildByTag(p.tag);
		if(node==nullptr){
			continue;
		}
		auto& polyPos = node->getPosition();
		if(!p.wasCut){
			p.position=polyPos;
		}
	}

	//切れてしまっている奴は、別の2つに生まれ変わっているので、元のは消す。
	for(auto& p : _polygons){
		if(p.wasCut){
			removeChild(getChildByTag(p.tag));
		}
	}

	class IFunction{
	public:
		bool operator()(MyPolygon& a){
			return a.wasCut;
		}
	};

	_polygons.erase(std::remove_if(_polygons.begin(),_polygons.end(),IFunction()),_polygons.end());

	std::copy(addedpolygons.begin(),addedpolygons.end(),std::back_inserter(_polygons));
	
	///実際のポリゴン生成
	for(auto& pl : _polygons){
		if(!pl.wasCut){
			continue;
		}
		auto& v=pl.vertices;
		auto& uvs=pl.uvs;
		auto node = DrawNodeWithTex::create();
		node->SetTexture(pl.texId);
		//重心の計算(疑似)
		Vec2 center=Vec2(0,0);
		for(auto& vert : v){
			center+=vert;
		}
		center = center/v.size();
		for(auto& vert : v){
			vert-=center;
		}

		auto grave=PhysicsBody::createPolygon(&v[0],v.size(),_pm);

		node->drawPolygonT(&v[0],&uvs[0],v.size(),cocos2d::Color4F::YELLOW,0,Color4F::WHITE);
		
		for(Vec2&  uv : uvs){
			log("u=%f,v=%f",uv.x,uv.y);
		}

		pl.position+=center;
		node->setPosition(pl.position);
		node->setPhysicsBody(grave);
		node->setTag(_tag++);
		pl.tag=node->getTag();
		pl.wasCut=false;
		addChild(node);
		DrawNode* border=DrawNode::create();
		border->drawPolygon(&v[0],v.size(),Color4F(0,0,0,0.0),BORDER_WIDTH,Color4F::WHITE);
		node->addChild(border);
	}
	--_slushLimit;
}
Exemple #27
0
void Sensors::showSensorList() {
    // get http response
    auto http_response_data =
        lib::network::DataStoreSingleton::getInstance()->getResponseData(
            lib::network::DataStoreSingleton::Request_Pointcast_Home_e);

    const char* json = http_response_data.c_str();

    // JSON解析
    rapidjson::Document document;
    document.Parse<0>(json);
    if (document.HasParseError()) {
        // 解析エラー
        assert(false);
        return;
    }

    // read list view
    auto p_panel =
        this->_p_contents->getChildByName<ui::Layout*>("panelBackground");

    auto p_list_view = p_panel->getChildByName<ui::ListView*>("listSensors");
    p_list_view->setInnerContainerSize(p_list_view->getContentSize());
    p_list_view->setBounceEnabled(true);
    p_list_view->setTouchEnabled(true);

    p_list_view->addEventListener(
        [this](Ref* ref, ui::ListView::EventType eventType) {
            if (eventType == ui::ListView::EventType::ON_SELECTED_ITEM_END) {
                auto listView = static_cast<ui::ListView*>(ref);
                auto selectedIndex = listView->getCurSelectedIndex();

                // revert color all record
                for (auto widget : listView->getItems()) {
                    auto p_record = widget->getChildByTag(Tag_Id_Sensor_Record);
                    p_record->getChildByName<ui::Layout*>("panelRecord")
                        ->setColor(Color3B::WHITE);
                }
                // change color selected record
                auto widget = listView->getItem(selectedIndex);
                auto p_record = widget->getChildByTag(Tag_Id_Sensor_Record);
                p_record->getChildByName<ui::Layout*>("panelRecord")
                    ->setColor(Color3B(250, 219, 218));
                CCLOG("selected index %ld", selectedIndex);

                this->showAnalyticsDialog(widget->getTag());
            } else {
                CCLOG("touch list event type %d", eventType);
            }
        });

    std::map<int, lib::object::LocationItem> m_sensors =
        lib::network::DataStoreSingleton::getInstance()->getLocationItemAll();

    for (auto item : m_sensors) {
        auto p_record =
            CSLoader::getInstance()->createNode("res/sensors_record.csb");

        this->setMesurementData(p_record, item.second);

        auto widget = ui::Widget::create();
        p_record->setTag(Tag_Id_Sensor_Record);
        widget->addChild(p_record);
        widget->setTag(item.second.m_sensor_main_id);

        widget->setContentSize(p_record->getContentSize());
        p_list_view->pushBackCustomItem(widget);

        widget->setTouchEnabled(true);  // enable listview touch event
    }
}
void GameScene::step(float dt)
{
//	CCLog("Game::step");

	// Return if game suspended
	if(gameSuspended) return;

	// Get the bird sprite
	CCSprite *bird = (CCSprite*)getChildByTag(kBird);
	
	// Update the player x position based on velocity and delta time
	bird_pos.x += bird_vel.x * dt;
	
	// Flip the player based on it's x velocity and current looking direction
	if(bird_vel.x < -30.0f && birdLookingRight) 
	{
		birdLookingRight = false;
		bird->setScaleX(-1.0f);
	}
	else if (bird_vel.x > 30.0f && !birdLookingRight) 
	{
		birdLookingRight = true;
		bird->setScaleX(1.0f);
	}

	// Calculate the max and min x values for the bird
	// based on the screen and bird widths
	CCSize bird_size = bird->getContentSize();
	float max_x = (float)CCDirector::sharedDirector()->getWinSize().width - bird_size.width/2;
	float min_x = bird_size.width/2;
	
	// Limit the bird position based on max and min values allowed
	if(bird_pos.x>max_x) bird_pos.x = max_x;
	if(bird_pos.x<min_x) bird_pos.x = min_x;

	// Update the bird velocity based on acceleration and time
	bird_vel.y += bird_acc.y * dt;

	// Update the bird y positin based on velocity and time
	bird_pos.y += bird_vel.y * dt;
	
	////////////////////////////////////////////////////////////////////////////
	// Handle the bonus scoring
	CCSprite *bonus = (CCSprite*)getChildByTag(kBonusStartTag+currentBonusType);

	// If bonus is visible then see if the bird is within range to get the bonus
	if(bonus->isVisible() )
	{
		CCPoint bonus_pos = bonus->getPosition();
		float range = 20.0f;

		// If the player is within range of the bonus value then award the prize
		if(bird_pos.x > bonus_pos.x - range &&
		   bird_pos.x < bonus_pos.x + range &&
		   bird_pos.y > bonus_pos.y - range &&
		   bird_pos.y < bonus_pos.y + range ) 
		{
			// Update score based on bonus
			switch(currentBonusType) 
			{
				case kBonus5:   score += 5000;   break;
				case kBonus10:  score += 10000;  break;
				case kBonus50:  score += 50000;  break;
				case kBonus100: score += 100000; break;
			}

			// Build the score string to display
			char scoreStr[10] = {0};
			sprintf(scoreStr, "%d", score);
			CCLabelBMFont* scoreLabel = (CCLabelBMFont*) getChildByTag(kScoreLabel);
			scoreLabel->setString(scoreStr);

			// Highlight the score with some actions to celebrate the bonus win
			CCActionInterval* a1 = CCScaleTo::create(0.2f, 1.5f, 0.8f);
			CCActionInterval* a2 = CCScaleTo::create(0.2f, 1.0f, 1.0f);
			scoreLabel->runAction(CCSequence::create(a1, a2, a1, a2, a1, a2, NULL));

			// Reset the bonus to another platform
			resetBonus();
		}
	}

	// If the bird has stopped moving then make it jump from the platform it is on
	int t;
	if(bird_vel.y < 0) 
	{
		t = kPlatformsStartTag;

		// Search through all the platforms and compare the birds position with the platfor position
		for(t; t < kPlatformsStartTag + kNumPlatforms; t++) 
		{
			CCSprite *platform = (CCSprite*)getChildByTag(t);

			CCSize platform_size = platform->getContentSize();
			CCPoint platform_pos = platform->getPosition();
			
			max_x = platform_pos.x - platform_size.width/2 - 10;
			min_x = platform_pos.x + platform_size.width/2 + 10;

			float min_y = platform_pos.y + (platform_size.height+bird_size.height)/2 - kPlatformTopPadding;
			
			if(bird_pos.x > max_x &&
			   bird_pos.x < min_x &&
			   bird_pos.y > platform_pos.y &&
			   bird_pos.y < min_y) 
			{
				jump();
				break;	// Can only jump from one platform at a time to break out of the loop
			}
		}
	
		// If the bird has fallen below the screen then game over
		if(bird_pos.y < - bird_size.height/2) 
		{
			// [self showHighscores];   <== NEED TO IMPLEMENT THE HIGHTSCORE
			resetBird();	// Highscore not implmented yet so just keep on going.
		}
	} 
	else if ( bird_pos.y > ((float)CCDirector::sharedDirector()->getWinSize().height / 2)) 
	{
		// If bird position is greater than the middle of the screen then move the platforms
		// the difference between the bird y position and middle point of the screen
		float delta = bird_pos.y - ((float)CCDirector::sharedDirector()->getWinSize().height / 2);

		// Set the bird y position to the middle of the screen
		bird_pos.y = (float)CCDirector::sharedDirector()->getWinSize().height / 2;

		// Move the current platform y by the delta amount
		currentPlatformY -= delta;

		// Move the clouds vertically and reset if necessary
		t = kCloudsStartTag;
		for (t; t < kCloudsStartTag + kNumClouds; t++) 
		{
			CCSprite *cloud = (CCSprite*) getChildByTag(t);

			CCPoint pos = cloud->getPosition();

			// Calculate new position for cloud
			pos.y -= delta * cloud->getScaleY() * 0.8f;

			// If the cloud is off the screen then need to reset this cloud else set its new position
			if (pos.y < -cloud->getContentSize().height/2) 
			{
				currentCloudTag = t;
				resetCloud();
			} 
			else 
			{	// Update the new y position for the cloud.
				cloud->setPosition(pos);
			}
		}

		// Move the platforms vertically and reset if necessary
		t = kPlatformsStartTag;
		for (t; t < kPlatformsStartTag + kNumPlatforms; t++) 
		{
			CCSprite *platform = (CCSprite*)getChildByTag(t);
			
			CCPoint pos = platform->getPosition();

			// Calculate new position for platform
			pos = ccp(pos.x, pos.y - delta);

			// If the platform is off the screen then reset the platform else set its new position
			if(pos.y < - platform->getContentSize().height/2) 
			{
				currentPlatformTag = t;
				resetPlatform();
			} 
			else 
			{
				platform->setPosition(pos);
			}
		}

		// If the bonus is visible then adjust it's y position
		if(bonus->isVisible()) 
		{
			CCPoint pos = bonus->getPosition();

			// Calculate new position of bonus
			pos.y -= delta;
			
			// If the bonus is off the screen then reset the bonus else set its new position
			if(pos.y < -bonus->getContentSize().height/2 ) 
			{
				resetBonus();
			} 
			else 
			{
				bonus->setPosition(pos);
			}
		}
		
		// Update score based on how much the bird has moved
		score += (int)delta;

		// Display the new score value
		char scoreStr[10] = {0};
		sprintf(scoreStr, "%d", score);
		CCLabelBMFont* scoreLabel = (CCLabelBMFont*) getChildByTag(kScoreLabel);
		scoreLabel->setString(scoreStr);
	}

	// Set the birds position
	bird->setPosition(bird_pos);
}
void Scene_GameItem::onEnter()
{
    CCLayer::onEnter();
    this->initData();
    
    //隐藏pk界面
    this->setPkView(false);
	CCSprite* pSpriteBG = (CCSprite*)getChildByTag(eGameItemTagBg);
	CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
	//pSpriteBG->setPosition(ccp(visibleSize.width/2 , pSpriteBG->getContentSize().height/2 + origin.y));
	

	char str1[100]={0};
	switch(GameShare_Global::shareGlobal()->gameType)
	{
	case 1:
		sprintf(str1,"GameSceneBg1.json");
		break;
	case Game_Jelly:
		sprintf(str1,"GameSceneBg2.json");
		break;
	case Game_Fruit: 
		sprintf(str1,"GameSceneBg3.json");
		break;
	case Game_Link:
		sprintf(str1,"GameSceneBg4.json");
		break;
	case Game_TaiKo: 
		sprintf(str1,"GameSceneBg5.json");
		break;
	case Game_Cir:
		sprintf(str1,"GameSceneBg1.json");
		break;
	default:
		break;
	}

	UILayer* ul = UILayer::create();
	auto myLayout = dynamic_cast<Layout*>(GUIReader::shareReader()->widgetFromJsonFile(CStringUtil::convertToUIResPath(str1).c_str()));
	ul->addWidget(myLayout);
	this->addChild(ul, 0, 100);
	ul->setTouchEnabled(false);

	int nGameType = GameShare_Global::shareGlobal()->gameType;
	if (nGameType==1)
	{
		UIImageView* pHill = dynamic_cast<UIImageView*>(ul->getWidgetByName("san"));
		UIImageView* pHill2 = dynamic_cast<UIImageView*>(ul->getWidgetByName("san2"));
		//CCActionInterval*  actionTo = CCScaleTo::create(2.0f, 0.5f);
		CCActionInterval*  actionBy = CCScaleBy::create(1.0f, 1.0f, 1.1f);
		CCActionInterval*  actionBy2 = CCScaleBy::create(1.0f, 1.1f, 1.0f);
		CCFiniteTimeAction* seq = CCSequence::create(actionBy, actionBy->reverse(),NULL);
		CCActionInterval * repeatForever =CCRepeatForever::create((CCActionInterval* )seq);
		CCFiniteTimeAction* seq1 = CCSequence::create(actionBy2, actionBy2->reverse(),NULL);
		CCActionInterval * repeatForever2 =CCRepeatForever::create((CCActionInterval* )seq1);
		pHill->runAction(repeatForever);
		pHill2->runAction(repeatForever2);
	}
	else if (nGameType==2)
	{
		UIImageView*  pCloud = dynamic_cast<UIImageView*>(ul->getWidgetByName("yun2"));
		UIImageView*  pCloud2 = dynamic_cast<UIImageView*>(ul->getWidgetByName("yun3"));
		CCActionInterval*  actionBy = CCScaleBy::create(1.5f, 1.2f, 1.0f);
		CCActionInterval*  actionBy2 = CCScaleBy::create(1.5f, 1.2f, 1.0f);
		CCFiniteTimeAction* seq1 = CCSequence::create(actionBy, actionBy->reverse(),NULL);
		CCFiniteTimeAction* seq2 = CCSequence::create(actionBy2, actionBy2->reverse(),NULL);
		CCActionInterval * repeatForever1 =CCRepeatForever::create((CCActionInterval* )seq1);
		CCActionInterval * repeatForever2 =CCRepeatForever::create((CCActionInterval* )seq2);
		pCloud->runAction(repeatForever1);
		pCloud2->runAction(repeatForever2);
	}
	else if (nGameType==3)
	{
		UIImageView*  pSugar = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_15"));
		UIImageView*  pSugar1 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_20"));
		CCRotateBy* actionBy2 = CCRotateBy::create(1.5f, -25.0f, -25.0f);
		CCRotateBy* actionBy1 = CCRotateBy::create(1.5f, -25.0f, -25.0f);
		CCFiniteTimeAction* seq1 = CCSequence::create(actionBy2, actionBy2->reverse(), NULL);
		CCFiniteTimeAction* seq2 = CCSequence::create(actionBy1, actionBy1->reverse(), NULL);
		CCActionInterval * repeatForever1 =CCRepeatForever::create((CCActionInterval* )seq1);
		CCActionInterval * repeatForever2 =CCRepeatForever::create((CCActionInterval* )seq2);
		pSugar->runAction(repeatForever1);
		pSugar1->runAction(repeatForever2);

		//星星
		UIImageView*  pXx1 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_23"));
		UIImageView*  pXx2 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_32"));
		UIImageView*  pXx3 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_35"));
		UIImageView*  pXx4 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_39"));

		CCActionInterval*  actionBy3 = CCScaleBy::create(1.2f, 1.3f, 1.3f);
		CCActionInterval*  actionBy4 = CCScaleBy::create(1.2f, 1.3f, 1.3f);
		CCActionInterval*  actionBy5 = CCScaleBy::create(1.2f, 1.3f, 1.3f);
		CCActionInterval*  actionBy6 = CCScaleBy::create(1.2f, 1.3f, 1.3f);
		
		CCFiniteTimeAction* seq3 = CCSequence::create(actionBy3, actionBy3->reverse(),NULL);
		CCFiniteTimeAction* seq4 = CCSequence::create(actionBy4, actionBy4->reverse(),NULL);
		CCFiniteTimeAction* seq5 = CCSequence::create(actionBy5, actionBy5->reverse(),NULL);
		CCFiniteTimeAction* seq6 = CCSequence::create(actionBy6, actionBy6->reverse(),NULL);
		
		CCActionInterval * repeatForever3 =CCRepeatForever::create((CCActionInterval* )seq3);
		CCActionInterval * repeatForever4 =CCRepeatForever::create((CCActionInterval* )seq4);
		CCActionInterval * repeatForever5 =CCRepeatForever::create((CCActionInterval* )seq5);
		CCActionInterval * repeatForever6 =CCRepeatForever::create((CCActionInterval* )seq6);
		//pCloud->runAction(repeatForever1);
		pXx1->runAction(repeatForever3);
		pXx2->runAction(repeatForever4);
		pXx3->runAction(repeatForever5);
		pXx4->runAction(repeatForever6);
	}
	else if (nGameType==4)
	{
		UIImageView* pTree = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_8"));
		UIImageView* pTree1 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_13"));
		//CCActionInterval*  actionTo = CCScaleTo::create(2.0f, 0.5f);
		CCActionInterval*  actionBy = CCScaleBy::create(1.0f, 1.0f, 1.1f);
		CCActionInterval*  actionBy2 = CCScaleBy::create(1.0f, 1.0f, 1.1f);
		CCFiniteTimeAction* seq = CCSequence::create(actionBy, actionBy->reverse(),NULL);
		CCActionInterval * repeatForever =CCRepeatForever::create((CCActionInterval* )seq);
		CCFiniteTimeAction* seq1 = CCSequence::create(actionBy2, actionBy2->reverse(),NULL);
		CCActionInterval * repeatForever2 =CCRepeatForever::create((CCActionInterval* )seq1);
		pTree->runAction(repeatForever);
		pTree1->runAction(repeatForever2);
	}
	else if (nGameType ==5)
	{
		UIImageView* pXx1 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_38"));
		UIImageView* pXx2 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_41"));
		CCActionInterval*  actionBy = CCScaleBy::create(1.0f, 0.5f, 0.5f);
		CCActionInterval*  actionBy2 = CCScaleBy::create(1.0f, 0.5f, 0.5f);
		CCFiniteTimeAction* seq = CCSequence::create(actionBy, actionBy->reverse(),NULL);
		CCActionInterval * repeatForever =CCRepeatForever::create((CCActionInterval* )seq);
		CCFiniteTimeAction* seq1 = CCSequence::create(actionBy2, actionBy2->reverse(),NULL);
		CCActionInterval * repeatForever2 =CCRepeatForever::create((CCActionInterval* )seq1);
		pXx1->runAction(repeatForever);
		pXx2->runAction(repeatForever2);

		UIImageView* pUFO1 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_15"));
		UIImageView* pUFO2 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_21"));
		CCMoveBy* act1 = CCMoveBy::create(2.0, ccp(0, -25));
		CCMoveBy* act2 = CCMoveBy::create(1.0, ccp(0, 25));
		CCFiniteTimeAction* seq3 = CCSequence::create(act1, act1->reverse(),NULL);
		CCFiniteTimeAction* seq4 = CCSequence::create(act2, act2->reverse(),NULL);
		CCActionInterval * repeatForever3 =CCRepeatForever::create((CCActionInterval* )seq3);
		CCActionInterval * repeatForever4 =CCRepeatForever::create((CCActionInterval* )seq4);
		pUFO1->runAction(repeatForever3);
		pUFO2->runAction(repeatForever4);
	}

	if(nGameType ==2||nGameType ==3||nGameType ==4)
	{
		UIImageView* pMg1 = dynamic_cast<UIImageView*>(ul->getWidgetByName("mg1"));
		UIImageView* pMg2 = dynamic_cast<UIImageView*>(ul->getWidgetByName("mg2"));
		UIImageView* pMg3 = dynamic_cast<UIImageView*>(ul->getWidgetByName("mg3"));
		CCActionInterval*  actionBy10 = CCScaleBy::create(1.0f, 1.0f, 1.3f);
		CCActionInterval*  actionBy11 = CCScaleBy::create(1.0f, 1.0f, 1.3f);
		CCActionInterval * actionBy12 = CCSkewTo::create(1, 8, 8);
		CCActionInterval * actionBy13 = CCSkewTo::create(1, 0, 0);
		CCActionInterval * actionBy14 = CCSkewTo::create(1, -8, -8);
		CCFiniteTimeAction* seq10 = CCSequence::create(actionBy10, actionBy10->reverse(),NULL);
		CCActionInterval * repeatForever10 =CCRepeatForever::create((CCActionInterval* )seq10);
		CCFiniteTimeAction* seq11 = CCSequence::create(actionBy11, actionBy11->reverse(),NULL);
		CCActionInterval * repeatForever11 =CCRepeatForever::create((CCActionInterval* )seq11);
		CCFiniteTimeAction* seq12 = CCSequence::create(actionBy12, actionBy13,actionBy14,NULL);
		CCActionInterval * repeatForever12 =CCRepeatForever::create((CCActionInterval* )seq12);

		pMg1->runAction(repeatForever10);
		pMg2->runAction(repeatForever11);
		pMg3->runAction(repeatForever12);
	}
    //
	CCSprite* pAniSp = (CCSprite*)getChildByTag(AniLayerTag);
	pAniSp->stopAllActions();
	CCAnimation* pAni1 = CCAnimation::create();
	CCString str;
	for (int i = 1; i <= 4; ++i){
		str.initWithFormat("role/pig_tl/%d.png",i);
		pAni1->addSpriteFrameWithFileName(str.getCString());
	}
	pAni1->setDelayPerUnit(0.15f);
	pAni1->setLoops(1);

	CCActionInterval* pSeq = CCSequence::create(CCFlipX::create(false),CCAnimate::create(pAni1),CCFlipX::create(true),CCAnimate::create(pAni1),NULL);
	pAniSp->runAction(CCRepeatForever::create(pSeq));

	pAniSp->setPosition(ccp(visibleSize.width/2 + 20,visibleSize.height - pAniSp->getContentSize().height/2 - 93 + 19 -26));

	
}
void SGEquipStrengLayer::refreshView(SGEquipCard *card)
{
    _card = card;
    SGEquipmentDataModel *temp = SGStaticDataManager::shareStatic()->getEquipById(_card->getItemId());
	
    SGMainManager::shareMain()->addEquipPng(temp->getIconId(),sg_equipstrengLayer);
    CCString *str = CCString::createWithFormat("equip%d.png",temp->getIconId());
	
	
    CCSprite *item = CCSprite::createWithSpriteFrameName(str->getCString());

    static_cast<CCSprite *>(this->getChildByTag(123))->setDisplayFrame(item->displayFrame());
    
    
    this->setstar(_card->getCurrStar(),_card->getUpgradestar());
    
    SGEquipmentDataModel *general = SGStaticDataManager::shareStatic()->getEquipById(_card->getItemId());
    this->setCardType(general->getEquipType());
    
    
    equipName->setString(_card->getOfficerName()->getCString());
    int equipStar = _card->getCurrStar() - 2;
    equipStar = equipStar < 0 ? 0 : equipStar;
    if (equipStar >= 0 && equipStar < 5)
    {
        equipName->setInsideColor(ccStarLevelColor[equipStar]);
    }
    else
    {
        equipName->setInsideColor(ccWHITE);
    }
    
    equiplevel->setString(CCString::createWithFormat("Lv %d/%d",_card->getCurrLevel(), SGPlayerInfo::sharePlayerInfo()->getPlayerLevel())->getCString());
    
    
    setEquipLevel(_card->getCurrLevel());
    setCostCount(_card->getCurrLevel());
    setCurrStatus(_card->getCurrLevel());
    
    creatBostLevel(SGLayout::getPoint(kMiddleCenter));
    
    showMainChat(false);
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    //更换背景图片
    //创建4中颜色武将背景
    std::vector<std::string> str_vec;
    if(winSize.height != 1136)
    {
        str_vec.push_back("greenBg.png");
        str_vec.push_back("blueBg.png");
        str_vec.push_back("purpleBg.png");
        str_vec.push_back("orangeBg.png");
    }
    //inphone 5  根据武将地图来
    else
    {
        str_vec.push_back("greenBgI5.png");
        str_vec.push_back("blueBgI5.png");
        str_vec.push_back("purpleBgI5.png");
        str_vec.push_back("orangeBgI5.png");
    }
    int starLev = _card->getCurrStar();
    starLev = starLev<3?3:starLev;
    starLev = starLev>6?6:starLev;
    //光效背景图片
    CCSprite * refreshBg = CCSprite::createWithSpriteFrameName(str_vec[starLev-3].c_str());
    ((CCSprite*)getChildByTag(1919))->setDisplayFrame(refreshBg->displayFrame());

}