コード例 #1
0
 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);
 }
コード例 #2
0
 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);
 }
コード例 #3
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);
  }
コード例 #4
0
ファイル: TexturedQuad.java プロジェクト: daoo/polhemthegame
  @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();
  }
コード例 #5
0
ファイル: Entity.java プロジェクト: macs672/rgb4
  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
  }
コード例 #6
0
  /**
   * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer,
   *     org.newdawn.slick.Graphics)
   */
  public void render(GameContainer container, Graphics g) {

    g.rotate(400, 300, ang);
    g.fill(rect, gradient);
    g.fill(round, gradient);
    g.fill(poly, gradient2);
    g.fill(center, gradient4);

    g.setAntiAlias(true);
    g.setLineWidth(10);
    g.draw(round2, gradient2);
    g.setLineWidth(2);
    g.draw(poly, gradient);
    g.setAntiAlias(false);

    g.fill(center, gradient4);
    g.setAntiAlias(true);
    g.setColor(Color.black);
    g.draw(center);
    g.setAntiAlias(false);
  }