Example #1
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 #2
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 #3
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 #4
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 #5
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 #6
0
 private void render() {
   Graphics2D g = (Graphics2D) bufferStrategy.getDrawGraphics();
   g.clearRect(0, 0, mapSizex * gridSize, mapSizey * gridSize);
   render(g);
   g.dispose();
   bufferStrategy.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 #8
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();
  }
  /** Paints "Pause" on the canvas. */
  public void paintPauseScreen() {
    Graphics g = strategy.getDrawGraphics();

    GamePainters.paintPauseScreen(g, this, board);

    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
  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 #12
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 #13
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();
  }
Example #14
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 #15
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 #16
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 #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
  /** 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 #19
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 #20
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;
    }
  }
Example #21
0
  public void update() {
    bufferStrategy = getBufferStrategy();

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

      bufferStrategy.show();
    }
  }
 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();
 }
  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 #24
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 #25
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();
  }
  /** Main drawing method. */
  public void render() {

    Graphics2D g2d = (Graphics2D) bs.getDrawGraphics();
    g2d.fillRect(0, 0, getWidth(), getHeight());

    // Draw all the worlds where they belong
    for (WorldPreview w : worlds) {
      Graphics2D g2d2 = (Graphics2D) bs.getDrawGraphics();
      g2d2.translate(w.x * scaleFactorWidth, w.y * scaleFactorHeight);
      g2d2.scale(w.scaleWidth * scaleFactorWidth, w.scaleHeight * scaleFactorHeight);
      w.drawBackground(g2d2, this);
      w.drawLayer2(g2d2, this);
      w.drawLayer3(g2d2, this);
      g2d2.dispose();
    }

    g2d.scale(scaleFactorWidth, scaleFactorHeight);

    g2d.dispose();
    // Display contents of buffer.
    bs.show();
    Toolkit.getDefaultToolkit().sync();
  }
  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();
  }
  public void Render() {
    BufferStrategy bs = this.getBufferStrategy();
    if (bs == null) {
      this.createBufferStrategy(3);
    }
    bs = this.getBufferStrategy();
    Graphics g = bs.getDrawGraphics();

    g.drawImage(BackGroundGUI, 0, 0, null);
    g.drawImage(manager.Manager, 0, 0, null);
    manager.Render(g);
    manager.RenderGUI(g, InventoryGUI);

    g.dispose();
    bs.show();
  }
Example #29
0
  private void render() {
    BufferStrategy bs = this.getBufferStrategy();
    if (bs == null) {
      this.createBufferStrategy(3);
      return;
    }
    Graphics g = bs.getDrawGraphics();
    //////////////////////////////////////////
    // Ovde PAINT :D

    g.setColor(Color.cyan);
    g.fillRect(0, 0, getWidth(), getHeight());
    ////////////////////////////////////////
    g.dispose();
    bs.show();
  }
Example #30
0
  private void render() {
    BufferStrategy bs = getBufferStrategy();
    if (bs == null) {
      createBufferStrategy(4); // Too Slow? make this 3
      return;
    }
    // Optional clearing goes below
    screen.clear();

    // Rendering goes below:
    screen.fillBackRoundSolidColor(0x456654);
    int xScroll = player.getX() - screen.width / 2;
    int yScroll = player.getY() - screen.height / 2;

    screen.fillBackRoundImage("/Levels/TestBckgrnd.png", screen);
    level.render(xScroll, yScroll, screen);
    player.render(screen);

    for (int i = 0;
        i < pixels.length;
        i++) { // Sets the pixels array in MainGame to the pixel array in the Screen class
      pixels[i] = screen.pixels[i];
    }
    // Displaying goes below:
    Graphics g = bs.getDrawGraphics();
    g.drawImage(image, 0, 0, getWidth(), getHeight(), null); // Draws the buffered image (pixels[])

    // FrameRate Display
    if (Fframes >= 60) g.setColor(Color.white);
    else if (Fframes >= 55) g.setColor(Color.YELLOW);
    else if (Fframes > 65) g.setColor(Color.GREEN);
    else g.setColor(Color.red);
    g.setFont(new Font("Verdana", 0, 10));
    String err = "";
    if (Fframes <= 20 || Fframes > 65) err = "| CHECK FRAMERATE |";
    g.drawString(
        "(" + Fframes + ")" + " " + df.format(framePerc) + "% " + err, 10, HEIGHT * SCALE - 10);
    g.setColor(Color.white);
    g.drawString(
        "Version: " + PrefixVers + " " + NumberVers, WIDTH * SCALE - 150, HEIGHT * SCALE - 10);

    // End of FrameRateDisplay

    //		g.drawRect(0, 141 * SCALE, 300 * SCALE + 8 , 70);
    g.dispose(); // Disposes the graphics
    bs.show(); // Shows the next buffer
  }