Advertisement Jump to content
Sign in to follow this  
anupgupta

Endless Terrain Query

This topic is 1843 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello
 
i am currently working on a game like hill climb racing.
here is the link of what i have made till now: 
 
here is the terrain making code:
 
#define MAX_HILL_POINTS 30
CCArray *hillInfoArray;
struct hillStruct : public cocos2d::CCObject {
cocos2d::CCPoint point1;
cocos2d::CCPoint point2;
b2Fixture *fixture;
};
 
void CTerrainLayer::generateHillPoints() { 
//create ground
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(0, 0); //bottom-left corner
groundBodyDef.type = b2_staticBody;
 
groundBody = worldRef->CreateBody(&groundBodyDef);
groundBody->SetUserData((void*)TAG_GROUND);
 
   //slopes
    CCPoint point1 = ccp(0, 100);
    for(short i = 0; i < MAX_HILL_POINTS; ++i)
   {
        CCPoint point2 = ccp(0, 0);
        hillStruct *hillData = new hillStruct;
        float val = RandomFloat(0, 10);
        point2.x = point1.x + 25.0f;
        point2.y = point1.y + val * cosf(point2.x / 200.0f * b2_pi);
        b2EdgeShape groundShape;
        groundShape.Set(B2VEC_FROM_CCPOINT(point1), B2VEC_FROM_CCPOINT(point2));
        hillData->fixture = groundBody->CreateFixture(&groundShape,0);
        hillData->fixture->SetDensity(5.0f);
        hillData->fixture->SetFriction(0.5f);
        hillData->fixture->SetRestitution(0.2f);
       
       //hill info data
        hillData->point1 = point1;
        hillData->point2 = point2;
        hillInfoArray->addObject(hillData);
        point1 = point2;
    }    
}
hillInfoArray stores all the points of the hill, and as the screen moves new points are created
and points going outside screen gets destroyed at runtime.
 
i have made the terrain as an b2EdgeShape, i wanted to know how can i wrap my own custom
texture on the hills/ground which have an irregular shape.
 
Any suggestions Please.

Share this post


Link to post
Share on other sites
Advertisement

One way to do this is to fill in as much as possible with large quads and then use a random assortment of small sprites (randomly sized and rotated) to "fill in" the gaps.  You can use a further layer of grass or the like to contour the surface.

 

Aquaria is one example of a nicely polished indie game that does something like this.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!