Oh sorry, complety missunderstood what you said.
In this case I believe you need something like this:
[source lang="cpp"]srand(time(NULL));unsigned numberOfAsteroids = (SDL_GetTicks()/30000) + 1; // 1 extra asteroid per 30 secondsif (asteroidsOnScreen < numberOfAsteroids){ if (SDL_GetTicks() - lastTimeTriedToSpamAsteroid > 1000){ // try once per second unsigned chance = rand() % 100; if (chance >= 50){ // 50% chance to spawn an asteroid bool up = rand() % 2; if (up == false){ spawnAsteroid(x = rand()%WIDTH_OF_SCREEN, y = HEIGHT_OF_SCREEN); } else{ spawnAsteroid(x = rand()%WIDTH_OF_SCREEN, y = 0); } } lastTimeTriedToSpamAsteroid = SDL_GetTicks(); }}[/source]
EDIT: in this case y = 0 is top part of the screen.
Show differencesHistory of post edits
#5KnolanCross
Posted 26 November 2012 - 10:59 AM
Oh sorry, complety missunderstood what you said.
In this case I believe you need something like this:
[source lang="cpp"]srand(time(NULL));unsigned numberOfAsteroids = (SDL_GetTicks()/30000) + 1; // 1 extra asteroid per 30 secondsif (asteroidsOnScreen < numberOfAsteroids){ if (SDL_GetTicks() - lastTimeTriedToSpamAsteroid > 1000){ // try once per second unsigned chance = rand() % 100; if (chance >= 50){ // 50% chance to spawn an asteroid bool up = rand() % 2; if (up == false){ spawnAsteroid(x = rand()%WIDTH_OF_SCREEN, y = HEIGHT_OF_SCREEN); } else{ spawnAteroid(x = rand()%WIDTH_OF_SCREEN, y = 0); } } lastTimeTriedToSpamAsteroid = SDL_GetTicks(); }}[/source]
EDIT: in this case y = 0 is top part of the screen.
In this case I believe you need something like this:
[source lang="cpp"]srand(time(NULL));unsigned numberOfAsteroids = (SDL_GetTicks()/30000) + 1; // 1 extra asteroid per 30 secondsif (asteroidsOnScreen < numberOfAsteroids){ if (SDL_GetTicks() - lastTimeTriedToSpamAsteroid > 1000){ // try once per second unsigned chance = rand() % 100; if (chance >= 50){ // 50% chance to spawn an asteroid bool up = rand() % 2; if (up == false){ spawnAsteroid(x = rand()%WIDTH_OF_SCREEN, y = HEIGHT_OF_SCREEN); } else{ spawnAteroid(x = rand()%WIDTH_OF_SCREEN, y = 0); } } lastTimeTriedToSpamAsteroid = SDL_GetTicks(); }}[/source]
EDIT: in this case y = 0 is top part of the screen.
#4KnolanCross
Posted 26 November 2012 - 10:48 AM
Oh sorry, complety missunderstood what you said.
In this case I believe you need something like this:
[source lang="cpp"]srand(time(NULL));unsigned numberOfAsteroids = (SDL_GetTicks()/30000) + 1; // 1 extra asteroid per 30 secondsif (asteroidsOnScreen < numberOfAsteroids){ if (SDL_GetTicks() - lastTimeTriedToSpamAsteroid > 1000){ // try once per second unsigned chance = rand() % 100; if (chance >= 50){ // 50% chance to spawn an asteroid bool up = rand() % 2; if (up == false){ spawnAsteroid(x = rand()%WIDTH_OF_SCREEN, y = HEIGHT_OF_SCREEN); } else{ spawnAteroidOnLowerPart(x = rand()%WIDTH_OF_SCREEN, y = 0); } } lastTimeTriedToSpamAsteroid = SDL_GetTicks(); }}[/source]
EDIT: in this case y = 0 is top part of the screen.
In this case I believe you need something like this:
[source lang="cpp"]srand(time(NULL));unsigned numberOfAsteroids = (SDL_GetTicks()/30000) + 1; // 1 extra asteroid per 30 secondsif (asteroidsOnScreen < numberOfAsteroids){ if (SDL_GetTicks() - lastTimeTriedToSpamAsteroid > 1000){ // try once per second unsigned chance = rand() % 100; if (chance >= 50){ // 50% chance to spawn an asteroid bool up = rand() % 2; if (up == false){ spawnAsteroid(x = rand()%WIDTH_OF_SCREEN, y = HEIGHT_OF_SCREEN); } else{ spawnAteroidOnLowerPart(x = rand()%WIDTH_OF_SCREEN, y = 0); } } lastTimeTriedToSpamAsteroid = SDL_GetTicks(); }}[/source]
EDIT: in this case y = 0 is top part of the screen.
#3KnolanCross
Posted 26 November 2012 - 10:47 AM
Oh sorry, complety missunderstood what you said.
In this case I believe you need something like this:
[source lang="cpp"]srand(time(NULL));int numberOfAsteroids = (SDL_GetTicks()/30000) + 1; // 1 extra asteroid per 30 secondsif (asteroidsOnScreen < numberOfAsteroids){ if (SDL_GetTicks() - lastTimeTriedToSpamAsteroid > 1000){ // try once per second int chance = rand() % 100; if (chance >= 50){ // 50% chance to spawn an asteroid int up = rand() % 2; if (up == 0){ spawnAsteroid(x = rand()%WIDTH_OF_SCREEN, y = HEIGHT_OF_SCREEN); } else{ spawnAteroidOnLowerPart(x = rand()%WIDTH_OF_SCREEN, y = 0); } } lastTimeTriedToSpamAsteroid = SDL_GetTicks(); }}[/source]
EDIT: in this case y = 0 is top part of the screen.
In this case I believe you need something like this:
[source lang="cpp"]srand(time(NULL));int numberOfAsteroids = (SDL_GetTicks()/30000) + 1; // 1 extra asteroid per 30 secondsif (asteroidsOnScreen < numberOfAsteroids){ if (SDL_GetTicks() - lastTimeTriedToSpamAsteroid > 1000){ // try once per second int chance = rand() % 100; if (chance >= 50){ // 50% chance to spawn an asteroid int up = rand() % 2; if (up == 0){ spawnAsteroid(x = rand()%WIDTH_OF_SCREEN, y = HEIGHT_OF_SCREEN); } else{ spawnAteroidOnLowerPart(x = rand()%WIDTH_OF_SCREEN, y = 0); } } lastTimeTriedToSpamAsteroid = SDL_GetTicks(); }}[/source]
EDIT: in this case y = 0 is top part of the screen.
#2KnolanCross
Posted 26 November 2012 - 10:46 AM
Oh sorry, complety missunderstood what you said.
In this case I believe you need something like this:
[source lang="cpp"]srand(time(NULL));int numberOfAsteroids = (SDL_GetTicks()/30000) + 1; // 1 extra asteroid per 30 secondsif (asteroidsOnScreen < numberOfAsteroids){ if (SDL_GetTicks() - lastTimeTriedToSpamAsteroid > 1000){ // try once per second int chance = rand() % 100; if (chance >= 50){ // 50% chance to spawn an asteroid int up = rand() % 2; if (up == 0){ spawnAsteroid(x = rand()%WIDTH_OF_SCREEN, y = HEIGHT_OF_SCREEN); } else{ spawnAteroidOnLowerPart(x = rand()%WIDTH_OF_SCREEN, y = 0); } } lastTimeTriedToSpamAsteroid = SDL_GetTicks(); }}[/source]
In this case I believe you need something like this:
[source lang="cpp"]srand(time(NULL));int numberOfAsteroids = (SDL_GetTicks()/30000) + 1; // 1 extra asteroid per 30 secondsif (asteroidsOnScreen < numberOfAsteroids){ if (SDL_GetTicks() - lastTimeTriedToSpamAsteroid > 1000){ // try once per second int chance = rand() % 100; if (chance >= 50){ // 50% chance to spawn an asteroid int up = rand() % 2; if (up == 0){ spawnAsteroid(x = rand()%WIDTH_OF_SCREEN, y = HEIGHT_OF_SCREEN); } else{ spawnAteroidOnLowerPart(x = rand()%WIDTH_OF_SCREEN, y = 0); } } lastTimeTriedToSpamAsteroid = SDL_GetTicks(); }}[/source]
#1KnolanCross
Posted 26 November 2012 - 10:45 AM
Oh sorry, complety missunderstood what you said.
In this case I believe you need something like this:
srand(time(NULL));
int numberOfAsteroids = (SDL_GetTicks()/30000) + 1; // 1 extra asteroid per 30 seconds
if (asteroidsOnScreen < numberOfAsteroids){
if (SDL_GetTicks() - lastTimeTriedToSpamAsteroid > 1000){ // try once per second
int chance = rand() % 100;
if (chance >= 50){ // 50% chance to spawn an asteroid
int up = rand() % 2;
if (up == 0){
spawnAsteroid(x = rand()%WIDTH_OF_SCREEN, y = HEIGHT_OF_SCREEN);
}
else{
spawnAteroidOnLowerPart(x = rand()%WIDTH_OF_SCREEN, y = 0);
}
}
lastTimeTriedToSpamAsteroid = SDL_GetTicks();
}
}
In this case I believe you need something like this:
srand(time(NULL));
int numberOfAsteroids = (SDL_GetTicks()/30000) + 1; // 1 extra asteroid per 30 seconds
if (asteroidsOnScreen < numberOfAsteroids){
if (SDL_GetTicks() - lastTimeTriedToSpamAsteroid > 1000){ // try once per second
int chance = rand() % 100;
if (chance >= 50){ // 50% chance to spawn an asteroid
int up = rand() % 2;
if (up == 0){
spawnAsteroid(x = rand()%WIDTH_OF_SCREEN, y = HEIGHT_OF_SCREEN);
}
else{
spawnAteroidOnLowerPart(x = rand()%WIDTH_OF_SCREEN, y = 0);
}
}
lastTimeTriedToSpamAsteroid = SDL_GetTicks();
}
}