StarStar Phone Home!

By eloral

/* StarStar is lost! Press spacebar to make him jump from cloud to cloud and find his way home! */ int page = 1; Star myStar; float blX = 600; float blY = 600; int bldirection = -1; float cometX; float cometY; int cometdirection = 1; float satelliteX; float satelliteY; int satellitedirection = 1; float rocketX; float rocketY; int rocketdirection = -1; float planeX; float planeY; int planedirection = 1; float ufoX; float ufoY; int ufodirection = 1; float momsadX; float momsadY; float momhappyX; float momhappyY; PImage title; PImage bg; PImage lose; PImage sad; PImage surprised; PImage happy; PImage momsad; PImage momhappy; PShape cl00; PShape cl01; PShape cl02; PShape cl03; PShape cl04; PShape cl05; PShape cl06; PShape cl07; PShape cl08; PShape cl09; PShape cl010; PShape r00; PShape r01; PShape r02; PShape r03; PShape r04; PShape r05; PShape r06; PShape r07; PShape r08; PImage life; PImage bl; PImage comet; PImage satellite; PImage ufo; PShape rocket; PShape tramp; PShape plane; PShape atmosphere; PShape[] cloud = new PShape[11];//cloud array PShape[] rock = new PShape[9];//rock array int backgroundY = 0; int backgroundX = 0; int jumpTimer = 0; float jumpTimerMax = 50; boolean jumping = false; boolean scrolling = false; int cloudNum = 0;//for bezierPoint jump function //int charge;//for charge bar //float starSpeed = 0; ////////////SETUP///////////////// void setup(){ size(600,400); smooth(); noStroke(); title = loadImage("titleneww.png"); bg = loadImage("back2.png"); lose = loadImage("loser.png"); //cloud array for(int i = 0; i < 11; i++) { String cloudNum = "cloud0" + i + ".svg"; cloud[i] = loadShape(cloudNum); } //rock array for(int i = 0; i < 9; i++){ String rockNum = "rock0" + i + ".svg"; rock[i] = loadShape(rockNum); } //LOAD IMAGES// sad = loadImage("star_sad.png"); surprised = loadImage("star_surprised.png"); happy = loadImage("star_happy.png"); momsad = loadImage("momsad.png"); momhappy = loadImage("momhappy.png"); life = loadImage("lifestar.png"); bl = loadImage("blimp.png"); comet = loadImage("comet.png"); ufo = loadImage("ufo.png"); satellite = loadImage("satellite.png"); rocket = loadShape("rocket.svg"); tramp = loadShape("trampoline.svg"); plane = loadShape("plane.svg"); atmosphere = loadShape("atmosphere.svg"); //star class myStar = new Star(258, 215); } //turning pages void keyPressed() { if (key == ' '){ if (page == 1) { page = 2; } else if (page == 3){ if (key == ' '){ page = 2; } } else if (page == 2) { //star's face changes from sad to surprised when jumping if (!jumping && !scrolling) { jumpTimer = 0; jumping = true; //cloudNum++; myStar.state = "surprised"; } } } } void draw(){ if (page == 1){ background(title); } else if (page == 3){ background(lose); } else if (page == 2){ if (myStar.y < 250) { backgroundY+=5; myStar.y += 5; scrolling = true; } else { scrolling = false; } //moves background down when star jumps up pushMatrix(); translate(0, backgroundY); image(bg,0,-bg.height+height); //trampoline shape(tramp, 167,280); //clouds shape(cloud[01], 10, 93, 306, 91);//1 shape(cloud[02], 394, 47, 147, 51);//2 shape(cloud[02], 32, 10, 100, 60);//3 shape(cloud[02], 40, -140, 280, 75);//4 shape(cloud[02], 300, -255, 300, 90);// shape(cloud[01], 48, -300, 200, 70);//6 //shape(cloud[03], 286, -430, 105, 60);//7 shape(cloud[01], 475, -450, 107, 80);//7 shape(cloud[02], 34, -500, 245, 80);//9 //green middle cloud shape(atmosphere, 8, -615, 604, 75); //rocks shape(rock[00], 74, -800, 167, 90);//1 shape(rock[01], 384, -900, 166, 90);//2 shape(rock[02], 150, -1115, 260, 125);//3 shape(rock[03], 28, -980, 122, 66);//4 //shape(rock[06], 320, -1100, 167, 90);//7 shape(rock[04], 400, -1605, 200, 85);//5 shape(rock[05], 350, -1330, 205, 95);//6 shape(rock[07], 130, -1500, 150, 80);//8 //BLIMP if(blX-bl.width/2 > 600 || blX+bl.width/2 < 0){ bldirection = bldirection*-1; blX += 4*bldirection; } blX += 4*bldirection; image(bl, blX-0.4*bl.width, -71); if(backgroundY > 216 && backgroundY < 316 && myStar.x > blX-0.5*bl.width && myStar.x < blX-0.5*bl.width + bl.width) { //can't really do distance...have to do this instead because the background is moving! page = 3; } //PLANE if(planeX-plane.width/2 > 600 || planeX+plane.width/2 < 0){ planedirection = planedirection*-1; planeX += 4*planedirection; } planeX += 4*planedirection; shape(plane, planeX-0.5*plane.width, -415); if(backgroundY > 535 && backgroundY < 600 && myStar.x > planeX-0.5*plane.width && myStar.x < planeX-0.5*plane.width + plane.width){ page = 3; } //COMET cometX += random(-4,4); cometY += random(-4,4); image(comet, 39, -1830, 220, 40 ); //UFO if(ufoX-ufo.width/2 > 600 || ufoX+ufo.width/2 < 0){ ufodirection = ufodirection*-1; ufoX += 6*ufodirection; } ufoX += 6*ufodirection; image(ufo, ufoX-0.5*ufo.width, -1300); if(backgroundY > 1415 && backgroundY < 1500 && myStar.x > ufoX-0.5*ufo.width && myStar.x < ufoX-0.5*ufo.width + ufo.width){ page = 3; } //ROCKET //700 to 920 /* if(rocketX-rocket.width/2 > 600 || rocketX+rocket.width/2 < 0){ rocketdirection = rocketdirection*-1; rocketX += 3*rocketdirection; } rocketX += 2*rocketdirection; shape(rocket, rocketX-0.5*rocket.width+357, -800);*/ //SATELLITE if(satelliteX-satellite.width/2 > 600 || satelliteX+satellite.width/2 < 0){ satellitedirection = satellitedirection*-1; satelliteX += 4*satellitedirection; } satelliteX += 4*satellitedirection; image(satellite, satelliteX-0.5*satellite.width, -1775); if(backgroundY > 1880 && backgroundY < 1990 && myStar.x > satelliteX-0.5*satellite.width && myStar.x < satelliteX-0.5*satellite.width + satellite.width){ page = 3; } //MOM image(momsad, 320, -2050); if (backgroundY > 2000) { myStar.state = "happy"; image(momhappy, 320, -2050); } popMatrix(); myStar.display(); //JUMP TIMER so star jumps up then comes back down after a certain amount of time if (jumping) { jumpTimer++; //cloud jump animations float bezierPosition = jumpTimer / jumpTimerMax; //variables of bezier function float cp1x = 0; float cp2x = 0; float cp1y = 0; float cp2y = 0; float endx = 0; float endy = 0; if(cloudNum == 0){ cp1x = 5; cp2x = 5; endx = 189; cp1y = 5; cp2y = 5; endy = 99; } else if(cloudNum == 1){ cp1x = 5; cp2x = 5; endx = 450; cp1y = 5; cp2y = 5; endy = 10; } else if(cloudNum == 2){ cp1x = 5; cp2x = 5; endx = 200; cp1y = 25; cp2y = 25; endy = 10; } else if(cloudNum == 3){ cp1x = 150; cp2x = 80; endx = 450; cp1y = 25; cp2y = 25; endy = 20; } else if(cloudNum == 4){ cp1x = 150; cp2x = 80; endx = 156; cp1y = 25; cp2y = 25; endy = 10; } myStar.x = bezierPoint(myStar.x, cp1x, cp2x, endx, bezierPosition); myStar.y = bezierPoint(myStar.y, cp1y, cp2y, endy, bezierPosition); //star returns to sad face when not jumping if (jumpTimer == jumpTimerMax){ jumping = false; myStar.state = "sad"; cloudNum++; } if(backgroundY > 1900) { backgroundY = 1900; } } // end if jumping } //else if(page == 3){ //image(lose, 0, 0); // } if (key == ' '){ // page = 2; //} } //CREATE STAR CLASS class Star{ float x, y; String state = "sad"; Star(float newX, float newY) { x = newX; y = newY; } //star display makes it possible to change image when jumping void display() { if (state.equals("sad")) { image(sad, x, y); } else if (state.equals("surprised")) { image(surprised, x, y); } else if (state.equals("happy")) { image(happy, x, y); } } } void mousePressed() { println(backgroundY); println(backgroundX); }