Randomly Generating Different Sprite Types
To randomly generate sprites of different types, you need to first determine the
likelihood that each type will be created. Most of the sprites in this game will be
AutomatedSprites. ChasingSprites will be the next most common, and EvadingSprites will show up only occasionally. In this
section, you'll be assigning a percentage likelihood to each type of sprite. Each
time a new sprite is spawned, you'll determine which type of sprite to create based
on those percentages. The exact percentage likelihood for each sprite type is
something that you can play with as you test your game, and you can adjust the
values to the point where they feel right to you, the developer.
To begin, open the SpriteManager class and add
three new class-level variables representing the likelihood that each sprite type
will be spawned:
int likelihoodAutomated = 75; int likelihoodChasing = 20; int likelihoodEvading = 5;
You'll notice that the values added equal 100 (representing 100%). Essentially,
75% of the time you'll generate an AutomatedSprite, 20% of the time a ChasingSprite, and 5% an EvadingSprite.
Now, you have to add some code that will generate a random number, and, based on
the value of that random number, create one of the three sprite types. Open your
SpriteManager class and replace this call to
SpriteList.Add, which is at the end of the
SpawnEnemy method:
spriteList.Add( new EvadingSprite (Game.Content.Load<Texture2D>(@"images\skullball"), position, new ...