xxxxxxxxxx
307
// Music Source: https://www.youtube.com/watch?v=cpin7TtVWq0
let room;
let nishFront;
let nishSide = [];
let nishChar;
let nishX = 50;
let nishY = 300;
let nishW, nishH;
let frame, frameO, mum, mumO, didi, didiO, dad, dadO, mumbai, mumbaiO, auro, auroO, lib, libO, cam, camO, plants, plantsO;
let nishCharRight = [];
let nishCharLeft = [];
let nishIndex39 = 0;
let nishIndex37 = 0;
let sceneNum = 0;
let mumbaiX = 0;
let auroX = 0;
let speed = 1
function setup() {
createCanvas(600, 400);
textAlign(CENTER);
textFont(veteranFont);
nishChar = nishFront;
// O at the end of each name is for Object
frameO = new Objects(360, 107, frame, 360);
mumO = new Objects(686, 108, mum, 686);
didiO = new Objects(806, 130, didi, 806);
dadO = new Objects(930, 110, dad, 930);
mumbaiO = new Objects(1273, 100, mumbai, 1273);
auroO = new Objects(1828, 100, auro, 1828);
libO = new Objects(1593, 40, lib, 1593);
camO = new Objects(2165, 84, cam, 2165);
plantsO = new Objects(2277, 126, plants, 2277);
roomHome = new HomeScene(0, room, 0);
intro = new HomeScene(15, null, 15);
exit = new HomeScene(2660, null, 2660);
music = new HomeScene(250, null, 250);
backgroundMusic.play();
backgroundMusic.loop();
}
function draw() {
background(225);
switch (sceneNum) {
case 0:
roomScene();
break;
case 1:
frameScene();
break;
case 2:
easelMumScene();
break;
case 3:
easelDidiScene();
break;
case 4:
easelDadScene();
break;
case 5:
mumbaiScene();
break;
case 6:
libraryScene();
break;
case 7:
aurovilleScene();
break;
case 8:
photographyScene();
break;
case 9:
plantsScene();
break;
}
nishra();
}
// Room Background + Text (Home Scene)
class HomeScene {
constructor(x, object, limit) {
this.x = x
this.limit = limit // so that the room doesn't slide away out of Canvas
this.object = object
}
body() { // Room
image(this.object, this.x, 0);
}
// setting up movement of the Room and intro text based on arrow keys
move() {
if (keyIsDown(39)) {
this.x -= 4
if (this.x == -(room.width - width)) {
this.x += 4
}
}
if (keyIsDown(37)) {
this.x += 4
if (this.x == this.limit) {
this.x -= 4
}
if (this.x > this.limit) {
this.x = this.limit
}
}
}
textBody() { // Intro text
fill(80);
textSize(17);
push();
textAlign(LEFT);
// so that text appears one after another
if (frameCount > 5) {
text("Welcome to", this.x, 75);
}
if (frameCount > 120) {
fill(0);
text("Nishra's Fortress of Solitude!", this.x, 100);
}
if (frameCount > 240) {
fill(80);
text("Look closely, use arrow keys,", this.x, 135);
}
if (frameCount > 360) {
text("to let Nishra guide you", this.x, 160);
}
if (frameCount > 480) {
text("into her Realms of Solitude... ", this.x, 185);
}
pop();
}
textBody1() { // Music Info
push();
textAlign(RIGHT);
textSize(11);
fill(80)
text("Music: 'Vincent' by Don McLean", this.x, 260);
pop();
}
textBody2() { // Exit text
push();
textAlign(RIGHT);
text("Hope you enjoyed exploring \nNishra's Inspirations ", this.x, 135);
pop();
}
move2() { // setting up movement of exit text based on arrow keys
if (keyIsDown(39)) {
this.x -= 4
if (this.x == -(room.width - width)) {
this.x += 4
}
if (this.x == 580) {
this.x += 4
}
}
if (keyIsDown(37)) {
this.x += 4
if (this.x == this.limit) {
this.x -= 4
}
if (this.x > this.limit) {
this.x = this.limit
}
}
}
}
// Main Character + Movements that will define the Scene change
function nishra() {
nishCharRight = [nishSide0, nishSide1, nishSide2, nishSide1];
nishCharLeft = [nishSide3, nishSide4, nishSide5, nishSide4];
push();
imageMode(CENTER);
image(nishChar, nishX, nishY);
pop();
if (keyIsDown(39)) {
nishX++
nishChar = nishCharRight[Math.floor(nishIndex39)];
if (nishX == 500) {
nishX--
}
nishIndex39+=0.09;
if (Math.floor(nishIndex39) === nishCharRight.length) {
nishIndex39 = 0;
}
} else if (keyIsDown(37)) {
nishX--
nishChar = nishCharLeft[Math.floor(nishIndex37)];
if (nishX == 40) {
nishX++
}
nishIndex37+=0.09;
if (Math.floor(nishIndex37) === nishCharLeft.length) {
nishIndex37 = 0;
}
}
if (keyIsDown(38)) {
nishY--
nishChar = nishBack;
if (nishY < 190) {
nishY++
}
}
if (keyIsDown(40)) {
nishY++
nishChar = nishFront;
}
if (nishY > 310) {
nishY--
}
if (sceneNum == 0) {
if (dist(nishX, nishY, frameO.x + (frame.width / 2), frameO.y) < 120) {
sceneNum = 1;
}
if (dist(nishX, nishY, mumO.x + (mum.width / 2), mumO.y) < 120) {
sceneNum = 2;
}
if (dist(nishX, nishY, didiO.x + (didi.width / 2), didiO.y) < 120) {
sceneNum = 3;
}
if (dist(nishX, nishY, dadO.x + (dad.width / 2), dadO.y) < 120) {
sceneNum = 4;
}
if (dist(nishX, nishY, mumbaiO.x + (mumbai.width / 2), mumbaiO.y) < 120) {
sceneNum = 5;
}
if (dist(nishX, nishY, libO.x + (lib.width / 2), libO.y + 50) < 120) {
sceneNum = 6;
}
if (dist(nishX, nishY, auroO.x + (auro.width / 2), auroO.y) < 120) {
sceneNum = 7;
}
if (dist(nishX, nishY, camO.x + (cam.width / 2), camO.y + 10) < 120) {
sceneNum = 8;
}
if (dist(nishX, nishY, plantsO.x + (plants.width / 2), plantsO.y) < 120) {
sceneNum = 9;
}
}
if ((nishY > 280)) {
sceneNum = 0;
}
}
// Placement and movement of individual objects that has their own scenes
class Objects {
constructor(x, y, object, limitL) {
this.x = x;
this.y = y;
this.object = object;
this.limitR = -(room.width - this.x - width);
this.limitL = limitL;
}
body() {
image(this.object, this.x, this.y);
if (keyIsDown(39)) {
this.x -= 4;
if (this.x == this.limitR) {
this.x += 4;
}
}
if (keyIsDown(37)) {
this.x += 4;
if (this.x > this.limitL) {
this.x -= 4;
}
}
}
}
function homePageNavi() { // Instructions to return to Scene 0
fill(255, 180);
noStroke();
rect(0, 375, width, height);
textSize(16);
fill(80);
text("W a n d e r b a c k h e r e t o r e t u r n t o R e a l i t y !", width / 2, 395);
}