title: Pacman java movement issues
body: <p>I have faced a little problem with my pacman movement that i'm working on right now.</p>
  
  <p>I can't seem to find a way to make the movement similar to the originated pacman movement. In order to explain how i want it to move, i have uploaded this picture.</p>
  
  <p><img src="https://i.stack.imgur.com/7yeHy.png" alt="enter image description here"></p>
  
  <p>As it stand now, i have made the collision working between the yellow rectangle and the blue walls. The problem is when i move to the left as in the picture and i click the up arrow, it should not stop, but continue to move and then go up when there is a free space.</p>
  
  <p>Right now, the yellow rectangle will stop if you click on the up arrow like this:</p>
  
  <p><img src="https://i.stack.imgur.com/58UVn.png" alt="enter image description here"></p>
  
  <p>Have uploaded my pacman class which contains my movement, and code from my board class when collision is detected.</p>
  
  <p><strong>pacman class</strong></p>
  
  <pre><code>public class Pacman {
  
  private String pacmanup = "pacmanup.png";
  private String pacmandown = "pacmandown.png";
  private String pacmanleft = "pacmanleft.png";
  private String pacmanright = "pacmanright.png";
  
  private int dx;
  private int dy;
  private int x;
  private int y;
  private int width;
  private int height;
  private boolean visible;
  
  private Image imageup;
  private Image imagedown;
  private Image imageleft;
  private Image imageright;
  
  public Pacman() {
  
      Thread thread = new Thread();
  
      thread.start();
  
      ImageIcon i1 = new ImageIcon(this.getClass().getResource(pacmanup));
      imageup = i1.getImage();
  
      ImageIcon i2 = new ImageIcon(this.getClass().getResource(pacmandown));
      imagedown = i2.getImage();
  
      ImageIcon i3 = new ImageIcon(this.getClass().getResource(pacmanleft));
      imageleft = i3.getImage();
  
      ImageIcon i4 = new ImageIcon(this.getClass().getResource(pacmanright));
      imageright = i4.getImage();
  
      width = imageup.getWidth(null);
      height = imageup.getHeight(null);
      visible = true;
      x = 27;
      y = 27;
  
  }
  
  public int getDx() {
      return dx;
  }
  
  public void setDx(int dx) {
      this.dx = dx;
  }
  
  public int getDy() {
      return dy;
  }
  
  public void setDy(int dy) {
      this.dy = dy;
  }
  
  public int getX() {
      return x;
  }
  
  public int getY() {
      return y;
  }
  
  public void setX(int x) {
      this.x = x;
  }
  
  public void setY(int y) {
      this.y = y;
  }
  
  public Image getImageup() {
      return imageup;
  }
  
  public Image getImagedown() {
      return imagedown;
  }
  
  public Image getImageleft() {
      return imageleft;
  }
  
  public Image getImageright() {
      return imageright;
  }
  
  public void setVisible(boolean visible) {
      this.visible = visible;
  }
  
  public boolean isVisible() {
      return visible;
  }
  
  public Rectangle getBounds() {
      return new Rectangle(x, y, width, height);
  }
  
  public Rectangle getOffsetBounds() {
      return new Rectangle(x + dx, y + dy, width, height);
  }
  
  public void move() {
  
      x += dx;
      y += dy;
  }
  
  public void keyPressed(KeyEvent e) {
  
      int key = e.getKeyCode();
  
      if (key == KeyEvent.VK_LEFT) {
          dx = -1;
          dy = 0;
      }
  
      if (key == KeyEvent.VK_RIGHT) {
          dx = 1;
          dy = 0;
      }
  
      if (key == KeyEvent.VK_UP) {
          dx = 0;
          dy = -1;
      }
  
      if (key == KeyEvent.VK_DOWN) {
          dx = 0;
          dy = 1; 
      }
  }
  
  public void keyReleased(KeyEvent e) {
  
      int key = e.getKeyCode();
  
      if (key == KeyEvent.VK_LEFT) {
  
      }
  
      if (key == KeyEvent.VK_RIGHT) {
  
      }
  
      if (key == KeyEvent.VK_UP) {
  
      }
  
      if (key == KeyEvent.VK_DOWN) {
  
      }
  
  
  }
  </code></pre>
  
  <p><strong>code from Board class</strong></p>
  
  <pre><code>Rectangle r5 = pacman.getOffsetBounds();
  
      for (int j = 0; j&lt;barriers.size(); j++) {
          Barrier b = (Barrier) barriers.get(j);
          Rectangle r4 = b.getBounds();
  
          if (r5.intersects(r4)) {
  
              pacman.setDx(0);
              pacman.setDy(0);
              break;
  
          }
  
      }
  
      pacman.move();
  
  }
  </code></pre>
  
  <p>Have made an String called direction inside my board class which detects what direction the yellow rectangle are moving. </p>
  
  <p>"left" "up" "right" or "down"</p>
  
  <p>Have already tried to write some code, but not working. Here is what i tried:</p>
  
  <pre><code>      // moving to the left and tried go up
              else if (pacman.getDx() == 0 &amp;&amp; pacman.getDy() == -1 &amp;&amp; direction.equals("left")) {
                  pacman.setDy(0);
                  pacman.setDx(-1);
                  break;
  </code></pre>
  
  <p>Well, when it moves to the left and you click up, it will continue to move left, but it wont go up on the free space as it should do :)</p>
  
  <p>Is it something with the keydapter / pressed key? maybe the pressed up key is not activated or something when u click up?</p>