I can't get the object to bounce of the sides.
in
Programming Questions
•
6 months ago
Without sounding cliche, Hi I'm new and I need help :)
I'm trying to make the object (in this case a silly alien thingy) bounce of the bounds of the screen. I've followed the tutorial and example and yet I can't seem to get it to work. Its supposed to bounce on the position of the hat and the shoes.
void drawhat(){
rectMode(CENTER);
fill(random(255), random(255), random(255));
hatbrimxloc = facexloc;
hatbrimwidth = facewidth + facewidth/2;
hatbrimheight = faceheight / 10;
hatbrimyloc = faceyloc - (faceheight / 2) - (hatbrimheight - faceheight/5);
//hat
hatbodyxloc = facexloc;
hatbodywidth = hatbrimwidth - 200;
hatbodyheight = faceheight/2;
hatbodyyloc = hatbrimyloc - (hatbrimheight / 2)- (hatbodyheight / 2);
} //end hat
void drawleftshoe(){
//left
leftshoecorner1xloc = facexloc - 30;
leftshoecorner1yloc = faceyloc + (faceheight / 2) - (faceheight / 40);
leftshoecorner2xloc = leftshoecorner1xloc - facewidth/2;
leftshoecorner2yloc = leftshoecorner1yloc + (faceheight /6) ;
fill(random(255), random(255), random(255));;
rectMode (CORNERS);
rect (leftshoecorner1xloc, leftshoecorner1yloc, leftshoecorner2xloc, leftshoecorner2yloc);
}//end left shoe
void drawrightshoe(){
rightshoecorner1xloc = facexloc + 30;
rightshoecorner1yloc = faceyloc + (faceheight / 2) - (faceheight / 40);
rightshoecorner2xloc = rightshoecorner1xloc + facewidth/2;
rightshoecorner2yloc = rightshoecorner1yloc + (faceheight /6) ;
fill(random(255), random(255), random(255));
rectMode (CORNERS);
rect (rightshoecorner1xloc, rightshoecorner1yloc, rightshoecorner2xloc, rightshoecorner2yloc);
} //end right shoe
// end shoes
void move (){
int upperboundry = hatbodyyloc + hatbodyheight/2;
xdirection = random (1,5);
ydirection = random (1,5);
xspeed = random (1,5);
yspeed = random (1,5);
facexloc = facexloc + ((int)xspeed * (int)xdirection );
faceyloc = faceyloc + ( (int)yspeed * (int)ydirection );
//end moveybit
//left + right
if (LeftX2 <=0 || RightX3 >= width){
xdirection *=-1;
}//end if l+r
//up+down
if (upperboundry <=0 || rightshoecorner2yloc >= height){
ydirection*=-1;
}
if (RightX3 >= width || LeftX2 <=0) {
xdirection*=-1;
}
}//end move
1