Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am making a android game, it's a tower/base defense like type of game (yea I know it is kind of confusing), I was wondering if anyone knows a good way to have the attacking sprites randomly generate without the number of sprites being higher than the level. I want the attack sprites to equal the level. I have 2 sprite types that I want to be generated, I just don't know how to make it to where one of the two randomly comes. Ex: you on level 4 and Sprite A spawns and then 3 others right after it but which version you get is random.

share|improve this question
5  
I think you need to add more details. Or words. I think you forgot a few. –  Tetrad May 18 '11 at 6:59
5  
You accidentally the words! –  Ricket May 18 '11 at 15:29
add comment

1 Answer

up vote 1 down vote accepted

I presume you're running in Android's flavor of Java, so

For generating random numbers, see this.

You'll need to setup a loop, which will load your extra sprites:

// you may wish to use a seed, so you can re-generate these numbers later, this depends on your use
Random gen = new Random(); 
for(int i = 0; i < currentLevelNumber; i++)
{
    double r = generator.nextGaussian();

    if(r > 0)
        // sprite type A
    else
        // sprite type B
}

I'm assuming you already know how to load, draw, and update sprites. If not, start here.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.