Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
/*
 Interactive Toy designed and created by Francesca Ramirez
 Class: Into to Media Comp PROG14498, Section P04
 
 PROGRAM DESCRIPTION:
 This program will create an interactive toy similar to Taiko Osu or Guitar Hero!
 You play a girl waiting for her cute date to come. Don't get too nervous and let your heart beat too fast!
 
 INSTRUCTIONS
 Use the arrow keys on the keyboard
 Watch the arrows as they scroll by the screen
 Press the corresponding arrow key to its pose as it lines up with the hit box
 Try not to get 5 penalties!
 
 Some code referenced from these lovely programs:
 http://www-acad.sheridanc.on.ca/PROG14998/2017/interactive-toy/shayla_ly_interactive_toy/index.html
 http://www-acad.sheridanc.on.ca/PROG14998/2017/interactive-toy/victoria_palermo_interactive_toy/index.html
 */

//create variables for every hardcoded number in shapes/colours later
//variable declaration and initialization
float rectPosX = 0, circlePosX = 10;
float poseLeftX = 400, poseUpX = 450, poseDownX = 500, poseRightX = 550;
float poseSpeedLeft = random (1, 3), poseSpeedUp =random (1, 3), poseSpeedDown = random (1, 3), poseSpeedRight = random (1, 3);
float randomNumber;
float distHitLeft, distHitUp, distHitDown, distHitRight;
int penalty = 0;
float beatSpeed1 = 30, beatSpeed2 = 35;
void setup()
{
  //window size 400x400 pixels
  size(400, 400);
  //remove cursor
  noCursor();
  //make frame rate 60fps
  frameRate(60);
  println("Use the arrow keys on the keyboard\nWatch the arrows as they scroll by the screen\nPress the corresponding arrow key to its pose as it lines up with the hit box\nTry not to get 5 penalties!"
    + "\nThe characters breathing will increase with each penalty (hence why this game is called Heart Beats");
  println("Play https://listenonrepeat.com/?v=RALSyjNx_r4#elijah_who_-_a_cute_date to play to some cute beats!!!");
}//end setup

void draw()
{
  //initialize variables here to update
  distHitLeft = dist(poseLeftX, 50, 20, 0);
  distHitUp = dist(poseUpX, 20, 20, 0);
  distHitDown = dist(poseDownX, 80, 20, 0);
  distHitRight = dist(poseRightX, 50, 20, 0);
  randomNumber  = random(0, 1);

  drawStage();
  drawLights();
  drawPlayer();
  arrowIndicator();
  drawLeft();
  drawUp();
  drawDown();
  drawRight();
  drawScore();
  scoreIndicator();
  endScreen();
}//end draw

void drawStage()
{
  //stage ground and wall
  strokeWeight(2);
  stroke(255);
  fill(255, 142, 114);
  rect(0, 240, width, 80);
  fill(218, 70, 74);
  rect(0, 340, width, 60);
  fill(237, 106, 94);
  rect(0, 100, 400, 120);

  //draw panel
  fill(218, 70, 74);
  rect(0, 0, 400, 100);
  fill(255);
  rect(20, 0, 80, 100);
  stroke(0);
  strokeWeight(2);
  line(60, 40, 60, 60);
  line(50, 50, 70, 50);
}//end draw stage

void drawLights()
{
  //create a for loop to create multiple shapes
  strokeWeight(1);
  stroke(255);
  fill(76, 213, 153, 250);
  //loop for the width amount to draw the lights
  for (int i = 0; i < width/2; i++)
  {
    //top lights
    rect(rectPosX, 220, 20, 20);
    ellipse(circlePosX, 230, 20, 20);

    //bottom lights
    rect(rectPosX, 320, 20, 20);
    ellipse(circlePosX, 330, 20, 20);

    rectPosX = rectPosX + 20;
    circlePosX = circlePosX + 20;
  }//end for loop
}//end drawing lights

void drawPlayer()
{
  //make player bob up and down a little
  stroke(255);
  fill(76, 224, 179, 200);
  triangle(width/2, 4 * cos(frameCount / beatSpeed1) + 180, 230, 4 * cos(frameCount / beatSpeed1) + 250, 170, 4 * cos(frameCount / beatSpeed1) + 250);
  triangle(205, 4 * cos(frameCount / beatSpeed1) + 180, 215, 4 * cos(frameCount / beatSpeed1) + 200, 240, 4 * cos(frameCount / beatSpeed1) + 220);
  triangle(195, 4 * cos(frameCount / beatSpeed1) +180, 185, 4 * cos(frameCount / beatSpeed1) +200, 160, 4 * cos(frameCount / beatSpeed1) +220);
  triangle(width/2, 255, width/2 + 10, 255, width/2 + 5, 300);
  triangle(width/2 - 10, 255, width/2, 255, width/2 - 5, 300);
  triangle(240, 3 * cos(frameCount / beatSpeed2) + 120, 235, 3 * cos(frameCount / beatSpeed2) + 150, 260, 3 * cos(frameCount / beatSpeed2) + 160);
  triangle(160, 3 * cos(frameCount / beatSpeed2) + 120, 165, 3 * cos(frameCount / beatSpeed2) + 150, 140, 3 * cos(frameCount / beatSpeed2) + 160);
  ellipse(width/2, 3 * cos(frameCount / beatSpeed2) + 150, 60, 60);
}//end drawing

void arrowIndicator()
{
  stroke(76, 224, 179);
  fill(255);
  //left arrow
  triangle(70, 370, 100, 340, 100, 400);

  //up arrow
  triangle(150, 340, 180, 370, 120, 370);

  //down arrow
  triangle(200, 370, 230, 400, 260, 370);

  //right arrow
  triangle(280, 340, 310, 370, 280, 400);
  //highlight arrows when pressed
  stroke(255);
  fill(76, 224, 179);
  if (keyPressed && keyCode == LEFT)
  {
    triangle(70, 370, 100, 340, 100, 400);
  } else if (keyPressed && keyCode == UP)
  {
    triangle(150, 340, 180, 370, 120, 370);
  } else if (keyPressed && keyCode == DOWN)
  {
    triangle(200, 370, 230, 400, 260, 370);
  } else if (keyPressed && keyCode == RIGHT)
  {
    triangle(280, 340, 310, 370, 280, 400);
  }
}//end arrow indicator

void keyPressed()
{
  //when player presses arrow key once the corresponding arrow crosses the hit box, they're safe
  if (keyCode == LEFT)
  {
    if (distHitLeft > 70)
    {
      penalty = penalty + 1;
    }
  }
  if (keyCode == UP)
  {
    if (distHitUp > 70)
    {
      penalty = penalty + 1;
    }
  }
  if (keyCode == DOWN)
  {
    if (distHitDown > 90)
    {
      penalty = penalty + 1;
    }
  }
  if (keyCode == RIGHT)
  {
    if (distHitRight > 70)
    {
      penalty = penalty + 1;
    }
  }
}//end pose indicator

//draw up arrow
void drawUp()
{
  stroke(255);
  fill(76, 224, 179, 200);
  triangle(poseUpX, 20, poseUpX - 30, 50, poseUpX + 30, 50);
  poseUpX = poseUpX - poseSpeedUp;

  if (poseUpX < 0)
  {
    poseUpX = 400;
    poseSpeedUp = random (1, 3);
    poseSpeedUp = poseSpeedUp + randomNumber;
  }
}//end draw arrow

//draw down arrow
void drawDown()
{
  stroke(255);
  fill(76, 224, 179, 200);
  triangle(poseDownX, 80, poseDownX - 30, 50, poseDownX + 30, 50);
  poseDownX = poseDownX - poseSpeedDown;

  if (poseDownX < 0)
  {
    poseDownX = 400;
    poseSpeedDown = random (1, 3);
    poseSpeedDown = poseSpeedDown + randomNumber;
  }
}//end draw arrow

//draw left arrow
void drawLeft()
{
  stroke(255);
  fill(76, 224, 179, 200);
  triangle(poseLeftX, 50, poseLeftX + 30, 20, poseLeftX + 30, 80);
  poseLeftX = poseLeftX - poseSpeedLeft;

  if (poseLeftX < 0)
  {
    poseLeftX = 400;
    poseSpeedLeft = random (1, 3);
    poseSpeedLeft = poseSpeedLeft + randomNumber;
  }
}//end draw arrow

void drawRight()
{
  stroke(255);
  fill(76, 224, 179, 200);
  triangle(poseRightX + 60, 50, poseRightX + 30, 20, poseRightX + 30, 80);
  poseRightX = poseRightX - poseSpeedRight;

  if (poseRightX < 0)
  {
    poseRightX = 400;
    poseSpeedRight = random (1, 3);
    poseSpeedRight = poseSpeedRight + randomNumber;
  }
}//end draw arrow

void drawScore()
{
  fill(255);
  rect(10, 110, 10, 20);
  rect(30, 110, 10, 20);
  rect(50, 110, 10, 20);
  rect(70, 110, 10, 20);
  rect(90, 110, 10, 20);
}// end draw score

void scoreIndicator()
{
  if (penalty == 1)
  {
    beatSpeed1 = 25;
    beatSpeed2 = 30;
    fill(76, 224, 179);
    rect(10, 110, 10, 20);
  } else if (penalty == 2)
  {
    beatSpeed1 = 20;
    beatSpeed2 = 25;
    fill(76, 224, 179);
    rect(10, 110, 10, 20);
    rect(30, 110, 10, 20);
  } else if (penalty == 3)
  {
    beatSpeed1 = 15;
    beatSpeed2 = 20;
    fill(76, 224, 179);
    rect(10, 110, 10, 20);
    rect(30, 110, 10, 20);
    rect(50, 110, 10, 20);
  } else if (penalty == 4)
  {
    beatSpeed1 = 10;
    beatSpeed2 = 15;
    fill(76, 224, 179);
    rect(10, 110, 10, 20);
    rect(30, 110, 10, 20);
    rect(50, 110, 10, 20);
    rect(70, 110, 10, 20);
  } else if (penalty == 5)
  {
    beatSpeed1 = 5;
    beatSpeed2 = 10;
    fill(76, 224, 179);
    rect(10, 110, 10, 20);
    rect(30, 110, 10, 20);
    rect(50, 110, 10, 20);
    rect(70, 110, 10, 20);
    rect(90, 110, 10, 20);
  }
}//end penalty checker

void endScreen()
{
  if (penalty > 5)
  {
    frameRate(2);
    fill(218, 70, 74, 200);
    triangle(240, 140, 200, 220, 300, 220);
    triangle(160, 140, 100, 220, 200, 220);
    triangle(300, 220, 100, 220, 200, 320);
    strokeWeight(2);
    line(200, 220, 230, 250);
    line(230, 250, 180, 260);
    line(180, 260, 200, 320);
    println("GAME OVER! Refresh to play again and keep your heart beat steady!");
  }
}// end end screen
//end program