//// Project 2 Carl the robot chases allen the to steal gold but how when neither of them have eyes? //// CST 112 Talha Riaz 2015 Mar 11 String title= "carl the robot chases allen to steal his gold"; String author= "Talha Riaz: CST 112 3/11/15"; int score=0; float sunX=110, sunY=110; float horizon; float houseX=120,houseY=120; float goldX, goldY; float carlX, carlY, carlW=45, carlZ=60; // robot float allenX, allenY, allenW=60, allenH=80; // hero; float treeX= 15; float treeY= horizon+30; float houseW=90,houseL=110; void setup() { size( 820,700 ); horizon= height/2; sunY= horizon/3; score=0; reset(); frameRate( 60 ); } void reset() { // Carl and allen start on //opposite ends if (random(1)>0.8 ) { allenX= width-10; carlX=10; } else { allenX= width-10; carlX=10; } allenY= random( horizon, height-40 ); carlY= random( horizon, height-40 ); goldX= random( width/2, width*3/2 ); goldY= random( horizon+150,height-60); allenX= houseX; allenY= houseY; } void draw() { tree(); scene(); gold(); allen(); carl(); //-- collisons(); house(); fill(0); text( title, width/2, 25 ); text( author, 25, height-25 ); void gold() { fill(200,150,0); ellipse( goldX,goldY,50,50 ); } void mousePressed() { goldX=mouseX; goldY=mouseY; } void scene() { //sun,sky,grass// background( 155,155,255 ); // blue sky fill( 200,255,0 ); //sun ellipseMode( CORNER ); noStroke(); ellipse( sunX, sunY, 60,60 ); fill( 0,255,0 ); // Green Grass noStroke(); rectMode( CORNER ); rect(0, horizon, width, height ); if ( sunX > width ) { sunX= 1; sunY= random( 20, horizon+20 ); } sunX= sunX+4; } void house() { rect( houseX*7/3,houseY*7/3,190,150); // house rectMode( CORNER ); fill( 150,100,250 ); } void allen() { //Draw allen the hero // allenX = allenX + (goldX-allenX)/70; allenY = allenY + (goldY-allenY)/70; if (allenYwidth) carlW =-carlZ; if(carlX<2) carlW = -carlZ; carlY += ( allenY-carlY )/20; // carl bumps into allen// if (dist( carlX,carlY, allenX,allenY ) < allenW/3 ) { text(int(score += score - 110), 30, 30); reset(); } }