xxxxxxxxxx
113
let x1 = 0;
let x2 = 0;
let scrollSpeed = 2;
let character; // Influencer Madison
let song; // Game background music
let menuBG; // Background image of main menu
let tutorialBG; // Background image of tutorial
let gameBG; // Background image of actual game (cityview)
let gameOverBG; // Background image if player loses
let youWinBG; // Background image if player wins
let garbage = []; // Garbage obstacle
let crackhead =[]; // Crackhead obstacle
let rat =[]; // Rat obstacle
let score = 0; // Player's score
let gameState = 'menu'; //'menu,''game,' or 'tutorial'
let lives = 3; // Number of lives permitted
function preload(){
menuBG = loadImage('menubg.jpg'); // Background image for main menu
tutorialBG = loadImage
gameBG = loadImage('citybg.jpeg');// Background image of game
gameOverBG = loadImage
song = loadSound('Ratatouille Chase Soundtrack.mp3');
titleFont = loadFont('Bomber Dreams.ttf'); // Font of title on main menu
menuFont = loadFont('Street Hipster.ttf'); // Font of main menu buttons (start & tutorial)
tutorialFont = loadFont('Melody Break Demo.ttf') // Font of actual tutorial heading
tutorialTextFont = loadFont('Sen.ttf') // Font of instructions under tutorial
}
function setup() {
createCanvas(600, 400); // Canvas size
}
function draw() {
background(255); // Default background color if no background image is uploaded
// State of the game
if (gameState === 'menu') {
displayMenu(); // Main menu
} else if (gameState === 'tutorial') {
displayTutorial(); // Tutorial
} else if (gameState === 'game') {
displayGame(); // Game itself
}
}
// Visuals and text of main menu
function displayMenu() {
image(menuBG,0,0,width,height)
textFont(titleFont);
textSize(50);
fill(221, 220, 217);
stroke(0);
strokeWeight(7);
textAlign(CENTER, CENTER);
text('Escape From New York', width / 2, height / 4 + 63);
textFont(menuFont);
fill(221, 220, 217);
textStyle(BOLD);
textSize(30);
strokeWeight(5);
text('Click to Start', width / 2, height / 2 + 77);
text('Click for Tutorial', width / 2, height / 2 + 123);
}
// Visuals and text if user clicks on the tutorial
function displayTutorial() {
textFont(tutorialFont);
textSize(40);
fill(0);
strokeWeight(0);
textAlign(CENTER,CENTER);
text('Tutorial:', width / 2, height / 4 - 50);
textFont(tutorialTextFont);
textSize(20);
text('Social media influencer Madison just moved from suburban Mississipi to the romanticized New York City, where she is met with obstacles',width / 4, height / 4 + 60);
text('Help her move and avoid the obstacles to get her back out of here!!!', width / 2, height / 2 + 75);
text('Click anywhere to return to the menu',width / 2, height / 2 + 90);
}
function displayGame(){
image(gameBG, x1, 0, width, height);
image(gameBG, x2, 0, width, height);
x1 -= scrollSpeed;
x2 -= scrollSpeed;
if (x1 < -width) {
x1 = x2 + width;
}
if (x2 < -width) {
x2 = x1 + width;
}
}
// Mouse click functions
function mousePressed() {
if (gameState === 'menu') {
// Click to start
if (mouseY > height / 2 + 60 && mouseY < height / 2 + 90) {
gameState = 'game';
}
// Click for tutorial
else if (mouseY > height / 2 + 100 && mouseY < height / 2 + 140) {
gameState = 'tutorial';
}
} else if (gameState === 'tutorial') {
gameState = 'menu'; // Return to menu
}
}