title: Tile System with moving Platforms
body: <p>Using a tile based system I need to separate platform block from the rest and then allow them to move up and down at a constant speed.</p>
  
  <p><strong>How would I make the tile that is labeled '=' (Vertical Moving Platform) to move up or down until it hits either a '#' (Wall) or an end point '+' (Vertical Moving Platform Movement Area)?</strong></p>
  
  <p>There is a camera class that follows the player, a player class that controls the movement and a Block class that controls the collision of blocks.</p>
  
  <p>List were the blocks are stored:</p>
  
  <pre><code>List&lt;Block&gt; Blocks;
  </code></pre>
  
  <p>List were the levels are stored:</p>
  
  <pre><code>List&lt;char[,]&gt; Levels = new List&lt;char[,]&gt;();
  </code></pre>
  
  <p>Here is where the levels are created(Test Map):</p>
  
  <pre><code>    protected override void Initialize()
      {
          Blocks = new List&lt;Block&gt;();
  
          char[,] Level2 = {{'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'},
                            {'.','.','.','.','.','.','.','.','.','.','.','.','.','.','+','.'},
                            {'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'},
                            {'.','.','.','.','.','.','.','.','.','.','.','.','#','.','.','.'},
                            {'.','.','.','.','.','.','.','-','-','-','.','.','#','.','.','.'},
                            {'.','.','.','.','.','.','.','.','.','.','.','.','#','.','.','.'},
                            {'.','.','.','-','-','-','.','.','.','.','.','.','#','.','.','.'},
                            {'.','.','.','.','.','.','.','.','.','.','.','.','#','.','.','.'},
                            {'#','#','.','.','.','.','.','.','.','P','.','.','#','.','=','.'},
                            {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'}};
  
          Levels.Add(Level2);
          base.Initialize();
      }
  </code></pre>
  
  <p>Here is the void LoadLevel that will give meaning the to level(This is called when the player completes the level and in the LoadContent Method):</p>
  
  <pre><code>    void LoadLevel(int level)
      {
          Blocks.Clear();
  
          player.Position = Vector2.Zero;
  
          tileWidth = Levels[level].GetLength(1);
          tileHeight = Levels[level].GetLength(0);
          for (int x = 0; x &lt; tileWidth; x++)
          {
              for (int y = 0; y &lt; tileHeight; y++)
              {
                  //Background
                  Blocks.Add(new Block(background, new Vector2(x * 50, y * 50), 0));
  
                  //Impassable Blocks
                  if (Levels[level][y, x] == '#')
                  {
                      Blocks.Add(new Block(blockSpriteA, new Vector2(x * 50, y * 50), 1));
                  }
                  //Blocks that are only passable if going up them
                  if (Levels[level][y, x] == '-')
                  {
                      Blocks.Add(new Block(blockSpriteB, new Vector2(x * 50, y * 50), 2));
                  }
                  //Vertical Moving Platform Movement Area
                  if (Levels[level][y, x] == '+')
                  {
                      Blocks.Add(new Block(movingArea, new Vector2(x * 50, y * 50), 3));
                  }
                  //Vertical Moving Platform
                  if (Levels[level][y, x] == '=')
                  {
                      Blocks.Add(new Block(movingPlatform, new Vector2((x * 50), (y * 50) + movingPlatform.Height), 4));
                  }
                  //PlayerSpawn
                  if (Levels[level][y, x] == 'P' &amp;&amp; player.Position == Vector2.Zero)
                  {
                      player.Position = new Vector2(x * 50, (y + 1) * 50 - player.Texture.Height);
                      player.Velocity = new Vector2(0, 0);
                      player.initialVelocity = 0;
                      player.Time = 0;
                      player.isJumping = false;  
                  }
                  else if (Levels[level][y, x] == 'P' &amp;&amp; player.Position != Vector2.Zero)
                  {
                      throw new Exception("Only one 'P' is needed for each level");
                  }
              }
          }
          if (player.Position == Vector2.Zero)
          {
              throw new Exception("Player Position needs to be set with 'P'");
          }
      }
  </code></pre>
  
  <p>Update Method:</p>
  
  <pre><code>    protected override void Update(GameTime gameTime)
      {
          // Allows the game to exit
          if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
              this.Exit();
  
          // TODO: Add your update logic here
          HandleInput(Keyboard.GetState());
          player.Update(gameTime);
  
          Time += (float)gameTime.ElapsedGameTime.TotalSeconds;
  
          foreach (Block b in Blocks)
          {
              player = b.BlockCollision(player);
          }
          camera.thing(player);
  
          prevKB = Keyboard.GetState();
  
          base.Update(gameTime);
      }
  </code></pre>
  
  <p>Draw Method:</p>
  
  <pre><code>    protected override void Draw(GameTime gameTime)
      {
          GraphicsDevice.Clear(Color.White);
  
          // TODO: Add your drawing code here
          spriteBatch.Begin(SpriteSortMode.Texture, BlendState.AlphaBlend, null, null, null, null, camera.Transform());
          //spriteBatch.Begin();
  
          foreach (Block b in Blocks)
          {
              b.Draw(spriteBatch);
          }
          spriteBatch.End();
          base.Draw(gameTime);
      }
  </code></pre>