xxxxxxxxxx
201
let room;
let nishFront;
let nishSide = [];
let nishChar;
let nishX = 50;
let nishY = 300;
let nishW, nishH;
let frame, frameO;
let nishCharRight = [];
let nishCharLeft = [];
let nishIndex39 = 0;
let nishIndex37 = 0;
let sceneNum = 0;
function preload() {
room = loadImage('assets/sampleroom.png');
nishFront = loadImage('char/nish-front.png');
nishSide0 = loadImage('char/nish-side0.png');
nishSide1 = loadImage('char/nish-side1.png');
nishSide2 = loadImage('char/nish-side2.png');
nishSide3 = loadImage('char/nish-side3.png');
nishSide4 = loadImage('char/nish-side4.png');
nishSide5 = loadImage('char/nish-side5.png');
nishBack = loadImage('char/nish-back.png');
frame = loadImage('objects/frame.png');
FOP = loadImage('assets/FrameOfPossibilities.png');
}
function setup() {
createCanvas(600, 400);
textAlign(CENTER);
nishChar = nishFront;
frameO = new Objects(390, 107, frame, 360);
roomHome = new HomeScene(0, room, 0);
}
function draw() {
background(225);
switch (sceneNum) {
case 0:
roomScene();
break;
case 1:
frameScene();
break;
}
nishra();
}
function roomScene() { // Scene 0
roomHome.body();
roomHome.move();
frameO.body();
}
function frameScene() { // Scene 1
// image(wall, 0, 0);
image(FOP, -10, -10);
fill(40);
textSize(25);
text("Frame of Possibilities", width / 2, 110);
fill(80);
textSize(16);
text("Poem will appear here!", width / 2, 200);
homePageNavi();
}
// 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
}
}
}
}
// 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 ((nishY > 280)) {
sceneNum = 0;
}
}
// Placement and movement of individual objects that has their own scenes
// only one example for now as others will depend on the artwork
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);
}