Home Forums Programming Help about random city generating in C++ Reply To: Help about random city generating in C++

#27672
Anonymous
Inactive

Hello. I must tu generate random city maps in c++. I think to use a 2 dimensional matrix. According to the values in matrix I will draw the buildings,ways and cars,taxis,motobiycles etc on ways. How can I do these? Can you help me??? :?:[/quote:33d4e10d87]

have you not answered your question?

have something like the following:

in your setup do the following once:

int cityArray[5][5];

srand(timeGetTime());

const int CAR=1;
const int BUILDING=2;
const int TAXI =3;

const int NUMBER_OF_ITEMS = 3;

for(int i=0;i<5;i++)
{
for(int j=0;j<5;j++)
{
cityArray = rand()/%NUMBER_OF_ITEMS;
}
}

then during rendering do the following.

for(int i=0;i<5;i++)
{
for(int j=0;j<5;j++)
{
switch(cityArray
)
{
case CAR:
{
renderCar();
break;
}

case TAXI:
{
renderTaxi();
break;
}
case BUILDING:
{
renderBuilding();
break;
}
}

}
}

finally if you wanted to make this better, the array could be an array of structures(instead of int’s) which have stuff in them like x,y coordinates,textures etc.
Alternatively if your going the c++ way then you might make them class and create a polymorphic array where each different object type has an override render which gets called. If you arent familar with these terms then read up on them before you write your game.. these technqiues will save you an ass load of time

peter