Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Add these functions into your run function
- // addMouseListeners();
- // addPaddle();
- //Major method which moves the ball, causes constraints on the ball's movements(within the screen) and bounces the ball
- public void mouseMoved(MouseEvent me) {
- int x = me.getX();
- if(paddle!=null) {
- if(x > PADDLE_WIDTH/2 && x < getWidth()-PADDLE_WIDTH/2) //Keeps paddle on the screen
- paddle.setLocation(x - PADDLE_WIDTH/2,getHeight()-PADDLE_Y_OFFSET) ; //Centers the paddle to the mouse
- }
- }
- private void addPaddle() {
- paddle = new GRect(getWidth()/2-PADDLE_WIDTH/2,getHeight()-PADDLE_Y_OFFSET ,
- PADDLE_WIDTH, PADDLE_HEIGHT) ;
- paddle.setFilled(true) ;
- paddle.setFillColor(Color.BLACK);
- add(paddle) ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement