@irukandjijelly I tried something and it seems to work:
float y=770;
int back=20;
int dir=20;
float ySpeed = 5;
float yAcc = 9.81;
int level=3;
int[][] platforms = {
{60, 740},
{180, 680},
{350, 600},
{510, 545},
{330, 460},
{200, 400},
{0, 340},
{160, 280},
{320, 220},
{470, 160},
{620, 100} };
int pHeight = 20;
int pWidth = 100;
boolean died = false;
void setup() {
size(700, 800);
}
void draw() {
if (!died && level == 3) {
background(#02C2F0);
//if (level==0) {
// textSize(40);
// fill(0);
// text("Level 1", 100, 100);
//}
for (int frame = 0; frame < 20; frame++) {
ySpeed -= yAcc * 0.01;
y -= ySpeed * 0.01;
if (y+30 >= height && back < 60) {
ySpeed = 50;
} else if (y+30 > height && back > 60) {
text("you died!", width/2, height/2);
died = true;
} else if (back+30 > width && y+30 < 100) {
text("finished this level!", width/2, height/2);
level++;
}
for (int i = 0; i < platforms.length; i++) {
if ((back > platforms[i][0]) && (back < platforms[i][0]+pWidth) && (y+30 >= platforms[i][1]) && (y+30 <= platforms[i][1]+(pHeight/2))) {
ySpeed = 50;
if (i == 5) ySpeed = 45;
}
}
}
ellipse(back, y, 60, 60);
fill(#FFFFFF);
for (int i = 0; i < platforms.length; i++) {
rect(platforms[i][0], platforms[i][1], pWidth, pHeight);
}
fill(#FF0808);
rect(60, 780, 700, 20);
textSize(30);
fill(255, 45, 100);
text ("finish", 570, 50);
stroke(#0D0C0C);
textSize(20);
text ("Instructions: Use arrow keys to reach the finish. If you fall off, you DIE", 0, 780);
fill(#FF0808);
}
}
void keyPressed() {
if (key == ' ') {
died = false;
back = 20;
}
if (keyCode==RIGHT) {
back=back+40;
} //controll for circle
if (keyCode==LEFT) {
back=back-40;
} //controll for circle
}
as you can see i stored all x and y values of the platforms in an array to draw them all in a for-loop instead of seperate lines.
i also use a more physics based bounce, with actual acceleration downwards and only if it hits a platform will it gain speed upwards again.
If you land inside the red area on the bottom you die, which it will say and you can start again by pressing spacebar.
if you reach the end and jump out of the screen you have finished this level and it will count to the next one.
be sure to read all the code and fully understand it, if you have any questions, please ask, or try it out yourself 