Exemple #1
0
  public JackPanel(JumpingJack jj, long period) {
    jackTop = jj;
    this.period = period;

    setDoubleBuffered(false);
    setBackground(Color.white);
    setPreferredSize(new Dimension(PWIDTH, PHEIGHT));

    setFocusable(true);
    requestFocus(); // the JPanel now has focus, so receives key events

    addKeyListener(
        new KeyAdapter() {
          public void keyPressed(KeyEvent e) {
            processKey(e);
          }
        });

    // initialise the loaders
    ImagesLoader imsLoader = new ImagesLoader(IMS_INFO);
    clipsLoader = new ClipsLoader(SNDS_FILE);

    // initialise the game entities
    bricksMan = new BricksManager(PWIDTH, PHEIGHT, BRICKS_INFO, imsLoader);
    int brickMoveSize = bricksMan.getMoveSize();

    ribsMan = new RibbonsManager(PWIDTH, PHEIGHT, brickMoveSize, imsLoader);

    jack =
        new JumperSprite(
            PWIDTH,
            PHEIGHT,
            brickMoveSize,
            bricksMan,
            imsLoader,
            (int) (period / 1000000L)); // in ms

    fireball = new FireBallSprite(PWIDTH, PHEIGHT, imsLoader, this, jack);

    // prepare the explosion animation
    explosionPlayer =
        new ImagesPlayer("explosion", (int) (period / 1000000L), 0.5, false, imsLoader);
    BufferedImage explosionIm = imsLoader.getImage("explosion");
    explWidth = explosionIm.getWidth();
    explHeight = explosionIm.getHeight();
    explosionPlayer.setWatcher(this); // report animation's end back here

    // prepare title/help screen
    helpIm = imsLoader.getImage("title");
    showHelp = true; // show at start-up
    isPaused = true;

    // set up message font
    msgsFont = new Font("SansSerif", Font.BOLD, 24);
    metrics = this.getFontMetrics(msgsFont);
  } // end of JackPanel()
 public void draw(Graphics g, ImagesLoader imLoad) {
   for (int i = 0; i < pickupList.size(); i++) {
     Pickup p = pickupList.get(i);
     BufferedImage img = imLoad.getImage(p.type);
     g.drawImage(img, (int) p.x, (int) p.y, null);
   } // end for
 } // end draw
  public ImagesPlayer(
      String clave, long periodo, double duracion, boolean repeticion, ImagesLoader ci) {
    nombre = clave;
    periodoAnimacion = periodo;
    duracionTotal = duracion;
    loop = repeticion;
    cImagenes = ci;

    animacionTotal = 0L;
    if (!cImagenes.estaCargado(nombre)) {
      System.out.println("No se encontro esa clave en el mapa");
      ticksIgnorados = true;
      numImagenes = 0;
      posicionImagen = -1;
    } else {
      ticksIgnorados = false;
      numImagenes = cImagenes.numImagenes(nombre);
      posicionImagen = 0;
      duracionImagen = (int) ((duracionTotal * 1000) / numImagenes);
    }
  }
 public BufferedImage getImagenAt(int pos) {
   return cImagenes.getImagenAt(nombre, pos);
 }
 public BufferedImage imagenActual() {
   return cImagenes.getImagenAt(nombre, posicionImagen);
 }