We are about to switch to a new forum software. Until then we have removed the registration on this forum.
right rpad = new right();
ball b = new ball();
int pos;
int ballY,ballX;
void setup() {
size(800,600);
}
void draw() {
background(0,0,0);
rpad.display(pos);
b.move(ballY);
if ((ballY<pos+40) && (ballY>pos-40)) {
b.bounce();
}
class ball {
int x = width/2;
int y = height/2;
int velx = 4;
int vely = 4;
int locy;
void move(int locy) {
locy = y;
x+=velx;
y+=vely;
fill(255);
ellipse(x,y,15,15);
if (y>600 || y<0) {
vely=vely*-1;
}
if (x<10) {
velx*=-1;
}
}
void bounce() {
if (x > 790) {
velx*=-1;
}
}
}
class right {
int x = 790;
int y = 300;
void display(int posY) {
rectMode(mouseY);
rect(x,mouseY+40,x+10,mouseY-40);
posY = mouseY;
}
}
}
Answers
no clear understanding of classes and objects here
do the tutorial on objects please
Best, Chrisir ;-)
Basically, you need an if statement saying that if the ball touches the wall, it stops. I'm not sure on the code for this, but here's basically what you need:
That code WILL NOT COMPILE. I feel, however, that it will give you a good representation of what you need. The first conditional can be created by saing basically if the ball's center x is 15 less than the paddle's center x and the ball's center y is within 40 of the paddle's center y, they are touching. The second one seems self-explanatory. I'm pretty sure it's your int x in your Ball class.