Ejemplo n.º 1
0
void HelloWorld::startGame( float dt)
{
	delete this->world;
	this->score = 0;
	this->down_bar = NULL;
	this->Xdownbar = 0;
	this->Xbird = 0;
	barTag = 0;
	barArray[0]=false;
	barArray[1]=false;

	isTouch = false;
	gameend = false;

	removeAllChildren();

	setTouchEnabled(true);
	
	initWorld();


	CCLabelAtlas* label2 = CCLabelAtlas::create("0123456789", "1.png", 17, 22, '0');
	addChild(label2, 1, 9);
	label2->setPosition(ccp(this->screenSize.width/2-30,this->screenSize.height/2+360));
	//label2->setColor(ccWHITE);
	label2->setScale(4);
	char string[12] = {0};
	sprintf(string,"%d",this->score);
	label2->setString(string);

	scheduleUpdate();
	schedule(schedule_selector(HelloWorld::addBar),1);
	//scheduleOnce(schedule_selector(HelloWorld::addBar),1);

	addBg();
	addGround(123);
	addBrid();
	addBarContainer();


}
Ejemplo n.º 2
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    screenSize = CCDirector::sharedDirector()->getVisibleSize();
    
    initWorld();
    addBarContainer();
    addBird();
    addGround();
    setTouchEnabled(true);
    startGame();
    
    
    return true;
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    ////////////////////////////////////////////////////
    // 下面添加创建自己的Sprite的代码
    ////////////////////////////////////////////////////
    
    mScreenSize = CCDirector::sharedDirector()->getVisibleSize();
    initWorld();
    addBird();
    addBarContainer();
    
    setTouchEnabled(true);
    
    scheduleOnce(schedule_selector(HelloWorld::startGame), 3);
    
    return true;
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
	//////////////////////////////
	// 1. super init first
	if ( !CCLayer::init() )
	{
		return false;
	}
	mbirdstr.push_back("birdblue");
	mbirdstr.push_back("birdred");
	mbirdstr.push_back("birdyellow");
	mbirdclolor=rand()%100%3;
//	EFFECT_PLAY(true,MUSIC_SWOOSHING);
	//播放背景音乐
	// CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic(MUSIC_JUMP, true);
	////////////////////////////////////////////////////
	// 下面添加创建自己的Sprite的代码
	////////////////////////////////////////////////////

	mScreenSize = CCDirector::sharedDirector()->getWinSize();
	mFPS=CCDirector::sharedDirector()->getAnimationInterval();


	mfac=CCDirector::sharedDirector()->getContentScaleFactor();
	mfax = 320.f/mScreenSize.width;
	//gBardis = 5.f*gUpVelocity/mfac;
	gBardis = mScreenSize.height*2.f/9.0f-5;
	//m_addbartime=mScreenSize.width*mFPS*mfax*1.f/2.f/MOVESPEED-10;
	//m_addbartime=3;
	initWorld();	
	for (int i = 0; i<GBACKGROUNDNUM; i++)
	{
		addBackGround(i);
	}
	int imaxgroundnum=1;
	for (int i = 0; i<imaxgroundnum; i++)
	{
		imaxgroundnum=addGround(i);
	}
	m_ilastground=imaxgroundnum-1;
	CCLOG("m_pLastGround->boundingBox() first x:%f,:%f  ", (m_pGroundVec[m_ilastground])->boundingBox().getMaxX(),
		(m_pGroundVec[m_ilastground])->boundingBox().size.width);
	addStart();
	addTop();
	//addRate();
	//addFlappyBird();

	addBird();
	addScore();
	addGameOver();

	m_pScore->setVisible(false);
	m_pGameOver->setVisible(false);
	this->goReady();
	addBarContainer();

	setTouchEnabled(true);
	myflag=0;
	m_istatus=GETREADY;
	m_bhitbar=false;
	//scheduleOnce(schedule_selector(HelloWorld::startGame), 1);
	this->scheduleUpdate();
	//创建动画
	initAction();
	myangle=0.f;
	return true;
}