Example #1
0
  @Override
  public void render() {
    BufferStrategy bs = canvas.getBufferStrategy();
    if (bs == null) {
      canvas.createBufferStrategy(3);
      return;
    }

    screen.clear();
    int xScroll = (int) player.x() - screen.getWidth() / 2;
    int yScroll = (int) player.y() - screen.getHeight() / 2;
    level.render(xScroll, yScroll, screen);
    for (int i = 0; i < pixels.length; i++) {
      pixels[i] = screen.getPixels()[i];
    }

    Graphics g = bs.getDrawGraphics();
    g.drawImage(image, 0, 0, canvas.getWidth(), canvas.getHeight(), null);
    g.setColor(Color.WHITE);
    g.setFont(new Font("Verdana", 0, 50));
    window.setTitle(
        TITLE
            + " | "
            + getFps()
            + " fps, "
            + getUps()
            + " update"
            + (getUps() > 1 ? " catchup" : "")
            + " per render");
    Toolkit.getDefaultToolkit().sync();
    g.dispose();
    bs.show();
  }
Example #2
0
  /** Draws the lines and ball. */
  public void drawScreen() {
    BufferStrategy bf = this.getBufferStrategy();
    Graphics g = null;
    try {
      g = bf.getDrawGraphics();

      g.setColor(Color.black);
      g.fillRect(0, 0, getWidth(), getHeight());

      g.setColor(Color.GREEN);

      g.drawOval(ballX, ballY, Ball.RADIUS * 2, Ball.RADIUS * 2);

      for (int i = 0; i < lines.size(); i++) {
        Line x = lines.get(i);
        g.drawLine(x.x1, x.y1, x.x2, x.y2);
      }
    } finally {
      g.dispose();
    }

    bf.show();

    Toolkit.getDefaultToolkit().sync();
  }
Example #3
0
  private void render() {
    BufferStrategy bs = getBufferStrategy();
    if (bs == null) {
      createBufferStrategy(2);
      requestFocus();
      return;
    }

    // render here

    screen.clear();

    renderBackground(screen);
    level.render(screen);

    for (int y = 0; y < screen.h; y++) {
      for (int x = 0; x < screen.w; x++) {
        pixels[x + y * WIDTH] = screen.pixels[x + y * screen.w];
      }
    }

    Graphics g = bs.getDrawGraphics();
    g.fillRect(0, 0, getWidth(), getHeight());

    int ww = WIDTH * SCALE;
    int hh = HEIGHT * SCALE;
    int xo = (getWidth() - ww) / 2;
    int yo = (getHeight() - hh) / 2;
    g.drawImage(image, xo, yo, ww, hh, null);

    g.dispose();
    bs.show();
  }
Example #4
0
  public void render() {
    // canvas
    bs = display.getCanvas().getBufferStrategy();
    if (bs == null) {
      display.getCanvas().createBufferStrategy(3);
      return;
    }
    g = bs.getDrawGraphics();

    // reset screen
    g.clearRect(0, 0, width, height);

    // draws background, player, wall
    try {
      imgBackground = ImageIO.read(new File("Background.PNG"));
    } catch (IOException e) {

      e.printStackTrace();
      System.exit(1);
    }

    g.drawImage(imgBackground, 0, 0, null);
    g.setColor(Color.WHITE);
    g.setFont(new Font("Serif", Font.BOLD, 50));

    // g.drawString("Score: " + getScore(), 100, 100);

    // displays image(buffered image)
    bs.show();
    g.dispose();
  }
Example #5
0
  private void render() {

    BufferStrategy bs = getBufferStrategy();
    if (bs == null) {
      createBufferStrategy(3);
      requestFocus();
      return;
    }

    Graphics g = bs.getDrawGraphics();
    g.fillRect(0, 0, getWidth(), getHeight());
    g.setColor(Color.BLUE);

    processPlayer1(g);
    processBullet(g);
    processPlayer2(g);

    g.drawString("Player 1 Score " + player1Score, 900, 450);
    g.drawString("Player 2 Score " + player2Score, 900, 500);
    g.dispose();
    bs.show();

    // controls the speed of the game
    try {
      Thread.sleep(2);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
Example #6
0
  // ---------- Main Render Method ----------
  private void render() {

    // Validates Buffer Strategy
    BufferStrategy bs = frame.getBufferStrategy();

    if (bs == null) {
      frame.createBufferStrategy(3);
      return;
    }

    Graphics g = bs.getDrawGraphics();

    // Renders Buffer Strategy Things / Direct Pixels
    render.render(g);
    g.drawImage(img, 0, 0, width, height, null);

    // Renders Trees
    render.renderTrees(g);

    // Renders Graphics Object Things
    render.renderOverlay(g, lastFPS);

    g.dispose();
    bs.show();
  }
Example #7
0
 private void render() {
   Graphics2D g = (Graphics2D) bufferStrategy.getDrawGraphics();
   g.clearRect(0, 0, mapSizex * gridSize, mapSizey * gridSize);
   render(g);
   g.dispose();
   bufferStrategy.show();
 }
Example #8
0
  private void render() {
    // TODO Auto-generated method stub
    BufferStrategy bs = this.getBufferStrategy();
    if (bs == null) {
      this.createBufferStrategy(3);
      return;
    }

    Graphics g = bs.getDrawGraphics();

    g.setColor(Color.BLACK);
    g.fillRect(0, 0, WIDTH, HEIGHT);

    /// draw borders
    g.setColor(Color.ORANGE);
    g.drawRect(LIMIT_X1, LIMIT_Y1, LIMIT_X2, LIMIT_Y2);

    g.setColor(Color.WHITE);
    g.drawString("Gravity : ", WIDTH - 200, 20);
    g.drawString(Double.toString(GRAVITY), WIDTH - 100, 20);

    // render landingzone
    g.setColor(Color.GREEN);
    g.drawLine(
        (int) landingZone1.getX(),
        (int) landingZone1.getY(),
        (int) landingZone1.getX1(),
        (int) landingZone1.getY1());

    handler.render(g);

    g.dispose();
    bs.show();
  }
  /**
   * Creates a new "game" from the current engine.Globals.game variable. While the ANN stays the
   * same, the speed, actor positions, score, et cetera, are all reset.
   */
  public void newGame() {
    stopped = true;
    player.setLives(STARTING_LIVES);
    player.setScore(0);
    Graphics g = strategy.getDrawGraphics();
    waiting = true;

    Globals.state = ENEMY_HUNTER_STATE;

    player.setCenter(board.getPlayerStartPoint());
    player.setDirection(Player.DEFAULT_STARTING_DIRECTION);

    board.reset();
    Globals.blipsLeft = Globals.game.getBoard().getBlipCount();

    for (Enemy enemy : enemies) {
      enemy.reset();
    }

    GamePainters.drawBoard(board, g, this);
    GamePainters.drawEnemies(enemies, g, this);
    GamePainters.drawPlayer(player, g, this);
    GamePainters.paintBottomBar(player, board, g, this);
    strategy.show();
  }
Example #10
0
  /** Paints "Game Over" on the canvas. */
  public void paintGameOver() {
    Graphics g = strategy.getDrawGraphics();

    GamePainters.paintGameOver(g, this, board);

    strategy.show();
  }
Example #11
0
  /** Paints "Pause" on the canvas. */
  public void paintPauseScreen() {
    Graphics g = strategy.getDrawGraphics();

    GamePainters.paintPauseScreen(g, this, board);

    strategy.show();
  }
Example #12
0
  public void render() {
    BufferStrategy bs = getBufferStrategy();

    if (bs == null) {
      createBufferStrategy(3);
      return;
    }

    Graphics g = bs.getDrawGraphics();

    g.drawImage(image, 0, 0, getWidth(), getHeight(), this);

    level.renderLevel(g);
    getPlayer().render(g);
    getInv().render(g);

    if (showDebug) debug.render(g);

    g.setColor(Color.WHITE);
    g.fillRect(103, 0, 160, 33);
    g.drawImage(getRes().toolMap, 103, 0, this);
    g.setColor(Color.BLACK);
    g.drawRect((Player.toolSelected * 32) + 71, 0, 32, 32);
    // Draw tool selected at mouse location
    g.drawImage(getRes().tools[Player.toolSelected - 1], mouseP.x, mouseP.y, this);

    g.dispose();
    bs.show();
  }
Example #13
0
  public void render(Graphics2D g) {
    do {
      do {
        g = (Graphics2D) strategy.getDrawGraphics();
        g.setRenderingHints(renderingHints);
        vi = createVolatileImage(getWidth(), getHeight());
        bi =
            GraphicsEnvironment.getLocalGraphicsEnvironment()
                .getDefaultScreenDevice()
                .getDefaultConfiguration()
                .createCompatibleImage(getWidth(), getHeight());
        vi.getGraphics().fillRect(0, 0, vi.getWidth(), vi.getHeight());

        for (Renderable renderable : Window.objects) {
          if (renderable.getShouldDestroy()) Window.objects.remove(renderable);
          if (renderable.isVisible()) renderable.render((Graphics2D) vi.getGraphics());
        }

        bi.getGraphics().drawImage(vi.getSnapshot(), 0, 0, getWidth(), getHeight(), null);
        bi = vi.getSnapshot();
        // gaussian.filter(bi, bi);
        // glow.filter(bi, bi);
        // motionBlur.filter(bi, bi);
        g.drawImage(bi, 0, 0, getWidth(), getHeight(), null);
        g.dispose();
        Toolkit.getDefaultToolkit().sync();
      } while (strategy.contentsRestored());
      strategy.show();
    } while (strategy.contentsLost());
  }
Example #14
0
  public void render() {
    BufferStrategy bs = getBufferStrategy();
    if (bs == null) {
      createBufferStrategy(3);
      return;
    }

    int xOffset = player.x - (screen.width / 2);
    int yOffset = player.y - (screen.height / 2);

    level.renderTiles(screen, xOffset, yOffset);
    level.renderEntities(screen);
    level.cleanUp();
    screen.renderHud();

    for (int y = 0; y < screen.height; y++) {
      for (int x = 0; x < screen.width; x++) {
        int colorCode = screen.pixels[x + y * screen.width];
        if (colorCode < 255) pixels[x + y * WIDTH] = colors[colorCode];
      }
    }

    Graphics g = bs.getDrawGraphics();
    g.drawImage(image, 0, 0, getWidth(), getHeight(), null);

    g.dispose();
    bs.show();
  }
Example #15
0
  /** Replaces the current player icon with one showing that the player has died. */
  public void paintDeadPlayer() {
    Graphics g = strategy.getDrawGraphics();

    GamePainters.drawBoard(board, g, this);
    GamePainters.drawDeadPlayer(player, g, this);

    strategy.show();
  }
Example #16
0
 /**
  * En metode som returnerer canvaset som grafikken kan tegnes på.
  *
  * @return g: Graphics2D - Grafikken som blir tegnet
  */
 public Graphics2D getGraphics() {
   Window window = getWindow();
   if (window != null) {
     BufferStrategy strategy = window.getBufferStrategy();
     return (Graphics2D) strategy.getDrawGraphics();
   }
   return null;
 }
Example #17
0
 /** @return Retorna el entorno de dibujado. */
 public Graphics2D getGraphics() {
   Window window = device.getFullScreenWindow();
   if (window != null) {
     BufferStrategy strategy = window.getBufferStrategy();
     return (Graphics2D) strategy.getDrawGraphics();
   } else {
     return null;
   }
 }
Example #18
0
    @Override
    public void dispose() {
      if (isShowing()) {
        hide();
      }

      if (myWindowListener != null) {
        myWindowListener.saveSize();
        removeWindowListener(myWindowListener);
        myWindowListener = null;
      }

      if (myComponentListener != null) {
        removeComponentListener(myComponentListener);
        myComponentListener = null;
      }

      if (myFocusTrackback != null
          && !(myFocusTrackback.isSheduledForRestore()
              || myFocusTrackback.isWillBeSheduledForRestore())) {
        myFocusTrackback.dispose();
        myFocusTrackback = null;
      }

      final BufferStrategy strategy = getBufferStrategy();
      if (strategy != null) {
        strategy.dispose();
      }
      super.dispose();

      if (rootPane != null) { // Workaround for bug in native code to hold rootPane
        try {
          Field field = rootPane.getClass().getDeclaredField("glassPane");
          field.setAccessible(true);
          field.set(rootPane, null);

          field = rootPane.getClass().getDeclaredField("contentPane");
          field.setAccessible(true);
          field.set(rootPane, null);
          rootPane = null;

          field = Window.class.getDeclaredField("windowListener");
          field.setAccessible(true);
          field.set(this, null);
        } catch (Exception ignored) {
        }
      }

      // http://bugs.sun.com/view_bug.do?bug_id=6614056
      try {
        final Field field = Dialog.class.getDeclaredField("modalDialogs");
        field.setAccessible(true);
        final List<?> list = (List<?>) field.get(null);
        list.remove(this);
      } catch (final Exception ignored) {
      }
    }
Example #19
0
 // updates Display
 public void update() {
   Window w = vc.getFullScreenWindow();
   if (w != null) {
     BufferStrategy s = w.getBufferStrategy();
     if (!s.contentsLost()) {
       s.show();
     }
   }
 }
Example #20
0
 /** En metode som viser grafikken som er blitt tegnet på canvaset. */
 public void update() {
   Window window = getWindow();
   if (window != null) {
     BufferStrategy strategy = window.getBufferStrategy();
     if (!strategy.contentsLost()) {
       strategy.show();
     }
   }
   Toolkit.getDefaultToolkit().sync();
 }
Example #21
0
  /** Updates the canvas. */
  public void update() {
    Graphics g = strategy.getDrawGraphics();

    GamePainters.drawBoard(board, g, this);
    GamePainters.drawEnemies(enemies, g, this);
    GamePainters.drawPlayer(player, g, this);
    GamePainters.paintBottomBar(player, board, g, this);

    strategy.show();
  }
Example #22
0
File: Game.java Project: h2n0/IRH
  public void render() {
    BufferStrategy bs = getBufferStrategy();
    if (bs == null) {
      createBufferStrategy(3);
      requestFocus();
      return;
    }

    int xScroll = this.player.x - this.screen.w / 2;
    int yScroll = this.player.y - (this.screen.h - 8) / 2;
    if (xScroll < 16) xScroll = 16;
    if (yScroll < 16) yScroll = 16;
    if (xScroll > this.level.w * 16 - this.screen.w - 16)
      xScroll = this.level.w * 16 - this.screen.w - 16;
    if (yScroll > this.level.h * 16 - this.screen.h - 16)
      yScroll = this.level.h * 16 - this.screen.h - 16;
    if (this.currentLevel > 3) {
      int col = Colour.get(20, 20, 121, 121);
      for (int y = 0; y < 14; y++) {
        for (int x = 0; x < 24; x++) {
          this.screen.render(x * 8 - (xScroll / 4 & 0x7), y * 8 - (yScroll / 4 & 0x7), 0, col, 0);
        }
      }
    }
    this.level.renderBackground(this.screen, xScroll, yScroll);
    this.level.renderSprites(this.screen, xScroll, yScroll);

    if (this.currentLevel < 3) {
      this.lightScreen.clear(0);
      this.level.renderLight(this.lightScreen, xScroll, yScroll);
      this.screen.overlay(this.lightScreen, xScroll, yScroll);
    }

    renderGui();

    if (!hasFocus()) renderFocusNagger();

    for (int y = 0; y < this.screen.h; y++) {
      for (int x = 0; x < this.screen.w; x++) {
        int cc = this.screen.pixels[(x + y * this.screen.w)];
        if (cc < 255) this.pixels[(x + y * 160)] = this.colors[cc];
      }
    }

    Graphics g = bs.getDrawGraphics();
    g.fillRect(0, 0, getWidth(), getHeight());

    int ww = 480;
    int hh = 360;
    int xo = (getWidth() - ww) / 2;
    int yo = (getHeight() - hh) / 2;
    g.drawImage(this.image, xo, yo, ww, hh, null);
    g.dispose();
    bs.show();
  }
Example #23
0
  public void update() {
    bufferStrategy = getBufferStrategy();

    if (getBufferStrategy() == null) {
      createBufferStrategy(3);
    } else {
      bufferStrategy.getDrawGraphics().fillRect(0, 0, getWidth(), getHeight());

      bufferStrategy.show();
    }
  }
Example #24
0
  // we will set Graphics object = to this
  public Graphics2D getGraphics() {

    Window w = vc.getFullScreenWindow();

    if (w != null) {
      BufferStrategy bs = w.getBufferStrategy();
      return (Graphics2D) bs.getDrawGraphics();
    } else {
      return null;
    }
  }
 private void render() {
   BufferStrategy bs = this.getBufferStrategy();
   if (bs == null) {
     this.createBufferStrategy(2);
     return;
   }
   Graphics g = bs.getDrawGraphics();
   if (scene != null) scene.render();
   g.drawImage(image, 0, 0, WIDTH * SCALE, HEIGHT * SCALE, this);
   g.dispose();
   bs.show();
 }
Example #26
0
  /** Actualiza la pantalla con el doble buffer e intenta sincronizar la imagen. */
  public void update() {
    Window window = device.getFullScreenWindow();

    if (window != null) {
      BufferStrategy strategy = window.getBufferStrategy();
      if (!strategy.contentsLost()) {
        strategy.show();
      }
    }
    // Sync the display on some systems.
    // (on Linux, this fixes event queue problems)
    Toolkit.getDefaultToolkit().sync();
  }
  public void doit() throws Exception {

    Image image = (Image) this.pullInput(0);
    Rectangle bounds = mainFrame.getBounds();
    Graphics g = bufferStrategy.getDrawGraphics();
    if (!bufferStrategy.contentsLost()) {
      g.drawImage(image, 0, 0, null);
      // g.drawImage(image, 0, 0, bounds.width, bounds.height, null);
      // g.fillRect(0, 0, bounds.width, bounds.height);
      bufferStrategy.show();
      g.dispose();
    }
  }
Example #28
0
 private void animateNextFrame() {
   // Animate next frame on buffer
   Graphics2D g = (Graphics2D) buffer.getDrawGraphics();
   drawFrame(g);
   // Display the buffer
   if (!buffer.contentsLost()) {
     buffer.show();
   }
   g.dispose();
   // Repainting solves the problem of the applet not updating properly
   // on the Red Hat Linux computers.
   repaint();
 }
Example #29
0
  public void render() {
    Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
    // Blank this buffer out
    g.setColor(Color.black);
    g.fillRect(0, 0, getWidth(), getHeight());
    g.setColor(Color.white);
    g.drawString(AvgFps, (getWidth() - g.getFontMetrics().stringWidth(AvgFps)), (getHeight()));

    blobs.render(g);

    g.dispose();
    strategy.show();
  }
  private void render() {
    BufferStrategy bs = getBufferStrategy();
    if (bs == null) {
      createBufferStrategy(3);
      return;
    }

    Graphics g = bs.getDrawGraphics();

    g.drawImage(image, 0, 0, getWidth(), getHeight(), null);

    g.dispose();
    bs.show();
  }