Tuesday, June 28, 2011

paddle

class Paddle I
public int x, y, width, height;
private Color color;
Paddle (int x, int y, int width, int height,
Color color) I
th'is.x = x:
this.y = y;
this.width = width;
this.height = height;
this.color = color;
public void move (int x, Rectangle bd) I
i f ( x > (width >> 1) && x < (bd.width - (width )> l)))
this.x = x;
public int checkReturn (Ball ball, boolean plyr,
i nt rl, int r2, int r3) I
if (plyr && ball.y > (y - ball.radius)
! plyr && ball.y < (y + ball.radius))
if ((int) Math.abs(ball.x - x) < (width 1 2 +
ball.radius)) I
ball.dy = -ball.dy;
1! Put a little english on the ball
ball.dx += (int) (ball.dx * Math.abs(ball.x - x) /
(width / 2));
return r2;
else
return r3;
return rl;
public void draw (Graphics g) f
g.setColor(color);
g.fillRect(x - (width >> 1), y, width, height);

No comments:

Post a Comment