//Made by Christopher Tristano //Date of last modification // 3/3/14 /// //Project 2 ---- Gold, Heroes, Monsters, and things that tag along //Action instances PImage[] images = new PImage[3]; Monster monster; Pot pot; Dood dood; Bird[] birds = new Bird[5]; Dog[] dogs = new Dog[3]; //scene instances Cloud[] clouds = new Cloud[int(random(60))]; sceneRect atmosphere; sceneRect land; Sun sun; Moon moon; // variables float potX; //Pot x position float potY; //Pot y position float horizon; //y location of horizon int maxImages = 2; int imageIndex = 0; int score = 0; PFont f; void setup() { size(600,600); //Set window smooth(); //Create font f = createFont("Arial", 16, true); //Initialize sceneInitialize(); actionInitialize(); } //Draw loop void draw() { scene(); action(); notes(); } //Things to do when mouse is pressed void mousePressed() { potX = mouseX; //New pot of gold position x potY = mouseY; //New pot of gold position y imageChange(); //Change the image of Monster } //Action!!!!! void action() { birdMethods(); potMethods(); monsterMethods(); dogMethods(); doodMethods(); } void scene() { sky(); land(); } //Sky Stuff void sky() { //Clear Day if(clouds.length < 20) { atmosphere.display(0,0,255); sun.display(); cloudMethods(255,255,255); } //Cloudy Day if (clouds.length >= 20 && clouds.length < 40) { atmosphere.display(150,150,255); sun.display(); cloudMethods(200,200,200); } //Cloudy Night if (clouds.length >= 40) { atmosphere.display(0,0,0); moon.display(); cloudMethods(30,30,30); } //println(clouds.length); } //For loop that initializes all cloud objects void cloudInitialize() { for (int i = 0; i < clouds.length; i++) { //Cloud(x,y,speedX,t) clouds[i] = new Cloud((random(width)),random(255),0.4,0.4*(i+1), random(10,50)); } } //for loop that call all Cloud Methods void cloudMethods( float tempR, float tempG, float tempB) { for (int i = 0; i < clouds.length; i++) { clouds[i].display(tempR,tempG,tempB); clouds[i].move(); } } //Color of land void land() { rectMode(CORNER); fill(100,255,100); rect(0, horizon, width, height-horizon); } //Dog methods void dogMethods() { dogs[0].move(dood.x,dood.y); dogs[0].display(); for(int i = 1; i maxImages) { imageIndex = 0; } } //Notes void notes() { textFont(f); fill(0); textAlign(LEFT); text("Christopher Tristano",10,height*30/31); //Display Score! textAlign(CENTER); text("You're score is " + score, width/2,height*15/16); } //Bird class class Bird { float x,y,w,h; //Positions float speedX,speedY ; //Speed of bird movement float t; //Time float theta; //angle //Constructor Bird(float tempX, float tempY) { x = tempX; y = tempY; w = 30; h = 20; speedX = 3; speedY = 1; theta = 0; t = 1; } //Display Bird in window void display() { stroke(0); fill(200,200,250); triangle(x,y,x,y+h,x+w,y+h/2); } //Move bird across the screen void move() { x += speedX; y += noise(t)*(sin(theta))*speedY; t += 0.05; theta += 0.01; //if bird leaves the screen to the right, move him to the left side if (x > width) { x = -w; } if (y < -h) { speedY *= -1; } if (y > horizon) { speedY *= -1; } } } //Cloud Class class Cloud { float x,y,r; //position and radius float speedX,speedY; //speed of cloud float t; //Time float R,G,B; //Color //Constructor Cloud(float tempX, float tempY, float tempSpeedX, float tempT, float tempR) { x = tempX; y = tempY; speedX = tempSpeedX; t = tempT; r = tempR; speedY = 1; } //Dislay Cloud void display( float tempR, float tempG, float tempB) { R = tempR; G = tempG; B = tempG; noStroke(); fill(R,G,B); ellipse(x,y,r,r); ellipse(x+r/2,y+r/2,r,r); ellipse(x-r/2,y+r/2,r,r); ellipse(x-r/2,y-r/2,r,r); ellipse(x-r,y,r,r); ellipse(x+r,y,r,r); ellipse(x+r/2,y-r/2,r,r); } //Move cloud across the screen void move() { x += speedX; y += sin(t)/3.5; t += 0.01; if (x > width+r+r/2) { x = -r*3/2; } if (y > horizon + r) { y = -r; } if (y < -r) { y = horizon + r; } } } //Dog class class Dog { float x,y,w,h; //Position and Dimensions float ownerX,ownerY; //Position of dood float c; //color of animal //Constructor Dog(float tempW, float tempH, float tempC) { x = 0; y = 0; w = tempW; h = tempH; c = tempC; ownerX = 0; ownerY = 0; } //Display dog on screen void display() { ////Dog look right if (x < ownerX) { //Body stroke(0); fill(100,c,50); ellipse(x,y,w,h); //tail stroke(0); line(x-w/3,y,x-w,y-h); ellipse(x-w,y-h,w/5,h/5); //neck stroke(0); line(x+w/3,y-h/3,x+w,y-h); //head pushMatrix(); translate(x+w*4/3,y-h*4/3); rotate(radians(30)); stroke(0); fill(50,c,100); ellipse(0,0,w*5/3,h*4/3); popMatrix(); //ears stroke(0); fill(50,c,100); ellipse(x+w,y-h,h/2,w); //Nose stroke(0); fill(0); ellipse(x+w*2,y-h,w/3,h/2); //eyes stroke(0); fill(255); ellipse(x+w*4/3,y-h*5/3,w/3,h/2); ellipse(x+w*7/4,y-h*5/3,w/3,h/2); //pupils stroke(0); fill(0); ellipse(x+w*7/4,y-h*5/3,w/10,h/8); ellipse(x+w*4/3,y-h*5/3,w/10,h/8); } else { ////Dog look left //Body stroke(0); fill(50,c,100); ellipse(x,y,w,h); //tail stroke(0); line(x+w/3,y,x+w,y-h); ellipse(x+w,y-h,w/5,h/5); //neck stroke(0); line(x-w/3,y-h/3,x-w,y-h); //head pushMatrix(); translate(x-w*4/3,y-h*4/3); rotate(radians(150)); stroke(0); fill(50,c,100); ellipse(0,0,w*5/3,h*4/3); popMatrix(); //ears stroke(0); fill(50,c,100); ellipse(x-w,y-h,h/2,w); //Nose stroke(0); fill(0); ellipse(x-w*2,y-h,w/3,h/2); //eyes stroke(0); fill(255); ellipse(x-w*4/3,y-h*5/3,w/3,h/2); ellipse(x-w*7/4,y-h*5/3,w/3,h/2); //pupils stroke(0); fill(0); ellipse(x-w*7/4,y-h*5/3,w/10,h/8); ellipse(x-w*4/3,y-h*5/3,w/10,h/8); } } //Move dog towards the Owner void move(float tempOwnerX, float tempOwnerY) { ownerX = tempOwnerX; ownerY = tempOwnerY; x = x + (ownerX - x)/40; y = y + (ownerY - y)/40; } void jiggle() { x = x + random(-2,2); } } //Dood Class class Dood { //Dood Variables float x,y,w,h,eyeSize; float theta; //Dood Constructor Dood() { x = width/3; y = height/3; w = width/10; h = height/10; eyeSize = w/4; theta = 0.0; } //Jiggle Dood void breathe( ) { w = w - sin(theta)/8; h = h - sin(theta)/10; theta += 0.02; } //Display doody Boy void display() { //set ellipse and rect origin to center ellipseMode(CENTER); rectMode(CENTER); //for Dood cilia for(float i = y+h/12; i potY){ //arms dawg line(x-w/6,y+h/12,x-w/3,y+h/2); line(x+w/6,y+h/12,x+w/3,y+h/2); //rectangle body stroke(0); fill(255,0,200); rect(x,y,w/2,h*5/3); //hoody fill(255,0,200); ellipse(x,y - h*7/12,w*17/12,h*13/12); noStroke(); ellipse(x, y-h/2, w*4/3, h); } else { //rectangle body stroke(0); fill(255,0,200); rect(x,y,w/2,h*5/3); //arms dawg line(x-w/6,y+h/12,x-w/3,y+h/2); line(x+w/6,y+h/12,x+w/3,y+h/2); //hoody stroke(0); ellipse(x,y - h*7/12,w*17/12,h*13/12); //head fill(255,200,150); ellipse(x, y-h/2, w*4/3, h); //eyeballs fill(255-(mouseX+mouseY)/2,255-mouseY,255-mouseX); ellipse(x-w/3,y-h/2,eyeSize,eyeSize); ellipse(x+w/3,y-h/2,eyeSize,eyeSize); //Mouth triangle(x-w/6,y-h/4,x+w/6,y-h/4,x,y-h/12); } //legs yo stroke(0); line(x-w/6,y+h*5/6,x-w/3,y+h); line(x+w/6,y+h*5/6,x+w/3,y+h); //feet fill(0); stroke(0); ellipse(x+w/3,y+h,w/6,h/12); ellipse(x-w/3,y+h,w/6,h/12); } void move() { x = x + (potX - x)/60; y = y + (potY - y)/60; }} //Monster Class class Monster { float x,y; //Position of monster float w; //Constructor Monster() { x = random(width); y = random(height); w = 20; } //Display Monster in window void display(int tempImageIndex) { imageMode(CENTER); image(images[tempImageIndex],x,y); } //Move Monster toward the Owner void move(float ownerX, float ownerY) { x = x + (ownerX - x)/200; y = y + (ownerY - y)/200; } boolean intersect(Dood d) { float distance = dist(x,y,d.x,d.y); //Calculate Distance if (distance < w + d.w) { return true; } else { return false; } } void resetMonster(float tempX, float tempY) { x = tempX; y = tempY; } } //Moon class class Moon { float x,y,r; //position and radius //constructor Moon() { //Moon Position x = width/random(1,4); y = height/8; //Moon radius r = 50; } //display moon object on the screen void display() { ellipseMode(CENTER); noStroke(); fill(255); ellipse(x,y,r,r); } } //Pot Class class Pot { float x,y,w,h,r; //Position and dimensions //Pot Constructor Pot() { x = width/2; y = height/2; w = 30; h = 30; r = 10; //gold radius } //Dislplay Pot in the window void display(float tempX,float tempY) { x = tempX; y = tempY; ellipseMode(CENTER); stroke(0); fill(0,0,0); ellipse(x,y,w,h); //Base stroke(0); ellipse(x,y-h/2,w,h/3); //Top stroke(200,150,40,int(random(255))); fill(200,255,40); ellipse(x,y-h*2/3,r,r); ellipse(x-w/3,y-h*2/3,r,r); ellipse(x+w/3,y-h*2/3,r,r); ellipse(x,y-h*5/6,r,r); ellipse(x-w/6,y-h*3/4,r,r); ellipse(x+w/6,y-h*3/4,r,r); } } //Sun Class class Sun { float x,y,r; //position and radius //Constructer Sun() { //suns position x = width/int(random(1,4)); y = height/8; //Suns radius r = 80; } //display the sun object on the screen void display() { ellipseMode(CENTER); stroke(0); fill(255,255,0); ellipse(x,y,r,r); } } //Scene rectangles class sceneRect { float x,y,w,h; //position and dimension sceneRect(float tempX,float tempY, float tempW, float tempH) { x = tempX; y = tempY; w = tempW; h = tempH; } void display( float r, float g, float b) { rectMode(CORNER); noStroke(); fill(r,g,b); rect(x,y,w,h); } }