using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework; using DW.Stream; namespace DWGame.Player { public class Background { //struct to hold background attributes public struct background { public Vector2 position; public Rectangle bgBox; public Texture2D bgTex; } //array for backround entities public static background[] bgrnd; //array to hold collision boxes public static Rectangle[] frgrnd; //counter to hold currect background frame public static int fgCounter; //constructor public Background() { fgCounter = 3; frgrnd = new Rectangle[28]; bgrnd = new background[6]; for (int i = 0; i < bgrnd.Length; i++) { switch (i) { case 0: bgrnd[i].bgTex = Renderer.content.Load("starfield/Starfield4"); bgrnd[i].position = new Vector2(0, 0); break; case 1: bgrnd[i].bgTex = Renderer.content.Load("starfield/Starfield5"); bgrnd[i].position = new Vector2(bgrnd[0].position.X + bgrnd[0].bgBox.Width, 0); break; case 2: bgrnd[i].bgTex = Renderer.content.Load("starfield/Starfield6"); bgrnd[i].position = new Vector2(bgrnd[1].position.X + bgrnd[1].bgBox.Width, 0); break; case 3: bgrnd[i].bgTex = Renderer.content.Load("starfield/Starfield2"); bgrnd[i].position = new Vector2(bgrnd[0].position.X, 0); break; case 4: bgrnd[i].bgTex = Renderer.content.Load("starfield/Starfield3"); bgrnd[i].position = new Vector2(bgrnd[1].position.X, 0); break; case 5: bgrnd[i].bgTex = Renderer.content.Load("starfield/Starfield1"); bgrnd[i].position = new Vector2(bgrnd[2].position.X, 0); break; } bgrnd[i].bgBox = new Rectangle((int)bgrnd[i].position.X, (int)bgrnd[i].position.Y, (int)bgrnd[i].bgTex.Width, (int)bgrnd[i].bgTex.Height); } } //method used to update background and foreground position public static void Update() { if (PhoenixGame.gameTimer.IsRunning) { for (int i = 0; i < bgrnd.Length; i++) { switch (i) { case 0: bgrnd[i].position.X -= 2; if ((bgrnd[i].position.X + bgrnd[i].bgBox.Width) < 0) bgrnd[i].position.X = bgrnd[2].position.X + bgrnd[2].bgBox.Width - 2; break; case 1: bgrnd[i].position.X -= 2; if ((bgrnd[i].position.X + bgrnd[i].bgBox.Width) < 0) bgrnd[i].position.X = bgrnd[0].position.X + bgrnd[0].bgBox.Width; break; case 2: bgrnd[i].position.X -= 2; if ((bgrnd[i].position.X + bgrnd[i].bgBox.Width) < 0) bgrnd[i].position.X = bgrnd[1].position.X + bgrnd[1].bgBox.Width; break; case 3: bgrnd[i].position.X -= 1; if ((bgrnd[i].position.X + bgrnd[i].bgBox.Width) < 0) { bgrnd[i].position.X = bgrnd[5].position.X + bgrnd[5].bgBox.Width - 2; fgCounter = 4; } break; case 4: bgrnd[i].position.X -= 1; if ((bgrnd[i].position.X + bgrnd[i].bgBox.Width) < 0) { bgrnd[i].position.X = bgrnd[3].position.X + bgrnd[3].bgBox.Width; fgCounter = 5; } break; case 5: bgrnd[i].position.X -= 1; if ((bgrnd[i].position.X + bgrnd[i].bgBox.Width) < 0) { bgrnd[i].position.X = bgrnd[4].position.X + bgrnd[4].bgBox.Width; fgCounter = 3; } break; } bgrnd[i].bgBox = new Rectangle((int)(bgrnd[i].position.X), (int)bgrnd[i].position.Y, (int)bgrnd[i].bgTex.Width, (int)bgrnd[i].bgTex.Height); } } Background.setFrgrnd(); } //method used to draw background and foreground public static void Draw() { for (int i = 0; i < bgrnd.Length; i++) { Renderer.spriteBatch.Draw(bgrnd[i].bgTex, bgrnd[i].bgBox, Color.White); } //for (int i = 0; i < frgrnd.Length; i++) //{ // Renderer.spriteBatch.Draw(bgrnd[5].bgTex, frgrnd[i], Color.Yellow); //} } //method used by AI to generate enemies based on current bg frame public static int getCounter() { return fgCounter; } //method used to pass foreground collsion boxes to Collision public static Rectangle[] getFrgrnd() { return frgrnd; } //method used to set the values for the collsion boxes to the values from Collision public static void setFrgrnd() { frgrnd[0] = new Rectangle((int)bgrnd[5].bgBox.X, (int)bgrnd[5].bgBox.Y, 109, 187); frgrnd[1] = new Rectangle((int)(frgrnd[0].X + frgrnd[0].Width), (int)frgrnd[0].Y, 82, 104); frgrnd[2] = new Rectangle((int)(frgrnd[1].X + frgrnd[1].Width), (int)frgrnd[1].Y, 102, 299); frgrnd[3] = new Rectangle((int)(frgrnd[2].X + frgrnd[2].Width), (int)frgrnd[2].Y, 275, 59); frgrnd[4] = new Rectangle((int)(frgrnd[3].X + frgrnd[3].Width), (int)frgrnd[3].Y, 98, 265); frgrnd[5] = new Rectangle((int)(frgrnd[4].X + frgrnd[4].Width), (int)frgrnd[4].Y, 124, 160); frgrnd[6] = new Rectangle((int)bgrnd[5].bgBox.X, (int)bgrnd[5].bgBox.Height - 168, 78, 168); frgrnd[7] = new Rectangle((int)(frgrnd[6].X + frgrnd[6].Width), (int)bgrnd[5].bgBox.Height - 236, 84, 236); frgrnd[8] = new Rectangle((int)(frgrnd[7].X + frgrnd[7].Width), (int)bgrnd[5].bgBox.Height - 153, 139, 153); frgrnd[9] = new Rectangle((int)(frgrnd[8].X + frgrnd[8].Width), (int)bgrnd[5].bgBox.Height - 178, 55, 178); frgrnd[10] = new Rectangle((int)(frgrnd[9].X + frgrnd[9].Width), (int)bgrnd[5].bgBox.Height - 125, 56, 125); frgrnd[11] = new Rectangle((int)(frgrnd[10].X + frgrnd[10].Width), (int)bgrnd[5].bgBox.Height - 348, 72, 348); frgrnd[12] = new Rectangle((int)(frgrnd[11].X + frgrnd[11].Width), (int)bgrnd[5].bgBox.Height - 153, 163, 153); frgrnd[13] = new Rectangle((int)(frgrnd[12].X + frgrnd[12].Width), (int)bgrnd[5].bgBox.Height - 184, 133, 184); frgrnd[14] = new Rectangle((int)bgrnd[3].bgBox.X, (int)bgrnd[3].bgBox.Y, 93, 150); frgrnd[15] = new Rectangle((int)(frgrnd[14].X + frgrnd[14].Width), (int)frgrnd[14].Y, 76, 108); frgrnd[16] = new Rectangle((int)(frgrnd[15].X + frgrnd[15].Width), (int)frgrnd[15].Y, 51, 65); frgrnd[17] = new Rectangle((int)(frgrnd[16].X + frgrnd[16].Width), (int)frgrnd[16].Y, 580, 23); frgrnd[18] = new Rectangle((int)bgrnd[3].bgBox.X, (int)bgrnd[3].bgBox.Height - 142, 92, 142); frgrnd[19] = new Rectangle((int)(frgrnd[16].X + frgrnd[16].Width), (int)bgrnd[3].bgBox.Height - 96, 46, 96); frgrnd[20] = new Rectangle((int)(frgrnd[16].X + frgrnd[16].Width), (int)bgrnd[3].bgBox.Height - 69, 662, 69); frgrnd[21] = new Rectangle((int)bgrnd[4].bgBox.X, (int)bgrnd[4].bgBox.Y, 666, 58); frgrnd[22] = new Rectangle((int)(frgrnd[21].X + frgrnd[21].Width), (int)frgrnd[21].Y, 79, 92); frgrnd[23] = new Rectangle((int)(frgrnd[22].X + frgrnd[22].Width), (int)frgrnd[22].Y, 55, 152); frgrnd[24] = new Rectangle((int)bgrnd[4].bgBox.X, (int)bgrnd[4].bgBox.Height - 87, 295, 87); frgrnd[25] = new Rectangle((int)(frgrnd[24].X + frgrnd[24].Width), (int)bgrnd[4].bgBox.Height - 107, 258, 107); frgrnd[26] = new Rectangle((int)(frgrnd[25].X + frgrnd[25].Width), (int)bgrnd[4].bgBox.Height - 169, 181, 169); frgrnd[27] = new Rectangle((int)(frgrnd[26].X + frgrnd[26].Width), (int)bgrnd[4].bgBox.Height - 160, 66, 160); } } }