We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I would like to ask you for help with bouncing off the wall.I would like that ball bounce exactly off the wall(not bounce off other parts of screen).
PImage wall1;
int wall1X,wall1Y,wall1W,wall1H;
int x;
float y;
boolean collision;
void setup()
{
size(900,300);
frameRate(30);
background(255);
wall1=loadImage("wall.png");
wall1X=90;
wall1Y=10;
wall1W=10;
wall1H=100;
x=width/2+200;
y=random(100,200);
}
void draw() { background(255); fill(0); ellipse(x,y,25,25); image(wall1,wall1X,wall1Y,wall1W,wall1H); x-=5;
if(wall1Y<11)
{
collision=true;
}
if(collision)
{ wall1Y+=5; }
if(wall1Y>200) {
collision=false;
} if(collision==false) { wall1Y-=5; } }
Answers
Please edit your post, select your code and hit ctrl+o to format your code. Make sure there is an empty line above and below your code
Kf
ok, main idea here is to have a variable that you add to the position of wall (and another for ball); now on reflection you change that directional var.