xxxxxxxxxx
517
const notesArray = [];
const stormsSong = [0, 1, 4, 0, 1, 4];
const forestSong = [1, 2, 3, 1, 2, 3];
const sunSong = [2, 1, 4, 2, 1, 4];
const horseSong = [4, 3, 2, 4, 3, 2];
const timeSong = [2, 0, 1, 2, 0, 1];
const lullabySong = [3, 4, 2, 3, 4, 2];
let stormsAudio;
let forestAudio;
let sunAudio;
let horseAudio;
let timeAudio;
let lullabyAudio;
let stormsVid;
let stormsSFX;
let forestGif;
let sunGif;
let horseVid;
let timeVid;
let lullabyVid;
let buttons = [];
//Typewriter Effect from: https://editor.p5js.org/pippinbarr/sketches/bjxEfpiwS
let stormsString = `
You remembered the thunderstorm . . .
And how nature is beauteous
in its indifference.`;
let forestString = `
You remembered the friends of the forest . . .
And how innocence and curiosity
need not be immature.`;
let sunString = `
You remembered the sun and the moon . . .
And how the past has looked at them,
how the future will look at them.`;
let horseString = `
You remembered the horses’s rhythmic gait . . .
And how each step taken by every being
is vastly idiosyncratic, decidedly personal.`;
let timeString = `
You remembered the flow of time . . .
And how its continuity is
callous yet reassuring.`;
let lullabyString = `
You remembered what it means . . .
To love someone, to care for someone,
to be cared for, to be loved. To live.`;
let pageMargin = 50;
let currentCharacter = 0;
let mainBG;
let textBG;
let memoryBG;
let finaleBG;
let button;
let songlist;
let gameState = 'Start Screen';
let connectState = false;
let stormsTrigger = false;
let horseTrigger = false;
let sunTrigger = false;
let forestTrigger = false;
let timeTrigger = false;
let lullabyTrigger = 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 &&
timeAudio.isPlaying() == false)
{return false;}
else {return true;}
}
function stormsMemory(){
let stormImg = stormsVid.get();
image(stormImg, 0, 0, 960, 540);
stormsVid.play();
tint(255, 150);
image(memoryBG, 40, 308, 880, 182);
noTint();
fill(185, 159, 102);
textSize(40);
//Typewriter Effect from: https://editor.p5js.org/pippinbarr/sketches/bjxEfpiwS
let currentString = stormsString.substring(0, currentCharacter);
push();
text(currentString, pageMargin + 10, 313, width - pageMargin*2, height - pageMargin);
pop();
currentCharacter += random(0.3, 0.5);
for(i = 0; i < 200; i++) {
raindrop[i].rain();
raindrop[i].reset();
}
}
function forestMemory(){
image(forestGif, 0, 0, 960, 540);
tint(255, 150);
image(memoryBG, 40, 308, 880, 182);
noTint();
fill(185, 159, 102);
textSize(40);
let currentString = forestString.substring(0, currentCharacter);
push();
text(currentString, pageMargin + 10, 313, width - pageMargin*2, height - pageMargin);
pop();
currentCharacter += random(0.3, 0.5);
}
function sunMemory(){
image(sunGif, 0, 0, 960, 540);
tint(255, 150);
image(memoryBG, 40, 308, 880, 182);
noTint();
fill(185, 159, 102);
textSize(40);
let currentString = sunString.substring(0, currentCharacter);
push();
text(currentString, pageMargin + 10, 313, width - pageMargin*2, height - pageMargin);
pop();
currentCharacter += random(0.2, 0.4);
}
function horseMemory(){
let horseImg = horseVid.get();
image(horseImg, 0, 0, 960, 540);
horseVid.play();
tint(255, 150);
image(memoryBG, 40, 308, 880, 182);
noTint();
fill(185, 159, 102);
textSize(40);
let currentString = horseString.substring(0, currentCharacter);
push();
text(currentString, pageMargin + 10, 313, width - pageMargin*2, height - pageMargin);
pop();
currentCharacter += random(0.3, 0.5);
}
function timeMemory(){
let timeImg = timeVid.get();
image(timeImg, 0, 0, 960, 540);
timeVid.play();
tint(255, 150);
image(memoryBG, 40, 308, 880, 182);
noTint();
fill(185, 159, 102);
textSize(40);
let currentString = timeString.substring(0, currentCharacter);
push();
text(currentString, pageMargin + 10, 313, width - pageMargin*2, height - pageMargin);
pop();
currentCharacter += random(0.3, 0.5);
}
function lullabyMemory(){
let lullabyImg = lullabyVid.get();
image(lullabyImg, 0, 0, 960, 540);
lullabyVid.play();
tint(255, 150);
image(memoryBG, 40, 308, 880, 182);
noTint();
fill(185, 159, 102);
textSize(40);
let currentString = lullabyString.substring(0, currentCharacter);
push();
text(currentString, pageMargin + 10, 313, width - pageMargin*2, height - pageMargin);
pop();
currentCharacter += random(0.3, 0.5);
}
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(){
noTint();
image(songlist, 40, 50, 880, 440);
fill(185, 159, 102);
textSize(40);
for (let i = 0; i < notesArray.length; i++){
let noteNumber = notesArray[i];
image(buttons[noteNumber], 335 + i * 55, 420);
}
tint(255, 220);
image(button, 675, 410, 225, 60);
textSize(35);
text("Done Playing", 680, 455);
}
function endScreen(){
noTint();
background(finaleBG);
fill(185, 159, 102);
textSize(100);
text("Thank You", 50, 200);
text("for Playing!", 60, 300);
tint(255, 220);
image(button, 70, 350, 280, 100);
textSize(40);
text("Back to Title", 85, 415);
}
function preload(){
mainBG = loadImage('BOTW Vista 1.jpeg');
textBG = loadImage('Map BG.png');
memoryBG = loadImage('Text BG.png');
finaleBG = loadImage('BOTW Vista 2.jpg');
songlist = loadImage('Songlist.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');
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');
timeAudio = loadSound('Song of Time.mp3');
timeVid = createVideo('Time Vid.mp4');
lullabyAudio = loadSound('Zeldas Lullaby.mp3');
lullabyVid = createVideo('Peace.mp4');
buttons[0] = loadImage("Red Button.png");
buttons[1] = loadImage("Yellow Button.png");
buttons[2] = loadImage("Green Button.png");
buttons[3] = loadImage("Blue Button.png");
buttons[4] = loadImage("White Button.png");
}
function setup() {
createCanvas(960, 540);
setUpSerial();
textFont(botwFont);
stormsVid.hide();
horseVid.hide();
timeVid.hide();
lullabyVid.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' && songPlaying() == false) {
mainMenu();
}
else if (gameState == 'End Screen' && songPlaying() == false){
endScreen();
}
if (stormsTrigger == true){
stormsMemory();
}
if (forestTrigger == true){
forestMemory();
}
if (sunTrigger == true){
sunMemory();
}
if (horseTrigger == true){
horseMemory();
}
if (timeTrigger == true){
timeMemory();
}
if (lullabyTrigger == true){
lullabyMemory();
}
if (songPlaying() == false){
stormsTrigger = false;
stormsVid.stop();
horseTrigger = false;
horseVid.stop();
sunTrigger = false;
forestTrigger = false;
timeTrigger = false;
timeVid.stop();
lullabyTrigger = false;
lullabyVid.stop();
currentCharacter = 0;
}
if ((songCheck(notesArray, stormsSong)) == true){
if (songPlaying() == false){
stormsAudio.play();
stormsSFX.play();
stormsTrigger = true;
}
}
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;
}
}
if ((songCheck(notesArray, timeSong)) == true){
if (songPlaying() == false){
timeAudio.play();
timeTrigger = true;
}
}
if ((songCheck(notesArray, lullabySong)) == true){
if (songPlaying() == false){
lullabyAudio.play();
lullabyTrigger = 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 if(connectState == false){
print("Connected", 20, 30);
connectState = true;
}
}
function keyPressed() {
if (key == " ") {
// important to have in order to start the serial connection!!
setUpSerial(SELECT_PORT);
}
}
function mousePressed() {
if (gameState == 'Start Screen') {
if (340 < mouseX && mouseX < 620 && 380 < mouseY && mouseY < 460){
gameState = 'Intro';
}
}
else if (gameState == 'Intro'){
if (620 < mouseX && mouseX < 900 && 410 < mouseY && mouseY < 470){
gameState = 'Main Menu';
}
}
else if (gameState == 'Main Menu'){
if (675 < mouseX && mouseX < 900 && 410 < mouseY && mouseY < 470){
gameState = 'End Screen';
}
}
else if (gameState == 'End Screen'){
if (70 < mouseX && mouseX < 350 && 350 < mouseY && mouseY < 450){
gameState = 'Start Screen';
}
}
}
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);
}
}
}
*/