Modify a text file: $/z2.pde
$/z2.pde
////409b CST 112 PR #2 / Miguel ROdriguez //// String title= "Project #2 c"; String author= "Miguel Rodriguez"; //Declarations// Button one; Hero max; Dog rob; Monster dev; Star sol; House home; Tree wood; int ntrees = 3; float horizon; boolean day=true; color SKY=color(100,200,250); color NITE= color(0,0,0); void setup() { size(800, 600); background(255); smooth(); horizon = height/4; //initiate objects// max = new Hero(); rob = new Dog(); dev = new Monster(); sol = new Star(); home = new House(); wood = new Tree(); one = new Button(); reset(); } void reset(){ //rob.reset(); //dev.reset(); max.reset(); } void draw() { scene(); action(); messages(); rob.show(); max.show(); max.bounce(); dev.show(); } void scene(){ background(SKY); noStroke(); //nigth code if (day) background(SKY); else background(NITE); fill(0,250,0); rect(0,horizon,width,height-horizon); // one.show(); sol.show(); sol.move(); home.show(); wood.show(); one.show(); } void action(){ //Monster chases dog rob.chase(max.x, max.y); dev.chase(rob.x, rob.y); max.move(); } void messages(){ } //EVENT HANDLERS// void keyPressed(){ if(key=='q'){exit();} if(key=='r'){ reset();} if(key=='t'){wood.replace();} } void mousePressed(){ if (one.hit() ) {day = ! day; } } //OBJECTS// class Dog{ float x; float y; Dog(){ x = width/7; y = height/2; } void show(){ //body fill(250,120,0); rect(x,y-40,80,30); fill(0,120,100); text("ROB", x+30,y-20); //legs fill(0,0,0); rect(x+70, y-10, 10, 30); rect(x,y-10,10,30); //head fill(0,0,0); rect(x+70, y-55, 35,25); //eyes strokeWeight(1); fill(255,255,255); ellipse(x+100,y-50,12,12); fill(0); ellipse(x+100,y-50,5,5); //ears fill(255); triangle(x + 70, y-55, x +80, y - 70, x + 85, y - 55); triangle(x +90, y - 55, x+100, y - 70, x +105, y - 55); } void chase(float xhero, float yhero){ x = x+ (xhero-x) / 60; y = y + (yhero-y) /60; } } class Hero{ float x, y, dx =3, dy=2; Hero(){ x = 300; y = 250; } void show(){ stroke(0); fill(120,0,120); rect(x,y,40,70); //body fill(255,255,100); ellipse(x+20,y-20,40,40); //head rect(x+5,y+70,10,40); //legs rect(x+25,y+70,10,40); fill(255); ellipse(x+12,y-24,10,10); fill(0); ellipse(x+12,y-24,4,4); fill(255); ellipse(x+30,y-24,10,10); fill(0); ellipse(x+30,y-24,4,4); text("MAX", x+10,y+35); } void move(){ x = x + dx; y = y + dy; } void reset(){} void bounce(){ if (x>width-30 || x<10){dx = -dx;} if (y
height){dy = -dy;} } } class House{ float x; float y; float w; float h; House(){ x = 50; y = 100; w = 200; h = 100; } void show(){ stroke(0); fill(150,30,20); rect(x,y,w,h); fill(200,100,20); triangle(x,y,x+w,y,x+w/2,y-h/2); //house door fill(100,10,20); rect(w/2+x,h/2+y,35,50); //doorknob fill(255,255,0); ellipse(x+130,180,10,10); } } class Monster{ float x; float y; float w; float l; float li; Monster(){ x = width/3; y = horizon*3; w = 10; l = 30; li = 30; } void show(){ noStroke(); fill(0); rect(x,y,50,100); ellipse(x+25,y-25,50,50); rect(x+10,y+100,w,l); rect(x+30,y+100,w,li); fill(255); ellipse(x+25,y-25,15,15); fill(0); ellipse(x+25,y-25,5,5); l = l+.8; li= li+.5; if (l > 45){l = 30;} if (li > 48){li=25;} } void chase(float xdog, float ydog){ //Chase the dog.// x = x + (xdog - x) / 90; y = y + (ydog - y) / 90; } } class Star{ float x; float y; color c = color(255,255,0); float dx; Star(){ y = horizon/4; dx=1; } void show(){ if (day) c = color(255,255,0); else c =color(200,180,180); fill(c); ellipse(x,y,80,80); } void move(){ x = x+dx; if (x>width) {sunset();} } void sunset(){ day = ! day; x=0; } } class Tree{ float x; float y; float w; Tree(){ x = width/2; y = height/3; w = 20; } void show(){ noStroke(); fill(150,20,50); rect(x,y,w,100); fill(0,100,0); ellipse(x+10,y,110,110); fill(150,20,50); rect(x+100,y+150,w,80); fill(0,150,0); ellipse(x+110,y+150,110,110); fill(150,20,50); rect(x-300,y+250,w,80); fill(10,200,20); ellipse(x-290,y+230,110,110); } void replace(){ x = random(0,width); y = random(0,height-100); } } class Button{ float x= 700, y=250; int w=80, h=30; String name= "Day n Night"; color c=color(255,200,200); Button(){} Button( String nn) { name=nn; } Button( float xx, float yy) {x=xx; y=yy;} Button( String nn, float xx, float yy){ name=nn; x=xx; y=yy; } void show(){ fill(c); rect(x,y,w,h); fill(0); textSize(12); text( name, x+10,y+20); } boolean hit(){ return( mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h); } boolean hit( float xx, float yy) { if (xx < x) return false; if (xx > x+w) return false; if (yy < y) return false; if (yy > y+h) return false; return false; } }