Final Project- Pitch Controlled Game

Starting from a game I previously made with an ellipse controlled by the up, down, left and right keys, I created a new game with more interaction. I had created previous sketches with sound input before; colors, shapes or movement that reacted to the sound loudness that was input into the microphone. For this final project I wanted to find a way to use the pitch of the sound that was input, as opposed to the loudness. It was more challenging and took many experimentations. My overall goal was to have the same original gmae idea with a controlled ellipse, but this time, the directions would be determined by the pitch.

I had many draft sketches where the ellipse would just go up when the pitch was high, and go down when the pitch was low. After that I created certain ranges for each pitch. The highest pitch would make the ellipse go right, and the lowest would make it go left.

The next step was trying to control the speed the ellipse would travel in the desired direction. Also, I added a if mousepressed command that would bring the ellipse back to the center of the sketch incase it was lost.

The goal of the game then was created, to make the small pitch controlled ellipse meet up with the larger ellipse on the screen. With each sketch, the larger ellipse is placed in a random location, and when the player gets the smaller one to touch it, they both change color for  a moment.

I am very happy with how the sketch turned out, and I am surprised I was able to do what I originally had planned. I would like to take this game further and create a points system and possibly more levels where each level gets more difficult by the speed of the small ellipse getting faster. Also, in the beginning having a moment for the player to get their pitches adjusted to determine which pitch corresponds with which direction.

CODE:

import ddf.minim.*;
import ddf.minim.signals.*;

Minim minim;
AudioInput in;
AudioSample jump;

AudioPlayer player;
pitchDetector pitchdetect;
TriangleWave osc;
boolean switched=true;
float x = 0;
float y = 0;
float aX = 0;
float aY = 0;
float velX=0;
float velY=0;
float radiusMe = 10;
float radius = 20;
//

 
void setup() {
size(600, 600, P2D);
aX = random(width);
aY = random(height);
minim = new Minim(this);

in = minim.getLineIn(Minim.STEREO, 512);

pitchdetect = new pitchDetector();
in.addEffect(pitchdetect);
}

void draw() {
background(255);
// SPEED control
ellipse(x/2,y/2,10,10);
println(pitchdetect.getPitch());

// if( x< 0 ) x = 0;
// if (x> width) x = width;
//if (

// ellipse(x,y,10,10);

float distance = dist(x,y,aX, aY);
if(distance <radius + radiusMe){
fill(155,10,90);
}else{
fill(255);

}
// background(0);
//float pitch = pitchdetect.getPitch();
ellipse(aX,aY, radius*2, radius*2);

x += velX;
y += velY;
velX-= velX * .1;
velY-= velY * .1;
float pitch = pitchdetect.getPitch();
if( pitch > 550){
// do something
x-=5;
// velY -= 2;
}else if( pitch > 400){
x+=5;

}else if( pitch > 250){
y-=5;

}else if (pitch > 30){
y+=5;
}
if (mousePressed == true) {
x=width;
y=height;
}

}
//if( x< 0 ) x = 0;
//if (x> width) x = width;
// if (y<height)y=height;

// SPEED control
// ellipse(x/2,y/2,10,10);
// println(pitchdetect.getPitch());
//
// if( x< 0 ) x = 0;
// if (x> width) x = width;

//void mousePressed(){

//if (‘mousePressed’){
// x=width/2;
//y=height/2;
// }
//between 100-250=left
//between 250-400= right
//between 400-550= up
//between 550-900= down

VIDEO OF GAME DRAFT:

Screen Shot 2014-12-14 at 8.38.09 PM

Leave a reply