/** * Course Number: 22491 * Assignment Number: Final Project * Game "Cross The Street" * Ignas Jauneika G00247692 * 30/04/2009 */ PFont font; PFont font1; PImage StopSign; Car car1; Car car2; Car car3; Car car4; Player player; boolean button = false; boolean button1 = false; int start = 0; // for button 1 int i = 80; int p = 60; int c = 90; int t = 25; // for button 2 int w = 95 ; int q = 95; int o = 60; int l = 25; // for buuton 3 int m = 80; int m1 = 60; int m2 = 90; int m3 = 25; // button color float c1=147; float c2=16; float c3=1; float r1 =147; float r2 =16; float r3 =1; void setup() { size (250,200); smooth(); car1 = new Car(10,70,0.5); car2 = new Car(20,130,0.7); car3 = new Car(150,70, 0.5); car4 = new Car(150,130, 0.7); player = new Player(); font = loadFont ("Monospaced.bolditalic-48.vlw"); font1 = loadFont ("ArialNarrow-Bold-48.vlw"); StopSign = loadImage ("stopsign4c.gif"); } void draw() { switch (start) { case 0: if ( button ) { start = 1; } if ( button1 ){ exit(); } image(StopSign,0,0,250,200); //Button 1 if (mouseX > i && mouseX < i+c && mouseY > p && mouseY < p +t){ c1 = 247; c2 =45 ; c3 =45 ; }else{c1=147;c2=16;c3=1; } fill(c1,c2,c3,200); rect (i,p,c,t); //Button 2 if (mouseX > w && mouseX < w+o && mouseY > q && mouseY < q +l){ r1=247;r2=45;c3=45;} else{r1 =147; r2 =16;r3 =1;} fill(r1,r2,r3,200); rect(w,q,o,l); //Words fill (76,216,7); textFont (font1,19); text ("New Game",86,80); text ("Exit",110,115); break; case 1: if(player.hit(car1) || player.hit(car2) || player.hit(car3)||player.hit(car4)) { println("hit"); start = 4; } darwbackground(); car1.display(); car1.move(); car2.display(); car2.move(); car3.display(); car3.move(); car4.move(); car4.display(); player.display(); player.keyPressed(); break; case 3: background(0); rectMode(CORNER); fill(255); textFont(font,30); text("You Win!!!",40,60); if (mouseX > m && mouseX < m2+m && mouseY > m1+30 && mouseY < m1+30 +m3){ c1 = 247; c2 =45 ; c3 =45 ; }else{c1=147;c2=16;c3=1; } if (mouseX > m && mouseX < m2+m && mouseY > m1+30 && mouseY < m1+30 +m3 && mousePressed){ player.reset(); start = 1; } fill(c1,c2,c3); rect (m,m1+30,m2,m3); fill(255); textFont (font1,19); text ("Play Again",86,109); break; case 4: background (255,3,3); fill(0); textFont (font1,30); text ("GAME OVER",50,80); if (mouseX > m && mouseX < m2+m && mouseY > m1+30 && mouseY < m1+30 +m3){ c1 = 247; c2 =45 ; c3 =45 ; }else{c1=147;c2=16;c3=1; } if (mouseX > m && mouseX < m2+m && mouseY > m1+30 && mouseY < m1+30 +m3 && mousePressed){ player.reset(); start = 1; } fill(c1,c2,c3); rectMode(CORNER); rect (m,m1+30,m2,m3); fill(255); textFont (font1,19); text ("Play Again",86,109); textFont (font1,14); text ("LOOSER =D",60,30); break; } } void darwbackground() { background (203,203,203); //Road rectMode(CORNER); fill(255); noStroke(); rect (0,45,250,110); //Kerbs fill(0); stroke(0); strokeWeight(2); line (0,45,250,45); line (0,155,250,155); //Road signs for (int i = 5; i < width; i += 30) { rectMode(CENTER); stroke(0); rect(i, height/2, 10 , 3); } //Pavement for (int i = 5; i < width;i += 15) { strokeWeight(1); fill (255); rect (i,193,15,15); rect (i,178,15,15); rect (i,164,15,15); } //Grass noStroke(); fill(103,240,46); rect( 0 , 0 , 500, 88); //Bush 1 fill(47,152,3); ellipse ( 20 ,16 , 15,15); ellipse ( 28, 23, 15,15); ellipse ( 18, 25, 15,15); //Bush 2 ellipse ( 110,21,15,15); ellipse ( 118,28,15,15); ellipse ( 108,30,15,15); //Bush 3 ellipse ( 220,16,15,15); ellipse ( 228,23,15,15); ellipse ( 218,25,15,15); } void mousePressed() { if (mouseX > i && mouseX < i+c && mouseY > p && mouseY < p +t){ button = !button; } if (mouseX > w && mouseX < w+o && mouseY > q && mouseY < q +l){ button1 = !button; } }