I have a question, I want to create a game- with bombs falling down from the top of the screen.
I have tried to create so that 10 bombs are generated and placed on a special position depending on what number the number generator gives.
The first problem I got is that when I run the program the generated number is never the same which in turn say every number from 1 to 10 is used and they are falling down.
The first question I got is how to create an timer to tell the program to wait 1-2 seconds between each creation of the bombs?
I want it so that the program works at the following way:
each second a bomb is created at a specific point depending on the number(already done) each second, so that not every bomb is created at the same time.
Code for the generator:
srand( ( unsigned ) time( 0 ) );
int random_integer;
for( int index = 0; index < 20; index++ )
{
random_integer = ( rand()%10) +1;
switch( random_integer )
{
case 1: addBomb(20, 0, 0.01f); break;
case 2: addBomb(120, 0, 0.01f); break;
case 3: addBomb(230, 0, 0.01f); break;
case 4: addBomb(400, 0, 0.01f); break;
case 5: addBomb(550, 0, 0.01f); break;
case 6: addBomb(660, 0, 0.01f); break;
case 7: addBomb(770, 0, 0.01f); break;
case 8: addBomb(880, 0, 0.01f); break;
case 9: addBomb(990, 0, 0.01f); break;
case 10: addBomb(1100, 0, 0.01f); break;
}
}
Oh and at the same time I might as well ask about a question I think I know the answer to but not sure:
When the bombs are created i use an update method in the game loop, and each time I set it to:
void Bombs::Update()
{
y += speed;
}
So far I don't got any frames per second to limit the number of times it runs, and when I run the program the bombs falls down very fast, even though its just 1.0f.
What I think it is, is because of that I don't have any fps limit on how many time it runs/sec, or am I wrong ?


Sign In
Create Account


Back to top









