Charlene - Project 2

By Charlene
float x; float y; float speed; int direction; int page = 1; //int lives; PImage a; PImage b; PImage d; PImage e; PImage f; PImage h; PImage i; PImage j; PImage k; Guy g; //Declare the object Catcher c; void setup() { size(600, 400); smooth(); noStroke(); x = -10.0; y = -15.0; speed = 0.5; direction = 1; // lives = 5; a = loadImage("cliff.png"); b = loadImage("cloud.png"); d = loadImage("cloud2.png"); e = loadImage("cloud3.png"); f = loadImage("cloud4.png"); h = loadImage("sky.png"); i = loadImage("guy.png"); j = loadImage("page1.png"); k = loadImage("page3.png"); g = new Guy(-40, 150, 1.5); // Construct the object c = new Catcher(275, 350); } void draw() { if (page == 1) { background(j); if ((keyPressed == true) && (key == ' ')) { page = 2; } } else if (page == 2) { background(h); image(a, 0, 220); x = x + (speed * direction); if(x > 650) { direction *= -1; } else if (x < -50) { direction *= -1; } image(b, x, y); image(d, x + 160, y - 15); image(e, x - 250, y + 20); image(f, x - 450, y); image(f, x + 450, y - 40); fill(102); c.display(); c.move(); c.drawTimeBar(); fill(255); g.display(); g.move(); // for(int i = lives; i > 0; i--) { // ellipse(465 + i *20, 370, 15, 15); // } } else if (page == 3) { background(k); } } class Guy { float gx, gy; float gspeed; int power; int lives; Guy(float gxpos, float gypos, float gsp) { gx = gxpos; gy = gypos; gspeed = gsp; power = 200; lives = 5; } void move() { if((keyPressed == true) && (key == ' ')) { power = 55; } else { power = 200; } gx = gx + gspeed; if(gx < 210) { gy = 196; } else if (gx < 300) { float n = norm(gx, 210.0, 300.0); gy = pow(n, 2); gy *= power; gy += 196; } else if(gx < 390) { if((keyPressed == true) && (key == ' ')) { float n = norm(gx, 300.0, 390.0); gy = pow((1-n),2); gy *= power; gy += 199; } else { gx = 0; lives = lives - 1; println("lost one"); } if (lives == 0) { page = 3; } } else if (gx < 600) { if((keyPressed == true) && (key == ' ')) { float n = norm(gx, 390.0, 600.0); gy = 199; } } else { gx = 0; } gspeed = gspeed + 0.002; } void display() { image(i, gx, gy); for(int i = lives; i > 0; i--) { ellipse(465 + i *20, 370, 15, 15); } } } class Catcher { float timeUp; float cx, cy; Catcher(float cx, float cypos) { cx = 260.0; cy = cypos; timeUp = 100; } void move() { if ((timeUp > 0) && (keyPressed == true)&& (key == ' ')){ cy = 280; timeUp = timeUp - 0.2; }else { cy = 350; timeUp = timeUp + 0.05; timeUp = constrain(timeUp, 0, 100); } if (timeUp < 0) { page = 3; } } void display() { rect(290, cy, 50, 200); fill(0); rect(30, 370, 100, 15); fill(242, 0, 69); rect(30, 370, timeUp, 15); } void drawTimeBar() { println(timeUp); } }

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*