xxxxxxxxxx
327
const notesArray = [];
const stormsSong = [0, 1, 4, 0, 1, 4];
const lullabySong = [3, 4, 2, 3, 4, 2];
const forestSong = [1, 2, 3, 1, 2, 3];
const sunSong = [2, 1, 4, 2, 1, 4];
const horseSong = [4, 3, 2, 4, 3, 2];
let stormsAudio;
let lullabyAudio;
let forestAudio;
let sunAudio;
let horseAudio;
let stormsVid;
let stormsSFX;
let horseVid;
let sunGif;
let forestGif;
let mainBG;
let textBG;
let button;
let gameState = 'Start Screen';
let stormsTrigger = false;
let horseTrigger = false;
let sunTrigger = false;
let forestTrigger = false;
let songPlay = true;
let raindrop = [];
let botwFont;
class Raindrop{
constructor(){
this.x = random(0, width);
this.y = random(0, -height);
}
rain(){
noStroke();
fill(255);
ellipse(this.x, this.y, random(1, 5), random(5, 10));
}
reset(){
this.speed = random(5, 10);
this.gravity = 3;
this.y = this.y + (this.speed * this.gravity);
if (this.y > height) {
this.y = random(0, -height);
this.gravity = 0;
}
}
}
function songCheck(s1, s2){
return s1.toString() == s2.toString();
}
function songPlaying(){
if (stormsAudio.isPlaying() == false &&
lullabyAudio.isPlaying() == false &&
forestAudio.isPlaying() == false &&
sunAudio.isPlaying() == false &&
horseAudio.isPlaying() == false &&
stormsSFX.isPlaying() == false)
{return false;}
else {return true;}
}
function startScreen(){
tint(255, 150);
image(textBG, 40, 50, 880, 440);
textSize(100);
fill(185, 159, 102);
text("Arduino of Time", 110, 175);
textSize(45);
text("A Small Project By Seo Yoon (Ian) Lee", 80, 275);
text("Inspired By the Legend of Zelda Series", 75, 340);
tint(255, 220);
image(button, 340, 380, 280, 80);
textSize(55);
text("START", 393, 440);
}
function intro(){
tint(255, 150);
image(textBG, 40, 50, 880, 440);
fill(185, 159, 102);
textSize(40);
text("They say music is the vessel of memory,", 100, 130);
text("and memory the muse of music.", 270, 190);
text("Waking up in a field with no recollection,", 100, 250);
text("the musical box in your hand is the only key.", 75, 310)
text("5 notes to play. 6 notes in a song.", 100, 370)
text("And in a song, a memory.", 150, 430);
tint(255, 220);
image(button, 620, 410, 280, 60);
text("N E X T", 675, 455)
}
function mainMenu(){
tint(255, 150);
image(textBG, 40, 50, 880, 440);
fill(185, 159, 102);
textSize(40);
text("Your song:" + notesArray, 150, 100);
}
function preload(){
mainBG = loadImage('BOTW Vista 1.jpeg');
textBG = loadImage('Map BG.png');
button = loadImage('BOTW Button.png');
botwFont = loadFont('BOTW Font.otf');
stormsAudio = loadSound('Song of Storms.mp3');
stormsSFX = loadSound('Storm.mp3');
stormsVid = createVideo('Storm Video.mp4');
lullabyAudio = loadSound('Zeldas Lullaby.mp3');
forestAudio = loadSound('Sarias Song.mp3');
forestGif = loadImage('Korok Gif.gif');
sunAudio = loadSound('Suns Song.mp3');
sunGif = loadImage('Sun Gif.gif');
horseAudio = loadSound('Eponas Song.mp3');
horseVid = createVideo('Epona Vid.mp4');
}
function setup() {
createCanvas(960, 540);
textFont(botwFont);
stormsVid.hide();
horseVid.hide();
for(i = 0; i < 200; i++){
raindrop[i] = new Raindrop();
}
}
function draw() {
background(mainBG);
if (gameState == 'Start Screen') {
startScreen();
}
else if (gameState == 'Intro') {
intro();
}
else if (gameState == 'Main Menu') {
mainMenu();
}
if (stormsTrigger == true){
let stormImg = stormsVid.get();
image(stormImg, 0, 0, 960, 540);
stormsVid.play();
for(i = 0; i < 200; i++) {
raindrop[i].rain();
raindrop[i].reset();
}
}
if (horseTrigger == true){
let horseImg = horseVid.get();
image(horseImg, 0, 0, 960, 540);
horseVid.play();
}
if (sunTrigger == true){
image(sunGif, 0, 0, 960, 540);
}
if (forestTrigger == true){
image(forestGif, 0, 0, 960, 540);
}
if (songPlaying() == false){
stormsTrigger = false;
stormsVid.stop();
horseTrigger = false;
horseVid.stop();
sunTrigger = false;
forestTrigger = false;
}
if ((songCheck(notesArray, stormsSong)) == true){
if (songPlaying() == false){
stormsAudio.play();
stormsSFX.play();
stormsTrigger = true;
}
}
if ((songCheck(notesArray, lullabySong)) == true){
if (songPlaying() == false){
lullabyAudio.play();
}
rect(0, 200, 20, 300);
}
if ((songCheck(notesArray, forestSong)) == true){
if (songPlaying() == false){
forestAudio.play();
forestTrigger = true;
forestGif.reset();
}
}
if ((songCheck(notesArray, sunSong)) == true){
if (songPlaying() == false){
sunAudio.play();
sunTrigger = true;
sunGif.reset();
}
}
if ((songCheck(notesArray, horseSong)) == true){
if (songPlaying() == false){
horseAudio.play();
horseTrigger = true;
}
}
notesNum = notesArray.length;
if (notesNum == 6 && songPlaying() == true){
for (i = 0; i < notesNum; i++){
notesArray.pop();
}
}
/*
notesNum = notesArray.length;
if (notesNum >= 5){
for (i = 0; i < notesNum; i++){
notesArray.pop();
}
}*/
if (!serialActive) {
print("Press Space Bar to select Serial Port", 20, 30);
} else {
print("Connected", 20, 30);
}
}
function keyPressed() {
if (key == " ") {
// important to have in order to start the serial connection!!
setUpSerial();
}
}
function mousePressed() {
//For Start Button
if (gameState == 'Start Screen') {
if (340 < mouseX && mouseX < 620 && 380 < mouseY && mouseY < 460){
gameState = 'Intro';
mainMenu();
}
} //For Finish Button
else if (gameState == 'Intro'){
if (620 < mouseX && mouseX < 900 && 410 < mouseY && mouseY < 470){
gameState = 'Main Menu';
intro();
}
}
else if (gameState == 'Main Menu'){
if (620 < mouseX && mouseX < 900 && 410 < mouseY && mouseY < 470){
gameState = 'Start Screen';
intro();
}
}
}
function readSerial(data) {
////////////////////////////////////
//READ FROM ARDUINO HERE
////////////////////////////////////
if (data != null) {
// make sure there is actually a message
let fromArduino = data;
if (notesNum >= 6){
for (i = 0; i < notesNum; i++){
notesArray.pop();
}
}
notesArray.push(data);
//////////////////////////////////
//SEND TO ARDUINO HERE (Handshake)
//////////////////////////////////
//let sendToArduino = left + "," + right + "\n";
//writeSerial(sendToArduino);
}
}
//Arudino Code
/*
void setup() {
Serial.begin(9600);
pinMode(2, OUTPUT);
pinMode(5, OUTPUT);
// start the handshake
while (Serial.available() <= 0) {
Serial.println("0,0"); // send a starting message
delay(300); // wait 1/3 second
}
}
void loop() {
// wait for data from p5 before doing something
while (Serial.available()) {
int left = Serial.parseInt();
int right = Serial.parseInt();
if (Serial.read() == '\n') {
digitalWrite(2, left);
digitalWrite(5, right);
int sensor = analogRead(A0);
delay(1);
int sensor2 = analogRead(A1);
delay(1);
Serial.print(sensor);
Serial.print(',');
Serial.println(sensor2);
}
}
}
*/