Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. class Ball {
  2.  
  3. float xspeed= 2;
  4. float yspeed= random(-1,1);
  5.  
  6. PVector locationball= new PVector(random(width),random(height));
  7. PVector dir;
  8. //float distance= dist(location.x,location.y,locationball.x,locationball.y);
  9.  
  10.  
  11. void display (){
  12. noStroke();
  13. fill (255);
  14. ellipse(locationball.x,locationball.y,20,20);
  15.  
  16. }
  17.  
  18. void move (){
  19. locationball.x+=xspeed;
  20. locationball.y+=yspeed;
  21. }
  22.  
  23. void bounce (){
  24. if (locationball.x<0 || locationball.x>width){
  25. xspeed=(xspeed)*-1;
  26. } else if (locationball.y<0 || locationball.y>height){
  27. yspeed=(yspeed)*-1;
  28. }
  29.  
  30. }
  31.  
  32. void repel (){
  33. dir= PVector.sub(locationball,mover);
  34. dir.normalize();
  35. dir.mult(-0.5);
  36. dir.add(mover);
  37. mover.limit(3);
  38.  
  39. }
  40.  
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement