// Project 1 // Juan delgado 9/12/14 int score=0 ; float sunx=100 , suny=100; float horizon; float coinx, coiny; float titox,titoy; float evilx, evily; void setup(){ //setup// size(800,600); horizon= height/4; suny= horizon/2; titox=width/2; titoy= height/2; evilx=30; evily= random(horizon,height-60 ); coinx= width-50; coiny= random(horizon+50,height-50); } void draw(){ //next frame// scene(); coin(); hero(); monster(); scoring(); } void scene(){ //sky, sun ,etc background(200,200,255); fill(255,255,0); ellipse(sunx,suny,100,100); //sun fill(200,255,200); rectMode(CORNER); rect(0,horizon,width,height*3/4); //grass //sun moves across sky// if (sunx > width) { sunx=0; suny= random(10, horizon-20); } sunx= sunx+2; fill(0); text ("SCORE=" + score, width-200, 50); } void hero(){ //move and draw hero titox= titox + (mouseX-titox) /30; titoy= titoy + (mouseY-titoy) /30; //draw tito// fill(255,225,100); rectMode(CENTER); rect(titox,titoy, 50,100); fill(0); text("TITO", titox-15, titoy-10); fill(50,255,255); ellipse(titox,titoy-70,40,50); //arms rectMode( CORNERS ); fill(0); rect ( titox-25, titoy-40, titox-30-60,titoy-45+15 ); rect ( titox+25, titoy-40, titox+30+60,titoy-45+15 ); // get the coin,// if ( dist( titox,titoy, coinx,coiny) < 50 ) { score += random(100,200); reset(); } } void monster(){ ///chase tito evilx= evilx+(titox-evilx)/150; evily= evily+(titoy-evily)/150; if ( dist( titox,titoy, evilx, evily) < 50 ) { eat(); } //draw evil fill(0,0,0); rectMode(CENTER); rect(evilx,evily, 70,100); fill(150,50,250); text("EVIL", evilx-10, evily-10 ); fill(50,0,100); ellipse(evilx,evily-70, 50,60); //arms rectMode (CORNERS); fill(50); rect ( evilx-35, evily-45, evilx-35-70,evily-45+15); rect (evilx+35, evily-45, evilx+35+70,evily-45+15); } void coin(){ // draw the coin.// fill(random(250),random(50),random(150)); ellipse(coinx,coiny, 40,40); } void scoring(){ } void eat (){ /// evil eats tito lose 100 from score. score= score - 200; background(255,0,0); titox= width; titoy= height; evilx=0; evily=horizon; } void reset() { // start at corners,// coinx= random( width/4, width*3/4); coiny= random( horizon +20, height-20);; titox= width; titoy=height; evilx=0; evily=horizon; } void mousePressed() { titox= mouseX; titoy= mouseY; score= score - 50; evilx=0; }