private void renderHealth() {
   Health health = healthMapper.get(player);
   g.translate(35, container.getHeight() - 45);
   {
     font.drawString(-26, 8, "Health");
     g.rotate(0, 0, -90);
     float healthStatus = health.getHealthStatus();
     g.setDrawMode(Graphics.MODE_ADD);
     statusBar.draw(
         0,
         0,
         statusBar.getWidth() * healthStatus,
         statusBar.getHeight(),
         0,
         0,
         statusBar.getWidth() * healthStatus,
         statusBar.getHeight(),
         healthStatus < 0.25 ? Color.red : healthStatus < 0.6 ? Color.yellow : Color.green);
     statusBar.draw(
         statusBar.getWidth() * healthStatus,
         0,
         statusBar.getWidth(),
         statusBar.getHeight(),
         statusBar.getWidth() * healthStatus,
         0,
         statusBar.getWidth(),
         statusBar.getHeight(),
         new Color(0.15f, 0.15f, 0.15f));
     g.setDrawMode(Graphics.MODE_NORMAL);
     g.rotate(0, 0, 90);
   }
   g.translate(-35, -container.getHeight() + 45);
 }
 private void renderAmmo() {
   Ammo ammo = ammoMapper.get(player);
   g.translate(container.getWidth() - 64, container.getHeight() - 45);
   {
     font.drawString(-16, 8, "Ammo");
     g.rotate(0, 0, -90);
     float ammoStatus = ammo.getAmmoStatus();
     g.setDrawMode(Graphics.MODE_ADD);
     statusBar.draw(
         0,
         0,
         statusBar.getWidth() * ammoStatus,
         statusBar.getHeight(),
         0,
         0,
         statusBar.getWidth() * ammoStatus,
         statusBar.getHeight(),
         ammoStatus < 0.25 ? Color.red : ammoStatus < 0.6 ? Color.yellow : Color.green);
     statusBar.draw(
         statusBar.getWidth() * ammoStatus,
         0,
         statusBar.getWidth(),
         statusBar.getHeight(),
         statusBar.getWidth() * ammoStatus,
         0,
         statusBar.getWidth(),
         statusBar.getHeight(),
         new Color(0.15f, 0.15f, 0.15f));
     g.setDrawMode(Graphics.MODE_NORMAL);
     g.rotate(0, 0, 90);
   }
   g.translate(-container.getWidth() + 64, -container.getHeight() + 45);
 }
Ejemplo n.º 3
0
 public void render(Graphics g) {
   g.setColor(Color.red);
   Images.ITEMS
       .getSubImage(0, 2)
       .draw(
           ox + (x * Constants.TILE_SIZE + (Inventory.SLOT_SPACING * x)),
           oy + (y * Constants.TILE_SIZE + (Inventory.SLOT_SPACING * y)));
   g.translate(ox, oy);
   if (hasItem()) {
     item.render(g);
   }
   g.translate(-ox, -oy);
   g.setColor(color);
   g.fillRect(
       ox + (x * Constants.TILE_SIZE + (Inventory.SLOT_SPACING * x)),
       oy + (y * Constants.TILE_SIZE + (Inventory.SLOT_SPACING * y)),
       Constants.TILE_SIZE,
       Constants.TILE_SIZE);
   if (tooltip) {
     int x = ox + (this.x * Constants.TILE_SIZE + (Inventory.SLOT_SPACING * this.x));
     int y = oy + (this.y * Constants.TILE_SIZE + (Inventory.SLOT_SPACING * this.y));
     g.setColor(Color.black);
     g.fillRect(x, y - 25, Fonts.CLASS_TEXT.getWidth("Remove"), 20);
     g.setColor(Color.white);
     Fonts.CLASS_TEXT.drawString(x, y - 23, "Remove");
   }
 }
Ejemplo n.º 4
0
  /** @see AbstractComponent#render(GUIContext, org.newdawn.slick.Graphics) */
  public void render(GUIContext container, Graphics g) {
    if (lastKey != -1) {
      if (input.isKeyDown(lastKey)) {
        if (repeatTimer < System.currentTimeMillis()) {
          repeatTimer = System.currentTimeMillis() + KEY_REPEAT_INTERVAL;
          keyPressed(lastKey, lastChar);
        }
      } else {
        lastKey = -1;
      }
    }
    Rectangle oldClip = g.getClip();
    g.setWorldClip(x, y, width, height);

    // Someone could have set a color for me to blend...
    Color clr = g.getColor();

    if (background != null) {
      g.setColor(background.multiply(clr));
      g.fillRect(x, y, width, height);
    }
    g.setColor(text.multiply(clr));
    Font temp = g.getFont();

    int cpos = font.getWidth(value.substring(0, cursorPos));
    int tx = 0;
    if (cpos > width) {
      tx = width - cpos - font.getWidth("_");
    }

    g.translate(tx + 2, 0);
    g.setFont(font);
    g.drawString(value, x + 1, y + 1);

    if (hasFocus() && visibleCursor) {
      g.drawString("_", x + 1 + cpos + 2, y + 1);
    }

    g.translate(-tx - 2, 0);

    if (border != null) {
      g.setColor(border.multiply(clr));
      g.drawRect(x, y, width, height);
    }
    g.setColor(clr);
    g.setFont(temp);
    g.clearWorldClip();
    g.setClip(oldClip);
  }
Ejemplo n.º 5
0
  @Override
  public void render(Graphics g) {
    g.pushTransform();
    if (flip) {
      // Be sure to flip around the center
      g.translate(centerX, 0);
      g.scale(-1, 1);
      g.translate(-centerX, 0);
      // Alternatively, translate by width after flip
    }
    g.rotate(centerX, centerY, angle);

    g.drawImage(img, 0, 0);
    g.popTransform();
  }
Ejemplo n.º 6
0
  public void drawBoxBody(Graphics g, Body body, Box box) {
    Vector2f[] pts = box.getPoints(body.getPosition(), body.getRotation());

    Vector2f v1 = pts[0];
    Vector2f v2 = pts[1];
    Vector2f v3 = pts[2];
    Vector2f v4 = pts[3];

    g.translate(camX, camY);
    g.setColor(new Color(255, 255, 255));
    g.drawLine((int) v1.x, (int) v1.y, (int) v2.x, (int) v2.y);
    g.drawLine((int) v2.x, (int) v2.y, (int) v3.x, (int) v3.y);
    g.drawLine((int) v3.x, (int) v3.y, (int) v4.x, (int) v4.y);
    g.drawLine((int) v4.x, (int) v4.y, (int) v1.x, (int) v1.y);
    g.translate(-camX, -camY);
  }
  private void renderMinimap() {
    int minimapWidth = minimapBg.getWidth();
    int minimapHeight = minimapBg.getHeight();

    int boundaryWidth = boundarySystem.getBoundaryWidth();
    int boundaryHeight = boundarySystem.getBoundaryHeight();

    float scaleX = (float) minimapWidth / (float) boundaryWidth;
    float scaleY = (float) minimapHeight / (float) boundaryHeight;

    g.setColor(Color.white);

    g.translate(container.getWidth() - minimapWidth - 20, 20);
    {
      minimapBg.draw();

      float offsetX = cameraSystem.getStartX();
      float offsetY = cameraSystem.getStartY();
      g.drawRect(
          offsetX * scaleX,
          offsetY * scaleY,
          scaleX * cameraSystem.getWidth(),
          scaleY * cameraSystem.getHeight());

      ImmutableBag<Entity> entities = world.getManager(GroupManager.class).getEntities("crates");
      for (int i = 0; entities.size() > i; i++) {
        Entity crate = entities.get(i);
        Physics cratePhysics = physicsMapper.get(crate);
        float crateX = cratePhysics.getX() * scaleX;
        float crateY = cratePhysics.getY() * scaleY;
        g.fillRect(crateX - 1, crateY - 1, 2, 2);
      }

      ImmutableBag<Entity> tanks = world.getManager(GroupManager.class).getEntities("tanks");
      for (int i = 0; tanks.size() > i; i++) {
        Entity t = tanks.get(i);
        String tp = world.getManager(PlayerManager.class).getPlayer(t);
        Physics physics = physicsMapper.get(t);
        g.setColor(Color.green);
        float tx = physics.getX() * scaleX;
        float ty = physics.getY() * scaleY;
        g.fillRect(tx - 3, ty - 3, 6, 6);
      }
    }
    g.translate(-container.getWidth() + minimapWidth + 20, -20);
  }
Ejemplo n.º 8
0
  /**
   * gets called evey render
   *
   * @param g the graphics object on which should be drawn
   */
  public void render(Graphics g) {

    g.translate(camX, camY);

    particles.render(g);

    entities.render(g);

    interfaces.render(g);
  }
Ejemplo n.º 9
0
  protected void preRender(final Graphics graphicContext) {
    graphicContext.pushTransform();

    graphicContext.translate(
        this.getData()[Entity.X], this.getData()[Entity.Y]); // move to pos // position

    graphicContext.translate(
        this.getData()[Entity.CENTER_X], this.getData()[Entity.CENTER_Y]); // translate back

    graphicContext.rotate(0, 0, this.getData()[Entity.ROTATION]); // rotate

    graphicContext.scale(this.getData()[Entity.SCALE_X], this.getData()[Entity.SCALE_Y]); // zoom
    // from
    // point

    graphicContext.translate(
        -this.getData()[Entity.CENTER_X],
        -this.getData()[Entity.CENTER_Y]); // set center of rotation
  }
Ejemplo n.º 10
0
  @Override
  public void render(Camera camera, GameContainer gameContainer) {
    Graphics graphics = gameContainer.getGraphics();
    graphics.pushTransform();
    graphics.translate(0, 40f);
    super.render(camera, gameContainer);
    graphics.popTransform();

    if (BattleToads.ALLOW_DEBUGGING) graphics.setColor(Color.magenta);
    if (BattleToads.ALLOW_DEBUGGING) graphics.draw(getCollisionHitbox(position));
  }
Ejemplo n.º 11
0
  public void resetAnimState() {
    if (stateNew == null) return;

    if (stateNew.scaleH != 1 || stateNew.scaleV != 1) g.scale(stateNew.scaleH, stateNew.scaleV);
    if (stateNew.angle != 0) gl.glRotatef(stateNew.angle, 0f, 0f, 1f);
    if (stateNew.pos.x != 0 || stateNew.pos.y != 0) g.translate(stateNew.pos.x, stateNew.pos.y);
    Color.white.bind();
    g.setColor(stateColor);

    stateNew = null;
  }
Ejemplo n.º 12
0
  public void setAnimState(AnimState state) {
    if (state != null) resetAnimState();

    getPrivates();
    stateColor = g.getColor();
    stateNew = new AnimState(state);

    g.setColor(state.color);
    state.color.bind();
    if (state.pos.x != 0 || state.pos.y != 0) g.translate(-state.pos.x, -state.pos.y);
    if (state.angle != 0) gl.glRotatef(-state.angle, 0f, 0f, 1f);
    if (state.scaleH != 1 || state.scaleV != 1) g.scale(1f / state.scaleH, 1f / state.scaleV);
  }
Ejemplo n.º 13
0
  @Override
  public void render(GameContainer gc, Graphics g) throws SlickException {
    // center player and follow player around
    g.translate(
        (Game.SCREEN_WIDTH / 2)
            - (player.boundingBox().getX() + (player.boundingBox().getWidth() / 2)),
        (Game.SCREEN_HEIGHT / 2)
            - (player.boundingBox().getY() + (player.boundingBox().getHeight() / 2)));

    this.currentLevel.draw(this.currentLevel.getX(), this.currentLevel.getY(), player, g);
    if (this.miniMap.isVisible)
      this.miniMap.draw(this.miniMap.xPos, this.miniMap.yPos, this.currentLevel, this.player);
    this.player.draw(g);
  }
Ejemplo n.º 14
0
  /**
   * Render the TiledMap, Player and Backdrop.
   *
   * @param gc Slick GameContainer.
   * @param g Java Graphics.
   * @throws SlickException
   */
  public void render(GameContainer gc, Graphics g) throws SlickException {

    if (backdrop != null) {
      backdrop.render(screenRight, screenDown);
    }

    g.translate(camX, camY);

    tileOffsetX = (camX % mapWidth);
    tileOffsetY = (camY % mapHeight);
    tileIndexX = -1 * (camX / mapWidth);
    tileIndexY = -1 * (camY / mapHeight);
    renderLayer("BACKGROUND");
    renderLayer("PLATFORMS");

    for (Entity e : entity) {
      e.render(gc, g);
    }
    player.render(gc, g);
    renderFore();

    g.translate(-camX, -camY);
  }
Ejemplo n.º 15
0
  @Override
  protected final void processEntities(ImmutableBag<Entity> entities) {
    float scale = camera.getScale();
    Vector2 position = camera.getPosition();

    float offsetX = container.getWidth() / (2 * scale) - position.getX();
    float offsetY = container.getHeight() / (2 * scale) - position.getY();

    graphics.scale(scale, scale);
    graphics.translate(offsetX, offsetY);
    for (int i = 0, s = entities.size(); s > i; i++) {
      Entity e = entities.get(i);
      final Transform transform = transformMapper.get(e);
      final Render render = renderMapper.get(e);

      if (render == null) {
        Log.warn("render was null for " + e.getId());
        continue;
      }

      Assert.isTrue(render != null);
      Assert.isTrue(render.getRenderables() != null);

      Vector2 translation = transform.getTranslation();
      float rotation = transform.getRotation();

      graphics.rotate(translation.getX(), translation.getY(), rotation);
      graphics.translate(translation.getX(), translation.getY());
      for (Renderable renderable : render.getRenderables()) {
        renderable.render(graphics);
      }
      graphics.translate(-translation.getX(), -translation.getY());
      graphics.rotate(translation.getX(), translation.getY(), -rotation);
    }
    graphics.translate(-offsetX, -offsetY);
    graphics.scale(1 / scale, 1 / scale);
  }
Ejemplo n.º 16
0
  /**
   * Implementation of the core rendering function that just renders the map to the assigned graphic
   * context.
   *
   * @param g the graphics context used for the render operation
   */
  private void renderImpl(final Graphics g) {
    final Camera camera = Camera.getInstance();

    g.pushTransform();

    g.translate(-camera.getViewportOffsetX(), -camera.getViewportOffsetY());
    Camera.getInstance().clearDirtyAreas(g);

    synchronized (display) {
      synchronized (GameMap.LIGHT_LOCK) {
        // draw all items
        for (int i = 0, displaySize = display.size(); i < displaySize; i++) {
          display.get(i).draw(g);
        }
      }
    }

    g.popTransform();
  }
Ejemplo n.º 17
0
  /**
   * @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
   */
  @Override
  public void render(GameContainer container, Graphics g) throws SlickException {
    String text = "abc";
    font.drawString(610, 100, text);

    GL11.glDisable(GL11.GL_BLEND);
    GL11.glEnable(GL11.GL_ALPHA_TEST);
    GL11.glAlphaFunc(GL11.GL_GEQUAL, 0.5f);
    font.drawString(610, 150, text);
    GL11.glDisable(GL11.GL_ALPHA_TEST);
    GL11.glEnable(GL11.GL_BLEND);

    g.translate(-50, -130);
    g.scale(10, 10);
    font.drawString(0, 0, text);

    GL11.glDisable(GL11.GL_BLEND);
    GL11.glEnable(GL11.GL_ALPHA_TEST);
    GL11.glAlphaFunc(GL11.GL_GEQUAL, 0.5f);
    font.drawString(0, 26, text);
    GL11.glDisable(GL11.GL_ALPHA_TEST);
    GL11.glEnable(GL11.GL_BLEND);

    g.resetTransform();
    g.setColor(Color.lightGray);
    g.drawString("Original Size on Sheet", 620, 210);
    g.drawString("10x Scale Up", 40, 575);

    g.setColor(Color.darkGray);
    g.drawRect(40, 40, 560, 530);
    g.drawRect(610, 105, 150, 100);

    g.setColor(Color.white);
    g.drawString("512x512 Font Sheet", 620, 300);
    g.drawString("NEHE Charset", 620, 320);
    g.drawString("4096x4096 (8x) Source Image", 620, 340);
    g.drawString("ScanSize = 20", 620, 360);
  }
Ejemplo n.º 18
0
 public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
   g.translate(Main.getWidth() / 2, Main.getHeight() / 2);
   l.get(0).show(g);
   p.show(g);
   p.displayChat(g);
 }
Ejemplo n.º 19
0
 public void translate(Graphics g) {
   g.translate((int) (-x + (Game.width / 2f)), (int) (-y + (Game.height / 2)));
 }
Ejemplo n.º 20
0
 public void render(GameContainer container, StateBasedGame game, Graphics g) {
   g.translate(-viewport.getX(), -viewport.getY());
   g.setWorldClip(viewport);
   world.render(container, game, g);
   g.clearWorldClip();
 }
Ejemplo n.º 21
0
 public void drawEntity(Entity e, GameContainer gc, Graphics g) throws SlickException {
   g.translate(camX, camY);
   e.render(gc, g);
   g.translate(-camX, -camY);
 }
Ejemplo n.º 22
0
  @Override
  public void render(GameContainer container, StateBasedGame game, Graphics g)
      throws SlickException {
    // TODO Graphics?
    g.drawString("Distance: " + distance, 10, 25);
    g.drawString("Speed: " + ((double) ((int) (speed * 10000.0))) / 10000.0, 10, 40);

    // all the graphics below will be affected by the translation
    g.translate(spX, 0);

    // The smoke
    ((ConfigurableEmitter) trail.getEmitter(0))
        .setPosition(dudeWidth - dudeSize.width / 2 - spX, dudeHeight);
    trail.render();
    // the death explosion
    ((ConfigurableEmitter) explosion.getEmitter(0))
        .setPosition(dudeWidth - dudeSize.width / 2 - spX, dudeHeight);
    ((ConfigurableEmitter) explosion.getEmitter(1))
        .setPosition(dudeWidth - dudeSize.width / 2 - spX, dudeHeight);
    explosion.render();

    // the walls
    // upper wall
    for (int i = 0; i < upperWall.size() - 1; i++) {
      for (int j = 0; j < 5; j++) {
        g.drawLine(
            i * WALL_RES + wallOffset - spX,
            upperWall.get(i) - j,
            (i + 1) * WALL_RES + wallOffset - spX,
            upperWall.get(i + 1) - j);
      }
    }
    // lower wall
    for (int i = 0; i < lowerWall.size() - 1; i++) {
      for (int j = 0; j < 5; j++) {
        g.drawLine(
            i * WALL_RES + wallOffset - spX,
            lowerWall.get(i) + j,
            (i + 1) * WALL_RES + wallOffset - spX,
            lowerWall.get(i + 1) + j);
      }
    }
    // The object
    g.fillRect(
        dudeWidth - dudeSize.width / 2 - spX,
        (int) dudeHeight - dudeSize.height / 2,
        dudeSize.width,
        dudeSize.height);

    // if(dead) g.drawString("Le jeu est terminé, appuyez sur Entrée pour continuer", 250, 150);

    // Sounds
    AlUtils.setAlListenerPosition((float) (WALL_RES + dudeSize.width / 2), dudeHeight, 0f);

    if (movingUp) AlUtils.setAlListenerVelocity((float) (WALL_RES + dudeSize.width / 2), -20, 0f);
    else AlUtils.setAlListenerVelocity((float) (WALL_RES + dudeSize.width / 2), 20, 0f);
    enterSound.setSourcePosition((float) (WALL_RES + dudeSize.width / 2), dudeHeight, 0f, 0);
    sonG.setSourcePosition((float) (WALL_RES + dudeSize.width / 2), actualUpperWall, 0f, 0);
    sonD.setSourcePosition((float) (WALL_RES + dudeSize.width / 2), actualLowerWall, 0f, 1);
    sonG.setSourceVelocity(
        (float) (WALL_RES + dudeSize.width / 2),
        upperWall.get(currentWallNo - 1) - upperWall.get(currentWallNo),
        0f,
        0);
    sonD.setSourceVelocity(
        (float) (WALL_RES + dudeSize.width / 2),
        lowerWall.get(currentWallNo) - lowerWall.get(currentWallNo - 1),
        0f,
        1);

    distSonBas = (float) (1.0 / ((actualLowerWall - dudeHeight) / 50.0));
    distSonHaut = (float) (1.0 / ((dudeHeight - actualUpperWall) / 50.0));
    sonG.setPitch(distSonHaut);
    sonD.setPitch(distSonBas, 1);
  }
Ejemplo n.º 23
0
 public void render(GameContainer gc, StateBasedGame sb, Graphics gr) {
   gr.translate(xPos, yPos);
   map.render(0, 0, map.getLayerIndex("tiles"));
 }