//// Project 1 //// B.A.Martin, 2014 Sep 12 int score=0; float sunX=100, sunY=100; float horizon; float vladX, vladY; float frankX, frankY; void setup() { //// setup //// size( 600,400 ); horizon= height/4; sunY= horizon/2; vladX=width/2; vladY= height/2; frankX=30; frankY= random( horizon,height-60 ); } void draw() { // next frame // scene(); hero(); monster(); scoring(); } void scene() { // sky, sun, etc. background( 200,200,255 ); fill(255,255,0); // yellow sun ellipse(sunX,sunY, 50,50); fill( 200,255,200); // grass rectMode( CORNER ); rect(0,horizon, width,height*3/4); // sun moves across sky // if (sunX > width) { sunX=0; sunY= random( 10, horizon-20); score= score+10; } sunX= sunX+2; fill(0); // text( sunX, sunX, sunY+40); text( "SCORE= " + score, width-200, 50 ); } void hero() { // move & draw Vlad // vladX= vladX + (mouseX-vladX)/30; vladY= mouseY + (mouseY-vladY)/30; // draw fill( 0,150,0 ); rectMode( CENTER ); rect( vladX, vladY, 50,80 ); fill(255,127,0); ellipse(vladX,vladY-40, 40,50); } void monster() { // move & draw Vlad // // chase vlad frankX= frankX + (vladX-frankX)/150; frankY= frankY + (vladY-frankY)/150; if ( dist( vladX,vladY, frankX,frankY ) < 50 ) { eat(); } // draw frank // fill( 150,0,0 ); rectMode( CENTER ); rect( frankX, frankY, 70,90 ); fill(127,255,0); ellipse(frankX,frankY-40, 50,60); // arms rectMode( CORNERS ); fill(0); rect( frankX-35,frankY-45, frankX-35-70,frankY-45+15 ); rect( frankX+35,frankY-45, frankX+35+70,frankY-45+15 ); } void scoring() { } void eat() { //// Monster eats hero!!!! Deduct 200 from score. score= score - 200; background(255,0,0); vladX= width; vladY= height; frankX=0; frankY=horizon; } void mousePressed() { //// vladX= mouseX; vladY= mouseY; score= score - 50; frankX=0; }