Guest User

Untitled

a guest
May 30th, 2019
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. float x, y, speedX, speedY;
  2. float diam = 10;
  3. float rectSize = 200;
  4. int points;
  5.  
  6. void setup() {
  7. fullScreen();
  8. fill(0, 255, 0);
  9. reset();
  10. }
  11.  
  12. void reset() {
  13. x = width/2;
  14. y = height/2;
  15. speedX = random(3, 5);
  16. speedY = random(3, 5);
  17. points = 0;
  18. }
  19.  
  20. void draw() {
  21. background(0);
  22.  
  23. ellipse(x, y, diam, diam);
  24.  
  25. rect(0, 0, 20, height);
  26. rect(width-30, mouseY-rectSize/2, 10, rectSize);
  27.  
  28. x += speedX;
  29. y += speedY;
  30.  
  31. // if ball hits movable bar, invert X direction
  32. if ( x > width-30 && x < width -20 && y > mouseY-rectSize/2 && y < mouseY+rectSize/2 ) {
  33. speedX = speedX * -1;
  34. points++;
  35. }
  36.  
  37. // if ball hits wall, change direction of X
  38. if (x < 25) {
  39. speedX *= -1.1;
  40. speedY *= 1.1;
  41. x += speedX;
  42. }
  43.  
  44. // if ball hits up or down, change direction of Y
  45. if ( y > height || y < 0 ) {
  46. speedY *= -1;
  47. }
  48.  
  49. textAlign(CENTER);
  50. if (points < 3) {
  51. text("Points: " + points, width/2, 20);
  52. } else {
  53. String s = "V yvrq, V npghnyyl pna'g pbqr ,guvf jnf qbar ol fbzrbar ba erqqvg.";
  54. String out = "";
  55. for (int i = 0; i < s.length(); i++) {
  56. char c = s.charAt(i);
  57. if (c >= 'a' && c <= 'm') c += 13;
  58. else if (c >= 'A' && c <= 'M') c += 13;
  59. else if (c >= 'n' && c <= 'z') c -= 13;
  60. else if (c >= 'N' && c <= 'Z') c -= 13;
  61. out+=c;
  62. }
  63. text(out, width/2, 20);
  64. }
  65. }
  66.  
  67. void mousePressed() {
  68. reset();
  69. }
Advertisement
Add Comment
Please, Sign In to add comment