xxxxxxxxxx
564
// Thanks Olivier for the help!
// array colliion detection from: https://stackoverflow.com/questions/64724183/collision-detection-of-array-objects
// Twinkling Stars from: https://editor.p5js.org/wvnl/sketches/5wnuHAXKd
let stars = [];
let clouds = [];
let timekeeper = [];
let timekNum = 4;
let fps = 60;
let currSec = 0;
let localFC = 0;
let scene = 0;
let cloudNum = 5;
let myFont;
let title_S, meImg, carmine, hourgalss, memory1, memory2, memory3, memory4, me, me2, vid, textbox, audio1, audio2, audio3, audio4, instruction;
let y = 0;
let x = 0;
let n = 0;
function preload() {
myFont = loadFont("Pixel.ttf");
myFont2 = loadFont("PixelSa.ttf");
title_S = loadImage('Title.png');
cloud_1 = loadImage('Cloud_1.png');
meImg = loadImage('meImg.png');
carmine = loadImage('carmine.png');
vid = createVideo('transition.mp4');
hourglass = loadImage('hourglass.png');
memory1 = loadImage('memory1.png');
memory2 = loadImage('memory2.png');
memory3 = loadImage('memory3.png');
memory4 = loadImage('memory4.png');
textbox = loadImage('TextBox.png');
instruction = loadImage('instructions.png')
audio1 = loadSound('opening.mp3');
audio2 = loadSound('NYC.wav');
audio3 = loadSound('spiral.mp3');
audio4 = loadSound('hourglassR.wav');
}
function setup() {
createCanvas(640, 360);
noStroke();
frameRate(fps);
y = 359;
vid.loop();
vid.hide();
for (let i = 0; i < cloudNum; i++) {
clouds[i] = new Cloud(random(width), random(height - 180));
}
// avatar 1 degree of movement
me = new Emi(10, 220);
// avatar 8 degrees of movement
me2 = new Emi(20, 300);
for (let i = 0; i < timekNum; i++) {
timekeeper[i] = new HourGlass(100, height / 2);
}
for (var i = 0; i < 1000; i++) {
stars[i] = new Star();
}
}
function draw() {
let checkScene = scene;
localFC++;
switch (scene) {
case 0:
clear();
audio4.stop();
title_scene();
break;
case 1:
clear();
audio1.stop();
instructions();
break;
case 2:
clear();
backStory();
break;
case 3:
clear();
appartment();
// me.body();
break;
case 4:
clear();
audio2.stop();
cutScene();
break;
case 5:
clear();
audio3.stop();
hourGlassroom1();
break;
case 6:
clear();
memory_1();
break;
case 7:
clear();
hourGlassroom2();
break;
case 8:
clear();
memory_2();
break;
case 9:
clear();
hourGlassroom3();
break;
case 10:
clear();
memory_3();
break;
case 11:
clear();
hourGlassroom4();
break;
case 12:
clear();
memory_4();
break;
case 13:
clear();
endScene();
break;
}
if (checkScene !== scene) {
localFC = 0;
}
}
function title_scene() {
push();
background(41, 171, 226);
for (let i = 0; i < cloudNum; i++) {
clouds[i].body();
clouds[i].move();
}
image(title_S, -250, 10);
textFont(myFont);
textSize(38);
fill(208, 21, 76);
text('The Journey', 60, 100);
text('Home', 160, 145);
textSize(20);
text('START', 185, 200);
if (!audio1.isPlaying()) {
audio1.play();
audio1.setVolume(0.2);
}
pop();
}
function mouseClicked() {
if (mouseY >= 180 && mouseY <= 200 && mouseX >= 185 && mouseX <= 270 && scene == 0) {
scene++
}
}
function instructions() {
background(0);
image(instruction, 0, 0, 640, 360);
if (localFC == 250) {
scene++
}
}
function backStory() {
push();
background(0);
let s = `After unsuccessfully applying 3 times for an H1B visa, I followed my lawyer's advice to enroll in ANYTHING that would grant me a student visa. I decided to pursue one of my dreams, and to enroll in flight school.
I left NYC at the end of November 2014 to get my new F1 visa and spend Xmas with my family, with plans to return to NYC at the end of January to start my training.
Unfortunately, the American Embassy in Milan had different plans. They denied my request for a new F1 and, for all intents, locked me out of the USA.
I will finally be able to go back to the States and to my apartment in January 2021 after more than 6 years! Much has changed during all these years. The city has changed, friends have moved away, relationships have ended. What did not change is my apartment, a sealed time capsule stuck in 2014.`
fill(255)
textSize(15);
textLeading(25);
textFont(myFont2);
text(s, 35, y, 600, height * 10)
y -= 0.5;
if (y < -600) {
scene++;
}
pop();
}
function appartment() {
push();
image(carmine, 0, 0);
textFont(myFont);
textSize(20);
fill(255, 255, 255);
text('13', 240, 190);
me.body();
me.move();
if (!audio2.isPlaying()) {
audio2.play();
audio2.setVolume(0.1);
}
pop();
}
function cutScene() {
push();
background(0);
image(vid, 80, -20);
// vid.loop();
me.rotate();
if (!audio3.isPlaying()) {
audio3.play();
audio3.setVolume(0.1);
}
pop();
}
function hourGlassroom1() {
push();
background(25, 25, 50);
for (var i = 0; i < stars.length; i++) {
stars[i].body();
}
for (let i = 0; i < timekNum; i++) {
timekeeper[i].body(i);
}
me2.body();
me2.move2();
timekeeper[0].checkCollision(6);
if (!audio4.isPlaying()) {
audio4.loop();
audio4.setVolume(0.1);
}
pop();
}
function hourGlassroom2() {
push();
background(25, 25, 50)
for (var i = 0; i < stars.length; i++) {
stars[i].body();
}
for (let i = 0; i < timekNum; i++) {
timekeeper[i].body(i);
}
me2.body();
me2.move2();
timekeeper[1].checkCollision(8);
pop();
}
function hourGlassroom3() {
push();
background(25, 25, 50);
for (var i = 0; i < stars.length; i++) {
stars[i].body();
}
for (let i = 0; i < timekNum; i++) {
timekeeper[i].body(i);
}
me2.body();
me2.move2();
timekeeper[2].checkCollision(10);
pop();
}
function hourGlassroom4() {
push();
background(25, 25, 50);
for (var i = 0; i < stars.length; i++) {
stars[i].body();
}
for (let i = 0; i < timekNum; i++) {
timekeeper[i].body(i);
}
me2.body();
me2.move2();
timekeeper[3].checkCollision(12);
pop();
}
function memory_1() {
push();
backTo7();
image(memory1, 0, 0);
image(textbox, 310, 30, width / 2.4, height / 5.2);
fill(0);
textSize(12);
textLeading(16);
textFont(myFont2);
if (localFC === 1) {
n = 0;
}
if (localFC % 10 === 0) {
n++;
}
let sentence = 'My first fligth lesson \nwith my then girlfriend.';
text(sentence.substring(0, n + 1), 330, 60);
pop();
}
function memory_2() {
push();
backTo9();
image(memory2, 0, 0);
image(textbox, 300, 10, width / 2, height / 3.5);
fill(0);
textSize(12);
textLeading(16);
textFont(myFont2)
if (localFC === 1) {
n = 0;
}
if (localFC % 10 === 0) {
n++;
}
let sentence = 'My best friends \nPhilippe, Luca, and Andrea \nwith whom I share \nunforgettable memories.';
text(sentence.substring(0, n + 1), 330, 43);
pop();
}
function memory_3() {
push();
backTo11();
image(memory3, 0, 0);
image(textbox, 287, 10, width / 1.9, height / 6);
fill(0);
textSize(12);
textLeading(16);
textFont(myFont2);
if (localFC === 1) {
n = 0;
}
if (localFC % 10 === 0) {
n++;
}
let sentence = 'The endless open-air parties.';
text(sentence.substring(0, n + 1), 310, 43);
pop();
}
function memory_4() {
push();
toEnd();
image(memory4, 0, 0);
image(textbox, 260, 10, width / 1.78, height / 6);
fill(0);
textSize(12);
textLeading(16);
textFont(myFont2);
if (localFC === 1) {
n = 0;
}
if (localFC % 10 === 0) {
n++;
}
let sentence = 'The friends met along the way.';
text(sentence.substring(0, n + 1), 285, 43);
pop();
}
function endScene() {
push();
background(0);
textAlign(CENTER, CENTER);
textFont(myFont);
textSize(38);
fill(255);
text('Welcome home! \nA new chapter \n awaits you!', width / 2, height / 2.5);
textFont(myFont);
textSize(15);
fill(255);
text('Press Enter to restart', width / 2, height / 1.3);
backToStart();
pop();
}
function resetSketch(){
// avatar 1 degree of movement
me = new Emi(10, 220);
// avatar 8 degrees of movement
me2 = new Emi(20, 300);
}
function backTo7() {
if (keyIsDown(8)) {
scene = 7;
}
}
function backTo9() {
if (keyIsDown(8)) {
scene = 9;
}
}
function backTo11() {
if (keyIsDown(8)) {
scene = 11;
}
}
function toEnd() {
if (keyIsDown(8)) {
scene = 13;
}
}
function backToStart() {
if (keyIsDown(13)) {
scene = 0;
resetSketch();
localFC = 0;
}
}
class Cloud {
constructor(x, y) {
this.x = x;
this.y = y;
this.w = 10;
this.h = 15;
}
body() {
push();
rect(this.x, this.y, this.w, this.h);
imageMode(CENTER);
image(cloud_1, this.x, this.y, cloud_1.width / 2, cloud_1.height / 2);
pop();
}
move() {
this.x -= 0.4;
if (this.x < 0) {
this.x = width;
}
}
}
class Emi {
constructor(x, y) {
this.x = x;
this.y = y;
this.w = 10;
this.h = 15;
}
body() {
push();
image(meImg, this.x, this.y, meImg.width / 10, meImg.height / 10);
pop();
}
rotate() {
imageMode(CENTER)
x += 0.02;
translate(width / 2, height / 2);
rotate(x);
image(meImg, 0, 0, (meImg.width / 6) / (localFC / 50), (meImg.height / 6) / (localFC / 50));
if (localFC > 200) {
scene++;
}
}
move() {
if (keyIsDown(39)) {
this.x += 3;
if (this.x > 240) {
scene++;
}
}
}
move2() {
if (keyIsDown(39)) {
this.x += 2;
}
if (keyIsDown(37)) {
this.x -= 2;
}
if (keyIsDown(40)) {
this.y += 2;
}
if (keyIsDown(38)) {
this.y -= 2;
}
}
}
class HourGlass {
constructor(x, y) {
this.x = x;
this.y = y;
this.w = 60
this.h = 80
}
body(i) {
imageMode(CENTER);
this.x = 100 + (i * 150);
this.y = (height / 2) + (sin(localFC / (i + 10)) * (i + 20));
image(hourglass, this.x, this.y, this.w, this.h);
}
checkCollision(sceneWanted) {
if (me2.x + me2.w > this.x && me2.x < this.x + me2.w && me2.y + me2.h > this.y && me2.y < this.y + this.h) {
scene = sceneWanted;
}
}
}
class Star {
constructor() {
this.x = random(width);
this.y = random(height);
this.size = random(0.25, 3);
this.t = random(TAU);
}
body() {
this.t += 0.1;
var scale = this.size + sin(this.t) * 2;
noStroke();
fill(255);
rect(this.x, this.y, scale, scale);
}
}