fPaste.me

A free, anonymous, minimalist and open source paste tool.


Untitled
16-06-2020 11:15:12
Anonymous
float x = width/2;
float y = height/10;
float numberX = width/2 - 10;
int numberY = (height -10);
float ballMoveHor = 0;
float ballMoveVer = 0;
int afstand = 15;
int levens = 3;
int points = 0;
int highscore = 0;
int ellipseH = height/10;
int ellipseB = width/10;
int rectB = width/5;
int rectH = height/12;

void setup() {
fullScreen();
}

void draw() {
background(55, 155, 5);

//After 3 errors, 'levens' = 0 -> Game Over!

if (levens == 0) {
println("GAME OVER!");
println("Your score: ");
println(points);
if (points > highscore) { //Highscore?
highscore = points;
println("New Highscore!");
} else {
delay(2000);
println("You failed!!!");
delay(3000);
println("But wait...");
delay(2000);
}
println("The processing Lord gives you 3 new levens for free"); //three more lives!
//println(levens);
delay(2000);
println("Press SPACE to continue.");
levens = 3;
points = 0;
}


if (keyPressed == true) { //press space to (re)start the game
if (key == ' ') {
ballMoveVer = random(1, 2);
ballMoveHor = random(1, 2);
} else if (keyCode == RIGHT) { //move right
numberX++;
} else if (keyCode == LEFT) { //move left
numberX--;
}
}

fill(10, 100, 10);
ellipse(x, y, ellipseH, ellipseB); //draw the ball

//bal moves horizontal

if (x > width) { //make ball bounce from sidewalls
ballMoveHor = random(-1, -2);
} else if (x < 0) {
ballMoveHor = random(1, 2);
}
x += ballMoveHor;

//ball moves vertical

if (y+5 > height) { //ball touches ground!
y = 10;
x = width/2;
ballMoveVer = 0;
ballMoveHor = 0;
levens--;
println("levens: ");
println(levens);
} else if (y < 0) {
ballMoveVer = random(1, 2);
}
y += ballMoveVer;

fill(100, 10, 100);
rect(numberX, numberY, rectB, rectH); //draw rectangle to catch ball


if (numberX >= (width-20)) { //add boundaries for rectangle
numberX = (width-20);
} else if (numberX <= -10) {
numberX = -10;
}

//distance check

float dist2 = dist(numberX+15, height+5, x, y+5);
//float dist3 = dist(numberX, numberY, x, y);

if (dist2 < afstand) {

y-=4;
ballMoveHor = random(1, 2);
ballMoveVer = random(-1, -2);
points++;
println("punten: ");
println(points);
}
}