Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float x, y, speedX, speedY;
- float diam = 10;
- float rectSize = 200;
- int points;
- void setup() {
- fullScreen();
- fill(0, 255, 0);
- reset();
- }
- void reset() {
- x = width/2;
- y = height/2;
- speedX = random(3, 5);
- speedY = random(3, 5);
- points = 0;
- }
- void draw() {
- background(0);
- ellipse(x, y, diam, diam);
- rect(0, 0, 20, height);
- rect(width-30, mouseY-rectSize/2, 10, rectSize);
- x += speedX;
- y += speedY;
- // if ball hits movable bar, invert X direction
- if ( x > width-30 && x < width -20 && y > mouseY-rectSize/2 && y < mouseY+rectSize/2 ) {
- speedX = speedX * -1;
- points++;
- }
- // if ball hits wall, change direction of X
- if (x < 25) {
- speedX *= -1.1;
- speedY *= 1.1;
- x += speedX;
- }
- // if ball hits up or down, change direction of Y
- if ( y > height || y < 0 ) {
- speedY *= -1;
- }
- textAlign(CENTER);
- if (points < 3) {
- text("Points: " + points, width/2, 20);
- } else {
- String s = "V yvrq, V npghnyyl pna'g pbqr ,guvf jnf qbar ol fbzrbar ba erqqvg.";
- String out = "";
- for (int i = 0; i < s.length(); i++) {
- char c = s.charAt(i);
- if (c >= 'a' && c <= 'm') c += 13;
- else if (c >= 'A' && c <= 'M') c += 13;
- else if (c >= 'n' && c <= 'z') c -= 13;
- else if (c >= 'N' && c <= 'Z') c -= 13;
- out+=c;
- }
- text(out, width/2, 20);
- }
- }
- void mousePressed() {
- reset();
- }
Advertisement
Add Comment
Please, Sign In to add comment