Advertisement
ffpaladin

Breakout01 Paddle

Jul 10th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. // Add these functions into your run function
  2.  
  3. // addMouseListeners();
  4. // addPaddle();
  5.        
  6.        
  7.     //Major method which moves the ball, causes constraints on the ball's movements(within the screen) and bounces the ball
  8.  
  9.     public void mouseMoved(MouseEvent me) {
  10.         int x = me.getX();
  11.         if(paddle!=null) {
  12.             if(x > PADDLE_WIDTH/2 && x < getWidth()-PADDLE_WIDTH/2) //Keeps paddle on the screen
  13.                 paddle.setLocation(x - PADDLE_WIDTH/2,getHeight()-PADDLE_Y_OFFSET) ; //Centers the paddle to the mouse
  14.         }
  15.     }
  16.    
  17.     private void addPaddle() {
  18.         paddle = new GRect(getWidth()/2-PADDLE_WIDTH/2,getHeight()-PADDLE_Y_OFFSET ,
  19.                 PADDLE_WIDTH, PADDLE_HEIGHT) ;
  20.         paddle.setFilled(true) ;
  21.         paddle.setFillColor(Color.BLACK);
  22.         add(paddle) ;
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement