xxxxxxxxxx
450
let sceneNum = 0;
let x = 240;
let char1;
let char1W = 80;
let char1H = 120;
let char2;
let char2W = 80;
let char2H = 120;
let char3;
let char3W = 80;
let char3H = 120;
let poke1;
let poke1W = 130;
let poke1H = 30;
let alpha = 255;
function preload() {
//audio
song1 = loadSound("Assets/SpookyMusiccut.mp3");
//images
bgs1 = loadImage("Assets/BackgroundImg.jpg");
bgs2 = loadImage("Assets/Background2.png");
bgs3 = loadImage("Assets/Background3.png");
M1 = loadImage("Assets/Scare1M1.png");
M2 = loadImage("Assets/Scare2M2.png");
arrowsImg = loadImage("Assets/arrows.png");
girlchar = loadImage("Assets/scaredlilgirl.png");
sword = loadImage("Assets/sword2.png");
//font
font = loadFont("Assets/who asks satan.ttf");
}
function setup() {
createCanvas(600, 400);
rectMode(CENTER);
let color1 = color(74, 67, 124);
char1 = new Character(150, 250, 1, color1);
let color2 = color(211, 168, 82);
char2 = new Character1(200, 0, 4, color2);
char3 = new Character2(100, 0, 4, color2);
let color3 = color(255, 100, 100);
poke1 = new Sword(0, 180, 2, color3);
}
function draw() {
background(220);
char1.display(char1W, char1H);
char1.move();
char2.display(char2W, char2H);
//char2.move();
poke1.display(poke1W, poke1H);
poke1.move(char1.x, char1.y);
// scenes
switch (sceneNum) {
case 0:
// console.log("scene 0");
//background image (Haveli)
imageMode(CORNER);
image(bgs1, 0, 0);
//game title
fill(210, 180, 140);
textAlign(CENTER, CENTER);
textSize(34);
noStroke();
textFont(font);
text("Something is Approaching", 200, 100);
textSize(16);
text("press ENTER to continue", 200, 140);
//next scene
if (keyIsDown(13)) {
sceneNum = 1;
}
break;
case 1:
// console.log("scene 1");
//background image (Intro Background)
image(bgs2, 0, 0);
//sign
push();
translate(100, 150);
fill(10, 10, 10, 93);
stroke(210, 180, 140);
strokeWeight(3);
rect(80, 50, 200, 300);
rect(155, 350, 50, 50);
pop();
//info
fill(210, 180, 140);
textAlign(CENTER, CENTER);
textSize(20);
noStroke();
textFont(font);
text("Welcome to the", 170, 80);
textAlign(CENTER, CENTER);
textSize(20);
noStroke();
textFont(font);
text("Spooky Indian Mansion", 170, 110);
textSize(15);
text("Use arrow keys to", 170, 150);
textSize(15);
text("navigate through Halls", 170, 170);
text("Dont be afraid;or atleast try", 170, 190);
//arrow keys image
image(arrowsImg, 130, 220, 100, 60);
textSize(14);
text("press space bar", 170, 300);
textSize(14);
text("to continue", 170, 320);
//next scene
if (keyIsDown(32)) {
sceneNum = 2;
}
break;
case 2:
// console.log("scene 2");
//background image (Intro Background)
image(bgs3, 0, 0);
//bedroom
push();
//lamp
translate(0, 80);
fill(150);
rect(220, 170, 10, 180, 8, 8, 8, 8);
fill(210, 180, 140);
quad(180, 120, 200, 80, 240, 80, 260, 120, 8, 8, 8, 8);
//table
quad(400, 200, 410, 190, 560, 190, 570, 200);
fill(150);
rect(401, 235, 10, 70, 3, 3, 3, 3);
rect(560, 235, 10, 70, 3, 3, 3, 3);
pop();
//bed
push();
translate(0, 20);
fill(210, 180, 140);
quad(0, 400, 120, 330, 420, 330, 400, 400);
quad(0, 400, 60, 300, 160, 300, 120, 400);
line(240, 400, 290, 300);
pop();
char1.display(char1W, char1H);
char1.move();
if (char1.x > width - 200) {
sceneNum = 3;
}
if (char1.x < 0) {
sceneNum = 4;
}
break;
case 3:
// console.log("scene 3");
//background image (Fight)
image(bgs2, 0, 0);
//hall
push();
translate(100, 0);
fill(200);
rect(260, 280, 80, 60);
rect(350, 280, 80, 60);
quad(240, 320, 400, 320, 420, 380, 220, 380);
ellipse(320, 320, 250, 60);
pop();
char1.display(char1W, char1H);
char1.move();
char2.display(char2W, char2H);
poke1.display(poke1W, poke1H);
poke1.move(char1.x, char1.y);
let hit = rectRect(
char2.x + 200,
char2.y + 200,
char2W,
char2H,
poke1.x,
poke1.y,
poke1W,
poke1H
);
if (hit) {
ellipse(300, 50, 20, 20);
fill(255, 0, 0, alpha);
alpha -= 5;
console.log(alpha);
if (alpha <= -100) {
sceneNum = 5;
}
}
if (char1.x > width / 3) {
char1.x -= 15;
}
if (char1.x < -100) {
sceneNum = 4;
}
if (char1.y < 0) {
char1.y = 200;
}
break;
case 4:
//background image (Fight)
image(bgs2, 0, 0);
//hall
push();
translate(100, 0);
fill(210, 180, 140);
rect(260, 280, 80, 60);
rect(350, 280, 80, 60);
quad(240, 320, 400, 320, 420, 380, 220, 380);
ellipse(320, 320, 250, 60);
pop();
char1.display(char1W, char1H);
char1.move();
char3.display(char3W, char3H);
poke1.display(poke1W, poke1H);
poke1.move(char1.x, char1.y);
let hit1 = rectRect(
char3.x + 200,
char3.y + 200,
char3W,
char3H,
poke1.x,
poke1.y,
poke1W,
poke1H
);
if (hit1) {
ellipse(300, 50, 20, 20);
fill(255, 0, 0, alpha);
alpha -= 5;
console.log(alpha);
if (alpha <= 0) {
sceneNum = 5;
}
}
if (char1.x > width / 3) {
char1.x -= 15;
}
if (char1.y < 0) {
sceneNum = 6;
}
if (char1.x < -500) {
sceneNum = 6;
}
break;
case 5:
//background image
image(bgs1, 0, 0);
//wooden sign
fill(150, 121, 105);
stroke(210, 180, 140);
strokeWeight(3);
rect(110, 160, 160, 50);
//winner message
fill(210, 180, 140);
textAlign(CENTER, CENTER);
textSize(40);
noStroke();
textFont(font);
text("Good Job!", 100, 150);
textSize(16);
text("press ENTER to play again", 100, 100);
if (keyIsDown(13)) {
sceneNum = 0;
}
break;
case 6:
//background image ( Background)
image(bgs3, 0, 0);
//death message
fill(210, 180, 140);
textAlign(CENTER, CENTER);
textSize(32);
noStroke();
textFont(font);
text("Alas! You weren't able to overcome Monsters.", 300, 250);
textSize(16);
text("press ENTER to play again", 300, 300);
if (keyIsDown(13)) {
sceneNum = 0;
}
break;
}
}
class Sword {
constructor(x, y, speed, Color) {
this.x = x;
this.y = y;
this.speed = speed;
this.Color = Color;
}
move(charX, charY) {
if (this.x > width / 2) {
this.x = charX + 300;
this.x -= 15;
}
if (this.y > 340) {
this.y -= 5;
}
if (this.y < 160) {
this.y += 5;
}
if (keyIsDown(LEFT_ARROW)) {
this.x = charX + 300;
this.x -= 15;
}
if (keyIsDown(RIGHT_ARROW)) {
this.x = charX + 300;
this.x += 15;
}
if (keyIsDown(UP_ARROW)) {
this.y -= 5;
}
if (keyIsDown(DOWN_ARROW)) {
this.y += 5;
}
}
display(swordW, swordH) {
image(sword, this.x - 200, this.y, sword.width * 1, sword.height * 1);
}
}
class Character {
constructor(x, y, speed, Color) {
this.x = x;
this.y = y;
this.speed = speed;
this.Color = Color;
}
move() {
// if (this.x > width / 5) {
// this.x -= 15;
// }
if (this.y < 60 && this.y > 45) {
this.y -= 5;
}
if (keyIsDown(LEFT_ARROW)) {
this.x -= 15;
}
if (keyIsDown(RIGHT_ARROW)) {
this.x += 15;
}
if (keyIsDown(UP_ARROW)) {
this.y -= 5;
}
if (keyIsDown(DOWN_ARROW)) {
this.y += 5;
}
}
display(charW, charH) {
push();
imageMode(CENTER);
image(
girlchar,
this.x,
this.y,
girlchar.width * 0.09,
girlchar.height * 0.09
);
pop();
}
}
class Character1 {
constructor(x, y, speed, Color) {
this.x = x;
this.y = y;
}
display(charW, charH) {
push();
imageMode(CENTER);
image(M1, this.x + 200, this.y + 250, M1.width * 0.4, M1.height * 0.4);
pop();
}
}
class Character2 {
constructor(x, y) {
this.x = x;
this.y = y;
}
display(charW, charH) {
push();
imageMode(CENTER);
image(M2, this.x + 340, this.y + 250, M2.width * 0.4, M2.height * 0.4);
pop();
}
}
function rectRect(r1x, r1y, r1w, r1h, r2x, r2y, r2w, r2h) {
// are the sides of one rectangle touching the other
if (
r1x + r1w / 2 >= r2x - r2w / 2 && // r1 right edge past r2 left
r1x - r1w / 2 <= r2x + r2w / 2 && // r1 left edge past r2 right
r1y + r1h / 2 >= r2y - r2h / 2 && // r1 top edge past r2 bottom
r1y - r1h / 2 <= r2y + r2h / 2
) {
// r1 bottom edge past r2 top
return true;
}
return false;
}