/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.NQMRvuvcDnO/rev.1122
*
* authors:
*
* eduardo asta
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
/// FALTA ACERTAR LIMITES, COLOCAR O DELAY E FAZER AS CORES DOS NIVEIS INDEPENDENTES
Poligono esq,dir,sup,inf,polf,polm,pold,fundo;
Texto score,niveis,explica,facil,medio,dificil,over,result,resultM,resultF;
///BOLA///
//coordenadas
float xa=random(50,400);
float ya=random(50,400);
//tamanho
int s=10;
//velocidade
float xspeed=2;//velocidade horiz
float yspeed=2; //velocidade vert
//barras
int lar=10;
int alt=50;
//incrementos
float i=1;
float ipos=0.1;
void setup(){
size(500,500);
smooth();
///qdo x ou y forem iguais a zero, acionar o mouse
///objeto = new Poligono(x,y,AX,LX,r,g,b,fio);
///barras
esq = new Poligono(10,0,10,50,150,150,150,1);
dir = new Poligono(width-10,0,10,50,150,150,150,1);
sup = new Poligono(0,10,50,10,255,150,100,1);
inf = new Poligono(0,height-10,50,10,255,150,100,1);
///indicadores
polf= new Poligono(width/2-42,height/2+50,40,15,150,150,150,0);
polm= new Poligono(width/2,height/2+50,40,15,150,150,150,0);
pold= new Poligono(width/2+42,height/2+50,40,15,150,150,150,0);
//fundo mensagem
fundo=new Poligono(width/2,height/2+79,240,18,200,180,50,0);
//modelo=new Texto("xxx",tamanhotexto,r,g,b,x,y);
score=new Texto("Score: ",30,0,0,0,width/2,height/2);
gover=new Texto("GAME OVER",60,0,0,0,width/2,200);
niveis=new Texto("Bola mais rápida a cada rebatida",10,0,0,0,width/2,height/2+30);
explica=new Texto("Eduardo Asta : Pong : v.2",10,0,0,0,width/2,height-50);
facil=new Texto("Loser",10,0,0,0,width/2-42,height/2+50);
medio=new Texto("Médio",10,0,0,0,width/2,height/2+50);
dificil=new Texto("Fodão",10,0,0,0,width/2+42,height/2+50);
result=new Texto("Molengão, sejes homem e tente de novo",10,0,0,0,width/2,height/2+79);
resultM=new Texto("É isso né, você se contenta com pouco, tsc, tsc",10,0,0,0,width/2,height/2+79);
resultF=new Texto("Parabéns, poucos chegaram aqui e puderem ler essa linhas",10,0,0,0,width/2,height/2+79);
}
void draw(){
background();
///////////define os limites superior, inferior, esq e dir
boolean limiteDIR = boolean(xa+s/2 >= width-lar-5);
boolean limiteESQ = boolean(xa-s/2<=lar+5);
boolean limiteINF = boolean(ya+s/2>=height-lar-5);
boolean limiteSUP = boolean(ya-s/2<=lar+5);
////////////define os limites de contato com as barras
boolean largura = boolean (xa+s/2>=mouseX-lar/2-5 && xa-s/2<=mouseX+lar/2+5);
boolean altura = boolean (ya+s/2>=mouseY-alt/2+5 && ya-s/2<=mouseY+alt/2-5);
boolean limiteFORA = boolean(xa-s/2>=width || xa+s/2<=0 || ya>=height-s/2 || ya+s/2<=0);
/// esse grupo desenhas as barras///
esq.move();
esq.display();
dir.move();
dir.display();
sup.move();
sup.display();
inf.move();
inf.display();
polf.move();
polf.display();
polm.move();
polm.display();
pold.move();
pold.display();
///////////// CONDICOES MENSAGENS /////////////
if(i<=1.5){
polf.muda();
if (limiteFORA){
pushMatrix();
translate(width/2-42,height/2+72);
rotate(PI/4);
fill(200,180,50);
rect(0,0,15,15);
popMatrix();
fundo.move();
fundo.display();
result.escreve();
}
}
if(i>=1.5 && i<=2.5){
polf.muda();
polm.muda();
if(limiteFORA){
pushMatrix();
translate(width/2,height/2+72);
rotate(PI/4);
fill(200,180,50);
rect(0,0,15,15);
popMatrix();
fundo.move();
fundo.display();
resultM.escreve();
}
}
if(i>=2.5){
polf.muda();
polm.muda();
pold.muda();
if(limiteFORA){
pushMatrix();
translate(width/2+42,height/2+72);
rotate(PI/4);
fill(200,180,50);
rect(0,0,15,15);
popMatrix();
fundo.move();
fundo.display();
resultD.escreve();
}
}
////////////// CONDICOES DE REBATIMENTO //////////////
if (limiteFORA){
polm.muda();
gover.escreve();
}else{
if(xspeed>0){
if(yspeed>0){
if(limiteDIR){
if(altura){
xspeed= -xspeed;
i+=ipos;
}
}
if(limiteINF){
if(largura){
yspeed= -yspeed;
i+=ipos;
}
}
}
if(yspeed<0){
if(limiteDIR){
if(altura){
xspeed = -xspeed;
i+=ipos;
}
}
if(limiteSUP){
if(largura){
yspeed= -yspeed;
i+=ipos;
}
}
}
}
if(xspeed<0){
if(yspeed>0){
if(limiteESQ){
if(altura){
xspeed = -xspeed;
i+=ipos;
}
}
if(limiteINF){
if(largura){
yspeed = -yspeed;
i+=ipos;
}
}
}
if(yspeed<0){
if(limiteESQ){
if(altura){
xspeed = -xspeed;
i+=ipos;
}
}
if(limiteSUP){
if(largura){
yspeed = -yspeed;
i+=ipos;
}
}
}
}
}
///////////desenha a bola///////////
fill(0);
rectMode(CENTER);
rect(xa,ya,s,s);
xa+=i*xspeed;
ya+=i*yspeed;
///guias
stroke();
line(mouseX,16,mouseX,height-16);
line(16,mouseY,width-16,mouseY);
/// MENSAGENS FIXAS ///
explica.escreve();
niveis.escreve();
score.pontos();
facil.escreve();
medio.escreve();
dificil.escreve();
//text(i,width/2,450);
if (limiteFORA){
gameover.show();
delay();
}
}
///////////////////////AQUI ESTAO AS CLASSES//////////////////////
class Poligono{
float xp;
float yp;
int AX;
int LX;
int r;
int g;
int b;
int fio;
float xpos;
float ypos;
Poligono(float tempxp, float tempyp, int tempAX, int tempLX, int tempr, int tempg, int tempb, int tempfio){
xp=tempxp;
yp=tempyp;
AX=tempAX;
LX=tempLX;
r=tempr;
g=tempg;
b=tempb;
fio=tempfio;
}
void move(){
if(xp==0){
xpos=mouseX;
}else{
xpos=xp;
}
if (yp==0){
ypos=mouseY;
}else{
ypos=yp;
}
}
void display(){
fill(r,g,b);
rectMode(CENTER);
if(fio==0){
noStroke();
}else{
strokeWeight(fio);
stroke(0);
}
rect(xpos,ypos,AX,LX);
}
void muda(){
fill(200,180,50);
rectMode(CENTER);
if(fio==0){
noStroke();
}else{
strokeWeight(fio);
stroke(0);
}
rect(xpos,ypos,AX,LX);
}
}
class Texto{
String msg;
int x;
int y;
int letra;
int ra;
int ga;
int ba;
float t;
Texto(String tempmsg, int templetra, int tempra, int tempga, int tempba, int tempx, int tempy){
msg=tempmsg;
x=tempx;
y=tempy;
letra=templetra;
ra=tempra;
ga=tempga;
ba=tempba;
}
void escreve(){
pushStyle();
textSize(letra);
textAlign(CENTER,CENTER);
fill(ra,ga,ba);
text(msg,x,y);
popStyle();
}
void pontos(){
pushStyle();
textSize(letra);
textAlign(CENTER,CENTER);
fill(ra,ga,ba);
t=int(millis()/1000);
text(msg+t+" pts",x,y);
popStyle();
}
}