//x1 assignment// //Matthew Testa (CST 112; 9/11/15) //GLOBALS point plot and speed float x, y; float ax, ay; float dx, dy; float horizon; float ralphX, ralphY; float treasureX, treasureY; float villianX, villianY; //SETUP: size void setup() { size (800, 550); horizon = height/3; x = width/2; y = height/2; ax = width/5; ay = height/1.5; dx = 4; dy = 5; } ///FRAME: scene, ralph, villian void draw() { scene(); ralph(); villian(); treasure(); movement(); score(); } //SCENE: objects and shapes void scene() { background(230, 200, 200); // sky // fill(250, 200, 100); ellipse( width*4/5, height/9, 65,65); // sun // fill( 130,230, 120); rect(0, horizon, width, height*4/5); // grass // fill(200,100,60); //tree// rect( 100, horizon, width/35, -height/4 ); fill(80,240,20); triangle(60, horizon-40, 110, horizon-140, 160, horizon-40); triangle(80, horizon-100, 110, horizon-160, 140, horizon-100); fill(140, 60, 120); //house// rect(270, horizon, width/5, -height/6); fill(255,0,0); rect(335, horizon, width/35, -height/12); fill(0); text( "Matt Testa", 700, height/3); x= x + dx; y= y + dy; } void ralph() { fill(255); ellipse(x,y, 80,65); //eyes// fill(180); ellipse(x-15,y-5, 20,20); fill(180); ellipse(x+15,y-5, 20,20); //mouth// fill(200,0,0); rect(x,y+8, 40,25); //teeth// fill(255,255,255); rect(x,y+8, 10,5); rect(x+30,y+8, 10,5); fill(0); text( "Ralph", x,y+50); } //villian// void villian() { rect(ax, ay, 80, 100); //eyes// fill(255, 0, 0); ellipse(ax+20, ay+7, 15, 15); ellipse(ax+60, ay+7, 15, 15); line(ax-5, ay-20, ax+30, ay+5); line(ax+50, ay+5, ax+70, ay-20); fill(140, 190, 80); triangle(ax+20, ay+38, ax+50, ay+30, ax+80, ay+70); } void treasure() { fill(240, 180, 20); ellipse(x,y, 20, 20); } void movement() { if(abs(ralphX-treasureX)<3 && abs(ralphY-treasureY)<3 ) { treasureX= random(width+20, width-80); treasureY= random(height/2); ralphX= 60; ralphY= 120; villianX= random(width/3, width*1/2); villianY= random(height/2, height*3/4); score= score + 100; } if(abs(villianX-ralphX)<15 && abs(villianY-ralphY)<15) { score = score - 200; ralphX= 60; ralphY= 120; villianX= random(width/3, width*1/2); villianY= random(height/2, height*3/4); } } void score() { fill(0); } //speed, mouse clicks, exit// void mousePressed() { x= mouseX; y= mouseY; //speed// dx= random( -1, +4); dy= random( -2, +3); }