Lena - Project 2

By wangl
PImage img1, img2, img3, img4, img5, img6; //load images int page = 1; float speed = 1; //the speed at which the background is moving at float Rockx = 150; float Beesx = 0; float Objy = 0; float Objspeedy = 0; float Objx = 0; void setup () { //loading images size (600, 400); img1 = loadImage ("BG01.jpg"); img2 = loadImage ("Rockss.png"); img3 = loadImage ("Object01.png"); img4 = loadImage ("Bees01.png"); img5 = loadImage ("GameOver.png"); } void draw () { if (page == 1) { //setting up the images image (img1, 0, 0); image (img2, Rockx, 0); image (img3, 0, Objy); image (img4, Beesx, 0); } Rockx = Rockx + -speed; //background rocks if (Rockx == -1700) { Rockx = 600; } Beesx = Beesx + -speed; //background bees if (Beesx == -2380) { Beesx = 0; } Objy = Objy + Objspeedy; //object (hero) jumping Objspeedy += 0.3; Objy = constrain (Objy, -height, 0); color c = get (int(Objx+52), int(Objy+385)); //pixel determination float r = red (c); float g = green (c); float b = blue (c); if (((r == 102 && g == 51 && b == 0) || (r == 153 && g == 153 && b == 153) || (r == 255 && g == 255 && b == 204))) { image (img5, 0, 0); //if the tip of the mushroom detects these color pixels, then the image GAME OVER appears page = 0; } PFont font; //instructioons. font = loadFont ("ComicSansMS-10.vlw"); textFont (font, 12); text ("Press spacebar to jump. Hint: you can press and repress spacebar to do different jumps.", 20, 20); fill (0); } void keyPressed () { //spacebar == jump if (key == ' ') { Objspeedy = -4.5; } }

Post a Comment

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

*
*