Advertisement
Guest User

bouncing ball

a guest
Oct 18th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. class Ball {
  2. float x;
  3. float y;
  4. float speedX;
  5. float speedY;
  6. float s;
  7.  
  8. Ball(float _x, float _y) {
  9. x = _x;
  10. y = _y;
  11. speedX = random(-5, 5);
  12. speedY = random(-5, 5);
  13. s = random(5, 200);
  14. }
  15.  
  16. void render() {
  17. circle(x, y, s);
  18. }
  19.  
  20. void update() {
  21. x = x + speedX;
  22. y = y + speedY;
  23. }
  24.  
  25. void bounce() {
  26. if (x>width || x<0) {
  27. speedX = -speedX;
  28. }
  29. if (y>height || y<0) {
  30. speedY = -speedY;
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement