Escolar Documentos
Profissional Documentos
Cultura Documentos
posMaxBaixo=telaY; int posMaxCima=0; //muda direcoes das bolas int mudaX=1; int mudaY=1; //sorteia alguma posicao no eixo X int inicio=(int)random(30, telaX-30); //determina a direcao da bola nos eixos x e y PVector bolaDire; //velocidade da bola int velBola=3; //comando do teclado int tec2X=telaX/2; //velocidade das paletas int velPal=8; //tamanho das paletas int tamXPal=60; int tamYPal=10; //score int scoreJog1=0; int scoreJog2=0;
//centraliza os sprites ellipseMode(CENTER); rectMode(CENTER); bolaDire.x=bolaDire.x+velBola*mudaX; bolaDire.y=bolaDire.y+velBola*mudaY; condBola(); funcTeclado(); ellipse(bolaDire.x, bolaDire.y, 10, 10); rect(bolaDire.x, 0, tamXPal, tamYPal); rect(tec2X, 400, tamXPal, tamYPal); if(dist(bolaDire.x,bolaDire.y,tec2X,400)<10){ mudaY=-1; bolaDire.y=bolaDire.y+velBola*mudaY; } println("O score do jogador 1 eh:"+scoreJog1); } void funcTeclado() { if ( keyPressed == true ) { if ( key == 'a' ) { if( tec2X>0+tamXPal/2) tec2X=tec2X-velPal; } if ( key == 'd' ) { if(tec2X<telaX-tamXPal/2) tec2X=tec2X+velPal; } } } void condBola() { if (bolaDire.x>=posMaxDir) { mudaX=-1; bolaDire.x=bolaDire.x+velBola*mudaX; } if (bolaDire.x<=posMaxEsq) { mudaX=1; bolaDire.x=bolaDire.x+velBola*mudaX; }
if (bolaDire.y==posMaxCima) { mudaY=1; bolaDire.y=bolaDire.y+velBola*mudaY; } if (bolaDire.y==posMaxBaixo) { //mudaY=-1; //bolaDire.y=bolaDire.y+velBola*mudaY; scoreJog1+=1; bolaDire.x=(int)random(30, telaX-30); bolaDire.y=width/2; } }