Sound Game

https://vimeo.com/194973760

This is my final project for Interactive Authoring. This code made in Processing is a game which is controlled by sound volume, and have it bounce off the walls to reach the green circle.

Code:

import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;
Minim minim;
AudioInput mic;
float soundX;
float soundY;
float sound_dir_x = 1;
float sound_dir_y = 0;
int wall_width=100;
int wall_height=10;
int wall_dist=100;
int wall1_width=100;
int wall1_height=10;
int wall1_dist=300;
int wall2_width=100;
int wall2_height=10;
int wall2_distY=50;
int wall2_distX=300;
int goal = 200;
float step =0;
void setup(){
size(700,700);
rectMode(CENTER);
ellipseMode(RADIUS);
noStroke();
smooth();
soundY = 100;
soundX = 300;
step = 0;
minim = new Minim(this);
mic = minim.getLineIn();
}
void draw(){
background(30);
fill(0,255,0);
ellipse(goal,goal,50,50);
for(int r =20; r < mic.bufferSize()-1; r++){
float level = mic.left.get(r)*70;
if(level < 20){
soundX = 300;
soundY = 600;
sound_dir_x=1;
sound_dir_y=0;
}else if(level > 20){
soundX += sound_dir_x * 21;
soundY += sound_dir_y * 21;
}
float wall_y = width-wall_dist-wall_width-level;
if(soundX >= wall_y && soundY < height-wall_height/2){
sound_dir_x *= 0;
sound_dir_y = -1;
}
float wall1_x = wall1_dist+wall1_height+level;
if(soundY <= wall1_x && soundX < width-wall1_width/2){
sound_dir_x = -1;
sound_dir_y *=0;
}
float wall2_y = wall2_distY+wall2_width+level;
float wall2_x = wall2_distX+wall2_height+level;
if(soundX < wall2_y && soundY > wall2_x/2){
sound_dir_x *=0;
sound_dir_y =-1;
}
if (soundX < goal && soundY < goal){
soundX=goal;
soundY=goal;
}

fill(255,255,255,level);
ellipse(soundX,soundY,level,level);
}
fill(130);
translate(width-wall_dist-wall_width,600);
rotate(PI/-3);
rect(0,0,wall_width,wall_height);
translate(254,-140);
rotate(PI/-3);
rect(0,0,wall1_width,wall1_height);
translate(149,-331);
rotate(PI/-42);
rect(0,0,wall2_width, wall2_height);

if(soundX <= goal && soundY <= goal){
step=1;
}
if(step==1){
fill(255);
translate(-134,186);
rotate(PI/1.5);
rect(0,0,1000,830);
fill(255,0,0);
textSize(50);
textAlign(CENTER,CENTER);
text(“Game Clear!”,0,0);
}
}
void mouseClicked(){
step=0;
}

Advertisements

About degrafgo

I am a fun, green loving guy who owns 3 YouTube channels under the name DeGraphics.
This entry was posted in Research, Time Based and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s