xxxxxxxxxx
/*
SOFIA MATOS
LSI - FBAUP - 2016
*/
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;
import processing.video.*;
Minim mesa;
AudioInput microfone;
Capture camara;
Target[] targets = new Target[15];
boolean shooting;
boolean fim;
int nivel = 0;
int score=0;
int grava = 1;
int record_p = 0;
float record_v = 0;
float yletter = 200;
float xLoc=random(5,500);
float yLoc=random(5,595);
float xVel=3;
float yVel=-3;
//A
float ax,ay;
float rot;
ArrayList balls;
float t = 0;
int f = 0;
PImage roda;
float theta; //A
PImage[] imagens;
PImage shake, M, E, cima, baixo, win1, lost1, onda1, onda2, help,
logoS, logo1, logo2, logo3, logo4, logo5, logo;
void setup() {
noCursor();
size(600,600);
noStroke();
smooth();
ellipseMode(CENTER);
for (int i=0; i<targets.length;i++) {
targets[i] = new Target(random(width), random(height), random(1, 3), random(1, 3));
}//k
balls = new ArrayList();//S
logo = loadImage ("logo.png");
logo1 = loadImage ("logo1.png");
logo2 = loadImage ("logo2.png");
logo3 = loadImage ("logo3.png");
logo4 = loadImage ("logo4.png");
logo5 = loadImage ("logo5.png");
M = loadImage ("M.png");
help = loadImage ("help.png");
//E
E = loadImage ("E.png");
//A
roda = loadImage("roda.png");
ax = 0.0;
ay = width/2.0;
rot = 0.0;
//H
shake = loadImage ("shake.png");
cima = loadImage ("cima.png");
baixo = loadImage ("baixo.png");
win1 = loadImage ("win1.png");
lost1 = loadImage ("lost1.png");
//s
onda1 = loadImage ("onda1.png");
onda2 = loadImage ("onda2.png");
logoS = loadImage ("logoS.png");
mesa = new Minim(this);
microfone = mesa.getLineIn(mesa.MONO, 1024);
camara = new Capture(this, 640, 480);
camara.start();
}
void draw() {
if (nivel == 0) nivel0 ();
if (nivel == 1) nivel1 ();
if (nivel == 2) nivel2 ();
if (nivel == 3) nivel3 ();
if (nivel == 4) nivel4 ();
if (nivel == 5) nivel5 ();
if (nivel == 6) nivel6 ();
if (nivel == 7) nivel7 ();
if (nivel == 8) nivel8 ();
if (nivel == 9) nivel9 ();
if (nivel == 10) nivel10 ();
if (nivel == 11) nivel11 ();
if (nivel == 12) nivel12 ();
if (nivel == 13) nivel13 ();
if (nivel == 14) nivel14 ();
if (nivel == 15) nivel15 ();}
//---------------MENU---------------
void nivel0() {
background (255);
image (logo, 0, 0);
}
//---------------S---------------
void nivel1() {
background (0);
image (logo1, 0, 0);
if (key == ' ') nivel=2;
}
void nivel2 () {
background (0);
image (M, 0, 0);
t = t + .02;
drawBalls();
}
void drawBalls(){
int maxBalls = 6;
float factor;
while (balls.size() < maxBalls) {
factor = random(0,3);
balls.add(new Ball(random(0, width), random(0, height), factor));
}
for (int i = balls.size() - 1; i >= 0; i--) {
Ball ball = (Ball) balls.get(i);
ball.update(t);
ball.display(f);
}
}
class Ball {
float x, y;
float step;
float step2;
float factor;
Ball(float x, float y, float f) {
this.x = x;
this.y = y;
this.factor = f;
this.step = random(1.0, 2.0);
this.step2 = random(2.0, 2.5);
}
void update(float t) {
if ((microfone.mix.level() > 0.05) && (this.factor <= 1)) {
this.x = sin(step2*t) * 120 + 270;
this.y = cos(step*t) * 120 + 270;
} else if ((microfone.mix.level() > 0.05) && (this.factor <= 2)){
this.x = sin(step*t) * 120 + 270;
this.y = cos(step2*t) * 120 + 270;
} else if ((microfone.mix.level() > 0.05) && (this.factor <= 3)){
this.x = sin(step*t) * (110 + sin(.01*t) * 110) + 270;
this.y = cos(step*t) * (110 + sin(.01*t) * 110) + 270;
}
}
void display(float f) {
fill(0,0,255);
image(onda1,this.x, this.y);
image(logoS,200,280);
image(onda2,this.y, this.x);
}
}
//---------------H---------------
void nivel3() {
background (0);
image (logo2, 0, 0);
if (key == ' ') nivel=4;
}
void nivel4() {
background(0);
//ondas
image (cima, -5, 0);
image (baixo, -5, 575);
//shake
image (shake, 0, yletter);//ATENÇAOAAOOAOAOAO//ATENÇAOAAOOAOAOAO//ATENÇAOAAOOAOAOAO//ATENÇAOAAOOAOAOAO
yletter += 1*3;// para a palavra descer
if (microfone.mix.level() > 0.05) {
yletter -= 7;
} // se falar a palavra sobe
if(yletter < 25) nivel=11;
if(yletter > 575) nivel=12;
}
//---------------A---------------
void nivel5 () {
background (0);
image (logo3, 0, 0);
if (key == ' ') nivel=6;
}
void nivel6 () {
background(0);
image(M,0,0);
pushMatrix();
translate(width/2, height/2);
if(microfone.mix.level()>0.05) {
rotate(theta);
}
image(roda, 0, 0);
popMatrix();
theta += 0.02;
}
//---------------K---------------
void nivel7 () {
background (0);
image (logo4, 0, 0);
if (key == ' ') nivel=8;
}
void nivel8 () {
background (0);
shooting = true;
fim = true;
for (int i=0; i<targets.length;i++) {
if (!targets[i].hit) {
targets[i].checkHit(shooting,record_p / camara.width, record_p / camara.width);
targets[i].update();
targets[i].display();
fim =false;
}
}
noFill();
if (shooting) {
stroke(255);
strokeWeight (5);
}
else {
stroke(255);
}
record_v = 0;
if (camara.available()) {
camara.read();
pushMatrix();
scale(-1,1);
popMatrix();
camara.loadPixels();
for (int i = 0; i < camara.pixels.length; i++) {
if (brightness(camara.pixels[i]) >= record_v) {
record_v = brightness(camara.pixels[i]);
record_p = i;
}
}
int r = record_p / camara.width;
int t = record_p / camara.width;
ellipse(r, t, 60, 60);
}
if (fim) nivel=14;
}
class Target {
float x, y;
float vX, vY;
boolean hit;
Target(float _x, float _y, float _vX, float _vY) {
x= _x;
y =_y;
vX = _vX;
vY = _vY;
}
void update() {
x += vX;
y += vY;
if (x>width) {
vX *=-1;
x =width;
}
if (x<0) {
vX *=-1;
x =0;
}
if (y>height) {
vY *=-1;
y =height;
}
if (y<0) {
vY *=-1;
y =0;
}
}
void display() {
if (!hit) {
image (onda1, x, y);
}
}
void checkHit(boolean _p, float _x, float _y) {
float distance = dist(_x, _y, x, y);
if (_p && distance<15) {
hit =true;
}
}
}
//---------------E---------------
void nivel9 () {
background (0);
image (logo5, 0, 0);
if (key == ' ') nivel=10;
}
void nivel10 () {
background(0);
image(E,xLoc,yLoc);
xLoc+=xVel;
yLoc+=yVel;
if(xLoc<=5||xLoc+190>=595){
xVel=-xVel;}
if(yLoc<=5){
yVel=-yVel;}
if((500<=yLoc)&&(yLoc<=5)&&(yVel>5)&&(mouseX-50<=xLoc)&&(xLoc<=mouseX+200)){
yVel=-(yVel+0.1);
if(xVel>0){
xVel+=0.1;}
else{
xVel-=0.1;}
score+=1;}
if (microfone.mix.level() > 0.05) {
yVel=-3;}
if(yLoc>=595) nivel=13;
}
//-------------------------------
void nivel11 () {
background (0);
image (win1, 0, 0);
if(keyPressed && key ==' ') {
nivel=4;
yletter = 250;
}
}
void nivel12 () {
background (0);
image (lost1, 0, 0);
if(keyPressed && key ==' ') {
nivel=4;
yletter = 250;
}
}
void nivel13 () {
background (0);
image (lost1, 0, 0);
if(keyPressed && key ==' ') {
nivel=10;
xLoc=random(6,370);
yLoc=random(6,370);
}
}
void nivel14 () {
background (0);
image(win1,0,0);
if(keyPressed && key ==' ') {
nivel=8;
fim =false;
for (int i=0; i<targets.length;i++) {
targets[i] = new Target(random(width), random(height), random(1, 3), random(1, 3));
}
}
}
//-------------------------------
void nivel15 () {
background (255);
image(help, 0, 0);
}
void keyReleased () {
if (key == 's' || key == 'S') nivel=1;
if (key == 'h' || key == 'H') nivel=3;
if (key == 'a' || key == 'A') nivel=5;
if (key == 'k' || key == 'K') nivel=7;
if (key == 'e' || key == 'E') nivel=9;
if (key == 'm' || key == 'M') nivel=0;
if (key == '?') nivel = 15;
}