context: using System;
  using System.Collections.Generic;
  using System.Linq;
  using Microsoft.Xna.Framework;
  using Microsoft.Xna.Framework.Audio;
  using Microsoft.Xna.Framework.Content;
  using Microsoft.Xna.Framework.GamerServices;
  using Microsoft.Xna.Framework.Graphics;
  using Microsoft.Xna.Framework.Input;
  using Microsoft.Xna.Framework.Media;
  
  namespace PortalToMyWorld
  {
  
      public class Game1 : Microsoft.Xna.Framework.Game
      {
          GraphicsDeviceManager graphics;
          SpriteBatch spriteBatch;
  
          Portal[] portal = new Portal[3];
  
          Ground[] ground = new Ground[34];
  
          wall[] Wall = new wall[16];
  
          Spike[] spike = new Spike[10];
  
          Character player;
  
          int intsec;
  
          bool gameOn;
  
          KeyboardState ks;
          KeyboardState ks2;
          GamePadState oldpad1, pad1;
  
          SpriteFont font;
  
          double time;
          SoundEffectInstance musicInstance = null;
          SoundEffect song;
  
          public Game1()
          {
              graphics = new GraphicsDeviceManager(this);
              Content.RootDirectory = "Content";
          }
  
          protected override void Initialize()
          {
              player = new Character(this.Content.Load<Texture2D>("char"), this.Content.Load<Texture2D>("char2"), this.Content.Load<Texture2D>("sheetr"), this.Content.Load<Texture2D>("sheetl"));
  
              for (int i = 0; i < portal.Length; i++)
              {
                      portal[i] = new Portal();
              }
  
              for (int i = 0; i < Wall.Length; i++)
              {
                  Wall[i] = new wall(this.Content.Load<Texture2D>("wall"));
              }
  
              for (int i = 0; i < ground.Length; i++)
              {
                  ground[i] = new Ground(this.Content.Load<Texture2D>("wall"));
              }
  
              for (int i = 0; i < spike.Length; i++)
              {
                  spike[i] = new Spike(this.Content.Load<Texture2D>("spike"));
              }
  
              font = Content.Load<SpriteFont>("SpriteFont1");
              base.Initialize();
          }
  
          protected override void LoadContent()
          {
              spriteBatch = new SpriteBatch(GraphicsDevice);
              this.graphics.IsFullScreen = true;
  
              player.width = GraphicsDevice.DisplayMode.Width;
              player.height = GraphicsDevice.DisplayMode.Height;
              song = this.Content.Load<SoundEffect>("Deep");
              this.graphics.PreferredBackBufferWidth = player.width;
              this.graphics.PreferredBackBufferHeight = player.height;
  
              this.graphics.ApplyChanges();
          }
  
          protected override void UnloadContent()
          {
  
          }
          protected override void Update(GameTime gameTime)
          {
  
              pad1 = GamePad.GetState(PlayerIndex.One);
              ks = Keyboard.GetState();
              PlayMainMusic();
                  if (ks.IsKeyDown(Keys.Enter) && ks2.IsKeyUp(Keys.Enter))
                  {
                      if (player.CurrentLevel == 0 || player.CurrentLevel == 6)
                      {
                          player.CurrentLevel = 1;
                          player.PlayerDead = false;
                          for (int i = 0; i < portal.Length; i++)
                          {
                              portal[i] = new Portal();
                          }
  
                          for (int i = 0; i < Wall.Length; i++)
                          {
                              Wall[i] = new wall(this.Content.Load<Texture2D>("wall"));
                          }
  
                          for (int i = 0; i < ground.Length; i++)
                          {
                              ground[i] = new Ground(this.Content.Load<Texture2D>("wall"));
                          }
  
                          for (int i = 0; i < spike.Length; i++)
                          {
                              spike[i] = new Spike(this.Content.Load<Texture2D>("spike"));
                          }
                          intsec = -1;
                          player.OnGround = false;
                          player.PlayerintWall = false;
                          player.PlayerPos();
                          player.CharRect.X = player.XYPOS[0];
                          player.CharRect.Y = player.XYPOS[1];
                          gameOn = true;
                      }
                      else
                      {
                          player.CurrentLevel = 0;
                          player.PlayerDead = true;
                          for (int i = 0; i < portal.Length; i++)
                          {
                              portal[i] = new Portal();
                          }
  
                          for (int i = 0; i < Wall.Length; i++)
                          {
                              Wall[i] = new wall(this.Content.Load<Texture2D>("wall"));
                          }
  
                          for (int i = 0; i < ground.Length; i++)
                          {
                              ground[i] = new Ground(this.Content.Load<Texture2D>("wall"));
                          }
  
                          for (int i = 0; i < spike.Length; i++)
                          {
                              spike[i] = new Spike(this.Content.Load<Texture2D>("spike"));
                          }
                          intsec = -1;
                          player.OnGround = false;
                          player.PlayerintWall = false;
                          player.PlayerPos();
                          player.CharRect.X = player.XYPOS[0];
                          player.CharRect.Y = player.XYPOS[1];
                          gameOn = false;
                      }
                  }
  
                  ks2 = ks;
              if (gameOn)
              {
                  if (ks.IsKeyDown(Keys.Back) && (ks.IsKeyUp(Keys.Space) || player.PlayerSpeedY == 0 && player.direction != "up"))
                  {
                      player.PlayerDead = false;
                      for (int i = 0; i < portal.Length; i++)
                      {
                          portal[i] = new Portal();
                      }
  
                      for (int i = 0; i < Wall.Length; i++)
                      {
                          Wall[i] = new wall(this.Content.Load<Texture2D>("wall"));
                      }
  
                      for (int i = 0; i < ground.Length; i++)
                      {
                          ground[i] = new Ground(this.Content.Load<Texture2D>("wall"));
                      }
  
                      for (int i = 0; i < spike.Length; i++)
                      {
                          spike[i] = new Spike(this.Content.Load<Texture2D>("spike"));
                      }
                      intsec = -1;
                      player.OnGround = false;
                      player.PlayerintWall = false;
                      player.PlayerPos();
                      player.CharRect.X = player.XYPOS[0];
                      player.CharRect.Y = player.XYPOS[1];
                      player.direction = "";
                      player.PlayerSpeedY = -16;
                  }
                  ks2 = ks;
                  if (player.CurrentLevel == 1)
                  {
                      //Array.Resize(ref portal, player.GetPortalAmount());
                      //Array.Resize(ref Wall, player.GetWallAmount());
                      //Array.Resize(ref spike, player.GetSpikeAmount());
                      //Array.Resize(ref ground, player.GetGroundAmount());
  
                      spike[0].SpikeRect = new Rectangle(840, 930, 70, 120);
                      spike[1].SpikeRect = new Rectangle(260, 920, 70, 130);
  
                      portal[0].PortalRect = new Rectangle(1080, 920, 60, 80);
                      portal[1].PortalRect = new Rectangle(1100, 50, 60, 80);
                      portal[2].PortalRect = new Rectangle(560, 130, 60, 80);
  
                      Wall[0].wallRect = new Rectangle(290, 120, 10, 350);
                      Wall[1].wallRect = new Rectangle(710, 340, 10, 135);
                      Wall[2].wallRect = new Rectangle(540, 0, 10, 230);
                      Wall[3].wallRect = new Rectangle(740, 0, 10, 95);
                      Wall[4].wallRect = new Rectangle(1035, 0, 10, 195);
                      Wall[5].wallRect = new Rectangle(1170, 185, 10, 235);
                      Wall[6].wallRect = new Rectangle(685, 860, 10, 170);
                      Wall[7].wallRect = new Rectangle(845, 545, 10, 240);
                      Wall[8].wallRect = new Rectangle(1120, 750, 10, 95);
                      Wall[9].wallRect = new Rectangle(1050, 840, 10, 195);
                      Wall[10].wallRect = new Rectangle(250, 890, 10, 145);
                      Wall[11].wallRect = new Rectangle(580, 545, 10, 50);
                      //Wall[12].wallRect = new Rectangle(580, 745, 10, 115);
  
  
                      ground[0].GroundRect = new Rectangle(145, 142, 95, 10);
                      ground[1].GroundRect = new Rectangle(25, 233, 95, 10);
                      ground[2].GroundRect = new Rectangle(160, 320, 95, 10);
                      ground[3].GroundRect = new Rectangle(330, 260, 95, 10);
  
gt:                     ground[4].GroundRect = new Rectangle(0, 540, 1280, 10);