//// Project 2 Carl the robot chases allen to steal his gold //// 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, houseY; 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, houseH=110; void setup() { size( 820,700 ); horizon= height/3; sunY= horizon/3; score=0; reset(); } 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); mouseY= height; } void draw() { scene(); gold(); allen(); carl(); //-- collisons(); tree(); house(); fill(0); text( title, width/2, 25 ); text( author, 25, height-25 ); text( score, 30, 30 ); } 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 ); // Grass noStroke(); rectMode( CORNER ); rect(0, horizon, width, height ); if ( sunX > width ) { sunX= 1; sunY= random( 20, horizon+20 ); } sunX= sunX+4; for( float x=20; xwidth) carlW+= carlZ; if( carlX<2 ) carlW = -carlZ; carlY+= ( allenY-carlY )/20; //carl bumbs into allen// if (dist( carlX,carlY, allenX,allenY ) < allenW/3 ) { text(int( score += score - 110 ), 30,30 ); reset(); } } void collisions() { // carl catches the hero allen, allen gets the gold and carl gets the gold// if ( dist( allenX, allenY, carlX, carlY ) < 40 ) { allenX= houseX; allenY= houseY-houseH; } if ( dist( goldX, goldY, carlX, carlY ) < 40 ) { goldX= 40; goldY= random( horizon+50, height ); } if ( dist( goldX, goldY, carlX, carlY ) < 40 ) { reset(); } }