This is my code. What can I do to make the ball up and down on one platform. Right now when the right key is pressed, it goes straight up.
int y=770;
int back=20;
int dir=20;
int level=3;
void setup(){
size(700,800);
}
void draw(){
if(level==0){
textSize(40);
fill(0);
text("Level 1",100,100);}
delay(30);
background(#02C2F0);
fill(#FF0808);
ellipse(back,y,60,60);
y=y-dir;
{if(y<600||y>770){
dir=-dir;}} //makes the circle bounce before it hits first rectangle
{if(back>55) //makes circle go up on first rectangle
y=y-30;}
{if(back>180)
y=y-90;}
rect(0,780,700,20);
fill(#FFFFFF);
rect(60,740,100,20);
rect(180,680,100,20);
rect(350,600,100,20);
rect(510,545,100,20);
rect(330,460,100,20);
rect(200,400,100,20);
rect(0,340,100,20);
rect(160,280,100,20);
rect(320,220,100,20);
rect(470,160,100,20);
rect(620,100,100,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);
}
void keyPressed(){
if(keyCode==RIGHT) {back=back+40;} //controll for circle
if(keyCode==LEFT) {back=back-40;} //controll for circle
}