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;
b2Fixturefixture;
};
void CTerrainLayer::generateHillPoints() {
//create ground
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(0, 0); //bottom-left corner
groundBodyDef.type = b2_staticBody;
groundBody = worldRef~~>CreateBody;
groundBody~~>SetUserData((void**)TAG_GROUND);
//slopes
CCPoint point1 = ccp;
for
{
CCPoint point2 = ccp;
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.