Modify a text file: $/z2.pde
$/z2.pde
//// CST 112 Preliminary Project #2 / Jose Olvera //// String title = "Preliminary Project #2"; String hint = "Click 'r' to reset creature.\n Click 'q' to quit"; String author = "Jose Olvera"; //// ENVIRONMENT AND CHARACTERS //// //Tree & Sun Sun star = new Sun(); Tree arbol = new Tree(); //Pos. of House & Base //House home = new House(); //Doghouse base = new Doghouse(); //Characters Hero josuke = new Hero(); Dog danny = new Dog(); Creature dio = new Creature(); //// OTHER VARIABLES //// float horizon; boolean day = true; float val; int i = 0; //Colors color RED = color(255, 0, 0), GREEN = color(0, 255, 0), BLUE = color(0, 0, 255), YELLOW = color(255, 255, 0), MAGENTA = color(255, 0, 255), BROWN = color(127, 0, 0), BLACK = color(0, 0, 0), PALE = color(200, 200, 200), WHITE = color(255, 255, 255); //// SETUP: SCREEN SIZE AND MODES //// void setup() { size(800, 600); horizon = height / 2; sunReset(); treeReset(); houseReset(); doghouseReset(); josukeReset(); dannyReset(); dioReset(); } void sunReset() { star.x = width/2; //Sun starts half-way across the screen star.y = 100; } void treeReset() { arbol.x = width/3; arbol.y = horizon; } void houseReset() { // home.x = width/4; //home.y = horizon; } void doghouseReset() { // base.x = width/4 + 100; // base.y = horizon + 200; } void josukeReset() { josuke.x = width/3; //Start at left side josuke.y = 300; josuke.dx = random(1, 3); //Random Speed josuke.dy = random(-1, 1); } void dannyReset() { danny.x = width/3; //Start at left side with Hero danny.y = horizon; danny.dx = random(1, 3); //Random speed danny.dy = random(-1, 1); } void dioReset() { dio.x = 100; dio.y = 100; dio.dx = random(1, 3); //Random speed dio.dy = random(-1, 1); } //// DRAW: SKY, SUN, HOUSES, TREES, & CHARACTERS //// void draw() { scene(); action(); show(); messages(); //Remember to Display Messages last// } //// SCENE: Sky, Sun, Houses, Trees void scene() { background(150, 220, 250); //Blue sky fill(GREEN); rect(0, horizon, width, height - horizon); star.show(); //Yellow sun home(100, 100); //Says what it says } void home(float x, float y) { float w = 120, h = 50; //Size of Hero's house fill(WHITE); rect(x, y + 150, w, h); //Pale house at (x,y) fill(BROWN); triangle(x, y + 150, x + w, y + 150, x + w/2, y + 100); } void base(float x, float y) { float w = 60, h = 25; //Size of Dog's house fill(RED); rect(x, y, w, h); //Red house at (x, y) fill(BLACK); rect(x + 60, y + 25, w/3, h/3); } //// ACTION: Sun moves (then resets with moon at night) void action() { star.move(); dio.move(); if (dio.x > width) { dioReset(); } } //Bounce off walls for Josuke float josukeX, josukeY, josukeXspeed, josukeYspeed; { if (josukeX > width) { josukeXspeed = -josukeXspeed; } if (josukeX < 0) { josukeXspeed = -josukeXspeed; } if (josukeY > height) { josukeYspeed = -josukeYspeed; } if (josukeY < horizon/2) { josukeYspeed = -josukeYspeed; } } //// SHOW: Creature void show() { josuke.show(); danny.show(); dio.show(); } //// MESSAGES //Title, hints & author void messages() { fill(BLACK); text(title, width/3, 10); text(hint, 10, height/2); text("Jose Olvera", 10, height - 10); } //// EVENT HANDLERS //// void mousePressed() { //Set the position (x,y) danny.x = mouseX; danny.y = mouseY; } void keyPressed() { if (key == 'q') {exit();} if (key == 'r') {josukeReset(); dannyReset(); dioReset();} } class Sun { float x, y; //Sun Position float dx = 1; //METHODS// void show() { fill(YELLOW); ellipse(x, y, 30, 30); //Yellow sun } void move() { x += dx; if (x > width); fill(YELLOW); ellipse(x, y, 30, 30); fill(WHITE); ellipse(x, y, 30, 30); } } class Tree { float x, y; //Tree Position //METHODS// void show() { fill(BROWN); rect(width/3, horizon - 50, 30, 50); fill(GREEN); ellipse(x, y, 60, 60); } } class Hero { float x, y; //Position and speed float dx, dy; //METHODS// void move() { josuke.x = josuke.x + josuke.dx; //Move the Hero josuke.y = josuke.y + josuke.dy; } void show() { fill(BLUE); //Draw Hero rect(x, y, 50, 80); fill(250, 150, 120); ellipse(x + 25, y - 20, 40, 40); line(x + 50, y + 80, x + 55, y + 110); line(x, y + 80, x - 5, y + 110); eye(x + 15, y - 25); eye(x + 35, y - 25); } void eye(float eyeX, float eyeY) { fill(WHITE); ellipse(eyeX, eyeY, 12, 12); fill(BLUE); ellipse(eyeX, eyeY, 4, 4); } } class Dog { float x, y; //Position and speed float dx, dy; //METHODS// void move() { danny.x = danny.x + danny.dx; //Move the Dog danny.y = danny.y + danny.dy; } void show() { fill(BROWN); //Draw Dog rect(x + 90, y + 40, 80, 50); fill(BROWN); rect(x + 70, y + 20, 50, 30); eye(x + 95, y + 30); eye(x + 110, y + 30); } void eye(float eyeX, float eyeY) { fill(WHITE); ellipse(eyeX, eyeY, 12, 12); fill(BLACK); ellipse(eyeX, eyeY, 4, 4); } } class Creature { float x, y; //Position & speed float dx, dy; //METHODS// void move() { x = x + dx; //Move the Creature y = y + dy; } void show() { fill(YELLOW); //Draw Creature rect(x, y, 50, 80); fill(PALE); ellipse(x + 25, y - 20, 40, 40); eye(x + 15, y - 25); eye(x + 35, y - 25); } void eye(float eyeX, float eyeY) { fill(WHITE); ellipse(eyeX, eyeY, 12, 12); fill(RED); ellipse(eyeX, eyeY, 4, 4); } } //To professor, I forgot to tell you in our call today that my internet was down and for some reason, it did not allow my computer to run processing, that's why i did most of my work in my notebook because it was the only other place I could put it on. Sorry for the unfinished project 2 I handed in, but now that the internet came back, I'll do my best for project #3. Please stay safe from the virus.