xxxxxxxxxx
357
let gameState = "start";
// song variables
let currentSong;
let previousSongs = [];
let songs = [];
let album_covers = [];
// array variables
let count = 16;
let chosen = [];
let elton1S,
elton2S,
elton3S,
elton4S,
elton5S,
Sbeatles1,
Sbeatles2,
Sbeatles3,
Sbeatles4,
Sbeatles5,
Squeen1,
Squeen2,
Squeen3,
Squeen4,
Squeen5;
let elton1,
elton2,
elton3,
elton4,
elton5,
beatles1,
beatles2,
beatles3,
beatles4,
beatles5,
queen1,
queen2,
queen3,
queen4,
queen5,
iceBaby;
//game experience variables (strikes, round counter, score)
let strike = 0;
let counter = 0;
let score = 0;
// let songNames = ['Bernie and the Jets', 'Cold Heart', "I'm Still Standing", 'Tiny Dancer', 'Your Song', "You Can't Do That", 'While My Guitar Gently Weeps', 'Let it Be', 'Penny Lane', 'The End', 'Bohemian Rhapsody', 'Fat Bottomed Girls', 'Seven Seas of Rhye', 'Show Must Go On', 'Under Pressure']
// correcrt answer coordinates
let goodX;
let goodY;
let positionX = [50, 220];
let positionY = [50, 220];
// Image size and coordinates//
let imgSize = 125;
let img1X = 50;
let img1Y = 50;
let img2X = 50;
let img2Y = 220;
let img3X = 220;
let img3Y = 50;
let img4X = 220;
let img4Y = 220;
let lineThick = 10;
function preload() {
// Preloading images and sound to have things running correctly, first Elton
elton1 = loadImage("Elton/Bernie.jpeg");
elton1S = loadSound("SongsE/Bernie.mp3");
elton2 = loadImage("Elton/ColdHeart.png");
elton2S = loadSound("SongsE/ColdHeart.mp3");
elton3 = loadImage("Elton/StillStanding.jpeg");
elton3S = loadSound("SongsE/StillStanding.mp3");
elton4 = loadImage("Elton/TinyDancer.jpeg");
elton4S = loadSound("SongsE/TinyDancer.mp3");
elton5 = loadImage("Elton/YourSong.jpeg");
elton5S = loadSound("SongsE/YourSong.mp3");
// Second Beatles
beatles1 = loadImage("Beatles/DoThat.jpeg");
Sbeatles1 = loadSound("BeatlesS/DoThat.mp3");
beatles2 = loadImage("Beatles/GentlyWeeps.jpeg");
Sbeatles2 = loadSound("BeatlesS/GentlyWeeps.mp3");
beatles3 = loadImage("Beatles/LetItBe.jpeg");
Sbeatles3 = loadSound("BeatlesS/LetItBe.mp3");
beatles4 = loadImage("Beatles/PennyLane.jpeg");
Sbeatles4 = loadSound("BeatlesS/PennyLane.mp3");
beatles5 = loadImage("Beatles/TheEnd.jpeg");
Sbeatles5 = loadSound("BeatlesS/TheEnd.mp3");
//Third Queen
queen1 = loadImage("Queen/Bohemian.png");
Squeen1 = loadSound("QueenS/Bohemian.mp3");
queen2 = loadImage("Queen/Bottom.png");
Squeen2 = loadSound("QueenS/Bottom.mp3");
queen3 = loadImage("Queen/SevenSeas.jpeg");
Squeen3 = loadSound("QueenS/SevenSeas.mp3");
queen4 = loadImage("Queen/Show.png");
Squeen4 = loadSound("QueenS/Show.mp3");
queen5 = loadImage("Queen/Pressure.png");
Squeen5 = loadSound("QueenS/Pressure.mp3");
iceBaby = loadImage("Queen/Vanila.jpeg");
}
function setup() {
createCanvas(400, 400);
gameRestart();
//Resizing the images in order to make them fit the screen and be equally sized
elton1.resize(imgSize, imgSize);
elton2.resize(imgSize, imgSize);
elton3.resize(imgSize, imgSize);
elton4.resize(imgSize, imgSize);
elton5.resize(imgSize, imgSize);
beatles1.resize(imgSize, imgSize);
beatles2.resize(imgSize, imgSize);
beatles3.resize(imgSize, imgSize);
beatles4.resize(imgSize, imgSize);
beatles5.resize(imgSize, imgSize);
queen1.resize(imgSize, imgSize);
queen2.resize(imgSize, imgSize);
queen3.resize(imgSize, imgSize);
queen4.resize(imgSize, imgSize);
queen5.resize(imgSize, imgSize);
iceBaby.resize(imgSize, imgSize);
//Pushing the songs into the array (Make a previous songs array)
for (let i = 0; i < count; i++) {
chosen.push(false);
songs = [
elton1S,
elton2S,
elton3S,
elton4S,
elton5S,
Sbeatles1,
Sbeatles2,
Sbeatles3,
Sbeatles4,
Sbeatles5,
Squeen1,
Squeen2,
Squeen3,
Squeen4,
Squeen5,
];
album_covers = [
elton1,
elton2,
elton3,
elton4,
elton5,
beatles1,
beatles2,
beatles3,
beatles4,
beatles5,
queen1,
queen2,
queen3,
queen4,
queen5,
iceBaby,
];
}
}
function draw() {
background(220);
// Taken from gameState code in class, makes the game work cohesively
if (gameState == "start") {
drawInstructions();
} else if (gameState == "playing") {
drawGame();
} else if (gameState == "end") {
drawEndScreen();
}
}
// Instructions for the game
function drawInstructions() {
background(255, 140, 105);
text("Listen to the song and choose the correct album", 40, 50);
text("Get all 10 correctly to get a special surprise", 40, 70);
text("Press any key to start", 40, 90);
}
//Variables for drawGame function and game functioning itself
let choices = [];
let correctSong;
let repeatSong;
let wSong1, wSong2, wSong3, wSong4;
function drawGame() {
background("pink");
//Based on having a random result from a string
image(album_covers[wSong1], img1X, img1Y);
image(album_covers[wSong2], img2X, img2Y);
image(album_covers[wSong3], img3X, img3Y);
image(album_covers[wSong4], img4X, img4Y);
// Strikes and strike counter
push();
strokeWeight(5);
textSize(20);
text("Strikes: " + strike, 300, 30);
stroke(255, 0, 0);
pop();
//Correct song randomly placed over another picture
image(album_covers[currentSong], goodX, goodY);
//Text for round and score
text("Round " + counter, 25, 25);
text("Score: " + score + "/10", 25, 40);
}
function mouseClicked() {
console.log("gamestate is: ", gameState);
if (gameState == "start") {
// Makes it so that the game can be looped and work properly when multiple games are played
gameState = "playing";
randomize(); //the songs are randomized and in theory, don't loop
counter++; // round increase
} else if (gameState == "playing") {
if (mouse_is_over()) {
score++; // whem you get an answer your socre increases
nextRound(); // refreshes the game
} else {
strike++;
console.log("strike");
console.log(strike);
nextRound();
}
} else if (gameState == "end") {
gameRestart(); // game begins again and values reset
}
}
function mouse_is_over() {
// console.log (mouseX, goodX, mouseY, goodY) // This was for debugging
// Makes it so that mouse is relative to the corredct answer
if (
mouseX >= goodX &&
mouseX < goodX + imgSize &&
mouseY >= goodY &&
mouseY < goodY + imgSize
) {
return true;
} else {
return false;
}
}
// Game ends if 10+ rounds are reached
function rounds() {
if (counter == 11) {
songs[currentSong].stop();
rickRoll();
gameState = "end";
// drawEndScreen()
}
}
// makes the next round happen,randoized again
function nextRound() {
songs[currentSong].stop();
previousSongs.push(currentSong);
counter++;
rounds();
randomize();
gameOver();
}
// makes it so songs don;t repeat
function noRepeat() {
while (currentSong == previousSongs) {
currentSong = int(random(songs.length));
}
}
// functions and values reset
function gameRestart() {
print("Resetting game state");
strike = 0;
score = 0;
counter = 0;
previousSongs = [];
gameState = "start";
}
// Makes it so the right song is in one of the 4 possible combinations
function currentSongPosition() {
goodX = random(positionX);
goodY = random(positionY);
}
//Game ends if you get 3 wrong answers
function gameOver() {
if (strike > 3) {
gameState = "end";
}
}
//End screen with hint, makes song stop
function drawEndScreen() {
songs[currentSong].stop();
background("orange");
text("Congratulations, your score is: " + score, 200, 200);
text("Try and answer all 10 correctly", 200, 220);
text("Click to play again", 200, 240);
}
//makes it so the album pictures don't repeat as much by using while statements
function randomize() {
currentSong = int(random(songs.length));
while (currentSong in previousSongs) {
currentSong = int(random(songs.length));
}
wSong1 = int(random(songs.length));
while (wSong1 == currentSong) {
wSong1 = int(random(songs.length));
}
wSong2 = int(random(songs.length));
while (wSong2 == currentSong || wSong2 == wSong1) {
wSong2 = int(random(songs.length));
}
wSong3 = int(random(songs.length));
while (wSong3 == currentSong || wSong3 == wSong2 || wSong3 == currentSong) {
wSong3 = int(random(songs.length));
}
wSong4 = int(random(songs.length));
while (
wSong4 == currentSong ||
wSong4 == wSong3 ||
wSong4 == wSong2 ||
wSong4 == wSong1
) {
wSong4 = int(random(songs.length));
}
songs[currentSong].play();
currentSongPosition();
}
// special surprise
function rickRoll() {
if (score == 10) {
gameState = "end";
window.open("https://www.youtube.com/watch?v=dQw4w9WgXcQ");
}
}