// Project 1 Julio Moya float x, y; float dx, dy; float dxJoe = 2, dyJoe = 4; float xJoe = 0, yJoe = 0; float horizon; float xSun=0, dxSun=1, ySun=50; float xGold = random (50, width-50); float yGold = random (horizon+50, height-50); // SETUP void setup() { size( 800, 680 ); smooth(); x = 0; y = 0; horizon= height/2; reset(); frameRate = 30; xJoe = xJoe + dxJoe; dxJoe = (xGold - xJoe) / frameRate; xGold = random (50, width-50); yGold = random (horizon+50, height-50); } void reset() { x= mouseX; y= mouseY; dx= random( 4, 8 ); dy= random( 1.6, 3.9 ); } void draw() { scene(); action(); show(); messages(); } // SCENE void scene(){ // Sky blue background( 102,255,255 ); fill( 0,180,0 ); // Grass noStroke(); rectMode( CORNERS ); rect( 0,horizon, width,height ); // Sun fill( 255,220,0 ); ellipse( xSun,ySun, 80,80 ); xSun= xSun + dxSun; if (xSun>width) { xSun= 5; ySun= random( 80, 20 ); } // House fill( 222,184,135 ); rect( width/7,horizon-100, 200+width/10,horizon ); triangle( 90,260, 305,260, 190,160); // Brown Door fill( 205,133,63 ); rect( 180,340, 220,290 ); // Window 1 fill( 102,255,255 ); rect( 130,320, 170,270 ); // Window 2 fill( 102,255,255 ); rect( 230,320, 270,270 ); // Tree fill( 165, 42, 42 ); rectMode( CORNER ); // Brown trunk rect( width*3/4, horizon, 40, -70 ); fill( 0,100,0 ); ellipse( 20+width*3/4, horizon-70-40, 120,120 ); } ///Name void messages() { fill(0); text( "Julio Moya Project 1", width/2,30 ); } // ACTION: Monster void action() { x= x + dx; y= y + dy; moveJoe(); } //Monster void show() { noStroke(); rectMode( CENTER ); // Body. fill( 0,0,0 ); rect( x,y, 80,80 ); // Head fill( 0,255,0 ); ellipse( x, y-50-20, 105,105 ); text( "Joe", x,y ); // Eye fill(255, 255, 255); ellipse( x-0, y-50-25, 95,55 ); fill( 65, 105, 225); ellipse( x-0, y-50-25, 40,40 ); // Gold fill( random(300,415), random(180,220), random(0,30) ); ellipse( xGold, yGold, 30, 20 ); } void moveJoe() //MOVE SAM { // Go for the gold! dxJoe= (xGold -xJoe) / 30; dyJoe= (yGold -yJoe) / 30; // Move him. xJoe = xJoe + dxJoe; yJoe = yJoe + dyJoe; // Check for gold nearby. if (dist(xJoe, yJoe, xGold, yGold) < 5) { background(0); xGold= random( 0, width ); yGold= random( horizon, height ); } } // click mouse void mousePressed() { reset(); xGold= mouseX; yGold= mouseY; }