// x212Gao String title= "Project"; String author= "L. Gao"; float sunX=50, sunY=100; // Sun float horizon; boolean day=true; House home; Hero larry; Dog gary; void setup() { size(500, 500); horizon= height/4; home = new House(); home.x=200; larry = new Hero(); larry.x=300; gary = new Dog(); } void draw() { scene(); action(); messages(); } void scene() { //Sun turning night and day if (day) background( 150, 220, 250 ); else background( 50, 150, 150 ); ellipse( sunX, sunY, 40, 40 ); // Grass fill( 50,200,50 ); rect( 0,horizon, width,height-horizon ); home.show(); // Sun color if (day) fill (255, 255, 0); else fill(200,200,200); //Sun shape ellipse( sunX, sunY, 40, 40 ); } void messages () { fill(204, 102, 0); //orange text textSize(24); text( title, width/3, 30 ); textSize(12); text( author, 20, height-20 ); } // sun void action() { fill(300, 300, 300); sunX= sunX + 1; sunX=0; sunY= random( 20, 120 ); } //Larry movement larry.move(); //border wall bouncing if (x>width) xspeed = -xspeed; if (y>height) yspeed = -yspeed; } void mousePressed() { x= mouseX; y= mouseY; xspeed= random( -5, +5 ); yspeed= random( -3, +3 ); } //// OBJECTS //// class House { // DATA // float x=50,y=horizon-60; // Position of house. float wide=80, high=60; // Dimensions // METHODS // void show() { //house fill( 255,0,0 ); rect( x, y, wide, high ); //window1 fill(255,255,255); rect( x+60, y+15, 18, 18 ); //window2 rect( x+35, y+15, 18, 18 ); //roof fill( 255,0,0 ); triangle(x, y, 90, 40, 130, 65); //door fill(155,0,0); rect( x+5, y-10, 25, 50 ); } } class Hero{ float x, y, xx, yy; void show() { // Larry body rect( x-25,y, 50, 80 ); ellipse( x, y-10, 40, 50 ); //Larry eyes fill(255, 255, 255); ellipse( x-5, y-10, 10, 10 ); ellipse( x+10, y-10, 10, 10 ); //Larry movement x= x + xspeed; y= y + yspeed; } }// class Hero // class Dog{ float x, y, xx, yy; void show() { //Gary body rect( y-25,y, 40, 30 ); // Gary's body rect( X, y-10, 40, 50 ); // Gary's head //Gary eyes //Gary following Larry x= x + (x- x); y= y + (y- y); } }