The scenes will tell you how to interact, otherwise check the description block at the top of the code
A fork of Final Project by Evaine Sun
xxxxxxxxxx
/*Our final project is a choose your own adventure experience through a haunted house theme. There are animations, mini-games, sounds, and other interactive qualities
within the routes you can take in the house.
There are instructions for every scene on how to interact and get to the next scene.
Kai: Press 'space' to go from scene 1 to 2. Then choose out of the four options. Press 'k' to go to scene3k. Use the mouse to click on an ending.
Evaine: background IP is Roco Kingdom. Press "e" to go to my first scene. Find the 5 differences and press "f" to go to my second scene. Click the 5 objects and double click the middle one to go to win scene.
For Justine's scene, press 'm' to start. For Neha's, press 'z' to jump.
*/
//Kai's global variables
var titlefont;
var scene1background;
var batimage;
var witchimage;
var candiesimage;
var ratimage;
let startsound;
var blink = 0;
let frames = 3;
var death = false;
var escape = false;
//end Kai's variables
//Justine's global variables
let locationx, velocityx;
let newlocation = []
let newvelocity = [];
let difficulty = 0;
let textfont;
let spookymusicmp3;
//end Justine's global variables
//Neha's global variables
var spongebobimage;
var sand;
var backgroundimg;
var gameover;
var isgameover;
var mum;
var yspeed;
var changey;
var xspeed, xspeed2, yspeed2;
var changey2, changex, changex2;
var spacecounter;
//end Neha's global variables
function preload(){
//Kai's preloads:
titlefont = loadFont('Gypsy Curse.ttf');
batimage = loadImage('batsprite.png');
witchimage = loadImage('witch3k.png');
candiesimage = loadImage('candies.png');
ratimage = loadImage('rat.png');
scene1background = loadImage('startscene.jpg');
scene2background = loadImage('scene2pic.png');
scene3kbackground = loadImage('scene3kpic.jpg');
startsound = loadSound('scene1sound.mp3');
wcackle = loadSound('witchlaugh.mp3');
wscream = loadSound('scream.mp3');
//end Kai's preloads
//Justine's preloads
startimage = loadImage('spookyarcade.jpg');
//spookymusicmp3 = loadSound('spookymusic.mp3');
//end Justine's preloads
//Neha's preloads
spongebobimage = loadImage('person.png');
backgroundimg = loadImage('mummy.jpg');
mum = loadImage('obs.png');
sand = loadImage('sand.png');
gameover = loadImage('gameover.jpg');
//end Neha's preloads
E_background1 = loadImage('E_Hall.jpg'); // Evaine: background of SCENE 3E
E_background2 = loadImage('E_Hall_Again.jpg'); // Evaine: background of SCENE 4E
E_sound1 = loadSound('E_Sound1.mp3'); // Evaine: sound of SCENE 3E
E_sound2 = loadSound('E_Sound2.mp3'); // Evaine: sound of SCENE 4E
loadImage('E_Candle1.png'); // Evaine: image of left candle in SCENE 3E and its src below
E_srccandle1 = 'https://deckard.openprocessing.org/user285108/visual1395888/ha535128fd5bbe92fbca45d81b025b2f0/E_Candle1.png';
loadImage('E_Candle2.png'); // Evaine: image of right candle in SCENE 3E and its src below
E_srccandle2 = 'https://deckard.openprocessing.org/user285108/visual1395888/ha535128fd5bbe92fbca45d81b025b2f0/E_Candle2.png';
loadImage('E_Broom.png'); // Evaine: image of broom in SCENE 3E and its src below
E_srcbroom = 'https://deckard.openprocessing.org/user285108/visual1395888/ha535128fd5bbe92fbca45d81b025b2f0/E_Broom.png';
loadImage('E_Carpet.png'); // Evaine: image of carpet in SCENE 3E and its src below
E_srccarpet = 'https://deckard.openprocessing.org/user285108/visual1395888/ha535128fd5bbe92fbca45d81b025b2f0/E_Carpet.png';
loadImage('E_Sword.png'); // Evaine: image of sword in SCENE 3E and its src below
E_srcsword = 'https://deckard.openprocessing.org/user285108/visual1395888/ha535128fd5bbe92fbca45d81b025b2f0/E_Sword.png';
loadImage('E_Flame.png'); // Evaine: image of flame in SCENE 3E and its src below
E_srcflame = 'https://deckard.openprocessing.org/user285108/visual1395888/ha535128fd5bbe92fbca45d81b025b2f0/E_Flame.png';
loadImage('E_Flask.png'); // Evaine: image of flask in SCENE 4E and its src below
E_srcflask = 'https://deckard.openprocessing.org/user285108/visual1395888/ha535128fd5bbe92fbca45d81b025b2f0/E_Flask.png';
loadImage('E_Picture.png'); // Evaine: image of picture in SCENE 4E and its src below
E_srcpicture = 'https://deckard.openprocessing.org/user285108/visual1395888/ha535128fd5bbe92fbca45d81b025b2f0/E_Picture.png';
loadImage('E_Coffin.png'); // Evaine: image of coffin in SCENE 4E and its src below
E_srccoffin = 'https://deckard.openprocessing.org/user285108/visual1395888/ha535128fd5bbe92fbca45d81b025b2f0/E_Coffin.png';
loadImage('E_Cage.png'); // Evaine: image of cage in SCENE 4E and its src below
E_srccage = 'https://deckard.openprocessing.org/user285108/visual1395888/ha535128fd5bbe92fbca45d81b025b2f0/E_Cage.png';
loadImage('E_Pen.png'); // Evaine: image of pen in SCENE 4E and its src below
E_srcpen = 'https://deckard.openprocessing.org/user285108/visual1395888/ha535128fd5bbe92fbca45d81b025b2f0/E_Pen.png';
}
function setup() {
//Kai's scene3k setup
createCanvas(windowWidth, windowHeight);
frameRate(frames);
candyB = createButton('CANDY');
candyB.size(170, 60);
candyB.style('background-color', 'pink');
candyB.style('font-size', '40px');
candyB.position(590, 590);
candyB.hide();
candyB.mouseClicked(playCackle);
ratsB = createButton('RATS');
ratsB.size(170, 60);
ratsB.style('background-color', 'gray');
ratsB.style('font-size', '40px');
ratsB.position(1400, 620);
ratsB.hide();
ratsB.mouseClicked(playScream);
//end Kai's setup
locationx = createVector(20,20); //Justine's setup
velocityx = createVector(0,0); //Justine's setup
yspeed = 10; //Neha's setup
changey = 400;
yspeed2 = 5;
xspeed = 5;
xspeed2 = -10;
changex = 60;
changey2 = 100;
changex2 = 900;
spacecounter = 0; //end Neha's setup
E_candle1 = createImg(E_srccandle1, ''); // Evaine: button of left candle in SCENE 3E
E_candle1.position(80, 528); // Evaine: position of left candle in SCENE 3E
E_candle1.hide();
E_candle2 = createImg(E_srccandle2, ''); // Evaine: button of left candle in SCENE 3E
E_candle2.position(804, 528); // Evaine: position of left candle in SCENE 3E
E_candle2.hide();
E_broom = createImg(E_srcbroom, ''); // Evaine: button of broom in SCENE 3E
E_broom.position(1188, 312); // Evaine: position of broom in SCENE 3E
E_broom.hide();
E_carpet = createImg(E_srccarpet, ''); // Evaine: button of carpet in SCENE 3E
E_carpet.position(1018, 448); // Evaine: position of carpet in SCENE 3E
E_carpet.hide();
E_sword = createImg(E_srcsword, ''); // Evaine: button of sword in SCENE 3E
E_sword.position(1324, 296); // Evaine: position of sword in SCENE 3E
E_sword.hide();
E_flame = createImg(E_srcflame, ''); // Evaine: button of flame in SCENE 3E
E_flame.position(788, 380); // Evaine: position of flame in SCENE 3E
E_flame.hide();
E_flask = createImg(E_srcflask, ''); // Evaine: button of flask in SCENE 4E
E_flask.position(64, 580); // Evaine: position of flask in SCENE 4E
E_flask.hide();
E_picture = createImg(E_srcpicture, ''); // Evaine: button of picture in SCENE 4E
E_picture.position(318, 152); // Evaine: position of picture in SCENE 4E
E_picture.hide();
E_coffin = createImg(E_srccoffin, ''); // Evaine: button of coffin in SCENE 4E
E_coffin.position(600, 400); // Evaine: position of coffin in SCENE 4E
E_coffin.hide();
E_cage = createImg(E_srccage, ''); // Evaine: button of cage in SCENE 4E
E_cage.position(1014, 178); // Evaine: position of cage in SCENE 4E
E_cage.hide();
E_pen = createImg(E_srcpen, ''); // Evaine: button of pen in SCENE 4E
E_pen.position(1248, 386); // Evaine: position of pen in SCENE 4E
E_pen.hide();
}
function keyPressed() {
//Kai's keys
if(key == ' '){
scene2();
}
if(key == 'k'){
scene3k();
}//end Kai's keys
if(key === 'e') { // Evaine: click "e" to go to SCENE 3E
E_scene3(); // Evaine: function in SCENE 3E
}
if (key === 'f') { // Evaine: click "f" to go to SCENE 4E (Question)
E_scene4(); // Evaine: function in SCENE 4E
}
//Neha's keys
if(key == 'z') {
yspeed = -8;
spacecounter++;
}
if(key == 'n'){
scene3n();
} //end Neha's keys
//Justine's keys
if(key == 'j'){
scene3j();
}
if(keyCode === RIGHT_ARROW){
velocityx.x++;
}else if(keyCode === LEFT_ARROW){
velocityx.x--;
}else if(keyCode === DOWN_ARROW){
velocityx.y++;
}else if(keyCode === UP_ARROW){
velocityx.y--;
}//end Justine's keys
}
//Justine's game functions
function keyReleased(){ // user must use arrow keys to direct the yellow ball
if(keyCode === RIGHT_ARROW && locationx.x < width-5){
velocityx.x--;
}else if(keyCode === LEFT_ARROW && locationx.x > 5){
velocityx.x++;
}else if(keyCode === DOWN_ARROW && locationx.y < height-5){
velocityx.y--;
}else if(keyCode === UP_ARROW && locationx.y > 5){
velocityx.y++;
}
}
function keyTyped(){
if(key === 'n' && difficulty != 0){
difficulty--;
}else if(key === 'm'){ // was initially going to have multiple levels where difficulty gets increased as you continue winning
difficulty++; // kept it to only one difficulty level (unless players want a more difficult game, they can continue pressing "m"
}
if(key == 'n' || key === 'm'){ // if you keep pressing "m", more circles will be added
newlocation = [];
newvelocity = [];
locationx = createVector(20,20);
for(let n=0; n < difficulty*10; n++){
newlocation[n] = createVector(Math.floor(random(50,width-50)),Math.floor(random(50,height-50)));
newvelocity[n] = createVector(random(-1,1),random(-1,1));
}
}
} //end Justine's game functions
function scene1(){ //Kai: created the loading/start screen
background(scene1background);
//text
textAlign(CENTER); textSize(180); textFont(titlefont); fill(20); stroke(180); strokeWeight(10);
text('Will You Survive?', 590, 410);
textSize(100);
text('Evaine, Justine, Kai, Neha', 590, 540);
//add in music
startsound.play();
//bat animation
push(); //bat1
translate(width/2, height/2);
translate(p5.Vector.fromAngle(millis()/1000, 200));
image(batimage, 180, -70, 300, 150);
pop();
push(); //bat2
translate(width/2, height/2);
translate(p5.Vector.fromAngle(millis()/1000, 80));
image(batimage, -400, 200, 260, 130);
pop();
push(); //bat3
translate(width/2, height/2);
translate(p5.Vector.fromAngle(millis()/1000, 40));
image(batimage, -720, -400, 300, 150);
pop();
//text
frameRate(frames); strokeWeight(1);
blink +=1;
if(blink%3 == 0){
fill(160, random(0,40), random(0, 40));
}
else{
noFill();
}
textSize(100);
text('[Press Space to Begin]', 590, 760);
loop();
} //end Kai's loading/start screen
function scene2(){ //Kai: Created scene 2
background(scene2background);
//add in music
//add in text animations
blink +=1; frameRate(frames);
fill(0); textSize(160); textFont(titlefont); strokeWeight(5);
text('You open the front door and...', windowWidth/2, 300);
//Option 1
fill(160); textSize(90); strokeWeight(1);
text('walk straight ahead.', windowWidth/2, 500);
textSize(65);
if(blink%3 == 0){
fill(160, random(0,40), random(0, 40));
}
else{
noFill();
}
text('[Press e]', windowWidth/2, 580);
//Option 2
fill(160); textSize(90);
text('go down the left hallway.', windowWidth/5 - 80, 590);
textSize(65);
if(blink%3 == 0){
fill(160, random(0,40), random(0, 40));
}
else{
noFill();
}
text('[Press j]', windowWidth/5 - 80, 670);
//Option 3
fill(20); textSize(90);
text('go down the right hallway.', 4*windowWidth/5 + 80, 590);
textSize(65);
if(blink%3 == 0){
fill(160, random(0,40), random(0, 40));
}
else{
noFill();
}
text('[Press k]', 4*windowWidth/5 + 80, 670);
//Option 4
fill(20); textSize(90);
text('stay where you are.', windowWidth/2, 740);
textSize(65);
if(blink%3 == 0){
fill(160, random(0,40), random(0, 40));
}
else{
noFill();
}
text('[Press n]', windowWidth/2, 820);
loop();
}//end Kai's scene 2
function scene3k() { //Kai: scene 3k
//add in music & SE
background(scene3kbackground);
textSize(130); fill(20); stroke(180); strokeWeight(5);
text('You\'ve encountered a witch!', windowWidth/2, 150);
text('Give her either candy or rats.', windowWidth/2, 290);
image(witchimage, windowWidth/2, 400, 400, 400);
image(candiesimage, 570, 600, 250, 250);
image(ratimage, 1470, 480, 100, 100);
image(ratimage, 1420, 510, 100, 100);
image(ratimage, 1550, 550, 100, 100);
candyB.show();
ratsB.show();
if(death == true){ witchdeath();}
if(escape == true){ witchescape();}
noLoop();
}
function playCackle(){
wcackle.play();
death = true;
}
function playScream(){
wscream.play();
escape = true;
}
function witchdeath(){ //Kai: scene 4k death
if (death == true){
background(0); candyB.hide(); ratsB.hide(); textAlign(CENTER);
textSize(150); textFont(titlefont); fill(0, 150, 0); stroke(160);
text('She HATES candy!', windowWidth/2, 150);
text('Outraged, she casts a spell on you!', windowWidth/2, 300);
textSize(300); fill(150, 0, 0);
text('You Are DEAD!', windowWidth/2, 650);
}
}
function witchescape(){ //Kai: scene 4k escape
if (escape == true){
background(0); candyB.hide(); ratsB.hide(); textAlign(CENTER);
textSize(130); textFont(titlefont); fill(0, 150, 0); stroke(160);
text('"THEY ARE SO CUTE! I LOVE THEM!"', windowWidth/2, 150);
text('She gratefully shows you out of the haunted house!', windowWidth/2, 300);
textSize(300); fill(150, 0, 0);
text('You Have ESCAPED!', windowWidth/2, 650);
}
} //end Kai's scene 3&4k
function scene3j(){ //Justine scene3j
background(startimage);
stroke(0,0,0);
fill(225,225,225);
rect(0,0,40,40); // start box
rect(width-40,height-40,40,40); // end box
fill(211,211,211); // grey fill
textSize(60);
textFont(titlefont); // spooky font for the instructions @ top left
text("Press 'm' to start the game --- Manuver the yellow ball to the bottom right corner without touching the red balls",500,140); // instructions
text("You need to get in the box on the right in order to survive. Good luck!",580,725); // bottom right text
if(locationx.x > width-30 && locationx.y > height-30){
text("You made it!", width-200,height-50); // you won text pop up
}
fill(225,225,0); // yellow ball
frameRate(100);
ellipse(locationx.x,locationx.y,20,20); // location of start
if(locationx.x >= 10 && locationx.x <= width-10 && locationx.y >= 10 && locationx.y <= height-10){
if(locationx.x == 10 && velocityx.x == -1){
velocityx.x++;
}else if(locationx.x == width-10 && velocityx.x == 1){
velocityx.x--;
}else if(locationx.y == 10 && velocityx.y == -1){
velocityx.y++;
}else if(locationx.y == height-10 && velocityx.y == 1){
velocityx.y--;
}
locationx.add(velocityx);
}
fill(255,0,0); // red circles
if(newlocation != undefined){ // placements of red circles all over the screen
for(let i=0;i<newlocation.length;i++){
newlocation[i].add(newvelocity[i]);
ellipse(newlocation[i].x,newlocation[i].y,20,20);
if((newlocation[i].x < 10 || newlocation[i].x > width-10) ||
(Math.floor(newlocation[i].x) == 50 && newlocation[i].y < 50) ||
(Math.floor(newlocation[i].x) == width-50 && newlocation[i].y > height-50)){
newvelocity[i].x = newvelocity[i].x *(-1);
}else if((newlocation[i].y < 10 || newlocation[i].y > width-10) ||
(Math.floor(newlocation[i].y) == 50 && newlocation[i].x < 50) ||
(Math.floor(newlocation[i].y) == width-50 && newlocation[i].x > height-50)){
newvelocity[i].y = newvelocity[i].y *(-1);
}
if(sq(locationx.x-newlocation[i].x) + sq(locationx.y-newlocation[i].y) < 400){
locationx = createVector(20,20);
}
}
}
} //end Justine scene 3j
function E_scene3() {
startsound.stop();
E_sound1.play();
background(0);
image(E_background1, 0, -84, 1440, 900); // Evaine: background of SCENE 3E
textAlign(CENTER);
textSize(80);
fill(180);
text('Find the Differences [Click on the Right Side]', 720, 100);
text('Discover 5 or Die [Press f Only After you Discover All!]', 720, 675);
E_candle1.show();
E_candle2.show();
E_candle2.mouseClicked(E_draw1); // Evaine: function of candle in SCENE 3E
E_broom.show();
E_broom.mouseClicked(E_draw2); // Evaine: function of broom in SCENE 3E
E_carpet.show();
E_carpet.mouseClicked(E_draw3); // Evaine: function of carpet in SCENE 3E
E_sword.show();
E_sword.mouseClicked(E_draw4); // Evaine: function of sword in SCENE 3E
E_flame.show();
E_flame.mouseClicked(E_draw5); // Evaine: function of flame in SCENE 3E
if(E_candle2.mouseClicked & E_broom.mouseClicked) E_scene4();
}
function E_draw1() {
stroke('red');
noFill();
circle(106, 560, 75); // Evaine: circle left candle in SCENE 3E
circle(834, 560, 75); // Evaine: circle right candle in SCENE 3E
}
function E_draw2() {
stroke('red');
noFill();
circle(510, 376, 132); // Evaine: circle left broom in SCENE 3E
circle(1228, 376, 132); // Evaine: circle rigt broom in SCENE 3E
}
function E_draw3() {
stroke('red');
noFill();
circle(372, 486, 140); // Evaine: circle left carpet in SCENE 3E
circle(1090, 486, 140); // Evaine: circle right carpet in SCENE 3E
}
function E_draw4() {
stroke('red');
noFill();
circle(640, 370, 140); // Evaine: circle left sword in SCENE 3E
circle(1360, 370, 140); // Evaine: circle right sword in SCENE 3E
}
function E_draw5() {
stroke('red');
noFill();
circle(112, 426, 104); // Evaine: circle left flame in SCENE 3E
circle(832, 426, 104); // Evaine: circle right flame in SCENE 3E
}
function E_scene4() {
E_candle1.hide();
E_candle2.hide();
E_broom.hide();
E_carpet.hide();
E_sword.hide();
E_flame.hide();
E_sound1.stop();
E_sound2.play();
background(0);
image(E_background2, 0, 0, 1440, 800); // Evaine: background of SCENE 4E
textAlign(CENTER);
textSize(80);
noStroke();
fill(180);
text('Click the 5 Objects to Read the Messages', 720, 680);
E_flask.show();
E_flask.mouseClicked(E_draw6); // Evaine: function of flask in SCENE 4E
E_picture.show();
E_picture.mouseClicked(E_draw7); // Evaine: function of picture in SCENE 4E
E_coffin.show();
E_coffin.mouseClicked(E_draw8); // Evaine: function of coffin in SCENE 4E
E_coffin.doubleClicked(scene5); // Evaine: go to SCENE 5 when double clicked
E_cage.show();
E_cage.mouseClicked(E_draw9); // Evaine: function of cage in SCENE 4E
E_pen.show();
E_pen.mouseClicked(E_draw10); // Evaine: function of pen in SCENE 4E
}
function E_draw6() {
textAlign(LEFT);
textSize(40);
noStroke();
fill(160, 0, 0);
text('Do you really want to be immortal?', 48, 560); // Evaine: message of flask
}
function E_draw7() {
textAlign(CENTER);
textSize(40);
noStroke();
fill(160, 0, 0);
text('The portrait of the next Count will be here.', 348, 136); // Evaine: message of picture
}
function E_draw8() {
textAlign(CENTER);
textSize(40);
noStroke();
fill(160, 0, 0);
text('Promise me! Leave here right now and never come back again!', 708, 348); // Evaine: message of coffin
text('Double click the coffin.', 708, 388); // Evaine: message of win
}
function E_draw9() {
textAlign(CENTER);
textSize(40);
noStroke();
fill(160, 0, 0);
text('A bird in the cage... A bat in the cage... A soul in the cage...', 1048, 168); // Evaine: message of cage
}
function E_draw10() {
textAlign(RIGHT);
textSize(40);
noStroke();
fill(160, 0, 0);
text('He used the pen. He will use the pen? He is using the pen!', 1400, 468); // Evaine: message of pen
}
function scene5() { // win
E_candle1.hide();
E_candle2.hide();
E_broom.hide();
E_carpet.hide();
E_sword.hide();
E_flame.hide();
E_flask.hide();
E_picture.hide();
E_coffin.hide();
E_cage.hide();
E_pen.hide();
E_sound1.stop();
E_sound2.stop();
background(0);
textAlign(CENTER); textSize(100); textFont(titlefont);
noStroke();
fill(180);
text('You got out of the haunted house and survived!', windowWidth/2, windowHeight/2);
}
//Neha scene3n
function scene3n(){
background(backgroundimg);
frameRate(100);
changey = changey + yspeed;
changey2 = changey2 + yspeed2;
changex = changex + xspeed;
changex2 = changex2 +xspeed2;
if(changex > 1185 || changex < 0) {
xspeed *= -1;
}
if(changey2 > windowHeight || changey2 < 70) {
yspeed2 *= -1;
}
image(sand, -50, 500, 5000, 500);
image(spongebobimage, 200,changey,50,100);
image(mum, changex2, 450,100,50);
if (changex2 == 200){
if (changey == 410)
{
isgameover = true;
}
}
if(changex2 < 0) {
changex2 = 2000;
}
if(changey > 405) {
yspeed = 0;
} else if(changey < 200) {
yspeed = 8;
}
if (isgameover == true)
{
background(0);
fill(255);
textFont(titlefont);
textSize(100);
textAlign(CENTER);
text("You failed to survive.", windowWidth/2, windowHeight/2);
}
if (spacecounter==5)
{
//go to next scene because they passed
}
} //end Neha scene3n
function draw(){
scene1();
if(keyPressed(' ')){
scene2();
}
}