Results 1 to 2 of 2

Thread: Breakout Paddle

  1. #1
    Join Date
    Jul 2012
    Posts
    33
    Rep Power
    0

    Default Breakout Paddle

    Hi All

    I'm doing the Stanford cs106a Breakout exercise, making a simple game of breakout. A single line of code seems to be preventing my paddle from moving left and right on screen.

    private void setUpPaddle() {
    GRect paddle = new GRect((APPLICATION_WIDTH / 2) - PADDLE_WIDTH / 2, HEIGHT - PADDLE_Y_OFFSET, PADDLE_WIDTH, PADDLE_HEIGHT);
    paddle.setFilled(true);
    paddle.setColor(Color.BLACK);
    add(paddle);
    addMouseListeners();
    }
    public void mousePressed(MouseEvent e) {
    last = new GPoint(e.getX(), e.getY());
    paddle = getElementAt(last);
    }

    public void mouseDragged(MouseEvent e) {
    while (paddle.getX() > PADDLE_WIDTH && paddle.getX() < WIDTH - PADDLE_WIDTH) {
    if (paddle != null) {
    paddle.move(e.getX() - last.getX(), 0.0);
    last = new GPoint(e.getPoint());
    }
    }
    }
    private GObject paddle;
    private GPoint last;
    }

    It was working in as much as the paddle would move left and right when clicked on and dragged with the mouse. Then I inserted the while loop;

    while (paddle.getX() > PADDLE_WIDTH && paddle.getX() < WIDTH - PADDLE_WIDTH)

    to prevent it from travelling further than the canvas size. It's now stuck. I've also tried it with e.getX() and have the same result. Even though this library (the acm library) may not be familar to you, can anyone spot what I've done wrong?

    Thanks! R

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

Similar Threads

  1. Replies: 1
    Last Post: 06-26-2012, 12:39 AM
  2. Paddle Class: Trying to code details to ball & paddle..
    By CuppaCoffee in forum New To Java
    Replies: 1
    Last Post: 01-09-2012, 01:14 AM
  3. Need help with Breakout game
    By tfitz666 in forum New To Java
    Replies: 9
    Last Post: 03-22-2010, 06:26 AM
  4. Another Breakout question
    By jumpstart in forum New To Java
    Replies: 3
    Last Post: 07-29-2009, 05:48 AM
  5. Pong Paddle Not Stopping Ball At Certain Speed
    By JDCAce in forum Java Applets
    Replies: 2
    Last Post: 10-12-2008, 06:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •