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.
Answer
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.
No comments:
Post a Comment