Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 18.30 KB | None | 0 0
  1. //importação das classes:
  2. newgame novo;
  3. mainmenu menu;
  4. PrintWriter output;
  5. BufferedReader reader;
  6. String line;
  7. // Parâmetros do labirinto:
  8. int nCol, nLin;          // nº de linhas e de colunas
  9. int tamanho = 50;        // tamanho (largura e altura) das células do labirinto  
  10. int espacamento = 2;     // espaço livre entre células
  11. float margemV, margemH;  // margem livre na vertical e na horizontal para assegurar que as células são quadrangulares
  12. color corObstaculos =  color(0, 200 , 250);      // cor de fundo dos obstáculos
  13. double pontos[][];
  14. //Variaveis para aumentar dificuldade do jogo:
  15. int pontuacaoatual=0;
  16. int pontuacaomaxima=0;
  17. int nivel=1;
  18.  
  19. // Posicao e tamanho do Pacman:
  20. float px, py, pRaio;
  21.  
  22. // Posição dos fantasmas:
  23. float g1x, g1y, g2x, g2y, g3x, g3y, g4x, g4y;
  24.  
  25. // Velocidade do pacman:
  26. float vx, vy;
  27.  
  28. // Velocidade dos fantasmas:
  29. float vg1x, vg1y, vg2x, vg2y, vg3x, vg3y, vg4x, vg4y;
  30.  
  31. float cont=-0.52;
  32.  
  33. //Declarar a Fonte:
  34. PFont fonte;    
  35.  
  36. //Arrancar Menu:
  37. boolean mouseReleasedgame=false;
  38. boolean mouseReleasedexit=false;
  39. boolean menucalled=true;
  40.  
  41. //Colisões Pacman-Fantasmas:
  42. boolean collisions=false;
  43. int vidas=3;
  44.  
  45. void setup() {
  46.  
  47.   // Definir o tamanho da janela; notar que size() não aceita variáveis.
  48.   size(1100, 570);
  49.   background(0);
  50.  
  51.   //Criar a fonte:
  52.   fonte = createFont("Arial",16,true);
  53.  
  54.   nCol = (int)770/tamanho;
  55.   nLin = (int)height/tamanho;
  56.   pontos = new double[nCol][nLin];
  57.  
  58.   // Assegurar que nº de linhas e nº de colunas é maior ou igual a 3
  59.   assert nCol >= 5 && nLin >= 5;
  60.  
  61.   // Determinar margens para limitar a área útil do jogo
  62.   margemV = (770 - nCol * tamanho) / 2.0;
  63.   margemH = (height - nLin * tamanho) / 2.0;
  64.  
  65.   // Inicializar o Pacman
  66.   px = centroX(8);
  67.   py = centroY(8);
  68.   pRaio = (tamanho - 20) / 2;
  69.  
  70.   // Inicializar os fantasmas
  71.   // Fantasma Verde
  72.   g1x = centroX(1)+2;
  73.   g1y = centroY(1);
  74.   // Fantasma Vermelho
  75.   g2x = centroX(6)+2;
  76.   g2y = centroY(5);
  77.   // Fantasma Azul
  78.   g3x = centroX(8);
  79.   g3y = centroY(5);
  80.  
  81.   //specifies speeds in X and Y directions
  82.   vx = 0;
  83.   vy = 0;
  84.  
  85.   for(int a=0;a<nCol;a++){
  86.     for(int b=0;b<nLin;b++){  
  87.       pontos[a][b]=0;
  88.     }
  89.   }
  90.   //Declaração das classes importadas:
  91.     novo = new newgame();
  92.     menu = new mainmenu();
  93.   //
  94.   importHighscore();
  95. }
  96.  
  97. void draw(){
  98.   background(0);
  99.   //arrancar o menu e as suas opções
  100.   arrancarmenu();
  101.   //println(mouseX,"++++++",mouseY);
  102.   //println(vidas);
  103.  
  104. }
  105.  
  106. void arrancarmenu(){
  107.  if (menucalled){
  108.     menu.menudesign();
  109.   }
  110.   if (mousePressed==true && mouseX>502 && mouseY>243 && mouseX<642 && mouseY<273){
  111.      mouseReleasedgame=true;
  112.  
  113.   }
  114.   if (mousePressed==true && mouseX>487 && mouseY>358 && mouseX<603 && mouseY<394){
  115.      mouseReleasedexit=true;
  116.  
  117.   }
  118.   if(mouseReleasedgame==true){
  119.      menucalled=false;
  120.      novo.desenharLabirinto();
  121.      novo.desenharPontos();
  122.      novo.pacman();
  123.      novo.fantasmas();
  124.      novo.keypressed();
  125.      novo.desenharBarraLateral();
  126.      novo.BarraLateraldoJogo();
  127.      novo.pontuacoeseniveis();
  128.      novo.colisoes();
  129.      novo.updateHighscore();
  130.      
  131.   }
  132.   if(mouseReleasedexit==true){
  133.      exit();
  134.   }
  135. }
  136.  
  137.  
  138. class mainmenu{
  139.   void menudesign(){
  140.     //titulo                      
  141.     textFont(fonte,96);                
  142.     fill(232, 239, 40);                        
  143.     text("PACMAN",350,100);
  144.     //new game
  145.     textFont(fonte,26);                
  146.     fill(232, 239, 40);                        
  147.     text("New Game",470,270);
  148.     //scores
  149.     textFont(fonte,26);                
  150.     fill(232, 239, 40);                        
  151.     text("Scores",493,330);
  152.     //exit
  153.     textFont(fonte,26);                
  154.     fill(232, 239, 40);                        
  155.     text("Exit",510,390);
  156.   }
  157. }
  158.  
  159. class newgame{
  160.   //Funções responsaveis pelo jogo:
  161.  
  162.    
  163.   void pacman(){
  164.     float angle1, angle2, angle3, angle4, angle5, angle6, angle7, angle8;
  165.     angle1=2.25;
  166.     angle2=7.35;
  167.     angle3=5.15;
  168.     angle4=10.45;
  169.     angle5=3.67;
  170.     angle6=8.90;
  171.     angle7=0.52;
  172.     angle8=5.76;
  173.     if (px==centroX(8) && py==centroY(8) && vx==0 && vy==0){
  174.       desenharPacman(angle7,angle8);
  175.     }
  176.     if (keyCode==DOWN){
  177.       desenharPacman(angle1,angle2);
  178.     }
  179.     if (keyCode==UP){
  180.       desenharPacman(angle3,angle4);
  181.     }
  182.     if (keyCode==LEFT){
  183.       desenharPacman(angle5,angle6);      
  184.     }
  185.     if (keyCode==RIGHT){
  186.       desenharPacman(angle7,angle8);
  187.     }
  188.     if (keyCode==CONTROL){
  189.       desenharPacman(angle7,angle8);
  190.     }
  191.   }
  192.      
  193.   void desenharPacman(float mouthAngle,float mouthAngle2) {
  194.    
  195.     fill(232, 239, 40);
  196.     ellipseMode(RADIUS);
  197.     //noStroke();
  198.     cont+=0.05;
  199.     if (cont>=0.52){
  200.       cont=-0.52;}
  201.     arc(px, py, pRaio, pRaio, mouthAngle-cont, mouthAngle2+cont);
  202.     //fill(0);
  203.     //triangle(px, py, px+pRaio/1.828427125, py-pRaio/1.828427125, px+pRaio/1.828427125, py+pRaio/1.828427125);
  204.   }
  205.   void fantasmas(){
  206.     // Fantasma Verde
  207.     fantasma1();
  208.     if(g1y==centroY(1)){
  209.       vg1x=2;}
  210.     if(g1y==centroY(1) && g1x==centroX(nCol)){
  211.       vg1x=0;}
  212.     if(g1x==centroX(nCol)){
  213.       vg1y=2;}
  214.     if(g1x==centroX(nCol) && g1y==centroY(nLin)){
  215.       vg1y=0;}
  216.     if(g1y==centroY(nLin)){
  217.       vg1x=-2;}
  218.     if(g1y==centroY(nLin) && g1x==centroX(1)){
  219.       vg1x=0;}
  220.     if(g1x==centroX(1)){
  221.       vg1y=-2;}
  222.     if(g1x==centroX(1) && g1y==centroY(1)){
  223.       vg1y=0;}  
  224.       g1x+=vg1x;
  225.       g1y+=vg1y;
  226.     // Fantasma Vermelho
  227.     fantasma2();
  228.     if(g2y==centroY(5)){
  229.       vg2x=2;}
  230.     if(g2y==centroY(5) && g2x==centroX(10)){
  231.       vg2x=0;}
  232.     if(g2x==centroX(10)){
  233.       vg2y=2;}
  234.     if(g2x==centroX(10) && g2y==centroY(7)){
  235.       vg2y=0;}
  236.     if(g2y==centroY(7)){
  237.       vg2x=-2;}
  238.     if(g2y==centroY(7) && g2x==centroX(6)){
  239.       vg2x=0;}
  240.     if(g2x==centroX(6)){
  241.       vg2y=-2;}
  242.     if(g2x==centroX(6) && g2y==centroY(5)){
  243.       vg2y=0;}  
  244.       g2x+=vg2x;
  245.       g2y+=vg2y;
  246.      // Fantasma Azul
  247.     fantasma3();
  248.     if(g3x==centroX(nCol)){
  249.       vg3y=2;}
  250.     if(g3x==centroX(nCol) && g3y==centroY(4)){
  251.       vg3y=0;}
  252.     if (g3y==centroY(4) && g3x>centroX(12)){
  253.       vg3x=-2;}
  254.     if (g3y==centroY(4) && g3x==centroX(13)){
  255.       vg3x=0;}
  256.     if (g3x==centroX(13) && g3y>centroY(2)){
  257.       vg3y=2;}
  258.     if(g3y==centroY(5) && g3x==centroX(13)){
  259.       vg3y=0;}
  260.     if(g3y==centroY(5) && g3x>centroX(11)){
  261.       vg3x=-2;}
  262.     if(g3x==centroX(12) && g3y==centroY(5)){
  263.       vg3x=0;}
  264.     if(g3x==centroX(12) && g3y>centroY(4)){
  265.       vg3y=2;}
  266.     if(g3y==centroY(6) && g3x==centroX(12)){
  267.       vg3y=0;}
  268.     if(g3y==centroY(6) && g3x>centroX(8)){
  269.       vg3x=-2;}
  270.     if(g3x==centroX(10) && g3y==centroY(6)){
  271.       vg3x=0;}
  272.     if(g3x==centroX(10) && g3y>centroY(4)){
  273.       vg3y=2;}
  274.     if(g3x==centroX(10) && g3y==centroY(7)){
  275.       vg3y=0;}
  276.     if(g3y==centroY(7) && g3x>centroX(5)){
  277.       vg3x=-2;}
  278.     if(g3y==centroY(7) && g3x==centroX(7)){
  279.       vg3x=0;}
  280.     if(g3x==centroX(7) && g3y>centroY(6)){
  281.       vg3y=2;}
  282.     if(g3x==centroX(7) && g3y==centroY(9)){
  283.       vg3y=0;}
  284.     if(g3y==centroY(9) && g3x>centroX(2)){
  285.       vg3x=-2;}
  286.     if(g3x==centroX(4) && g3y==centroY(9)){
  287.       vg3x=0;}
  288.     if(g3x==centroX(4) && g3y>centroY(8)){
  289.       vg3y=2;}
  290.     if(g3x==centroX(4) && g3y==centroY(11)){
  291.       vg3y=0;}
  292.     if(g3y==centroY(nLin)){
  293.       vg3x=-2;}
  294.     if(g3y==centroY(nLin) && g3x==centroX(1)){
  295.       vg3x=0;}
  296.     if(g3x==centroX(1)){
  297.       vg3y=-2;}
  298.     if(g3y==centroY(8) && g3x==centroX(1)){
  299.       vg3y=0;}
  300.     if(g3y==centroY(8) && g3x<centroX(4)){
  301.       vg3x=2;}
  302.     if(g3y==centroY(8) && g3x==centroX(3)){
  303.       vg3x=0;}
  304.     if(g3x==centroX(3) && g3y<centroY(9)){
  305.       vg3y=-2;}
  306.     if(g3x==centroX(3) && g3y==centroY(7)){
  307.       vg3y=0;}
  308.     if(g3y==centroY(7) && g3x<centroX(5)){
  309.       vg3x=2;}
  310.     if(g3y==centroY(7) && g3x==centroX(4)){
  311.       vg3x=0;}
  312.     if(g3x==centroX(4) && g3y<centroY(8)){
  313.       vg3y=-2;}
  314.     if(g3x==centroX(4) && g3y==centroY(6)){
  315.       vg3y=0;}
  316.     if(g3y==centroY(6) && g3x<centroX(8)){
  317.       vg3x=2;}
  318.     if(g3x==centroX(6) && g3y==centroY(6)){
  319.       vg3x=0;}
  320.     if(g3x==centroX(6) && g3y==centroY(6)){
  321.       vg3y=-2;}
  322.     if(g3y==centroY(5) && g3x==centroX(6)){
  323.       vg3y=0;}
  324.     if(g3y==centroY(5) && g3x<centroX(11)){
  325.       vg3x=2;}
  326.     if(g3y==centroY(5) && g3x==centroX(9)){
  327.       vg3x=0;}
  328.     if(g3x==centroX(9) && g3y<centroY(6)){
  329.       vg3y=-2;}
  330.     if(g3y==centroY(3) && g3x==centroX(9)){
  331.       vg3y=0;}
  332.     if(g3y==centroY(3) && g3x<centroY(14)){
  333.       vg3x=2;}
  334.     if(g3y==centroY(3) && g3x==centroX(12)){
  335.       vg3x=0;}
  336.     if(g3x==centroX(12) && g3y<centroY(4)){
  337.       vg3y=-2;}
  338.     if(g3x==centroX(12) && g3y==centroY(1)){
  339.       vg3y=0;}
  340.     if(g3y==centroY(1)){
  341.       vg3x=2;}
  342.     if(g3y==centroY(1) && g3x==centroX(nCol)){
  343.       vg3x=0;}
  344.       g3x+=vg3x;
  345.       g3y+=vg3y;
  346.   }
  347.  
  348.   void fantasma1(){
  349.     fill(0, 255, 0);
  350.     ellipseMode(RADIUS);
  351.     ellipse(g1x, g1y-4, 14, 12);
  352.     ellipse(g1x-10.5, g1y+9.5, 3.4, 6);
  353.     ellipse(g1x-3.5, g1y+9.5, 3.4, 6);
  354.     ellipse(g1x+10.5, g1y+9.5, 3.4, 6);
  355.     ellipse(g1x+3.5, g1y+9.5, 3.4, 6);
  356.     rectMode(RADIUS);
  357.     rect(g1x, g1y+4, 14, 6);
  358.     fill(255);
  359.     ellipse(g1x-5, g1y-6, 4, 4);
  360.     ellipse(g1x+5, g1y-6, 4, 4);
  361.     fill(0);
  362.     ellipse(g1x-5, g1y-6, 1, 1);
  363.     ellipse(g1x+5, g1y-6, 1, 1);
  364.   }
  365.  
  366.   void fantasma2(){
  367.     fill(255, 0, 0);
  368.     ellipseMode(RADIUS);
  369.     ellipse(g2x, g2y-4, 14, 12);
  370.     ellipse(g2x-10.5, g2y+9.5, 3.4, 6);
  371.     ellipse(g2x-3.5, g2y+9.5, 3.4, 6);
  372.     ellipse(g2x+10.5, g2y+9.5, 3.4, 6);
  373.     ellipse(g2x+3.5, g2y+9.5, 3.4, 6);
  374.     rectMode(RADIUS);
  375.     rect(g2x, g2y+4, 14, 6);
  376.     fill(255);
  377.     ellipse(g2x-5, g2y-6, 4, 4);
  378.     ellipse(g2x+5, g2y-6, 4, 4);
  379.     fill(0);
  380.     ellipse(g2x-5, g2y-6, 1, 1);
  381.     ellipse(g2x+5, g2y-6, 1, 1);
  382.   }
  383.  
  384.   void fantasma3(){
  385.     fill(0, 0, 255);
  386.     ellipseMode(RADIUS);
  387.     ellipse(g3x, g3y-4, 14, 12);
  388.     ellipse(g3x-10.5, g3y+9.5, 3.4, 6);
  389.     ellipse(g3x-3.5, g3y+9.5, 3.4, 6);
  390.     ellipse(g3x+10.5, g3y+9.5, 3.4, 6);
  391.     ellipse(g3x+3.5, g3y+9.5, 3.4, 6);
  392.     rectMode(RADIUS);
  393.     rect(g3x, g3y+4, 14, 6);
  394.     fill(255);
  395.     ellipse(g3x-5, g3y-6, 4, 4);
  396.     ellipse(g3x+5, g3y-6, 4, 4);
  397.     fill(0);
  398.     ellipse(g3x-5, g3y-6, 1, 1);
  399.     ellipse(g3x+5, g3y-6, 1, 1);
  400.   }
  401.  
  402.   void desenharLabirinto() {
  403.  
  404.     // desenha a fronteira da área de jogo
  405.     fill(0);
  406.     stroke(0, 200, 250);
  407.     strokeWeight(1);
  408.     rectMode(CORNER);
  409.     rect(margemH, margemV, 770 - 2*margemH, height - 2*margemV);
  410.  
  411.     //Desenha obstáculos
  412.     //Cantos  
  413.     desenharObstaculo(2, 2, 2, 1);
  414.     desenharObstaculo(2, 2, 1, 2);
  415.     desenharObstaculo(14, 2, 1, 2);
  416.     desenharObstaculo(13, 2, 1, 1);
  417.     desenharObstaculo(2, 9, 1, 2);
  418.     desenharObstaculo(3, 10, 1, 1);
  419.     desenharObstaculo(14, 9, 1, 2);
  420.     desenharObstaculo(13, 10, 1, 1);
  421.     //Laterais Exteriores
  422.     desenharObstaculo(2, 5, 1, 3);
  423.     desenharObstaculo(3, 6, 1, 1);
  424.     desenharObstaculo(14, 5, 1, 3);
  425.     desenharObstaculo(13, 6, 1, 1);
  426.     //T's Superior e Inferior
  427.     desenharObstaculo(5, 2, 7, 1);
  428.     desenharObstaculo(5, 10, 7, 1);
  429.     desenharObstaculo(8, 3, 1, 2);
  430.     desenharObstaculo(8, 9, 1, 1);
  431.     //Peças Interiores
  432.     desenharObstaculo(4, 4, 3, 1);
  433.     desenharObstaculo(4, 8, 3, 1);
  434.     desenharObstaculo(10, 4, 3, 1);
  435.     desenharObstaculo(10, 8, 3, 1);
  436.     desenharObstaculo(5, 5, 1, 1);
  437.     desenharObstaculo(5, 7, 1, 1);
  438.     desenharObstaculo(11, 5, 1, 1);
  439.     desenharObstaculo(11, 7, 1, 1);
  440.     //Barra Interior
  441.     desenharObstaculo(7, 6, 3, 1);
  442.    
  443.     //Linhas
  444.     stroke(0, 200, 250);
  445.     strokeWeight(3);
  446.     //Cantos  
  447.     line(110, 60+2, 110, 110-2);
  448.     line(110, 460+2, 110, 570-60-2);
  449.     line(770-110, 60+2, 770-110, 110-2);
  450.     line(770-110, 460+2, 770-110, 570-60-2);
  451.     //Laterais Exteriores
  452.     line(110, 260+2, 110, 310-2);
  453.     line(770-110, 260+2, 770-110, 310-2);
  454.     //T's Superior e Inferior
  455.     line(360+2, 110, 410-2, 110);
  456.     line(360+2, 570-110, 410-2, 570-110);
  457.     //Peças Interiores
  458.     line(210+2, 210, 260-2, 210);
  459.     line(770-260+2, 210, 770-210-2, 210);
  460.     line(210+2, 570-210, 260-2, 570-210);
  461.     line(770-260+2, 570-210, 770-210-2, 570-210);
  462.    
  463.   }
  464.   void desenharBarraLateral(){
  465.     stroke(0, 200, 250);
  466.     strokeWeight(1);
  467.     rectMode(CORNERS);
  468.     rect(770, 10, 1090, 560);
  469.    
  470.    
  471.   }
  472.   /* Desenha um obstáculo interno de um labirinto:
  473.      x: índice da célula inicial segundo eixo dos X - gama (1..nCol)
  474.      y: índice da célula inicial segundo eixo dos Y - gama (1..nLin)
  475.      numC: nº de colunas (células) segundo eixo dos X (largura do obstáculo)
  476.      numL: nº de linhas (células) segundo eixo dos Y (altura do obstáculo)
  477.   */
  478.   void desenharObstaculo(int x, int y, int numC, int numL) {
  479.     float x0, y0, larg, comp;
  480.    
  481.     x0 = margemH + (x-1) * tamanho;
  482.     y0 = margemV + (y-1) * tamanho;
  483.     larg = numC * tamanho;
  484.     comp = numL * tamanho;
  485.  
  486.     fill(corObstaculos);
  487.     stroke(254);
  488.     rect(x0, y0, larg, comp);
  489.   }
  490.  
  491.   /*
  492.   Desenhar pontos nas células vazias (que não fazem parte de um obstáculo).
  493.   Esta função usa a cor de fundo no ecrã para determinar se uma célula está vazia ou se faz parte de um obstáculo.
  494.   */
  495.   void desenharPontos() {
  496.     float cx, cy;
  497.    
  498.     ellipseMode(CENTER);
  499.     fill(255);
  500.     noStroke();
  501.  
  502.     // Insere um ponto nas células vazias
  503.     for(int i=1; i<=nCol; i++){
  504.       for(int j=1; j<=nLin; j++) {
  505.         cx = centroX(i);
  506.         cy = centroY(j);
  507.         color c = get((int)cx, (int)cy);
  508.         if(pontos[i-1][j-1]==0) {
  509.           if(c != corObstaculos) {
  510.             fill(255);
  511.             ellipse(cx, cy, pRaio/2+3, pRaio/2+3);          
  512.           }      
  513.         }
  514.       }
  515.     }
  516.   }
  517.  
  518.   void keypressed(){
  519.     float pacU, pacD, pacR, pacL;
  520.     pacU=py-27;
  521.     pacD=py+27;
  522.     pacR=px+27;
  523.     pacL=px-27;
  524.    
  525.       if (keyCode==DOWN){
  526.         vy=2;
  527.         vx=0;
  528.         if(get((int)px, (int)pacD)==color(0, 200 , 250)){
  529.           vy=0;
  530.         }
  531.         pontos[(int)((px)/50)][(int)(((py-20)/50))]=2;
  532.       }
  533.       if (keyCode==UP){
  534.         vx=0;
  535.         vy=-2;
  536.         if(get((int)px, (int)pacU)==color(0, 200 , 250)){
  537.           vy=0;
  538.         }
  539.         pontos[(int)((px)/50)][(int)(((py)/50))]=2;
  540.       }
  541.       if (keyCode==LEFT){
  542.         vx=-2;
  543.         vy=0;
  544.         if(get((int)pacL, (int)py)==color(0, 200 , 250)){
  545.           vx=0;
  546.         }
  547.         pontos[(int)((px)/50)][(int)(((py)/50))]=2;
  548.       }
  549.       if (keyCode==RIGHT){
  550.         vx=2;
  551.         vy=0;
  552.         if(get((int)pacR, (int)py)==color(0, 200 , 250)){
  553.           vx=0;
  554.         }
  555.         pontos[(int)((px-20)/50)][(int)(((py)/50))]=2;
  556.       }
  557.       if (keyCode==CONTROL){
  558.         vx=0;
  559.         vy=0;
  560.       }
  561.         py+=vy;
  562.         px+=vx;
  563.       if (key == ESC || key == ESC) {
  564.         output.flush();
  565.         output.close();
  566.         exit();
  567.     }
  568.   }
  569.  
  570.   void margens(){
  571.     //Margem direita
  572.     if(px >= centroX(nCol)){
  573.        px=centroX(nCol);
  574.     }
  575.     //Margem esquerda
  576.     if(px <= centroX(1)){
  577.        px=centroX(1);
  578.     }
  579.       //Margem superior
  580.     if(py <= centroY(1)){
  581.        py=centroY(1);
  582.     }
  583.     //Margem inferior
  584.     if(py >= centroY(nLin)){
  585.        py=centroY(nLin);
  586.     }  
  587.   }
  588.   void BarraLateraldoJogo(){
  589.     //Desenhar o titulo Pontos:
  590.     textFont(fonte,26);                
  591.     fill(232, 239, 40);                        
  592.     text("Pontos:",887,70);
  593.     //Desenhar a pontuação
  594.     textFont(fonte,26);                
  595.     fill(232, 239, 40);                        
  596.     text(pontuacaoatual,920,120);
  597.     //Desenhar o titulo Melhor Pontuação:
  598.     textFont(fonte,26);                
  599.     fill(232, 239, 40);                        
  600.     text("Melhor Pontuação:",825,170);
  601.     //Desenhar o nivel:
  602.     textFont(fonte,26);                
  603.     fill(232, 239, 40);                        
  604.     text(pontuacaomaxima,920,220);
  605.     //Desenhar o titulo Vidas:
  606.     textFont(fonte,26);                
  607.     fill(232, 239, 40);                        
  608.     text("Vidas:",895,270);
  609.     //Desenhar o nivel:
  610.     textFont(fonte,26);                
  611.     fill(232, 239, 40);                        
  612.     text(vidas,920,320);
  613.     //Desenhar o titulo Nivel:
  614.     textFont(fonte,26);                
  615.     fill(232, 239, 40);                        
  616.     text("Nivel:",895,370);
  617.     //Desenhar o nivel:
  618.     textFont(fonte,26);                
  619.     fill(232, 239, 40);                        
  620.     text(nivel,920,420);
  621.  
  622.  
  623.   }
  624.   void pontuacoeseniveis(){
  625.   pontuacaoatual=pontuacao(pontos);
  626.     if(pontuacaoatual==109){
  627.       for(int a=0;a<nCol;a++){
  628.         for(int b=0;b<nLin;b++){  
  629.           pontos[a][b]=0;
  630.         }
  631.       }
  632.       nivel=nivel+1;
  633.     }
  634.   }
  635.  
  636.   void colisoes(){
  637.     if(get((int)px,(int) py)==color(255, 0, 0)){
  638.       collisions=true;
  639.     }
  640.      
  641.     if(get((int)px,(int) py)==color(0, 255, 0)){
  642.       collisions=true;
  643.     }
  644.      
  645.     if(get((int)px,(int) py)==color(0, 0, 255)){
  646.       collisions=true;
  647.     }
  648.     if(collisions==true){
  649.       px=centroX(8);
  650.       py=centroY(8);
  651.       keyCode=CONTROL;
  652.       vidas-=1;
  653.     }
  654.     collisions=false;
  655.   }
  656.  void updateHighscore() {
  657.     if (pontuacaomaxima < pontuacaoatual) {
  658.       pontuacaomaxima = pontuacaoatual;
  659.       //ficheiro pontuação máxima:
  660.       output = createWriter("highscore.txt");
  661.       output.println(pontuacaomaxima);
  662.       output.close();
  663.     }
  664.   }
  665.  
  666.  
  667.  }
  668.  
  669.  
  670.  
  671. void importHighscore() {
  672.   reader = createReader("highscore.txt");  
  673.   if (reader == null) {
  674.     pontuacaomaxima = 0;
  675.     return;
  676.   }
  677.   try {
  678.     line = reader.readLine();
  679.   } catch (IOException e) {
  680.     e.printStackTrace();
  681.     line = null;
  682.   }
  683.   if (line != null) {
  684.     pontuacaomaxima= int(line);
  685.   }
  686.   try {
  687.     reader.close();
  688.   } catch (IOException e) {
  689.     e.printStackTrace();
  690.   }
  691. }
  692.  
  693.  
  694. // transformar o índice de uma célula em coordenada no ecrã
  695. float centroX(int col) {
  696.   return margemH + (col - 0.5) * tamanho;
  697. }
  698.  
  699. // transformar o índice de uma célula em coordenada no ecrã
  700. float centroY(int lin) {
  701.   return margemV + (lin - 0.5) * tamanho;
  702. }
  703.  
  704. int pontuacao(double pontos[][]){
  705.  int cont=0;  
  706.   for(int i=1; i<=nCol; i++){
  707.       for(int j=1; j<=nLin; j++) {
  708.         if (pontos[i-1][j-1]==2){
  709.           cont=cont+1;
  710.         }
  711.       }
  712.     }
  713.   return cont;
  714. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement