xxxxxxxxxx
790
let backGround;
let easy;
let medium;
let hard;
let expert;
let gameOver;
let retry;
let quit;
let scoreBoard;
let bgMusic_Easy;
let bgMusic_Medium;
let bgMusic_Hard;
let bgMusic_Expert;
let _width;
let _height;
function setup() {
backGround = loadImage('Assets/menu.png');
easy = loadImage('Assets/easyNew.png');
medium = loadImage('Assets/mediumNew.png');
hard = loadImage('Assets/hardNew.png');
expert = loadImage('Assets/expertNew.png');
gameOver = loadImage('gameOverNew.png');
quit = loadImage('Assets/quitNew.png');
retry = loadImage('Assets/retryNew.png');
bgMusic_Easy = loadSound("Sel_Easy.mp3");
bgMusic_Medium = loadSound("jb_Medium.mp3");
bgMusic_Hard = loadSound("Blue Monday_Hard.mp3");
bgMusic_Expert = loadSound("GnR_Extreme.mp3")
width = windowWidth * 0.9;
height = windowHeight * 0.9;
scoreBoard = loadImage('ScoreBoardNew.png');
createCanvas(width, height);
rectMode(CENTER);
}
//note array
var n = [];
//hitbox array
var h = [];
var lowerPositionLimit = 400;
var score = 1000;
var hit = false;
var ht = 0;
var streak = 0;
var speed = 30;
var inc = 0;
var level = "easy";
var size2 = 1000;
var long = 0;
var tot = 0;
var notes = 0;
var miss = 0;
var arrowsXSize = 15;
var arrowsYSize = 15;
var arrowsOffset = 30;
var frameCounter = 0;
var scr = "menu";
function draw() {
// width = windowWidth * 0.9;
// height = windowHeight * 0.9; //menu screen
if (scr == "menu") {
background(backGround);
drawBack();
menu();
}
//game screen
if (scr == "game") {
frameCounter++;
background(0);
drawBack();
//sets longest streak
if (long < streak) {
long = streak;
}
//red background when miss
if (hit && ht < 5) {
background(255, 0, 0, 100);
ht++;
}
if (ht > 5) {
hit = false;
}
drawLines();
stroke(0);
//creates notes
if (level == "easy" || level == "medium") {
if(level == "easy") speed = 50;
else speed = 40;
if (frameCount % speed === 0) {
n.push(new Note(floor(random(2, 5))));
}
}
if (level == "hard" || level == "expert") {
if (frameCount % speed === 0) {
if(level == "hard") speed = 30;
else
speed = 15;
//generates random notes
ran = floor(random(2, 5));
ran2 = floor(random(2, 5));
while (ran2 == ran) {
ran2 = floor(random(2, 5));
}
n.push(new Note(ran));
// n.push(new Note(ran2));
}
}
//displays and moves notes
for (let i = 0; i < n.length; i++) {
n[i].display();
n[i].move();
}
//removes notes from array when off screen
for (let i = 0; i < n.length; i++) {
if (n[i].y > height) {
miss++;
score -= 200;
streak = 0;
hit = true;
ht = 0;
n.splice(i, 1);
tot++;
}
}
//displays and fades hitboxes
for (let i = 0; i < h.length; i++) {
h[i].display();
h[i].fade();
}
//removes hitboxes from array after faded
for (let i = 0; i < h.length; i++) {
if (h[i].f < 0) {
h.splice(i, 1);
}
}
//increases speed
if (inc % 20 === 0) {
speed--;
inc++;
}
sideBar();
// score < 0
//gameover if negative score
if (miss > 6) {
scr = "gameover";
}
if(frameCounter > 0 && scr == "game")
{
if(level == "easy" && !bgMusic_Easy.isPlaying())
scr = "gameover";
else if(level == "medium" && !bgMusic_Medium.isPlaying())
scr = "gameover";
else if(level == "hard" && !bgMusic_Hard.isPlaying())
scr = "gameover";
else if(level == "expert" && !bgMusic_Expert.isPlaying())
scr = "gameover";
}
}
//gameover screen
if (scr == "gameover") {
bgMusic_Easy.stop();
bgMusic_Medium.stop();
bgMusic_Hard.stop();
bgMusic_Expert.stop();
fill(0);
rect(600, 500, 1200, 1000);
EndPannel();
image(gameOver, width * 0.5 - 100, 30, 200, 100);
SetScoreBoard();
}
}
function windowResized()
{
resizeCanvas(windowWidth, windowHeight);
}
// GAME OVER PANNEL
function EndPannel()
{
// RETRY
image(retry, width * 0.5, height * 0.5 - 50);
if (mouseX > width * 0.5 + 50 && mouseX < width * 0.5 + 250){
if (mouseY > height * 0.5 - 100 && mouseY < height * 0.5 + 100) {
if (mouseIsPressed) {
mouseX = 2000;
score = 1000;
streak = 0;
hit = false;
ht = 0;
inc = 0;
notes = 0;
long = 0;
miss = 0;
tot = 0;
h.splice(0, h.length);
n.splice(0, n.length);
scr = "game";
if (level == "easy" || level == "hard") {
speed = 50;
} else {
speed = 40;
}
if(level == "easy")
bgMusic_Easy.play();
else if(level == "medium")
bgMusic_Medium.play();
else if(level == "hard")
bgMusic_Hard.play();
else
bgMusic_Expert.play();
}
}
}
//quit
image(quit, width * 0.5, height * 0.5 + 100);
if (mouseX > width * 0.5 + 50 && mouseX < width * 0.5 + 250) {
if (mouseY > height * 0.5+100-50 && mouseY < height * 0.5 + 100+50) {
if (mouseIsPressed) {
mouseX = 2000;
score = 1000;
streak = 0;
hit = false;
ht = 0;
miss = 0;
inc = 0;
notes = 0;
long = 0;
tot = 0;
h.splice(0, h.length);
n.splice(0, n.length);
scr = "menu";
if (level == "easy" || level == "hard") {
speed = 50;
} else {
speed = 40;
}
}
}
}
}
//draws sidebar
function sideBar() {
stroke(0);
fill(0, 194, 203);
noStroke();
SetScoreBoard();
}
function SetScoreBoard()
{
var y = height * 0.05;
var x = width * 0.01;
if(scr == "gameover")
y = height * 0.35;
x = 100;
image(scoreBoard, x, y, width * 0.2, height * 0.4);
text(streak, width * 0.13, height*0.25);
var per = round((notes / tot) * 100);
if (tot === 0) {
per = "-";
}
text(per + "%", width * 0.13, height * 0.42);
//text("RETRY", 100, 600);
text("QUIT", width * 0.05, height - 40);
fill(0);
//quit
if (mouseX > 0 && mouseX < width * 0.15) {
if (mouseY > height-80 && mouseY < height) {
if (mouseIsPressed) {
mouseX = 2000;
score = 1000;
streak = 0;
hit = false;
ht = 0;
inc = 0;
notes = 0;
long = 0;
tot = 0;
h.splice(0, h.length);
n.splice(0, n.length);
scr = "menu";
if (level == "easy" || level == "hard") {
speed = 50;
} else {
speed = 40;
}
if(level == "easy")
bgMusic_Easy.stop();
else if(level == "medium")
bgMusic_Medium.stop();
else if(level == "hard")
bgMusic_Hard.stop();
else
bgMusic_Expert.stop();
}
}
}}
//menu screen
function menu() {
//title
/*
for (i = 20; i > 0; i--) {
fill(255 - i * 10, 10, 255 - i * 2);
textSize(120);
text("GUITAR HERO", 100 + i, 120 + i);
}
*/
textSize(40);
image(easy, width * 0.42, height * 0.35, width * 0.15, height * 0.1);
image(medium, width * 0.42, height * 0.35 + 70, width * 0.15, height * 0.1);
image(hard, width * 0.42, height * 0.35 + 140, width * 0.15, height * 0.1);
image(expert, width * 0.42, height * 0.35 + 210, width * 0.15, height * 0.1);
// text("EASY", 500, 375);
// text("MEDIUM", 500, 525);
// text("HARD", 500, 675);
// text("EXPERT", 500, 825);
//buttons
//easy
if (mouseX > width*0.42 && mouseX < width*0.42 + 200) {
if (mouseY > height*0.35 && mouseY < height * 0.35 + 100) {
if (mouseIsPressed) {
scr = "game";
level = "easy";
mouseX = 2000;
bgMusic_Easy.play();
}
}
}
//medium
if (mouseX > width*0.42 && mouseX < width*0.42 + 200) {
if (mouseY > height * 0.35 + 70 && mouseY < height * 0.35 + 70 + 100) {
if (mouseIsPressed) {
scr = "game";
level = "medium";
speed = 40;
mouseX = 2000;
bgMusic_Medium.play();
}
}
}
//hard
if(mouseX > width*0.42 && mouseX < width*0.42 + 200 ) {
if (mouseY > height * 0.35 + 140 && mouseY < height * 0.35 + 140 + 100) {
if (mouseIsPressed) {
scr = "game";
level = "hard";
mouseX = 2000;
speed = 50;
bgMusic_Hard.play();
}
}
}
//expert
if (mouseX > width*0.42 && mouseX < width*0.42 + 200) {
if (mouseY > height * 0.3 + 210 && mouseY < height * 0.35 + 210 + 100) {
if (mouseIsPressed) {
scr = "game";
level = "expert";
speed = 75;
mouseX = 2000;
bgMusic_Expert.play();
}
}
}
}
//draws background
function drawBack() {
// rect(600, 500, 1200, size2);
// size2 += 8;
// if (size2 > 3000) {
// size2 = 2000;
// }
}
//more background
function circ(x, y, s) {
stroke(0);
noFill();
strokeWeight(s / 10);
ellipse(x, y, s, s);
if (s > 10) {
circ(x, y, s / 1.5);
}
}
//draws rows and note buttons
function drawLines() {
strokeWeight(10);
fill(255, 200);
// rect(200, 500, 150, 1200, 20);
fill(255, 102, 196);
rect(width * 0.5 - 100, 500, 80, 1200, 20);
fill(0, 194, 203);
rect(width * 0.5, 500, 80, 1200, 20);
fill(126, 217, 87);
rect(width * 0.5 + 100, 500, 80, 1200, 20);
// HORIZONTAL WHITE LINE
strokeWeight(4);
stroke(250);
fill(250);
rect(width * 0.5, height - 90, width * 0.5, 0.5, 10);
// LEFT FIRST ARROW
strokeWeight(5);
beginShape();
vertex(width * 0.5 - 100 - arrowsOffset *0.5,height - 50);//X1, Y1 of first point
vertex(width * 0.5 - 100 - arrowsOffset *0.5 + arrowsXSize,height-50 - arrowsYSize);
vertex(width * 0.5 - 100 - arrowsOffset *0.5 + arrowsXSize - arrowsYSize,height - 50 - arrowsYSize);
vertex(width * 0.5 - 100 - arrowsOffset *0.5 - arrowsYSize,height-50);
vertex(width * 0.5 - 100 - arrowsOffset *0.5 + arrowsXSize - arrowsYSize,height -50 + arrowsYSize);
vertex(width * 0.5 - 100 - arrowsOffset *0.5 + arrowsXSize,height-50 + arrowsYSize);
vertex(width * 0.5 - 100 - arrowsOffset *0.5,height-50);
endShape(CLOSE);
// LEFT SECOND ARROW
beginShape();
vertex(width * 0.5 - 100 - arrowsOffset *0.5 + arrowsOffset,height - 50);//X1, Y1 of first point
vertex(width * 0.5 - 100 - arrowsOffset *0.5 + arrowsOffset + arrowsXSize,height - 50 - arrowsYSize);
vertex(width * 0.5 - 100 - arrowsOffset *0.5 + arrowsOffset + arrowsXSize - arrowsYSize,height - 50 - arrowsYSize);
vertex(width * 0.5 - 100 - arrowsOffset *0.5 + arrowsOffset - arrowsYSize,height - 50);
vertex(width * 0.5 - 100 - arrowsOffset *0.5 + arrowsOffset + arrowsXSize - arrowsYSize,height - 50 + arrowsYSize);
vertex(width * 0.5 - 100 - arrowsOffset *0.5 + arrowsOffset + arrowsXSize,height - 50 + arrowsYSize);
vertex(width * 0.5 - 100 - arrowsOffset *0.5 + arrowsOffset,height - 50);
endShape(CLOSE);
// CENTER FIRST ARROW
strokeWeight(4);
stroke(230);
beginShape();
vertex(width * 0.5,height - 50 + arrowsOffset *0.5);//X1, Y1 of first point
vertex(width * 0.5 + arrowsXSize,height - 50 + arrowsYSize + arrowsOffset *0.5);
vertex(width * 0.5 + arrowsXSize,height - 50 + arrowsOffset *0.5);
vertex(width * 0.5,height - 50 - arrowsYSize + arrowsOffset *0.5);
vertex(width * 0.5 - arrowsXSize,height - 50 + arrowsOffset *0.5);
vertex(width * 0.5 - arrowsXSize,height - 50 + arrowsYSize + arrowsOffset *0.5);
vertex(width * 0.5,this.y);
endShape(CLOSE);
// CENTER SECOND ARROW
beginShape();
vertex(width * 0.5,height - 50 - arrowsOffset + arrowsOffset *0.5);//X1, Y1 of first point
vertex(width * 0.5 + arrowsXSize,height - 50 + arrowsYSize - arrowsOffset + arrowsOffset *0.5);
vertex(width * 0.5 + arrowsXSize,height - 50 - arrowsOffset + arrowsOffset *0.5);
vertex(width * 0.5,height - 50 - arrowsYSize - arrowsOffset + arrowsOffset *0.5);
vertex(width * 0.5 - arrowsXSize,height - 50 - arrowsOffset + arrowsOffset *0.5);
vertex(width * 0.5 - arrowsXSize,height - 50 + arrowsYSize - arrowsOffset + arrowsOffset *0.5);
vertex(width * 0.5,height - 50 - arrowsOffset + arrowsOffset *0.5);
endShape(CLOSE);
// RIGHT FIRST ARROW
strokeWeight(5);
beginShape();
vertex(width * 0.5 + 100 + arrowsOffset *0.25,height - 50);//X1, Y1 of first point
vertex(width * 0.5 + 100 + arrowsOffset *0.25 - arrowsXSize,height - 50 - arrowsYSize);
vertex(width * 0.5 + 100 + arrowsOffset *0.25 - arrowsXSize - arrowsYSize,height - 50 - arrowsYSize);
vertex(width * 0.5 + 100 + arrowsOffset *0.25 - arrowsYSize,height - 50);
vertex(width * 0.5 + 100 + arrowsOffset *0.25 - arrowsXSize - arrowsYSize,height - 50 + arrowsYSize);
vertex(width * 0.5 + 100 + arrowsOffset *0.25 - arrowsXSize,height - 50 + arrowsYSize);
vertex(width * 0.5 +100 + arrowsOffset *0.25,height - 50);
endShape(CLOSE);
// RIGHT SECOND ARROW
beginShape();
vertex(width * 0.5 + 100 + arrowsOffset *0.25 + arrowsOffset,height - 50);//X1, Y1 of first point
vertex(width * 0.5 + 100 + arrowsOffset *0.25 + arrowsOffset - arrowsXSize,height - 50 - arrowsYSize);
vertex(width * 0.5 + 100 + arrowsOffset *0.25 + arrowsOffset - arrowsXSize - arrowsYSize,height - 50 - arrowsYSize);
vertex(width * 0.5 + 100 + arrowsOffset *0.25 + arrowsOffset - arrowsYSize,height - 50);
vertex(width * 0.5 +100 + arrowsOffset *0.25 + arrowsOffset - arrowsXSize - arrowsYSize,height - 50 + arrowsYSize);
vertex(width * 0.5 + 100 + arrowsOffset *0.25 + arrowsOffset - arrowsXSize,height - 50 + arrowsYSize);
vertex(width * 0.5 + 100 + arrowsOffset *0.25 + arrowsOffset,height - 50);
endShape(CLOSE);
/*
// fill(255, 0, 0, 200);
// rect(200, 850, 150, 100, 20);
fill(255, 255, 0, 200);
rect(400, lowerPositionLimit, 150, 100, 20);
fill(0, 255, 0, 200);
rect(600, lowerPositionLimit, 150, 100, 20);
fill(51, 153, 255);
rect(800, lowerPositionLimit, 150, 100, 20);
fill(0);
noStroke();
// text("Z", 180, 870);
text("X", 380, lowerPositionLimit);
text("C", 580, lowerPositionLimit);
text("V", 780, lowerPositionLimit);
*/
stroke(0);
}
//checks which key is pressed
function keyPressed() {
/*
if (key === "z") {
checkDist(1);
}
*/
if (keyCode === LEFT_ARROW) {
checkDist(2);
}
if (keyCode === UP_ARROW) {
checkDist(3);
}
if (keyCode === RIGHT_ARROW) {
checkDist(4);
}
}
//note object
class Note {
constructor(n) {
switch (n) {
case 1:
this.x = 200;
break;
case 2:
this.x = width * 0.5 -100;
break;
case 3:
this.x = width * 0.5
break;
case 4:
this.x = width * 0.5 + 100;
break;
}
this.y = -200;
this.n = n;
}
display() {
noFill();
switch (this.n) {
case 1:
stroke(255, 0, 0);
break;
case 2:
stroke(255, 255, 0);
break;
case 3:
stroke(0, 255, 0);
break;
case 4:
stroke(51, 153, 255);
break;
}
if(this.n == 2)
{
// LEFT FIRST ARROW
strokeWeight(5);
beginShape();
vertex(this.x - arrowsOffset *0.5,this.y);//X1, Y1 of first point
vertex(this.x - arrowsOffset *0.5 + arrowsXSize,this.y - arrowsYSize);
vertex(this.x - arrowsOffset *0.5 + arrowsXSize - arrowsYSize,this.y - arrowsYSize);
vertex(this.x - arrowsOffset *0.5 - arrowsYSize,this.y);
vertex(this.x - arrowsOffset *0.5 + arrowsXSize - arrowsYSize,this.y + arrowsYSize);
vertex(this.x - arrowsOffset *0.5 + arrowsXSize,this.y + arrowsYSize);
vertex(this.x - arrowsOffset *0.5,this.y);
endShape(CLOSE);
// LEFT SECOND ARROW
beginShape();
vertex(this.x - arrowsOffset *0.5 + arrowsOffset,this.y);//X1, Y1 of first point
vertex(this.x - arrowsOffset *0.5 + arrowsOffset + arrowsXSize,this.y - arrowsYSize);
vertex(this.x - arrowsOffset *0.5 + arrowsOffset + arrowsXSize - arrowsYSize,this.y - arrowsYSize);
vertex(this.x - arrowsOffset *0.5 + arrowsOffset - arrowsYSize,this.y);
vertex(this.x - arrowsOffset *0.5 + arrowsOffset + arrowsXSize - arrowsYSize,this.y + arrowsYSize);
vertex(this.x - arrowsOffset *0.5 + arrowsOffset + arrowsXSize,this.y + arrowsYSize);
vertex(this.x - arrowsOffset *0.5 + arrowsOffset,this.y);
endShape(CLOSE);
}
else if(this.n == 3)
{
// UP FIRST ARROW
strokeWeight(5);
beginShape();
vertex(this.x,this.y);//X1, Y1 of first point
vertex(this.x + arrowsXSize,this.y + arrowsYSize);
vertex(this.x + arrowsXSize,this.y);
vertex(this.x,this.y - arrowsYSize);
vertex(this.x - arrowsXSize,this.y);
vertex(this.x - arrowsXSize,this.y + arrowsYSize);
vertex(this.x,this.y);
endShape(CLOSE);
// UP SECOND ARROW
beginShape();
vertex(this.x,this.y - arrowsOffset);//X1, Y1 of first point
vertex(this.x + arrowsXSize,this.y + arrowsYSize - arrowsOffset);
vertex(this.x + arrowsXSize,this.y - arrowsOffset);
vertex(this.x,this.y - arrowsYSize - arrowsOffset);
vertex(this.x - arrowsXSize,this.y - arrowsOffset);
vertex(this.x - arrowsXSize,this.y + arrowsYSize - arrowsOffset);
vertex(this.x,this.y - arrowsOffset);
endShape(CLOSE);
}
else if(this.n == 4)
{
// RIGHT FIRST ARROW
strokeWeight(5);
beginShape();
vertex(this.x + arrowsOffset *0.25,this.y);//X1, Y1 of first point
vertex(this.x + arrowsOffset *0.25 - arrowsXSize,this.y - arrowsYSize);
vertex(this.x + arrowsOffset *0.25 - arrowsXSize - arrowsYSize,this.y - arrowsYSize);
vertex(this.x + arrowsOffset *0.25 - arrowsYSize,this.y);
vertex(this.x + arrowsOffset *0.25 - arrowsXSize - arrowsYSize,this.y + arrowsYSize);
vertex(this.x + arrowsOffset *0.25 - arrowsXSize,this.y + arrowsYSize);
vertex(this.x + arrowsOffset *0.25,this.y);
endShape(CLOSE);
// RIGHT SECOND ARROW
beginShape();
vertex(this.x + arrowsOffset *0.25 + arrowsOffset,this.y);//X1, Y1 of first point
vertex(this.x + arrowsOffset *0.25 + arrowsOffset - arrowsXSize,this.y - arrowsYSize);
vertex(this.x + arrowsOffset *0.25 + arrowsOffset - arrowsXSize - arrowsYSize,this.y - arrowsYSize);
vertex(this.x + arrowsOffset *0.25 + arrowsOffset - arrowsYSize,this.y);
vertex(this.x + arrowsOffset *0.25 + arrowsOffset - arrowsXSize - arrowsYSize,this.y + arrowsYSize);
vertex(this.x + arrowsOffset *0.25 + arrowsOffset - arrowsXSize,this.y + arrowsYSize);
vertex(this.x + arrowsOffset *0.25 + arrowsOffset,this.y);
endShape(CLOSE);
}
// rect(this.x, this.y, 150, 100, 20);
}
move() {
if(level == "easy")
this.y += 4;
else if(level == "expert")
this.y += 8;
else
this.y += 7;
}
}
//hitbox object
class Hit {
constructor(n, y, c) {
switch (n) {
case 1:
this.x = 200;
break;
case 2:
this.x = width*0.5-100;
break;
case 3:
this.x = width*0.5;
break;
case 4:
this.x = width*0.5+100;
break;
}
this, (y = y);
this.c = c;
this.f = 255;
this.w = 100;
this.h = 50;
}
display() {
switch (this.c) {
case "e":
stroke(0, 255, 0, this.f);
break;
case "g":
stroke(0, 255, 0);
//stroke(102, 255, 153, this.f);
break;
case "m":
stroke(0, 255, 0);
// stroke(255, 255, 102, this.f);
break;
case "b":
stroke(0, 255, 0);
// stroke(204, 0, 0, this.f);
break;
}
noFill();
strokeWeight(12);
rect(this.x, height-50, this.w, this.h, 20);
}
fade() {
this.f -= 10;
this.w += 0.5;
this.h += 0.5;
}
}
//checks how close each note is to the hitbox
function checkDist(num) {
for (let i = 0; i < n.length; i++) {
if (n[i].n == num) {
//excellent
if (abs(n[i].y - (height-50)) < 10) {
h.push(new Hit(num, n[i].y, "e"));
score += 300;
streak++;
inc++;
notes++;
n.splice(i, 1);
tot++;
miss = 0;
break;
}
//good
else if (abs(n[i].y - (height-50)) < 20) {
h.push(new Hit(num, n[i].y, "g"));
score += 150;
streak++;
inc++;
notes++;
n.splice(i, 1);
tot++;
miss = 0;
break;
}
//medium
else if (abs(n[i].y - (height-50)) < 30) {
h.push(new Hit(num, n[i].y, "m"));
score += 100;
inc++;
streak++;
notes++;
n.splice(i, 1);
tot++;
miss = 0;
break;
}
//bad
else if (abs(n[i].y - (height-50)) < 40) {
h.push(new Hit(num, n[i].y, "b"));
score += 50;
streak++;
inc++;
notes++;
n.splice(i, 1);
tot++;
miss = 0;
break;
}
//miss
else {
if (scr != "gameover") {
score -= 100;
}
streak = 0;
hit = true;
ht = 0;
miss++;
}
}
}
stroke(0);
}