Results 1 to 4 of 4
  1. #1
    jumpstart is offline Member
    Join Date
    Jul 2009
    Posts
    2
    Rep Power
    0

    Default Another Breakout question

    hello, just started taking CS classes, I'm suppose to write in java, the game Breakout, only problem is I cannot for the life of me get the paddle to track with the mouse. what am I doing wrong?
    here is a break down oh just trying to get the paddle to work and move.
    Thanks in advance for help.

    import acm.graphics.GRect;
    import acm.program.*;
    import acm.util.*;
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;

    public class test extends GraphicsProgram {
    /** Width and height of application window in pixels */
    public static final int APPLICATION_WIDTH = 400;
    public static final int APPLICATION_HEIGHT = 600;

    /** Dimensions of game board (usually the same) */
    private static final int WIDTH = APPLICATION_WIDTH;
    private static final int HEIGHT = APPLICATION_HEIGHT;

    /** Dimensions of the paddle */
    private static final int PADDLE_WIDTH = 60;
    private static final int PADDLE_HEIGHT = 10;

    /** Offset of the paddle up from the bottom */
    private static final int PADDLE_Y_OFFSET = 30;

    /** Number of bricks per row */
    private static final int NBRICKS_PER_ROW = 10;

    /** Number of rows of bricks */
    private static final int NBRICK_ROWS = 10;

    /** Separation between bricks */
    private static final int BRICK_SEP = 4;

    /** Width of a brick */
    private static final int BRICK_WIDTH =
    (WIDTH - (NBRICKS_PER_ROW - 1) * BRICK_SEP) / NBRICKS_PER_ROW;

    /** Height of a brick */
    private static final int BRICK_HEIGHT = 8;

    /** Radius of the ball in pixels */
    private static final int BALL_RADIUS = 10;

    /** Offset of the top brick row from the top */
    private static final int BRICK_Y_OFFSET = 70;

    /** Number of turns */
    private static final int NTURNS = 3;
    public void run() {
    addMouseListeners();
    GRect paddle = new GRect((WIDTH / 2) - (PADDLE_WIDTH / 2), (HEIGHT - (PADDLE_HEIGHT / 2)) - PADDLE_Y_OFFSET, PADDLE_WIDTH, PADDLE_HEIGHT);
    paddle.setFilled(true);
    add(paddle);
    }
    public void mouseMoved(MouseEvent e) {
    paddle.setLocation(e.getX(), 0);
    }
    private GRect paddle;
    }

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    What you exactly wants to do? You just declare few constants and post a code segment here, which not make sense to me, and I believe most of members as well.

  3. #3
    jumpstart is offline Member
    Join Date
    Jul 2009
    Posts
    2
    Rep Power
    0

    Default

    Sorry, I figured it out. post can be deleted.
    GRect paddle = new GRect((WIDTH / 2) - (PADDLE_WIDTH / 2), (HEIGHT - (PADDLE_HEIGHT / 2)) - PADDLE_Y_OFFSET, PADDLE_WIDTH, PADDLE_HEIGHT);
    needed to be changed to...
    paddle = new GRect((WIDTH / 2) - (PADDLE_WIDTH / 2), (HEIGHT - (PADDLE_HEIGHT / 2)) - PADDLE_Y_OFFSET, PADDLE_WIDTH, PADDLE_HEIGHT);
    sadly, that took 4+ hours to debug =(((

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Actually no need to delete the post. Please ask your question next time, and even you find the solution your self no need to delete the thread. Post it here as well, someone else may use that.

Similar Threads

  1. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 09:49 AM
  2. Need help with Breakout game
    By tfitz666 in forum New To Java
    Replies: 9
    Last Post: 03-22-2010, 06:26 AM
  3. Question!
    By anjogomez in forum Java Applets
    Replies: 2
    Last Post: 02-21-2009, 04:24 AM
  4. question
    By zizou147 in forum New To Java
    Replies: 13
    Last Post: 07-04-2008, 08:05 PM
  5. Need help on this question
    By Deon in forum New To Java
    Replies: 3
    Last Post: 01-27-2008, 04:58 PM

Posting Permissions

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