//Global Declarations// //(x, y) coordinates of hero, dog, etc. float xGuy, yGuy; float gx, gy; float xClavin, yClavin; float xSun=0, ySun=55, xHouse, yHouse; float horizon; void setup() { size(700, 500); horizon= height/3; reset(); } void reset() { xGuy= width/2; yGuy= height/2; gx= random(2, 5); gy= random( -2, +2); } void draw(){ scene(); action(); show(); } void scene() { background(0, 255, 255); fill(0, 255, 0); rect(0, horizon, 700, 500); //green grass fill(255, 0, 255); rect(100, 200, 100, 100); //pink house fill(0); triangle(100, 200, 200, 200, 140, 130); //black house roof fill(0); rect(150, 250, 20, 50); //black door fill(255,0, 255); ellipse(155, 275, 6, 6); //pink door knob fill(255); rect(115, 220, 28, 28); //white window line(115, 235, 143, 235); line(129, 220, 129, 249); fill(139, 69, 19); rect(400, 200, 30, 100); //brown tree #1 fill(0,200, 0); ellipse(390, 210, 50, 50); fill(0,200, 0); ellipse(430, 210, 50, 50); fill(0,200, 0); ellipse(415, 210, 50, 50); fill(255, 255, 3); ellipse(xSun, ySun, 70, 70); fill(139, 69, 19); rect(470, 330, 30, 100); //brown tree#2 fill(0,200, 0); ellipse(460, 340, 50, 50); fill(0,200, 0); ellipse(500, 340, 50, 50); fill(0,200, 0); ellipse(485, 340, 50, 50); fill(255, 255, 3); ellipse(xSun, ySun, 70, 70); fill(139, 69, 19); rect(570, 270, 30, 100); //brown tree#3 fill(0,200, 0); ellipse(560, 280, 50, 50); fill(0,200, 0); ellipse(600, 280, 50, 50); fill(0,200, 0); ellipse(585, 280, 50, 50); fill(255, 255, 3); ellipse(xSun, ySun, 70, 70); } void action(){ xSun= xSun + 2; if (xSun> width) { xSun=0; ySun=50; } // Move the Guy // Bounce off right & left if (xGuy> width) { gx = -gx; } if (xGuy< 0) { gx = -gx; } // Bounce top, bottom if (yGuy> height) { gy = -gy; } if (yGuy< horizon) { gy = -gy; } xGuy= xGuy + gx; yGuy= yGuy + gy; } void show(){ //creature fill(175, 255, 255); rect(xGuy, yGuy, 30, 80); fill(0, 155, 255); ellipse(xGuy+18, yGuy-20, 40, 40); //eyes fill(255); ellipse(xGuy + 13, yGuy - 23, 12, 12); ellipse(xGuy + 29, yGuy - 23, 12, 12); fill(255, 0, 0); ellipse(xGuy + 13, yGuy - 23, 7, 7); ellipse(xGuy + 29, yGuy - 23, 7, 7); //dog fill(100); rect(xGuy - 130, yGuy + 50, 68, 30); //collar fill(255, 0, 0); rect(xGuy - 80, yGuy + 50, 20, 5); //head fill(100); rect(xGuy - 80, yGuy + 30, 40, 20); //dog eye fill(244); ellipse(xGuy - 70, yGuy + 35, 10, 10); } void mousePressed() { xGuy= mouseX; yGuy= mouseY; }