//// Project 1, 2, and 3 //// Matt Eannuzzi 11/13/2014 String title= "Snowman vs Cyborg - Plutonium Harvest - project 1,2,3"; int score=0; float sunX=150, sunY=150; float horizon; float plutoniumX, plutoniumY; float cyborgX, cyborgY; float snowmanX, snowmanY; int step; float x, y, w, h; int n; void setup() { //// setup //// size( 700,600 ); horizon= height/4; sunY= horizon/2; cyborgX=width/2; cyborgY= height/2; snowmanX=30; snowmanY= random( horizon,height-60 ); plutoniumX=width-50; plutoniumY= random(horizon+50,height-50); } void draw() { // next frame // scene(); plutonium(); cyborg(); snowman(); grass(); // bird frame // fill(random(250),random(200),random(150)); flock( n, x,y, w,h ); x += random(20); y= y +10 - random(20); } void scene() { // sky, sun, and points for sun movement background( 2,155,255 ); fill(255,255,0); // yellow sun ellipse(sunX,sunY, 50,50); fill( 64,64,64); // planet turf color rectMode( CORNER ); rect(0,horizon, width,height*3/4); // sun moves through the sky (-20 per day.) // if (sunX > width) { sunX=0; sunY= random( 10, horizon-20); score= score-20; } sunX= sunX+2; fill(0); // text( sunX, sunX, sunY+40); // Title, etc. text( title, width/3, 20 ); text( "CYBORG's SCORE= " + score, width-200, 50 ); } void cyborg() { // move & draw cyborg // cyborgX= cyborgX + (mouseX-cyborgX)/8; cyborgY= mouseY + (mouseY-cyborgY)/8; // draw cyborg // // Set ellipses and rects to CENTER ellipseMode(CENTER); rectMode(CENTER); // body stroke(0); fill(2,60,203); rect(cyborgX,cyborgY,20,100); // head stroke(0); fill(25,234,75); ellipse(cyborgX,cyborgY-30,60,60); // helmet stroke(0); fill(25,234,75); rect(cyborgX,cyborgY-40,60,60); // eyes fill(0); ellipse(cyborgX-19,cyborgY-30,16,32); ellipse(cyborgX+19,cyborgY-30,16,32); // eye center fill(23,137,206); ellipse(cyborgX-19,cyborgY-30,8,16); ellipse(cyborgX+19,cyborgY-30,8,16); // legs stroke(0); line(cyborgX-10,cyborgY+50,cyborgX-10,cyborgY+60); line(cyborgX+10,cyborgY+50,cyborgX+10,cyborgY+60); stroke(0); // foot2 line(cyborgX-15,cyborgY+60,cyborgX-10,cyborgY+60); line(cyborgX+15,cyborgY+60,cyborgX+10,cyborgY+60); stroke(0); // foot1 line(cyborgX-15,cyborgY+60,cyborgX-10,cyborgY+60); line(cyborgX+15,cyborgY+60,cyborgX+10,cyborgY+60); //// Cyborg pockets plutonium and radiation flashes // if ( dist( cyborgX,cyborgY, plutoniumX,plutoniumY ) < 50 ) { score= score + 100; background(0,50,200); reset(); } } void snowman() { // move & draw snowman // // chase cyborg snowmanX= snowmanX + (cyborgX-snowmanX)/65; snowmanY= snowmanY + (cyborgY-snowmanY)/65; // snowman catches cyborg. // if ( dist( cyborgX,cyborgY, snowmanX,snowmanY ) < 50 ) { bite(); } // snowman gets the plutonium. // if ( dist( plutoniumX,plutoniumY, snowmanX,snowmanY ) < 50 ) { plutoniumX= 50; plutoniumY= random(horizon,height); } // draw snowman // ellipseMode( CENTER ); fill( 0,0,0 ); //bottom ellipse( snowmanX, snowmanY+90, 190,190 ); fill( 120,120,120 ); //body ellipse( snowmanX, snowmanY, 130,130 ); fill(255,255,255); //head ellipse(snowmanX,snowmanY-60, 90,90); // Snowman's eyes fill(204,0,0); ellipseMode(CENTER); ellipse(snowmanX-20,snowmanY-70,20,20); ellipse(snowmanX+20,snowmanY-70,20,20); } void plutonium() { // Draw plutonium. // if (plutoniumY>horizon) { fill(3,250,0); ellipse(plutoniumX,plutoniumY, 30,30 ); } } void scoring() { } void bite() { // Snowman sucks Cyborgs life force (Score) //subtract 5 from score when . score= score - 5; background(random(250),random(200),random(150)); reset(); } void bite2() { //// birds catch cyborg subtract 200 from score. score= score - 200; background(255,0,0); reset(); } void reset() { // plutonium resets at random location // plutoniumX= random( width/4, width*3/4); plutoniumY= random(horizon+20,height-20);; // reset birds n= int ( random(3,10) ); x= random(width/2); y= random(height/2); w= random(10,70); h= w/3; } void mousePressed() { //// Click. //// plutoniumX= mouseX; plutoniumY= mouseY; score= score - 100; snowmanX=0; snowmanY= random(20,height-20); } void bird( float x, float y, float w, float h ) { //// draw 1 bird triangle( x,y, x-w,y-h, x-w,y+h ); } void flock( int n, float x, float y, float w, float h ) { // draw the birds // float xx= x; float hh= h * 2; float ww= w; bird( xx,y,w,h ); // xx= xx - 1*w; for (int j=2; j