title: Java side-scrolling game
body: <p>I am making my own version of mario. One problem im running into is how to do the side scrolling part of the game. But i dont quite know how to implement the imageableX and imageableY into the world display.
  Any help would be much appreciated! Here is what i have so far:</p>
  
  <pre><code>public class World extends JPanel implements Runnable, KeyListener{
  
  private static final int BEGINNING_X = 0, ENDING_X = 10000;
  private static final int TOP_Y = 0, BOTTOM_Y = 5000;
  private boolean inGame = false;
  
  private Player player;
  //set up a new world with a player
  public World(Player player){
      inGame = true;
      this.player = player;
  }
  
  @Override
  public void paintComponent(Graphics g){
      super.paintComponent(g);
      //the world size
      g.drawRect(0, 0, BEGINNING_X, ENDING_X);
  }
  
  //check to see if the new x postition is valid on the game board
  public boolean isValidXPosition(double x){
      if(x &lt; BEGINNING_X || x &gt; ENDING_X){
          return false;
      }
      return true;                
  }
  
  public double imageableStartX(Player player){
      if(player.returnX() - 100 &lt;= BEGINNING_X)
          return BEGINNING_X;
      else
          return player.returnX() - 100;
  }
  
  public double imageableTopY(Player player){
      if(player.returnY()-100 &lt;= BOTTOM_Y)
          return BOTTOM_Y;
      else
          return BOTTOM_Y - 100;
  }
  
  public double imageableEndX(Player player){
      if(player.returnX() + 200 &lt;= ENDING_X)
          return ENDING_X;
      else
          return player.getX() + 200;
  }
  
  public double imageableBottomY(Player player){
      if(player.returnY()+100 &gt;= BOTTOM_Y)
          return BOTTOM_Y;
      else
          return BOTTOM_Y + 100;
  }
  
  public void run() {
      while(inGame){
          //TODO run game code
      }
  }
  
  public void keyTyped(KeyEvent e) {}
  
  public void keyPressed(KeyEvent e) {
      if(e.getKeyCode() == KeyEvent.VK_RIGHT){
          player.moveRight();
      }
      if(e.getKeyCode() == KeyEvent.VK_LEFT){
          player.moveLeft();
      }
      if(e.getKeyCode() == KeyEvent.VK_SPACE){
          player.setSprint(true);
      }
      if(e.getKeyCode() == KeyEvent.VK_UP){
          player.Jump();
      }
  
  
  }
  
  public void keyReleased(KeyEvent e) {
      if(e.getKeyCode() == KeyEvent.VK_UP){
          player.Descend();
          player.setFalling(true);
      }
      if(e.getKeyCode() == KeyEvent.VK_SPACE){
          player.setSprint(false);
      }
  }
  }
  </code></pre>