Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
/* 
**Rolling Notes**
Created by Shayla Ly
In the style of 'Rock Band' and similar games, press the arrow keys when notes are
over the corresponding buttons to earn points.

Arrow Keys: green (left), red (up), blue (down), yellow (right)

Some code referenced from:
http://www-acad.sheridanc.on.ca/PROG14998/2016/interactive-toy/shawn_morey_interactive_toy/index.html
*/

int arrowPoint;
int arrowPressed;
int score;

// declare notes variables
float notes1X = 125;
float notes2X = 165;
float notes3X = 205;
float notes4X = 245;
float notes1Y = 0;
float notes2Y = 0;
float notes3Y = 0;
float notes4Y = 0;
float speed = 1;

// declare button variables
float greenButtonX = 125;
float greenButtonY = 360;
float redButtonX = 165;
float redButtonY = 360;
float blueButtonX = 205;
float blueButtonY = 360;
float yellowButtonX = 245;
float yellowButtonY = 360;

// key presses
boolean leftPressed;
boolean downPressed;
boolean upPressed;
boolean rightPressed;

// ---------------------------------------------------------------- //
// setup
void setup() {
  size(400, 400); 
  rectMode(CORNER);
  ellipseMode(CORNER);
  frameRate(60);
}

// drawing
void draw(){
  drawBackground();
  
  // overlay
  fill(255,255,255,85);
  rect(0,0,400,400);
  
  arrowPoint = (int) random (4);
  arrowPressed = 0;
  
  drawBars();
  drawButtons();
  drawNotes1();
  drawNotes2();
  drawNotes3();
  drawNotes4();
  drawScore();
}


// ---------------------------------------------------------------- //

void drawBackground(){
  noStroke();
  // wall;
  fill(182,156,109);
  rect(0,0,400,400);
  // door
  fill(124,100,53);
  rect(0,30,110,400);
  fill(255,235,104);
  rect(85,120,10,40);
  // floor
  fill(96,82,57);
  rect(0,250,400,400);
  // table
  fill(124,100,53);
  rect(345,210,8,70);
  rect(235,210,8,70);
  fill(140,114,63);
  rect(230,200,130,10);
  ellipse(230,200,130,20);
  ellipse(230,180,130,37);
  // chair
  fill(124,100,53);
  rect(180,230,6,50);
  rect(220,230,6,50);
  fill(140,114,63);
  rect(180,180,10,60);
  rect(180,230,45,10);
}



void drawBars(){
  strokeWeight(4);
  stroke(0);
  line(200,0,200,400);
  line(240,0,240,400);
  line(280,0,280,400);
  line(160,0,160,400);
  line(120,0,120,400);
  // bottom bar
  fill(0);
  noStroke();
  rect(120,350,160,100);
} 
  
  

void drawButtons(){
  // green button
  fill(96,225,71);
  ellipse(greenButtonX,greenButtonY,30,30);
  fill(#40AB2B);
  triangle(144,365,130,375,144,385);
  
  // red button
  fill(225,71,71);
  ellipse(redButtonX,redButtonY,30,30);
  fill(#A92A2A);
  triangle(180,365,170,380,190,380);
  
  // blue button
  fill(49,102,255);
  ellipse(blueButtonX,blueButtonY,30,30);
  fill(#2548BD);
  triangle(220,385,210,370,230,370);
  
  // yellow button
  fill(255,229,49);
  ellipse(yellowButtonX,yellowButtonY,30,30);
  fill(#D1B813);
  triangle(270,375,255,365,255,385);

}



void drawNotes1(){
  fill(0);
  stroke(255,255,255);
  strokeWeight(2);
  ellipse(notes1X,notes1Y,30,30);
  notes1Y = notes1Y + 3.5;
  speed = speed + 0.5;
  
  if (notes1Y >= 370) {
  notes1Y = 0;
  }
}



void drawNotes2(){
  fill(0);
  stroke(255,255,255);
  strokeWeight(2);
  ellipse(notes2X,notes2Y,30,30);
  notes2Y = notes2Y + 4;
  speed = speed + 0.5;
  
  if (notes2Y >= 370) {
  notes2Y = 0;
  }
}
  
  

void drawNotes3(){
  fill(0);
  stroke(255,255,255);
  strokeWeight(2);
  ellipse(notes3X,notes3Y,30,30);
  notes3Y = notes3Y + 4.5;
  speed = speed + 0.5;
  
  if (notes3Y >= 370) {
  notes3Y = 0;
  }
}



void drawNotes4(){
  fill(0);
  stroke(255,255,255);
  strokeWeight(2);
  ellipse(notes4X,notes4Y,30,30);
  notes4Y = notes4Y + 5;
  speed = speed + 0.5;
  
  if (notes4Y >= 370) {
  notes4Y = 0;
  }
}



void drawScore(){
  textSize(20);
  fill(255);
  text("Score:",10,25);
  text(score,75,25);
}



void keyPressed() {
  // green button points
  if (notes1Y >= 340 || notes1Y >= 380 || leftPressed == true)
  {
    arrowPoint = 0;
    score = score + 1; }
  else if (notes1Y <= 340){
    score = score + 0;
    }

  // red button points
  if (notes2Y >= 340 || notes2Y >= 380 || upPressed == true)
  {
    arrowPoint = 1;
    score = score + 1; }
  else if (notes2Y <= 340){
    score = score + 0;
    }
  
  // blue button points
  if (notes3Y >= 340 || notes3Y >= 380 || downPressed == true)
  {
    arrowPoint = 2;
    score = score + 1; }
  else if (notes3Y <= 340){
    score = score + 0;
    }
  
  // yellow button points  
  if (notes4Y >= 340 || notes4Y >= 380 || rightPressed == true)
  {
    arrowPoint = 3;
    score = score + 1; }
  else if (notes4Y <= 340){
    score = score + 0;
    }  
    
}