private void SpawnEnemy() { Vector2 speed = Vector2.Zero; Vector2 position = Vector2.Zero; // Default frame size Point frameSize = new Point(75, 75); // Randomly choose which side of the screen to place enemy, // then randomly create a position along that side of the screen // and randomly choose a speed for the enemy switch (((Game1)Game).rnd.Next(4)) { case 0: // LEFT to RIGHT position = new Vector2( -frameSize.X, ((Game1)Game).rnd.Next(0, Game.GraphicsDevice.PresentationParameters.BackBufferHeight - frameSize.Y)); speed = new Vector2(((Game1)Game).rnd.Next( enemyMinSpeed, enemyMaxSpeed), 0); break; case 1: // RIGHT to LEFT position = new Vector2( Game.GraphicsDevice.PresentationParameters.BackBufferWidth, ((Game1)Game).rnd.Next(0, Game.GraphicsDevice.PresentationParameters.BackBufferHeight - frameSize.Y)); speed = new Vector2(-((Game1)Game).rnd.Next( enemyMinSpeed, enemyMaxSpeed), 0); break; case 2: // BOTTOM to TOP position = new Vector2(((Game1)Game).rnd.Next(0, Game.GraphicsDevice.PresentationParameters.BackBufferWidth - frameSize.X), Game.GraphicsDevice.PresentationParameters.BackBufferHeight); speed = new Vector2(0, -((Game1)Game).rnd.Next(enemyMinSpeed, enemyMaxSpeed)); break; case 3: // TOP to BOTTOM position = new Vector2(((Game1)Game).rnd.Next(0, Game.GraphicsDevice.PresentationParameters.BackBufferWidth - frameSize.X), -frameSize.Y); speed = new Vector2(0, ((Game1)Game).rnd.Next(enemyMinSpeed, enemyMaxSpeed)); break; } // Get random number between 0 and 99 int random = ((Game1)Game).rnd.Next(100); if (random < likelihoodAutomated) { // Create an AutomatedSprite. // Get new random number to determine whether to // create a three-blade or four-blade sprite. if (((Game1)Game).rnd.Next(2) == 0) { // Create a four-blade enemy spriteList.Add( new AutomatedSprite( Game.Content.Load<Texture2D>(@"images\fourblades"), position, new Point(75, 75), 10, new Point(0, 0), new Point(6, 8), speed, "fourbladescollision", automatedSpritePointValue)); } else { // Create a three-blade enemy spriteList.Add( new AutomatedSprite( Game.Content.Load<Texture2D>(@"images\threeblades"), position, new Point(75, 75), 10, new Point(0, 0), new Point(6, 8), speed, "threebladescollision", automatedSpritePointValue)); } } else if (random < likelihoodAutomated + likelihoodChasing) { // Create a ChasingSprite. // Get new random number to determine whether // to create a skull or a plus sprite. if (((Game1)Game).rnd.Next(2) == 0) { // Create a skull spriteList.Add( new ChasingSprite( Game.Content.Load<Texture2D>(@"images\skullball"), position, new Point(75, 75), 10, new Point(0, 0), new Point(6, 8), speed, "skullcollision", this, chasingSpritePointValue)); } else { // Create a plus spriteList.Add( new ChasingSprite( Game.Content.Load<Texture2D>(@"images\plus"), position, new Point(75, 75), 10, new Point(0, 0), new Point(6, 4), speed, "pluscollision", this, chasingSpritePointValue)); } } else { // Create an EvadingSprite if (((Game1)Game).rnd.Next(4) == 0) { if (((Game1)Game).rnd.Next(2) == 0) { EvadingSprite es = new EvadingSprite(Game.Content.Load<Texture2D>(@"images\bluehead"), position, new Point(45, 90), 10, new Point(0, 0), new Point(3, 4), speed, 100, "boltcollision1", this, .75f, 60, evadingSpritePointValue); spriteList.Add(es); } else { EvadingSprite es = new EvadingSprite(Game.Content.Load<Texture2D>(@"images\redhead"), position, new Point(45, 95), 10, new Point(0, 0), new Point(3, 4), speed, 100, "boltcollision2", this, .75f, 60, evadingSpritePointValue); spriteList.Add(es); } } else { // spriteList.Add( //new EvadingSprite( //Game.Content.Load<Texture2D>(@"images\bluehead"), //position, new Point(45, 90), 10, new Point(0, 0), //new Point(3, 4), speed, 100, "threebladescollision", //automatedSpritePointValue)); spriteList.Add( new EvadingSprite( Game.Content.Load<Texture2D>(@"images\bolt"), position, new Point(75, 75), 10, new Point(0, 0), new Point(6, 8), speed * 0.9f, "boltcollision", this, .75f, 40, evadingSpritePointValue)); } } }
private void SpawnEnemy() { Vector2 speed = Vector2.Zero; Vector2 position = Vector2.Zero; // Default frame size Point frameSize = new Point(75, 75); // Randomly choose which side of the screen to place enemy, // then randomly create a position along that side of the screen // and randomly choose a speed for the enemy switch (((Game1)Game).rnd.Next(4)) { case 0: // LEFT to RIGHT position = new Vector2( -frameSize.X, ((Game1)Game).rnd.Next(0, Game.GraphicsDevice.PresentationParameters.BackBufferHeight - frameSize.Y)); speed = new Vector2(((Game1)Game).rnd.Next( enemyMinSpeed, enemyMaxSpeed), 0); break; case 1: // RIGHT to LEFT position = new Vector2( Game.GraphicsDevice.PresentationParameters.BackBufferWidth, ((Game1)Game).rnd.Next(0, Game.GraphicsDevice.PresentationParameters.BackBufferHeight - frameSize.Y)); speed = new Vector2(-((Game1)Game).rnd.Next( enemyMinSpeed, enemyMaxSpeed), 0); break; case 2: // BOTTOM to TOP position = new Vector2(((Game1)Game).rnd.Next(0, Game.GraphicsDevice.PresentationParameters.BackBufferWidth - frameSize.X), Game.GraphicsDevice.PresentationParameters.BackBufferHeight); speed = new Vector2(0, -((Game1)Game).rnd.Next(enemyMinSpeed, enemyMaxSpeed)); break; case 3: // TOP to BOTTOM position = new Vector2(((Game1)Game).rnd.Next(0, Game.GraphicsDevice.PresentationParameters.BackBufferWidth - frameSize.X), -frameSize.Y); speed = new Vector2(0, ((Game1)Game).rnd.Next(enemyMinSpeed, enemyMaxSpeed)); break; } // Get random number between 0 and 99 int random = ((Game1)Game).rnd.Next(100); if (random < likelihoodAutomated) { // Create an AutomatedSprite. // Get new random number to determine whether to // create a three-blade or four-blade sprite. if (((Game1)Game).rnd.Next(2) == 0) { // Create a four-blade enemy spriteList.Add( new AutomatedSprite( Game.Content.Load <Texture2D>(@"images\fourblades"), position, new Point(75, 75), 10, new Point(0, 0), new Point(6, 8), speed, "fourbladescollision", automatedSpritePointValue)); } else { // Create a three-blade enemy spriteList.Add( new AutomatedSprite( Game.Content.Load <Texture2D>(@"images\threeblades"), position, new Point(75, 75), 10, new Point(0, 0), new Point(6, 8), speed, "threebladescollision", automatedSpritePointValue)); } } else if (random < likelihoodAutomated + likelihoodChasing) { // Create a ChasingSprite. // Get new random number to determine whether // to create a skull or a plus sprite. if (((Game1)Game).rnd.Next(2) == 0) { // Create a skull spriteList.Add( new ChasingSprite( Game.Content.Load <Texture2D>(@"images\skullball"), position, new Point(75, 75), 10, new Point(0, 0), new Point(6, 8), speed, "skullcollision", this, chasingSpritePointValue)); } else { // Create a plus spriteList.Add( new ChasingSprite( Game.Content.Load <Texture2D>(@"images\plus"), position, new Point(75, 75), 10, new Point(0, 0), new Point(6, 4), speed, "pluscollision", this, chasingSpritePointValue)); } } else { // Create an EvadingSprite if (((Game1)Game).rnd.Next(4) == 0) { if (((Game1)Game).rnd.Next(2) == 0) { EvadingSprite es = new EvadingSprite(Game.Content.Load <Texture2D>(@"images\bluehead"), position, new Point(45, 90), 10, new Point(0, 0), new Point(3, 4), speed, 100, "boltcollision1", this, .75f, 60, evadingSpritePointValue); spriteList.Add(es); } else { EvadingSprite es = new EvadingSprite(Game.Content.Load <Texture2D>(@"images\redhead"), position, new Point(45, 95), 10, new Point(0, 0), new Point(3, 4), speed, 100, "boltcollision2", this, .75f, 60, evadingSpritePointValue); spriteList.Add(es); } } else { // spriteList.Add( //new EvadingSprite( //Game.Content.Load<Texture2D>(@"images\bluehead"), //position, new Point(45, 90), 10, new Point(0, 0), //new Point(3, 4), speed, 100, "threebladescollision", //automatedSpritePointValue)); spriteList.Add( new EvadingSprite( Game.Content.Load <Texture2D>(@"images\bolt"), position, new Point(75, 75), 10, new Point(0, 0), new Point(6, 8), speed * 0.9f, "boltcollision", this, .75f, 40, evadingSpritePointValue)); } } }