Esempio n. 1
0
 void stop() {
   SoundStore.get().clear();
   InternalTextureLoader.get().clear();
   if (partido.fueGrabado()) {
     if (JOptionPane.showConfirmDialog(
             principal, "Desea guardar el partido?", "Guardar Partido", JOptionPane.YES_NO_OPTION)
         == 0) {
       if (jfc.showSaveDialog(principal) == JFileChooser.APPROVE_OPTION) {
         try {
           partido.getPartidoGuardado().save(jfc.getSelectedFile());
           if (principal != null) {
             principal.addGuardadoLocal(new File[] {jfc.getSelectedFile()});
           }
         } catch (Exception ex) {
           logger.error("Error al guardar partido", ex);
         }
       }
     }
   }
   if (sonidos) {
     for (Sound s : ambiente) {
       s.stop();
     }
     gol.stop();
     remate[0].stop();
     remate[1].stop();
     poste[0].stop();
     poste[1].stop();
     ovacion[0].stop();
     ovacion[1].stop();
     rebote.stop();
     silbato.stop();
   }
   if (principal != null) {
     principal.setVisible(true);
     principal.requestFocus();
   } else {
     System.exit(0);
   }
 }
Esempio n. 2
0
  /** Actualiza el juego, uso interno */
  @Override
  public void update(GameContainer gc, int fps) throws SlickException {
    Input i = gc.getInput();
    if (guardado && progreso) {
      if (i.isMouseButtonDown(0)) {
        double y =
            1 - (double) (Math.max(20, Math.min(i.getMouseY(), sy - 20)) - 20) / (double) (sy - 40);
        PartidoGuardado pguardado = (PartidoGuardado) partido;
        pguardado.setTiempo((int) (y * (double) pguardado.getIterciones()));
      }
    }
    if (i.isKeyDown(Input.KEY_SUBTRACT)) {
      escala = escala * 0.970;
    } else if (i.isKeyDown(Input.KEY_ADD)) {
      escala = escala / 0.970;
    }
    if (i.isKeyPressed(Input.KEY_F1)) {
      estadio = !estadio;
    }
    if (i.isKeyPressed(Input.KEY_F2)) {
      entorno = !entorno;
    }
    if (i.isKeyPressed(Input.KEY_F3)) {
      showfps = !showfps;
      gc.setShowFPS(showfps);
    }
    if (i.isKeyPressed(Input.KEY_F4)) {
      tipoTexto = (tipoTexto + 1) % 5;
    }
    if (i.isKeyPressed(Input.KEY_F5)) {
      marcador = !marcador;
    }
    if (i.isKeyDown(Input.KEY_ESCAPE)) {
      gc.setSoundVolume(0);
      gc.setSoundOn(false);
      stop();
      gc.exit();
    }
    if (i.isKeyDown(Input.KEY_P)) {
      pause = !pause;
      if (pause) {
        gc.pause();
      } else {
        gc.resume();
      }
    }
    if (guardado && i.isKeyPressed(Input.KEY_LEFT)) {
      if (incremento == 0) {
        incremento = -1;
      } else if (incremento == -1) {
        incremento = -2;
      } else if (incremento == -2) {
        incremento = -4;
      } else if (incremento == -4) {
        incremento = -4;
      } else if (incremento == 1) {
        incremento = 0;
      } else if (incremento == 2) {
        incremento = 1;
      } else if (incremento == 4) {
        incremento = 2;
      }
      iteracionControl = 30;
    }
    if (guardado && i.isKeyPressed(Input.KEY_RIGHT)) {
      if (incremento == 0) {
        incremento = 1;
      } else if (incremento == 1) {
        incremento = 2;
      } else if (incremento == 2) {
        incremento = 4;
      } else if (incremento == 4) {
        incremento = 4;
      } else if (incremento == -1) {
        incremento = 0;
      } else if (incremento == -2) {
        incremento = -1;
      } else if (incremento == -4) {
        incremento = -2;
      }
      iteracionControl = 30;
    }
    paso = 0;
    if (guardado && i.isKeyPressed(Input.KEY_UP)) {
      incremento = 0;
      paso = 1;
    }
    if (guardado && i.isKeyPressed(Input.KEY_DOWN)) {
      incremento = 0;
      paso = -1;
    }
    if (guardado && i.isKeyPressed(Input.KEY_HOME)) {
      inicio = pg.getTiempo();
    }
    if (guardado && i.isKeyPressed(Input.KEY_END)) {
      fin = pg.getTiempo();
    }
    if (guardado && i.isKeyPressed(Input.KEY_DELETE)) {
      if (JOptionPane.showConfirmDialog(
              null,
              "Desea eliminar los frames seleccionados?",
              "Eliminar Frames",
              JOptionPane.YES_NO_OPTION)
          == 0) {
        if (inicio < fin) {
          pg.delete(inicio, fin);
          fin = inicio;
        } else {
          pg.delete(inicio, pg.getIterciones() - 1);
          pg.delete(0, fin);
          inicio = 0;
          fin = pg.getIterciones() - 1;
          pg.setTiempo(0);
        }
      }
    }
    if (guardado && i.isKeyPressed(Input.KEY_S)) {
      if (JOptionPane.showConfirmDialog(
              null, "Desea gardar el partido?", "Guardar Partido", JOptionPane.YES_NO_OPTION)
          == 0) {
        // System.out.println(pg.getURL().getProtocol());
        if (jfc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
          try {
            pg.save(jfc.getSelectedFile());
          } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error al guardar partido...");
            if (principal != null) {
              try {
                principal.addGuardadoLocal(new File[] {jfc.getSelectedFile()});
              } catch (Exception ex) {
              }
            }
          }
        }
      }
    }
    if (iteracionControl > 0) {
      iteracionControl--;
    }

    vx = (partido.getPosiciones()[2][0].getX() - px) / Constants.SEGUIMIENTO_CAMARA;
    vy = (partido.getPosiciones()[2][0].getY() - py) / Constants.SEGUIMIENTO_CAMARA;

    px = px + vx;
    py = py + vy;

    for (int j = 0; j < 11; j++) {
      posPrev[j][0] = posActu[0][j];
      posPrev[j][1] = posActu[1][j];
    }

    if (partido != null) {
      if (guardado) {
        try {
          pg.setTiempo(pg.getTiempo() + incremento + paso);
        } catch (Exception ex) {
          logger.error("Error al establecer tiempo de partido guardo", ex);
          throw new SlickException(ex.getLocalizedMessage());
        }
      } else {
        try {
          partido.iterar();
        } catch (Exception ex) {
          logger.error("Error al iterar partido", ex);
          throw new SlickException(ex.getLocalizedMessage());
        }
      }

      boolean oldSound = sonidos;
      if (guardado && incremento == 0) {
        sonidos = false;
      }

      if (audioAmbiente == audioAmbienteIdx) {
        if (sonidos) {
          ambiente[audioIdx].play(pinch(), volumenAmbiente);
        }
        audioAmbiente = 50 + rand.nextInt(20);
        audioAmbienteIdx = 0;
        audioIdx = rand.nextInt(ambiente.length);
      }
      audioAmbienteIdx++;

      if (partido.estanSilbando()) {
        if (sonidos) {
          silbato.play(pinch(), volumenCancha);
        }
      }
      if (partido.estanRematando()) {
        if (sonidos) {
          remate[rand.nextInt(2)].play(pinch(), volumenCancha);
        }
      }
      if (partido.estanOvacionando()) {
        if (sonidos) {
          ovacion[rand.nextInt(2)].play(pinch(), volumenAmbiente);
        }
      }
      if (partido.esGol()) {
        if (sonidos) {
          gol.play(pinch(), volumenAmbiente);
        }
        golIter = 1;
      }

      if (golIter > 0) {
        golIter++;
        if (golIter == 50) {
          golIter = 0;
        }
      }

      if (partido.isLibreIndirecto()) {
        if (sonidos) {
          silbato.play(pinch(), volumenAmbiente);
        }
      }

      if (partido.isOffSide()) offSideIter = 1;

      if (offSideIter > 0) {
        offSideIter += dxsaque;
        if (offSideIter > 800) {
          offSideIter = 0;
        }
      }

      if (partido.cambioDeSaque()) {
        if (sonidos) {
          silbato.play(pinch(), volumenAmbiente);
        }
        saqueIter = 1;
      }

      if (saqueIter > 0) {
        saqueIter = saqueIter + dxsaque;
        if (saqueIter > sx + 2 * 177) {
          saqueIter = 0;
        }
      }
      if (partido.estaRebotando()) {
        if (sonidos) {
          rebote.play(pinch(), volumenCancha);
        }
      }
      if (partido.esPoste()) {
        if (sonidos) {
          poste[rand.nextInt(2)].play(pinch(), volumenCancha);
          ovacion[rand.nextInt(2)].play(pinch(), volumenAmbiente);
        }
      }
      sonidos = oldSound;
      if (partido.estanSacando()) {
        iterSaca = (iterSaca + 1) % 6;
      }
    }

    posActu = partido.getPosiciones();
    for (int j = 0; j < 11; j++) {
      dx = posPrev[j][0].getX() - posActu[0][j].getX();
      dy = posPrev[j][0].getY() - posActu[0][j].getY();
      if (dy != 0 || dx != 0) {
        iteraciones[j][0] = iteraciones[j][0] + 1;
        angulos[j][0] = posPrev[j][0].angle(posActu[0][j]) * 180 / Math.PI + 90;
        if (incremento < 0) {
          angulos[j][0] = angulos[j][0] + 180;
        }
      } else {
        iteraciones[j][0] = 3;
      }

      dx = posPrev[j][1].getX() - posActu[1][j].getX();
      dy = posPrev[j][1].getY() - posActu[1][j].getY();
      if (dy != 0 || dx != 0) {
        iteraciones[j][1] = iteraciones[j][1] + 1;
        angulos[j][1] = posPrev[j][1].angle(posActu[1][j]) * 180 / Math.PI + 90;
        if (incremento < 0) {
          angulos[j][1] = angulos[j][1] + 180;
        }
      } else {
        iteraciones[j][1] = 3;
      }
    }

    for (int j = 1; j < angulosAnteriores[0][0].length; j++) {
      for (int x = 0; x < 11; x++) {
        for (int y = 0; y < 2; y++) {
          angulosAnteriores[x][y][j - 1] = angulosAnteriores[x][y][j];
        }
      }
    }
    for (int x = 0; x < 11; x++) {
      for (int y = 0; y < 2; y++) {
        angulosAnteriores[x][y][angulosAnteriores[0][0].length - 1] = angulos[x][y];
      }
    }
    boolean ok = true;
    for (int x = 0; x < 11; x++) {
      for (int y = 0; y < 2; y++) {
        angVisible[x][y] = 0;
        for (int j = 0; j < angulosAnteriores[0][0].length; j++) {
          angVisible[x][y] = angVisible[x][y] + angulosAnteriores[x][y][j];
        }
        angVisible[x][y] = angVisible[x][y] / (double) angulosAnteriores[0][0].length;
      }
    }

    if (autoescala) {
      int[] escalas =
          (Transforma.transform(
              partido.getPosVisibleBalon(),
              Constants.centroCampoJuego,
              -Transforma.transform(px, escala),
              -Transforma.transform(py, escala),
              escala));
      escalaAjustada =
          escala
              * Math.min(
                  0.7d * sx2 / (double) Math.abs(escalas[0]),
                  0.7d * sy2 / (double) Math.abs(escalas[1]));
    }
    if (!noAutoEscalar && partido.esGol()) {
      noAutoEscalar = true;
    }
    if (noAutoEscalar && partido.estanRematando()) {
      noAutoEscalar = false;
    }
  }