xxxxxxxxxx
184
//layering class
let sceneManager;
//Scenes
let wscreen, instructions, bedroom; // Add missing scene variables
let welcomeScene, instructionsScene, bedroomScene;
//Preloading function
function preload() {
//Images
wscreen = loadImage("wscreen.png");
instructions = loadImage("instructions.png");
bedroom = loadImage("bedroom.png");
}
//Setup function
function setup() {
createCanvas(2000, 1000);
rectMode(CENTER);
//class for layers management
sceneManager = new SceneManager();
}
//Draw Function
function draw() {
sceneManager.display();
}
// Class for buttons
class Button {
constructor(x, y, label, onClick) {
this.x = x;
this.y = y;
this.label = label;
this.onClick = onClick;
this.width = 300;
this.height = 50;
}
display() {
rectMode(CENTER);
fill(150);
rect(this.x, this.y, this.width, this.height);
fill(0);
textSize(20);
textAlign(CENTER, CENTER);
text(this.label, this.x, this.y);
}
checkClicked() {
return (
mouseX > this.x - this.width / 2 &&
mouseX < this.x + this.width / 2 &&
mouseY > this.y - this.height / 2 &&
mouseY < this.y + this.height / 2
);
}
}
// WelcomeScene class
class WelcomeScene {
constructor() {
this.backgroundImage = wscreen;
this.goAheadButton = new Button(width / 2, 900, "GO AHEAD", () => sceneManager.showInstructions());
this.buttons = [this.goAheadButton];
this.isActive = false;
}
display() {
if (this.isActive) {
imageMode(CORNER);
image(this.backgroundImage, 0, 0);
this.buttons.forEach((button) => {
button.display();
});
}
}
showNextScene() {
this.isActive = false;
sceneManager.showInstructions();
}
}
// Scene classes
class InstructionsScene {
constructor() {
this.backgroundImage = instructions;
this.goAheadButton = new Button(width / 2, 900, "GO AHEAD", () => sceneManager.showBedroomScene());
this.buttons = [this.goAheadButton];
this.isActive = false;
}
display() {
if (this.isActive) {
imageMode(CORNER);
image(this.backgroundImage, 0, 0);
this.buttons.forEach((button) => {
button.display();
});
}
}
}
class Bedroom {
constructor() {
this.backgroundImage = bedroom;
this.choice1Button = new Button(width / 3, 800, "Choice 1", () => sceneManager.showBreakfastScene());
this.choice2Button = new Button((width * 2) / 3, 800, "Choice 2", () => sceneManager.showClassScene());
this.buttons = [this.choice1Button, this.choice2Button];
this.isActive = false;
}
display() {
if (this.isActive) {
imageMode(CORNER);
image(this.backgroundImage, 0, 0);
this.buttons.forEach((button) => {
button.display();
});
}
}
}
// SceneManager class
class SceneManager {
constructor() {
this.buttons = [];
//All buttons here
this.startButton = new Button(width / 2, 1000, "GO AHEAD", () => this.showWelcomeScene());
this.buttons.push(this.startButton);
this.welcomeScene = new WelcomeScene();
this.instructionsScene = new InstructionsScene();
this.bedroomScene = new Bedroom();
this.activeScene = this.welcomeScene;
}
display() {
// Display scenes based on flags
this.activeScene.display();
// Display buttons
this.buttons.forEach((button) => {
button.display();
});
// Handle button clicks
if (mouseIsPressed) {
this.buttons.forEach((button) => {
if (button.checkClicked()) {
button.onClick();
}
});
}
}
showWelcomeScene() {
this.activeScene.isActive = false;
this.welcomeScene.isActive = true;
this.activeScene = this.welcomeScene;
}
showInstructions() {
this.welcomeScene.isActive = false;
this.instructionsScene.isActive = true;
this.activeScene = this.instructionsScene;
}
showBedroomScene() {
this.instructionsScene.isActive = false;
this.bedroomScene.isActive = true;
this.activeScene = this.bedroomScene;
}
// Add methods to show other scenes
// ... (your existing code)
}