Modify a text file: $/q1.pde
$/q1.pde
//Project 1; Benjamin Canfora float xCat, yCat, cxSpeed, cySpeed; float xDO, yDO; float lSize; color hColor; int total; float xSun = -25; float ySun = 100; float xMoon = -25; float yMoon = 100; boolean day=true; void setup() { size(600, 600); lSize = 50; hColor = #A921BF; xSun=0; ySun=100; xCat = 300; yCat = 300; cxSpeed = 2; cySpeed = 2; xDO = 450; yDO = 500; total = 0; } void draw() { if (day) { sun(); } else { moon(); } //Instructions fill(255, 255, 255); textSize(20); text("p1: Animated House", width/3.5, 20); text("Author: Ben Canfora", width/3.5, 40); textSize(15); text("Press 'C' to change", 10, 20); text("the house color.", 10, 40); text("Press 'L' to change", 10, 65); text("the leaves' size.", 10, 85); textSize(13); text("Click to move the cat", 375, 65); text("to another part of the grass,", 375, 85); text("or press 'R' to move it to the house.", 375, 105); text("Press 'D' to make it day,", 400, 20); text("or 'N' to make it night.", 400, 40); textSize(16); //Grass fill(#35BC0D); rect(0, 195, 600, 600); text("Score: "+ total, 275, 550); //Tree Trunks fill(#713302); rect(60, 350, 20, 50); rect(170, 515, 22, 60); rect(380, 412, 20, 55); //Tree leaves fill(#226C03); ellipse(70, 335, lSize, lSize); ellipse(181, 500, lSize, lSize); ellipse(390, 397, lSize, lSize); //Small House fill(hColor); rect(130, 150, 150, 80); triangle(130, 150, 280, 150, 210, 90); //Door fill(#713B08); rect(240, 180, 30, 50); //Cat //Horizontal Movement xCat += cxSpeed; //Vertical Movement yCat += cySpeed; //Makes the cat Bounce of the edges of the screen and grass if (xCat >= width - 37 || xCat <= 0 + 37) { cxSpeed *= -1; total +=1; } if (yCat >= height - 20 || yCat <= 217) { cySpeed *= -1; total += 1; } fill(#000000); //Body rect(xCat, yCat, 30, 18); //Head rect(xCat-10, yCat-15, 20, 20); //Tail line(xCat +30, yCat, xCat+40, yCat+2); //Ear triangle(xCat-2, yCat-15, xCat+8, yCat-15, xCat+2, yCat-21); fill(#FFB7FA); triangle(xCat, yCat-15, xCat+6, yCat-15, xCat+2, yCat-19); //Makes the Doom Orb fill(#B20909); ellipse(xDO, yDO, 60, 60); fill(#FAE8E8); ellipse(xDO, yDO, 25, 25); fill(#24671A); ellipse(xDO, yDO, 10, 10); flower(); doom(); rocks(); ladder(); //Changes leaf size or house color based on pressed key if (keyPressed) { if (key == 'c' || key == 'C') { int c1, c2, c3; c1 = int(random(0, 256)); c2 = int(random(0, 256)); c3 = int(random(0, 256)); hColor = color (c1, c2, c3); } if (key == 'l' || key == 'L') { lSize = random(50, 85); } //Changes between Day and Night on key press if (key == 'd' || key == 'D') { day = true; if (day) { sun(); } else { moon(); } } if (key == 'n' || key == 'N') { day = false; if (day) { sun(); } else { moon(); } } if (key == 'r' || key == 'R') { xCat = 250; yCat = 220; } } } //Moves the Cat to the mouse's position as long as it is on the grass. void mousePressed() { if (mouseY >217) { xCat = mouseX; yCat = mouseY; } } void sun() { //display sun background(100, 100, 250); stroke(0); fill(255, 250, 0); float up= 50 * sin(PI * xSun/width ); ellipse(xSun, ySun-up, 50, 50); //movement sun xSun+=3; if (xSun > 625) { day = false; xSun=-25; // Get ready for next day. } } void moon() { //display moon background(10, 10, 80); stroke(50); fill(150); float up= 50 * sin(PI * xMoon/width ); ellipse(xMoon, yMoon-up, 40, 40); //movement Moon xMoon+=3; if (xMoon > 625) { day = true; xMoon=-25; } } //Creates pink flowwers to the right of the house void flower() { for (int i = 310; i < 590; i = i+40) { fill(#34EA28); rect(i, 180, 10, 15); fill(#DE86D8); ellipse(i+5, 178, 15, 15); } } //Makes the doom orb chase the cat, and updates score void doom() { if (day == false) { xDO += (xCat - xDO)/300; yDO += (yCat - yDO)/300; //if (xCat - xDO < 50 || yCat - yDO < 50) { // xCat = random(600); // yCat = random(200, 600); // xDO =450; // yDO = 500; // total -=10; //} } } //Makes rocks along the bottom void rocks() { int i = 0; while (i < 600) { fill(#866308); ellipse (i, 575, 10, 10); i += 30; } } void ladder() { int i = 195; while (i <= 550){ fill(#F50800); rect(10, i, 30, 30); fill(#35BC0D); rect(12,i+2,25,25); i = i + 30; } }