package main; import processing.core.*; import graphic.Moving; import graphic.Mountain; import graphic.Moon; import sound.DaySound; import sound.NightSound; import text.Text; import java.util.ArrayList; import controlP5.*; import noise.NoiseGenerator; public class D104_Yiting_Long_FinalProject_301183087 extends PApplet{ public ArrayList movingList = new ArrayList(); PImage sky; float yOff; float xOff; float xStar; float xSun; float ySun; float yStar; Text text; PImage smile; PImage backImage; boolean changeMood; boolean closeProgram; PFont font; ControlP5 controlP5; Button dayTimeButton; Button nightTimeButton; NoiseGenerator noiseObject; Moon second; Mountain minute; DaySound daySound; NightSound nightSound; int shoreColor; int starColor; int sunColor; int birdColor; int moonColor; int state; int buttonColorLeft; int buttonColorRight; public void setup(){ smooth(); size(500,500); frameRate(10); background(255); yOff = 0; xOff = 0; xSun = 80; ySun = 100; state = 0; changeMood = false; closeProgram = false; buttonColorLeft = color(0, 102, 153); buttonColorRight = color(0, 102, 153); controlP5 = new ControlP5(this); text = new Text(this); font = createFont("Berlin Sans FB", 40, true); textFont(font, 60); try{ backImage = loadImage("../images/grass.png"); smile = loadImage("../images/smile.png"); sky = loadImage("../images/Sky.png"); }catch(NullPointerException e){ println("There is an error with the image file."); } starColor = color(255,252,225); sunColor = color(245,111,22); birdColor = color(105); moonColor = color(250,250,210); minute = new Mountain(this,noiseObject, xSun, ySun,moonColor); if(hour() >= 12){ for(int i = 0; i < hour(); i++){ movingList.add(new Moving (this, noiseObject, random(500), random(250), starColor)); } second = new Moon(this,noiseObject, xSun, ySun,moonColor); }else{ for(int i = 0; i < hour(); i++){ movingList.add(new Moving (this, noiseObject, random(500), random(250), birdColor)); } second = new Moon(this,noiseObject, xSun, ySun,sunColor); } noiseObject = new NoiseGenerator(this); } public void keyPressed(){ changeMood = true; } public void keyReleased(){ changeMood = false; } public void draw(){ switch(state){ case 0: intro(); break; case 1: dayTime(); break; case 2: nightTime(); break; case 3: end(); break; } } void intro(){ imageMode(CORNER); image(backImage, 0, 0); text.displayTitle(); fill(buttonColorLeft); noStroke(); rectMode(CORNER); rect(95, 287, 110, 25); fill(buttonColorRight); rect(295, 287, 110, 25); text.displayOptions(); if(mouseX > 295 && mouseX < 405 && mouseY > 287 && mouseY < 312){ buttonColorRight = color(132, 220, 245); }else if (mouseX > 95 && mouseX < 205 && mouseY > 287&& mouseY < 312){ buttonColorLeft = color(132, 220, 245); }else{ buttonColorLeft = color(0, 102, 153); buttonColorRight = color(0, 102, 153); } if(mousePressed == true && mouseButton == LEFT){ if(mouseX > 295 && mouseX < 405 && mouseY > 287 && mouseY < 312){ state = 2; nightSound = new NightSound(this); nightSound.nightSound(); }else if(mouseX > 95 && mouseX < 205 && mouseY > 287&& mouseY < 312){ state = 1; daySound = new DaySound(this); daySound.daySound(); } } if(mousePressed == true && mouseButton == RIGHT){ state = 3; } } void dayTime(){ if(changeMood){ daySound.dayTime.pause(); state = 2; nightSound = new NightSound(this); nightSound.nightSound(); } if(mousePressed == true && mouseButton == RIGHT){ daySound.dayTime.pause(); state = 3; } imageMode(CORNER); image(sky,0,0,width,height); for (int n = 0; n < movingList.size(); n++){ Moving currentBird = movingList.get(n); currentBird.drawMeDaytime(); } minute.drawMe(); } void nightTime(){ if(changeMood){ nightSound.nightTime.pause(); state = 1; daySound = new DaySound(this); daySound.daySound(); } if(mousePressed == true && mouseButton == RIGHT){ nightSound.nightTime.pause(); state = 3; } background(0,0,50); for (int n = 0; n < movingList.size(); n++){ Moving currentStar = movingList.get(n); currentStar.drawMe(); } second.drawMeNight(); minute.drawMeNight(); } public void end(){ background(255); text.displayEnd(); imageMode(CENTER); image(smile, 250, 300); } }