コード例 #1
0
ann::gles::SceneNode* buildDungeonNode(const model::Dungeon& dungeon) {
    ann::gles::SceneNode* dungeonNode = new ann::gles::SceneNode();

    ann::gles::SceneNode* floorNode = createFloor();
    ann::gles::SceneNode* roofNode = createRoof();
    ann::gles::SceneNode* farWallNode = createFarWall();
    ann::gles::SceneNode* backWallNode = createBackWall();
    ann::gles::SceneNode* leftWallNode = createLeftWall();
    ann::gles::SceneNode* rightWallNode = createRightWall();

    int width = dungeon.getWidth();
    int height = dungeon.getHeight();

    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            if (!dungeon.floorCell(x, y)) {
                continue;
            }

            ann::gles::SceneNode* cellNode = new ann::gles::SceneNode();
            cellNode->translate(helpers::glPoint(x, y));
            dungeonNode->attachNode(cellNode);

            ann::gles::SceneNode* floor = new ann::gles::SceneNode(*floorNode);
            cellNode->attachNode(floor);

            ann::gles::SceneNode* roof = new ann::gles::SceneNode(*roofNode);
            cellNode->attachNode(roof);

            if (y == 0 || (y > 0 && !dungeon.floorCell(x, y - 1))) {
                ann::gles::SceneNode* leftWall = new ann::gles::SceneNode(*leftWallNode);
                cellNode->attachNode(leftWall);
            }

            if (y == height - 1 || (y < height - 1 && !dungeon.floorCell(x, y + 1))) {
                ann::gles::SceneNode* rightWall = new ann::gles::SceneNode(*rightWallNode);
                cellNode->attachNode(rightWall);
            }

            if (x == 0 || (x > 0 && !dungeon.floorCell(x - 1, y))) {
                ann::gles::SceneNode* backWall = new ann::gles::SceneNode(*backWallNode);
                cellNode->attachNode(backWall);
            }

            if (x == width - 1 || (x < width - 1 && !dungeon.floorCell(x + 1, y))) {
                ann::gles::SceneNode* farWall = new ann::gles::SceneNode(*farWallNode);
                cellNode->attachNode(farWall);
            }
        }
    }

    delete floorNode;
    delete roofNode;
    delete farWallNode;
    delete backWallNode;
    delete leftWallNode;
    delete rightWallNode;

    return dungeonNode;
}
コード例 #2
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{

    loader.SetFilePath(cocos2d::CCFileUtils::sharedFileUtils()->fullPathForFilename("YellowBall.json"));
    netPotLoader.SetFilePath(cocos2d::CCFileUtils::sharedFileUtils()->fullPathForFilename("netpot.json"));

    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }

    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();



    ///////////////////////////////////////////////////////////nazib edit//////////////////////////////////////////////////////
    CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 1, true);
    //bool b = this->isTouchEnabled();
    //this->setTouchEnabled(true);
    // b = this->isTouchEnabled();

    //========================================[create yellow ball sprite]================================
    CCSprite* pSpriteYellowBall;
    pSpriteYellowBall = CCSprite::create("YellowBall.png");
    pSpriteYellowBall->setPosition(ccp(100,300));
    this->addChild(pSpriteYellowBall,1);
    //====================================================================================================






    //========================================[Create world]==============================================
    b2Vec2 gravity = b2Vec2(0.0f,-9.8f);
    pworld = new b2World(gravity);
    //====================================================================================================


    //========================================[Create YellowBall Body]====================================

    // Create ball body and shape
    b2BodyDef yellowBallBodyDef;
    yellowBallBodyDef.type = b2_dynamicBody;
    yellowBallBodyDef.position.Set(100/PTM_RATIO, 300/PTM_RATIO);
    yellowBallBodyDef.userData = pSpriteYellowBall;
    pbodyYellowBall= pworld->CreateBody(&yellowBallBodyDef);

    //b2CircleShape circle;
    //circle.m_radius = 26.0/PTM_RATIO;

    b2FixtureDef ballShapeDef;
    //ballShapeDef.shape = &circle;
    ballShapeDef.density = 1.0f;
    ballShapeDef.friction = 0.2f;
    ballShapeDef.restitution = 0.8f;
    //pbodyYellowBall->CreateFixture(&ballShapeDef);
    loader.attachFixture(pbodyYellowBall, "Name", ballShapeDef, 50/PTM_RATIO);

    //====================================================================================================



    //////////////////////////////////////////////////////////////////////////

    //create netpot sprite
    createNetPot();


    //////////////////////////////////////////////////////////////////////////



    createGroundWall();
    createLeftWall();
    createRightWall();
    createTopWall();

    createCloseButton(origin, visibleSize);


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

    // add a label shows "Hello World"
    // create and initialize a label

    pLabel = CCLabelTTF::create("Hello World", "Arial", TITLE_FONT_SIZE);

    // position the label on the center of the screen
    pLabel->setPosition(ccp(origin.x + visibleSize.width/2,
                            origin.y + visibleSize.height - pLabel->getContentSize().height));

    // add the label as a child to this layer
    this->addChild(pLabel, 1);

    // add "HelloWorld" splash screen"
    /*CCSprite* */
    pSprite = CCSprite::create("BackGround.png");
    pNextSprite = CCSprite::create("BackGround.png");

    // position the sprite on the center of the screen
    // pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));

    // add the sprite as a child to this layer
    //this->addChild(pSprite, 0);

    //=============================================[Parallax Node]=========================================================



    pBackgroundNode = CCParallaxNodeExtras::node();
    this->addChild(pBackgroundNode, -1);

    CCPoint bgSpeed = ccp(0.05, 0.05);

    pBackgroundNode->addChild(pSprite, 0, bgSpeed, ccp(0,visibleSize.height/2) );
    pBackgroundNode->addChild(pNextSprite, 0, bgSpeed, ccp( pSprite->getContentSize().width,visibleSize.height/2));


    //====================================================================================================================

    this->schedule(schedule_selector(HelloWorld::tick),1/60);

    // CCDirector::sharedDirector() -> getTouchDispatcher() -> addStandardDelegate( this, 0 );

    return true;
}