Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Ball {
- float xspeed= 2;
- float yspeed= random(-1,1);
- PVector locationball= new PVector(random(width),random(height));
- PVector dir;
- //float distance= dist(location.x,location.y,locationball.x,locationball.y);
- void display (){
- noStroke();
- fill (255);
- ellipse(locationball.x,locationball.y,20,20);
- }
- void move (){
- locationball.x+=xspeed;
- locationball.y+=yspeed;
- }
- void bounce (){
- if (locationball.x<0 || locationball.x>width){
- xspeed=(xspeed)*-1;
- } else if (locationball.y<0 || locationball.y>height){
- yspeed=(yspeed)*-1;
- }
- }
- void repel (){
- dir= PVector.sub(locationball,mover);
- dir.normalize();
- dir.mult(-0.5);
- dir.add(mover);
- mover.limit(3);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement