Endless Terrain Query

Started by
0 comments, last by SeanMiddleditch 10 years, 3 months ago
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.
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.

Sean Middleditch – Game Systems Engineer – Join my team!

This topic is closed to new replies.

Advertisement