class Bouncer{ float xpos; float ypos; float xvel; float yvel; int r=30;//radius //keeps track of which direction the Bouncer is moving boolean negXVelocity = false; boolean negYVelocity = false; //****CONSTRUCTOR*****// Bouncer(float xp, float yp, float xv, float yv) { xpos=xp; ypos=yp; xvel=xv; yvel=yv; } void draw() { ellipseMode(CENTER); noStroke(); ellipse(xpos,ypos,r,r); } int getXPos(){ return int(xpos); } int getYPos(){ return int(ypos); } boolean testVel(boolean v){ if(v==true){ v=false; }else{ v=true; } return v; } void move() { if(keyPressed){ switch(key){ case '2': xvel = yvel = 2; break; case '3': xvel = yvel = 3; break; case '4': xvel = yvel = 4; break; case '5': xvel = yvel = 5; break; case '6': xvel = yvel = 6; break; case '7': xvel = yvel = 7; break; case '8': xvel = yvel = 8; break; case '9': xvel = yvel = 9; break; default: xvel = yvel = 1; } if (negXVelocity==true){ xvel*=-1; }; if (negYVelocity==true){ yvel*=-1; }; } //create movement xpos+=xvel; ypos+=yvel; int radius = r/2; //create vars for placement detection int left=radius; int right=width-radius; int top=radius; int bottom=height-radius-2; //if too far left or right, send opposite direction if(xpos > right){ xpos = right-10; xvel=xvel*-1; negXVelocity=testVel(negXVelocity); } else if(xpos bottom){ ypos = bottom-10; yvel=yvel*-1; negYVelocity=testVel(negYVelocity); } } }