示例#1
0
void GameWorld::CreateGame()
{
	// create the environment
	background_manager_ = BackgroundManager::create();
	background_manager_->game_world_ = this;
	addChild(background_manager_, E_LAYER_BACKGROUND);

	// create & add the batch node
	sprite_batch_node_ = CCSpriteBatchNode::create("cjtexset_01.png", 128);
	game_object_layer_->addChild(sprite_batch_node_);
	
	CreateWall();
	CreateClown();
	CreateBasePlatform();
	CreatePlatform();
	CreateCollectibles();
	CreateHUD();

	// enable touch & accelerometer
	setTouchEnabled(true);
	setAccelerometerEnabled(true);

	// everything created, start updating
	scheduleUpdate();
}
示例#2
0
Box2DTestLayer::Box2DTestLayer()
: m_pSpriteTexture(NULL)
{
    setTouchEnabled( true );
    setAccelerometerEnabled( true );

    // init physics
    this->initPhysics();
    // create reset button
    this->createResetButton();

    //Set up sprite
#if 1
    // Use batch node. Faster
    CCSpriteBatchNode *parent = CCSpriteBatchNode::create("Images/blocks.png", 100);
    m_pSpriteTexture = parent->getTexture();
#else
    // doesn't use batch node. Slower
    m_pSpriteTexture = CCTextureCache::sharedTextureCache()->addImage("Images/blocks.png");
    CCNode *parent = CCNode::create();
#endif
    addChild(parent, 0, kTagParentNode);


    addNewSpriteAtPosition(VisibleRect::center());

    CCLabelTTF *label = CCLabelTTF::create("Tap screen", "Marker Felt", 32);
    addChild(label, 0);
    label->setColor(ccc3(0,0,255));
    label->setPosition(ccp( VisibleRect::center().x, VisibleRect::top().y-50));
    
    scheduleUpdate();
}
// Initialize the GameScene
bool GameScene::init()
{
	CCLog("GameScene::init");
    bool bRet = false;
    do 
    {
        //////////////////////////////////////////////////////////////////////////
        // super init first
        //////////////////////////////////////////////////////////////////////////
        CC_BREAK_IF(! CCLayer::init());

		// Initialize the parent - gets the sprite sheet loaded, sets the background and inits the clouds
		MainScene::init();

		// Start off as game suspended
		gameSuspended = true;

		// Get the bird sprite
		CCSprite *bird = CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("bird.png"));
		this->addChild(bird, 4, kBird);

		// Initialize the platforms
		initPlatforms();

		// Create the bonus sprite
		CCSprite *bonus;

		// Load in the bonus images, 5, 10, 50, 100
		for(int i=0; i<kNumBonuses; i++) 
		{
			bonus = CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(bonus_image[i]));
			this->addChild(bonus,4, kBonusStartTag+i);
			bonus->setVisible(false);
		}

		// Create the Score Label
		CCLabelBMFont* scoreLabel = CCLabelBMFont::create("0",  "Images/bitmapFont.fnt");
		this->addChild(scoreLabel, 5, kScoreLabel);

		// Center the label
		scoreLabel->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width/2,CCDirector::sharedDirector()->getWinSize().height - 50));

		// Start the GameScene stepping
		schedule(schedule_selector(GameScene::step));

		// Enable the touch events
		setTouchEnabled(true);
		// Enable accelerometer events
		setAccelerometerEnabled(true);

		// Start the game
		startGame();

        bRet = true;
    } while (0);

    return bRet;
}
示例#4
0
ChipmunkTestLayer::ChipmunkTestLayer()
{
#if CC_ENABLE_CHIPMUNK_INTEGRATION      
    // enable events
    setTouchEnabled(true);
    setAccelerometerEnabled(true);

    // title
    auto label = LabelTTF::create("Multi touch the screen", "Marker Felt", 36);
    label->setPosition(Point( VisibleRect::center().x, VisibleRect::top().y - 30));
    this->addChild(label, -1);

    // reset button
    createResetButton();

    // init physics
    initPhysics();

#if 1
    // Use batch node. Faster
    auto parent = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 100);
    _spriteTexture = parent->getTexture();
#else
    // doesn't use batch node. Slower
    _spriteTexture = TextureCache::getInstance()->addImage("Images/grossini_dance_atlas.png");
    auto parent = Node::create();
#endif
    addChild(parent, 0, kTagParentNode);

    addNewSpriteAtPosition(Point(200,200));

    // menu for debug layer
    MenuItemFont::setFontSize(18);
    auto item = MenuItemFont::create("Toggle debug", CC_CALLBACK_1(ChipmunkTestLayer::toggleDebugCallback, this));

    auto menu = Menu::create(item, NULL);
    this->addChild(menu);
    menu->setPosition(Point(VisibleRect::right().x-100, VisibleRect::top().y-60));

    scheduleUpdate();
#else
    auto label = LabelTTF::create("Should define CC_ENABLE_CHIPMUNK_INTEGRATION=1\n to run this test case",
                                            "Arial",
                                            18);
    auto size = Director::getInstance()->getWinSize();
    label->setPosition(Point(size.width/2, size.height/2));
    
    addChild(label);
    
#endif
    
}
示例#5
0
ShmupHUD::ShmupHUD()
    : Cistron::Component("HUD"),
      health_(0),
      health_bar_background_(NULL),
      health_bar_(NULL),
      button_pause_(NULL),
      button_debug_(NULL)
{
    setTouchEnabled(true);
    setAccelerometerEnabled(true);

    SetupViewer();
}
示例#6
0
SkirmishHUD::SkirmishHUD()
    : Cistron::Component("HUD")
    , label_stage_background_(NULL)
    , stage_(0)
    , label_stage_(NULL)
    , button_pause_(NULL)
    , button_debug_(NULL)
    , title_("")
{
    setTouchEnabled(true);
    setAccelerometerEnabled(true);

    SetupViewer();
}
示例#7
0
PauseGameLayer::PauseGameLayer()
{
    setTouchEnabled(true);
    setAccelerometerEnabled(true);

    SetupViewer();
    
    scheduleUpdate();
    
    // Swallow all input below
    cocos2d::CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(
        this, 
        kLayerPriority, 
        true);
}
示例#8
0
bool Layer::init()
{
    bool bRet = false;
    do 
    {        
        Director * pDirector;
        CC_BREAK_IF(!(pDirector = Director::getInstance()));
        this->setContentSize(pDirector->getWinSize());
        setTouchEnabled(false);
        setAccelerometerEnabled(false);
        // success
        bRet = true;
    } while(0);
    return bRet;
}
示例#9
0
////////////////////////////////////////////////////////
//
// Bug624Layer2
//
////////////////////////////////////////////////////////
bool Bug624Layer2::init()
{
    if(BugsTestBaseLayer::init())
    {
        CCSize size = CCDirector::sharedDirector()->getWinSize();
        CCLabelTTF *label = CCLabelTTF::create("Layer2", "Marker Felt", 36);

        label->setPosition(ccp(size.width/2, size.height/2));
        addChild(label);
        setAccelerometerEnabled(true);
        schedule(schedule_selector(Bug624Layer2::switchLayer), 5.0f);

        return true;
    }

    return false;
}
示例#10
0
void AccelerometerTest::onEnter()
{
    CCLayer::onEnter();

    setAccelerometerEnabled(true);


    CCLabelTTF* label = CCLabelTTF::create(title().c_str(), "Arial", 32);
    addChild(label, 1);
    label->setPosition( ccp(VisibleRect::center().x, VisibleRect::top().y-50) );

    m_pBall = CCSprite::create("Images/ball.png");
    m_pBall->setPosition(ccp(VisibleRect::center().x, VisibleRect::center().y));
    addChild(m_pBall);

    m_pBall->retain();
}
示例#11
0
////////////////////////////////////////////////////////
//
// Bug624Layer2
//
////////////////////////////////////////////////////////
bool Bug624Layer2::init()
{
    if(BugsTestBaseLayer::init())
    {
        auto size = Director::getInstance()->getWinSize();
        auto label = LabelTTF::create("Layer2", "Marker Felt", 36);

        label->setPosition(Point(size.width/2, size.height/2));
        addChild(label);
        setAccelerometerEnabled(true);
        schedule(schedule_selector(Bug624Layer2::switchLayer), 5.0f);

        return true;
    }

    return false;
}
示例#12
0
void HelloWorld::initPhysic() {
#if CC_ENABLE_CHIPMUNK_INTEGRATION

    //启动重力加速度,系统会定时调用didAccelerate
    setAccelerometerEnabled(true);

    m_pSpace = cpSpaceNew();

    m_pSpace->gravity = cpv(0, -100);

    //
    // rogue shapes
    // We have to free them manually
    //
    // bottom
    m_pWalls[0] = cpSegmentShapeNew( m_pSpace->staticBody,
        cpv(VisibleRect::leftBottom().x,VisibleRect::leftBottom().y),
        cpv(VisibleRect::rightBottom().x, VisibleRect::rightBottom().y), 0.0f);

    // top
    m_pWalls[1] = cpSegmentShapeNew( m_pSpace->staticBody, 
        cpv(VisibleRect::leftTop().x, VisibleRect::leftTop().y),
        cpv(VisibleRect::rightTop().x, VisibleRect::rightTop().y), 0.0f);

    // left
    m_pWalls[2] = cpSegmentShapeNew( m_pSpace->staticBody,
        cpv(VisibleRect::leftBottom().x,VisibleRect::leftBottom().y),
        cpv(VisibleRect::leftTop().x,VisibleRect::leftTop().y), 0.0f);

    // right
    m_pWalls[3] = cpSegmentShapeNew( m_pSpace->staticBody, 
        cpv(VisibleRect::rightBottom().x, VisibleRect::rightBottom().y),
        cpv(VisibleRect::rightTop().x, VisibleRect::rightTop().y), 0.0f);

    for( int i=0;i<4;i++) {
        m_pWalls[i]->e = 1.0f;
        m_pWalls[i]->u = 1.0f;
        cpSpaceAddStaticShape(m_pSpace, m_pWalls[i] );
    }

    // Physics debug layer
    m_pDebugLayer = CCPhysicsDebugNode::create(m_pSpace);
    this->addChild(m_pDebugLayer, Z_PHYSICS_DEBUG);
#endif
}
示例#13
0
BattleHUD::BattleHUD()
    : Cistron::Component("HUD"),
      health_(0),
      combo_(0),
      total_kills_background_(NULL),
      total_kills_(0),
      label_combo_(NULL),
      label_total_kills_(NULL),
      health_bar_background_(NULL),
      health_bar_(NULL),
      button_pause_(NULL),
      button_debug_(NULL)
{
    setTouchEnabled(true);
    setAccelerometerEnabled(true);

    SetupViewer();
}
示例#14
0
void AccelerometerTest::onEnter()
{
    CCLayer::onEnter();

    setAccelerometerEnabled(true);

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

    CCLabelTTF* label = CCLabelTTF::create(title().c_str(), "Arial", 32);
    addChild(label, 1);
    label->setPosition( CCPointMake(s.width/2, s.height-50) );

    m_pBall = CCSprite::create("Images/ball.png");
    m_pBall->setPosition(ccp(s.width / 2, s.height / 2));
    addChild(m_pBall);

    m_pBall->retain();
}
示例#15
0
PhysicsTestLayer::PhysicsTestLayer()
: _spriteTexture(nullptr)
, _scene(nullptr)
{
#ifdef CC_USE_PHYSICS
    setTouchEnabled(true);
    setAccelerometerEnabled(true);
    
    // title
    auto label = LabelTTF::create("Multi touch the screen", "Marker Felt", 36);
    label->setPosition(Point( VisibleRect::center().x, VisibleRect::top().y - 30));
    this->addChild(label, -1);
    
    // menu for debug layer
    MenuItemFont::setFontSize(18);
    auto item = MenuItemFont::create("Toggle debug", CC_CALLBACK_1(PhysicsTestLayer::toggleDebugCallback, this));
    
    auto menu = Menu::create(item, NULL);
    this->addChild(menu);
    menu->setPosition(Point(VisibleRect::right().x-100, VisibleRect::top().y-60));
    
    auto sp = Sprite::create();
    auto body = PhysicsBody::createEdgeBox(VisibleRect::getVisibleRect().size);
    sp->setPhysicsBody(body);
    this->addChild(sp);
    sp->setPosition(VisibleRect::center());
    
    auto parent = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 100);
    _spriteTexture = parent->getTexture();
    
    addNewSpriteAtPosition(VisibleRect::center());
    
    createResetButton();
    
#else
    auto label = LabelTTF::create("Should define CC_USE_BOX2D or CC_USE_CHIPMUNK\n to run this test case",
                                  "Arial",
                                  18);
    auto size = Director::getInstance()->getWinSize();
    label->setPosition(Point(size.width/2, size.height/2));
    
    addChild(label);
#endif
}
Box2DTestLayer::Box2DTestLayer()
: _spriteTexture(NULL)
, world(NULL)
{
#if CC_ENABLE_BOX2D_INTEGRATION
    setTouchEnabled( true );
    setAccelerometerEnabled( true );

    // init physics
    this->initPhysics();
    // create reset button
    this->createResetButton();

    //Set up sprite
#if 1
    // Use batch node. Faster
    SpriteBatchNode *parent = SpriteBatchNode::create("Images/blocks.png", 100);
    _spriteTexture = parent->getTexture();
#else
    // doesn't use batch node. Slower
    _spriteTexture = TextureCache::getInstance()->addImage("Images/blocks.png");
    Node *parent = Node::create();
#endif
    addChild(parent, 0, kTagParentNode);


    addNewSpriteAtPosition(VisibleRect::center());

    LabelTTF *label = LabelTTF::create("Tap screen", "Marker Felt", 32);
    addChild(label, 0);
    label->setColor(Color3B(0,0,255));
    label->setPosition(Point( VisibleRect::center().x, VisibleRect::top().y-50));
    
    scheduleUpdate();
#else
    LabelTTF *label = LabelTTF::create("Should define CC_ENABLE_BOX2D_INTEGRATION=1\n to run this test case",
                                            "Arial",
                                            18);
    Size size = Director::getInstance()->getWinSize();
    label->setPosition(Point(size.width/2, size.height/2));
    
    addChild(label);
#endif
}
示例#17
0
GameLayer::GameLayer() {
    
    
    _screenSize = CCDirector::sharedDirector()->getWinSize();
    _running = false;
    
    createScreen();
    
    std::string levelsFile = CCFileUtils::sharedFileUtils()->fullPathForFilename("levels.plist");
    _levels = CCArray::createWithContentsOfFileThreadSafe(levelsFile.c_str());
    _levels->retain();
    
    initPhysics();
    
    createPools();
    
    setTouchEnabled( true );
    setAccelerometerEnabled( true );
    
    
}
void ShootingGameScene::balanceinterruption(float f) {
	if(_state == 3)
	{
		setAccelerometerEnabled(false);
		if (_deadCount > 30) {
					this->unschedule(schedule_selector(ShootingGameScene::balanceinterruption));
					standtimeE = _totallScore;
					type = 2;
					CCScene* pScene = HallofFame::scene();
					CCDirector::sharedDirector()->replaceScene(
							CCTransitionPageTurn::create(0.5f, pScene, false));
				} else
					_deadCount++;
	}else if(_state ==2)
	{
		if(_readyCount >20)
		{
			_bulletmark->setVisible(false);
			_shootBtn->setNormalImage(CCSprite::create("shootinggameScene/images/shootBtn.png"));
			_shootMenu->setEnabled(true);
			_readyCount = 0;
			_state = 1;
		}
		else
			_readyCount++;
	}
	else
	{
	int randvalueX = rand() % 70 + 1;
	float plusminusX = CCRANDOM_MINUS1_1();
	randvalueX = (int) randvalueX * plusminusX;

	int randvalueY = rand() % 70 + 1;
	float plusminusY = CCRANDOM_MINUS1_1();
	randvalueY = (int) randvalueY * plusminusY;

	_aim->setPosition(ccp(_aim->getPositionX()+randvalueX,_aim->getPositionY()+randvalueY));
	}
}
示例#19
0
// Initialize the GameScene
bool GameScene::init()
{
//	CCLog("GameScene::init");
    bool bRet = false;
    do 
    {
        coin50Platform = 12;
        coin100Platform = 15;
        coinJumpPlatform = 25;
        CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("GameFieldMusic.mp3", true);
        target_Score = 10000;
        //////////////////////////////////////////////////////////////////////////
        // super init first
        //////////////////////////////////////////////////////////////////////////
        CC_BREAK_IF(! CCLayer::init());

		// Initialize the parent - gets the sprite sheet loaded, sets the background and inits the clouds
		MainScene::init();

		// Start off as game suspended
		gameSuspended = true;

		// Get the jumper sprite
		jumper = CCSprite::create("jumper_0.png");
        this->addChild(jumper, 4, kjumper);
        CCArray * animArr = CCArray::create();
        for (int i = 0 ; i < 16; i++)
        {
            CCString * tempString  = CCString::createWithFormat("jumper_%d.png",i);
            CCSpriteFrame * tempFrame = CCSpriteFrame::create(tempString->getCString(),CCRectMake(jumper->getPosition().x, jumper->getPosition().y, jumper->getContentSize().width, jumper->getContentSize().height));
            animArr->addObject(tempFrame);
        }
        CCAnimation * jumpAnimation = CCAnimation::createWithSpriteFrames(animArr,0.1);
        jumpAnimate = CCAnimate::create(jumpAnimation);
        jumpAnimate->retain();

        coin50Anim = CCArray::create();
        coin100Anim = CCArray::create();
        coinJumpAnim = CCArray::create();
        
        CCSprite * coin1  = CCSprite::create("coin_1/coin50_1.png");
        for (int i = 1;i < 20 ; i++)
        {
            CCString * tempString  = CCString::createWithFormat("coin_1/coin50_%d.png",i);
            CCSpriteFrame * tempFrame = CCSpriteFrame::create(tempString->getCString(),CCRectMake(coin1->getPosition().x, coin1->getPosition().y, coin1->getContentSize().width, coin1->getContentSize().height));
            coin50Anim->addObject(tempFrame);
        }
        
        coin50Anim->retain();
        
        CCSprite * coin2  = CCSprite::create("coin_2/coin100_1.png");

        for (int i = 1;i < 20 ; i++)
        {
            CCString * tempString  = CCString::createWithFormat("coin_2/coin100_%d.png",i);
            CCSpriteFrame * tempFrame = CCSpriteFrame::create(tempString->getCString(),CCRectMake(coin2->getPosition().x, coin2->getPosition().y, coin2->getContentSize().width, coin2->getContentSize().height));
            coin100Anim->addObject(tempFrame);
        }
        coin100Anim->retain();
      

        
        
        CCSprite * coin3  = CCSprite::create("powerup/coinJump_1.png");
        for (int i = 1;i < 20 ; i++)
        {
            CCString * tempString  = CCString::createWithFormat("powerup/coinJump_%d.png",i);
            CCSpriteFrame * tempFrame = CCSpriteFrame::create(tempString->getCString(),CCRectMake(coin3->getPosition().x, coin3->getPosition().y, coin3->getContentSize().width, coin3->getContentSize().height));
            coinJumpAnim->addObject(tempFrame);
        }
        coinJumpAnim->retain();
        
        CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage("fx-leafe.png");
        particles = CCParticleFireworks::create();
        particles->setTexture( texture );
        particles->setLife(0.5);
        particles->setEmissionRate(100);
        particles->setPosVar(ccp(10,5));
        particles->setSpeed(60);
        particles->setPosition(0, 0);
        particles->setAngle(90);
        particles->setAngleVar(270);
        particles->setStartSize(10.0);
        particles->setStartSizeVar(5);
        particles->setStartColor( ccc4f(1.0,1.0,1.0,1.0) );
        particles->setEndColor(ccc4f(1.0,1.0,1.0,0.0) );
        particles->setStartSpin(-90);
        particles->setStartSpinVar(30);
        particles->setEndSpin(-90);
        particles->setEndSpinVar(30);
        particles->setSpeedVar(30);
        particles->setPositionType(	kCCPositionTypeGrouped );
        this->addChild(particles, 10);
        particles_counter = 1;
        
		// Initialize the platforms
       
        
        for(int i=0; i<kNumCoines; i++)
		{
            CCSprite *bonus = CCSprite::create("coin_1/coin50_1.png");
            this->addChild(bonus,4, kBonusStartTag+i);
            bonus->setScale(2.0);
            CCAnimation * coin50Animation = CCAnimation::createWithSpriteFrames(coin50Anim,0.03);
            CCAnimate * coin50Animate = CCAnimate::create(coin50Animation);
            
            bonus->runAction(CCRepeatForever::create(coin50Animate));
                bonus->setVisible(false);
            bonus = NULL;
		}
        for(int i=0; i<kNumCoines; i++)
		{
            CCSprite *bonus = CCSprite::create("coin_2/coin100_1.png");
            bonus->setScale(2.0);
            this->addChild(bonus,4, kBonusStartTag+i+30);
            CCAnimation * coin100Animation = CCAnimation::createWithSpriteFrames(coin100Anim,0.03);
             CCAnimate * coin100Animate = CCAnimate::create(coin100Animation);
             bonus->runAction(CCRepeatForever::create(coin100Animate));
            bonus->setVisible(false);
            bonus = NULL;
		}
        for(int i=0; i<kNumCoines; i++)
		{
            CCSprite *bonus = CCSprite::create("powerup/coinJump_1.png");
            this->addChild(bonus,4, kBonusStartTag+i+60);
            bonus->setScale(2.0);
            CCAnimation * coinJumpAnimation = CCAnimation::createWithSpriteFrames(coinJumpAnim,0.03);
            CCAnimate * coinJumpAnimate = CCAnimate::create(coinJumpAnimation);

             bonus->runAction(CCRepeatForever::create(coinJumpAnimate));
            bonus->setVisible(false);
            bonus = NULL;
		}
		initPlatforms();
        initTree();
		// Create the bonus sprite
		

		// Load in the bonus images, 5, 10, 50, 100
		

		// Create the Score Label
		CCLabelTTF* scoreLabel = CCLabelTTF::create("0",  "Arial", 15.0);
		this->addChild(scoreLabel, 5, kScoreLabel);

		// Center the label
		scoreLabel->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width/2,CCDirector::sharedDirector()->getWinSize().height - 50));

		// Start the GameScene stepping
		schedule(schedule_selector(GameScene::step));

		// Enable the touch events
		setTouchEnabled(true);
		// Enable accelerometer events
		setAccelerometerEnabled(true);

		// Start the game
		startGame();

        bRet = true;
    } while (0);

    return bRet;
}
void ShootingGameScene::onEnter() {
	CCLayer::onEnter();
	setAccelerometerEnabled(true);
}