function draw() { drawSprites(); //transfer between modes if (mode=="1 - opening") { opening(); } else if (mode=="2 - start lvl 1") { startlvl1(); } else if (mode=="3 - play lvl 1") { play(); } else if (mode=="4 - win lvl 1") { winLvl1(); } else if (mode=="5 - start lvl 2") { startlvl2(); } else if (mode=="6 - play lvl 2") { play(); } else if (mode=="7 - win lvl 2") { winLvl2(); } else if (mode=="8 - start lvl 3") { startlvl3(); } else if (mode=="9 - play lvl 3") { play(); } else if (mode=="10 - win game") { winLvl3(); } else if (mode=="11 - lose") { lose(); } //handle the continue between modes if (keyWentDown("space")) { if (mode=="1 - opening") { mode = "2 - start lvl 1"; } else if (mode=="4 - win lvl 1") { mode="5 - start lvl 2"; } else if (mode=="7 - win lvl 2") { mode="8 - start lvl 3"; } else if (mode=="10 - win game") { mode = "2 - start lvl 1"; } else if (mode=="11 - lose") { mode = "2 - start lvl 1"; } } } function play(){ ball.bounceOff(edges); ball2.bounceOff(edges); if(keyDown("right")&&you.x<380){ you.x+=speed+2; }else if(keyDown("left")&&you.x>20){ you.x-=speed+2; }else if(keyDown("up")&&you.y>20){ you.y-=speed+2; }else if(keyDown("down")&&you.y<380){ you.y+=speed+2; } timer--; fill("black"); textSize(20); text("Level "+level+" time left: "+timer, 10, 20); if(you.collide(ball)){ mode="11 - lose"; } else if(you.collide(ball2)){ mode="11 - lose"; } else if(timer<=0 && mode=="3 - play lvl 1") { mode="4 - win lvl 1"; } else if(timer<=0 && mode=="6 - play lvl 2") { mode="7 - win lvl 2"; } else if(timer<=0 && mode=="9 - play lvl 3") { mode="10 - win game"; } } function winLvl1(){ //Display win screen bg.setAnimation("court"); freeze(); you.x=200; you.y=250; textSize(50); fill("black"); text("Level 1", 130, 100); text("Complete!", 90, 150); textSize(30); text("Press space to continue", 40, 350); } function winLvl2(){ //Display win screen bg.setAnimation("court"); freeze(); you.x=200; you.y=250; mode="7 - win lvl 2"; textSize(50); fill("black"); text("Level 2", 130, 100); text("Complete!", 90, 150); textSize(30); text("Press space to continue", 40, 350); } function winLvl3(){ //Display win screen bg.setAnimation("court"); freeze(); you.x=200; you.y=250; textSize(50); fill("black"); text("You Win!", 90, 100); textSize(30); text("Press space to play again", 30, 350); text("All Levels Complete!", 50, 150); } function lose(){ //Display lose screen bg.setAnimation("court"); freeze(); ball.x=200; ball.y=250; textSize(50); fill("black"); text("You lose", 100, 150); textSize(30); text("Press space to play again", 30, 350); } function freeze(){ //freeze the pieces //move them all off screen ball.x=-200; ball.y=-200; ball.velocityX = 0; ball.velocityY = 0; ball2.x=-200; ball2.y=-200; ball2.velocityX = 0; ball2.velocityY = 0; you.x=-300; you.y=-300; you.velocityX = 0; you.velocityY = 0; }