xxxxxxxxxx
// Final, com niveis juntos
//som
import ddf.minim.spi.*;
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*;
Minim minim; // objecto que corresponde à 'mesa de mistura'
AudioSample whip ;
AudioSample apple ;
// nivel do 'jogo' (0 = início)
final int LINICIO = 0;
final int LEVEL1 = 1;
final int LEVEL2 = 2;
final int FIM = 3;
final int TUT = 4;
final int INFO = 5;
//Coisas do menu
PImage logo;
PImage start0;
PImage start1;
PImage end0;
PImage end1;
PImage tut0;
PImage tut1;
PImage bg;
PFont font;
int menuState = 0;
void menuSetup() {
logo = loadImage("nome.png");
start0 = loadImage("play.png");
start1 = loadImage("playesc.png");
end0 = loadImage("info.png");
end1 = loadImage("infesc.png");
tut0 = loadImage("inst.png");
tut1 = loadImage("instesc.png");
bg = loadImage("capa.png");
}
void menu0() {
image(start0, 5, 30, 150, 90);
image(tut0, 5, 130, 150, 90);
image(end0, 5, 230, 150, 90);
}
void menu1() {
image(start1, 5, 30, 150, 90);
image(tut0, 5, 130, 150, 90);
image(end0, 5, 230, 150, 90);
}
void menu2() {
image(start0, 5, 30, 150, 90);
image(tut1, 5, 130, 150, 90);
image(end0, 5, 230, 150, 90);
}
void menu3() {
image(start0, 5, 30, 150, 90);
image(tut0, 5, 130, 150, 90);
image(end1, 5, 230, 150, 90);
}
int level;
// definir transicao
boolean transition = false;
boolean init = true;
int score = 0;
int scoreLvl1 = 0;
int scoreLvl2 = 0;
int cont = 1;
int coluna = 0;
int linha = 0;
int transitionCount = 100;
// definir geometria
int ladoQuadrado = 700;
int raioCircunf = 300;
int alturaImagem = 35;
int larguraImagem = 50;
int ladoMaca = 35;
float pendulo = 0; //raio de trajetória asi
//coordenadas e distancia
int asix, asiy;
float asiScreenX, asiScreenY;
int macax, macay;
float macaScreenX, macaScreenY;
float distancia;
boolean macaCriada;
// definir transformações
float rot = 0;
PImage asi;
PImage maca;
PImage info;
PImage inicio;
PImage instrucoes;
PImage back;
int tamanho = 50;
// Caixa posição, largura
int x = 0;
int speed = 1;
int j = 0;
float x1=random(500);
float y1=random(500);
int asis = 5;
//tempo do segundo nivel
final int TEMPOLIMITE = 2000;
int tempo = TEMPOLIMITE; // tempo para jogar (rectangulo)
void setup () {
menuSetup();
size(ladoQuadrado, ladoQuadrado);
noStroke();
imageMode(CENTER);
//som
minim = new Minim(this);
whip = minim.loadSample("whip.wav", 512);
apple = minim.loadSample("apple.wav", 512);
// level 1: para as maças cairem
macay = height/2-height;
macax = int(random(-width/2+100, width/2-100));
maca = loadImage("maca.png");
//preparação do asi.
asi = loadImage("asi.png");
pendulo = height/2 -(height/2-raioCircunf +alturaImagem/2);
asix = 0;// coordenadas x da imagem
asiy = int(pendulo); // coordenada y da imagem, a partir de pendulo truncado
// bandeira de criação da maça é falsa, a maça ainda não foi criada
macaCriada = false;
// Preparação de informação (nomes, fbaup...)
info = loadImage("contracapajogo.png");
score = 0;
// Preparação de help
instrucoes = loadImage("instrucoes.png");
score = 0;
font = createFont("MotionControl-Bold.otf", 59);
textFont(font);
back = loadImage("back.png");
level = LINICIO;
}
void draw() {
//println(PFont.list());
ellipseMode(CENTER);
//translação de coordenadas
// para a origem estar no centro
translate(width/2, height/2);
// desenhar o nivel certo
if (transition == true) {
drawTransition();
rot=0;
} else {
// desenhar cena base
background(#045073);
ellipse(0, 0, 2*raioCircunf, 2*raioCircunf);
fill(#dae79e);
switch(level) {
case LINICIO:
menuSetup();
drawInicio();
break;
case TUT:
drawInstrucoes();
break;
case LEVEL1:
if (init) {
score = 0;
scoreLvl1 = 0;
speed = 1;
macay = height/2-height;
macax = int(random(-width/2+100, width/2-100));
asix = 0;// coordenadas x da imagem
asiy = int(pendulo); // coordenada y da imagem, a partir de pendulo truncado
rot = 0;
init = false;
}
drawLevel1();
break;
case LEVEL2:
if (init) {
score = 0;
scoreLvl2 = 0;
tempo = TEMPOLIMITE;
macaCriada = false;
asix = 0;// coordenadas x da imagem
asiy = int(pendulo); // coordenada y da imagem, a partir de pendulo truncado
rot = 0;
init = false;
}
drawLevel2();
break;
case FIM:
drawFim();
break;
case INFO:
drawInfo();
break;
}
}
}
void drawInicio() {
image(bg, 0, 0, ladoQuadrado, ladoQuadrado);
image(logo, 0, -150, 500, 200);
switch(menuState) {
case 0: //No buttons selected
menu0();
break;
case 1: //Upper button selected
menu1();
break;
case 2: //Middle button selected
menu2();
break;
case 3: //Lower button selected
menu3();
break;
}
}
void drawInstrucoes() {
image(instrucoes, 0, 0, ladoQuadrado, ladoQuadrado);
}
void drawLevel1() {
// desenho do nivel 1
if (score >= 13) {
level = LEVEL2;
transition = true;
init = true;
} else {
// barra
fill(#d43e27);
float larg = map(scoreLvl1 % TEMPOLIMITE, 0, TEMPOLIMITE, 0, width-150);// 2000 = tempo para jogar
rect(-width/2+50, -height/2+670, larg, 20);
fill(#dae79e);
// desenhar maca:
image(maca, macax, macay, 32, 32);
macaScreenX = screenX(macax, macay);
macaScreenY = screenY(macax, macay);
rotate(rot);
image(asi, asix, asiy, larguraImagem, alturaImagem);// tamanho imagem.// largura, altura.
rotate(0);
asiScreenX = screenX(asix, asiy); // da-nos as coordenadas do boneco no ecra e não do boneco em si
asiScreenY = screenY(asix, asiy);
// Calcular a distância entre asi e maca
distancia = sqrt( pow((asiScreenX -macaScreenX), 2) + pow((asiScreenY -macaScreenY), 2)); // Teorema Pitágoras
if ( distancia < speed*5) {
//println( "PAPEI"); // para sabermos se esta a funcionar
macay = height;
speed++;
score++;
apple.trigger();
}
scoreLvl1++;
// se a maca tiver caído:
if (macay > height/2) {
macay = height/2-height;
macax = int(random(-width/2+100, width/2-100));
} else
{
macay = macay + speed;
}
}
}
void drawTransition() {
if ( transitionCount > 0) {
transitionCount--;
} else {
transitionCount = 11;
transition = false;
}
fill(#045073);
noStroke();
j=0;
while (j<100) {
ellipse(random(-300, 300), random(-300, 300), 20, 20);
j=j+1;
}
fill(#cbf56e);
}
void drawLevel2() {
// desenho do nivel 2
background(#045073);
fill(255);
ellipseMode(CENTER);
//translação de coordenadas
// para a origem estar no centro
translate(CENTER, CENTER);
// desenhar o campo
fill(#74a805);
ellipse(0, 0, 2*raioCircunf, 2*raioCircunf);
fill(#7db408);
ellipse(0, 0, (5/3.0)*raioCircunf, (5/3.0)*raioCircunf);// circulo maior
fill(#95d210);
ellipse(0, 0, (4/3.0)*raioCircunf, (4/3.0)*raioCircunf);
fill(#a9eb1b);
ellipse(0, 0, (3/3.0)*raioCircunf, (3/3.0)*raioCircunf);
fill(#c3fa4b);
ellipse(0, 0, (2/3.0)*raioCircunf, (2/3.0)*raioCircunf);
fill(#cbf56e);
ellipse(0, 0, (1/3.0)*raioCircunf, (1/3.0)*raioCircunf);
fill(#dcf89f);
ellipse(0, 0, (1/9.0)*raioCircunf, (1/9.0)*raioCircunf);// circulo menor
// barra
fill(#dae79e);
float larg = map(tempo, 0, TEMPOLIMITE, 0, width-150);// 2000 = tempo para jogar
rect(-width/2+50, -height/2+670, larg, 20);
fill(#dae79e);
//Prints score on screen
String scoreStr = "Score: " + Integer.toString(scoreLvl2);
textSize(64);
text(scoreStr, -300, -300);
// instrução condicional é executada se a condição for verdadeira
// com tem que ser feita quando macaCriada == false, a bandeira tem que ser negada
if ( !macaCriada) {
float angulo = random(0, TWO_PI);
float ro = random(0, (raioCircunf-ladoMaca));
macax = int(ro*cos(angulo)); // ""
macay = int(ro*sin(angulo)); //conversão polar- rectangular
// coordenadas de ecran
macaScreenX = screenX(macax, macay);
macaScreenY = screenY(macax, macay);
macaCriada = true; // levantar a bandeira
//println( "maca ", macax, macay, macaScreenX, macaScreenY);
}
image(maca, macax, macay, ladoMaca, ladoMaca);
rotate(rot);
image(asi, asix, asiy, larguraImagem, alturaImagem);// tamanho imagem.// largura, altura.
asiScreenX = screenX(asix, asiy); // da-nos as coordenadas do boneco no ecra e não do boneco em si
asiScreenY = screenY(asix, asiy);
// Calcular a distância entre asi e maca
distancia = sqrt( pow((asiScreenX -macaScreenX), 2) + pow((asiScreenY -macaScreenY), 2)); // Teorema Pitágoras
if ( distancia < 15) {
println( "PAPEI");
macaCriada = false;
score++;
scoreLvl2++;
apple.trigger();
}
rotate(0);
if (tempo >= 0) {
tempo--;
} else {
level = FIM;
transition = true;
init = true;
}
}
void drawInfo(){
image(info, 0, 0, ladoQuadrado, ladoQuadrado);
}
void drawFim() {
// preparação fonte
font = createFont("MotionControl-Bold.otf", 59);
//font = loadFont("MotionControl-Bold");//.otf);
String scoreStr = "Score 1: " + Integer.toString(int(scoreLvl1/60)) + " S"; // o que escrever
textFont(font, 59);
text(scoreStr, -150, -50);
scoreStr = "Score 2: " + Integer.toString(scoreLvl2) + " Apple";
text(scoreStr, -150, 50);
fill(#045073);
}
void keyPressed() {
switch (level) {
case LINICIO:
switch(menuState) {
case 0:
if (keyCode == UP || keyCode == DOWN)
menuState = 1;
break;
case 1:
if (keyCode == UP)
menuState = 3;
else if (keyCode == DOWN)
menuState = 2;
else if (keyCode == ENTER) {
whip.trigger();
level = LEVEL1;
}
break;
case 2:
if (keyCode == UP)
menuState = 1;
else if (keyCode == DOWN)
menuState = 3;
else if (keyCode == ENTER){
whip.trigger();
level = TUT;
}
break;
case 3:
if (keyCode == UP)
menuState = 2;
else if (keyCode == DOWN)
menuState = 1;
else if (keyCode == ENTER){
whip.trigger();
level = INFO;
}
break;
}
break;
case LEVEL1:
if (keyCode == LEFT && rot <= PI/2) {// comando do teclado
rot = rot + PI/45;// rotação, altera a velocidade a que anda o boneco.
}
if (keyCode == RIGHT && rot >= -PI/2) {
rot = rot - PI/45;
}
break;
case LEVEL2:
if (keyCode == LEFT ) {// comando do teclado
rot = rot + PI/(8*map(abs(asiy), 0, raioCircunf, 1, 10));
}
if (keyCode == RIGHT) {
rot = rot - PI/(8*map(abs(asiy), 0, raioCircunf, 1, 10));
}
if (keyCode == UP && asiy >= 0) {
asiy = asiy - 4;
}
if (keyCode == DOWN && asiy <= (raioCircunf -alturaImagem/2)) {
asiy = asiy + 4;
}
break;
case TUT:
if (keyCode == ENTER){
whip.trigger();
level = LINICIO;
}
break;
case FIM:
if (keyCode == ENTER){
whip.trigger();
level = LINICIO;
}
break;
case INFO:
if(keyCode == ENTER){
whip.trigger();
level = LINICIO;
}
break;
}
/*if(keyCode == ENTER){
if(level == LEVEL1)
level = LEVEL2;
else if(level == LEVEL2)
level = FIM;
}*/
}