//Camera function for moving the bg void camera(Player player) { float shift; //Set shift amount to the distance from the center. shift = player.position.X - (screenCenter - player.spriteWidth/2); //Move the player to the center of the screen. player.position.X = (screenCenter - player.spriteWidth / 2); //Move the CMs and BGs for (int i = 0; i < stages.Count; i++) { stages.ElementAt(i).position.X -= shift; } //Move the fragments for (int i = 0; i < fragments.Count; i++) { fragments.ElementAt(i).position.X -= shift; } //Increase score based on shift tempScore += (int)shift; if (tempScore > 35) { score += (int)(2*bps); tempScore = 0; } if (score > displayedScore) displayedScore = score; //Parallaxing Background for(int j = 0; j < numParallax; j++) { for (int i = 0; i < 2; i++)//There should only be 2 parallax backgrounds on each layer. Each one needs to be > 1920 in width. { int other = (i == 0) ? 1 : 0; parallaxPosition[i,j].X -= shift / parallaxFactor[j]; if (parallaxPosition[i,j].X + parallaxImage[j].Width <= 0) { parallaxPosition[i,j].X = parallaxPosition[other,j].X + parallaxImage[j].Width - shift;//Move it to the end of the other one. } else if (parallaxPosition[i,j].X >= parallaxImage[j].Width) { parallaxPosition[i,j].X = parallaxPosition[other,j].X - parallaxImage[j].Width - shift; } } } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { //Set/Reset variables lives = 5; level = 0; bps = 2; tempScore = 0; score = 0; displayedScore = 0; playerHurtTimer = 0; random = new Random(); //Initialize the player player = new Player(); //Camera cameraView = new Camera(GraphicsDevice.Viewport); //Background stuff screenRectangle = new Rectangle(0, 0, screenWidth, screenHeight); parallaxPosition = new Vector2[2,numParallax]; parallaxImage = new Texture2D[numParallax]; //Stages stages = new LinkedList<Stage>(); bg = new Texture2D[numStages]; cm = new Texture2D[numStages]; collisionColorArray = new LinkedList<Color[]>(); //Sounds //Fragments fragments = new LinkedList<Fragment>(); fireworks = new LinkedList<Firework>(); //Windows 8 stuff Windows8.Initialize(); //Touch stuff TouchPanel.EnabledGestures = GestureType.FreeDrag | GestureType.Flick | GestureType.Tap | GestureType.DoubleTap | GestureType.VerticalDrag | GestureType.Hold | GestureType.PinchComplete | GestureType.None; base.Initialize(); }