コード例 #1
0
ファイル: GameRenderer.java プロジェクト: mjerkovic/shooter
  public void render(Vehicle vehicle) {
    Vector adjustedPosition = vehicle.position().add(viewPoint);
    int x = (int) adjustedPosition.x();
    int y = (int) adjustedPosition.y();

    Vector tip = new Vector(x + vehicle.boundingRadius(), y);
    Vector left = new Vector(x - 5, y - 5);
    Vector right = new Vector(x - 5, y + 5);

    int[] xPos = {(int) tip.x(), (int) left.x(), (int) right.x()};
    int[] yPos = {(int) tip.y(), (int) left.y(), (int) right.y()};

    AffineTransform orig = graphics.getTransform();

    AffineTransform rot =
        AffineTransform.getRotateInstance(vehicle.heading().x(), vehicle.heading().y(), x, y);
    graphics.transform(rot);
    graphics.drawPolygon(xPos, yPos, 3);
    graphics.setTransform(orig);

    if (showFeelers) {
      Vector[] feelers = createFeelersFor(vehicle);
      for (Vector feeler : feelers) {
        graphics.drawLine(x, y, (int) feeler.x(), (int) feeler.y());
      }
    }
    renderHealthBar(vehicle, x, y);
    renderEnergyBar(vehicle, x, y);
  }
コード例 #2
0
ファイル: GameRenderer.java プロジェクト: mjerkovic/shooter
 public void render(BaseCamp baseCamp) {
   Vector pos = baseCamp.position().add(viewPoint);
   int radius = (int) baseCamp.boundingRadius();
   int length = radius * 2;
   graphics.drawRect((int) pos.x() - radius, (int) pos.y() - radius, length, length);
   graphics.drawString("Base", (int) pos.x() - 10, (int) pos.y());
 }
コード例 #3
0
ファイル: GameRenderer.java プロジェクト: mjerkovic/shooter
 public void render(Mine mine) {
   Vector pos = mine.position().add(viewPoint);
   int radius = (int) mine.boundingRadius();
   int length = radius * 2;
   graphics.drawRect((int) pos.x() - radius, (int) pos.y() - radius, length, length);
   graphics.drawString(String.valueOf(mine.yield()), (int) pos.x() - 10, (int) pos.y());
 }
コード例 #4
0
ファイル: GameRenderer.java プロジェクト: mjerkovic/shooter
 private void renderEnergyBar(Entity entity, int x, int y) {
   int yPos = y + ((int) entity.boundingRadius() + 10);
   graphics.drawRect(x - 15, yPos, 30, 7);
   Color originalColor = graphics.getColor();
   graphics.setColor(Color.BLUE);
   double energyBarLength = 29.0 * entity.energy();
   graphics.fillRect(x - 14, yPos + 1, (int) energyBarLength, 6);
   graphics.setColor(originalColor);
 }
コード例 #5
0
ファイル: GameRenderer.java プロジェクト: mjerkovic/shooter
 private void renderHealthBar(Entity entity, int x, int y) {
   int yPos = y - ((int) entity.boundingRadius() + 10);
   graphics.drawRect(x - 15, yPos, 30, 7);
   Color originalColor = graphics.getColor();
   double health = entity.health();
   graphics.setColor(getColorFor(health));
   double healthBarLength = 29.0 * health;
   graphics.fillRect(x - 14, yPos + 1, (int) healthBarLength, 6);
   graphics.setColor(originalColor);
 }
コード例 #6
0
ファイル: GameRenderer.java プロジェクト: mjerkovic/shooter
 public void render(TargetingSystem targetingSystem) {
   Vector pos = targetingSystem.position().add(viewPoint);
   int x = (int) pos.x();
   int y = (int) pos.y();
   int radius = (int) targetingSystem.boundingRadius();
   int diameter = radius * 2;
   graphics.drawOval(x - radius, y - radius, diameter, diameter);
   double hx = targetingSystem.heading().x();
   double hy = targetingSystem.heading().y();
   graphics.drawLine(
       x + (int) (hx * radius),
       y + (int) (hy * radius),
       x + (int) (hx * diameter),
       y + (int) (hy * diameter));
 }
コード例 #7
0
ファイル: GameRenderer.java プロジェクト: mjerkovic/shooter
 public void render(Obstacle obstacle) {
   Vector adjustedPosition = obstacle.position().add(viewPoint);
   graphics.drawOval(
       (int) (adjustedPosition.x() - obstacle.boundingRadius()),
       (int) (adjustedPosition.y() - obstacle.boundingRadius()),
       (int) (obstacle.boundingRadius() * 2),
       (int) (obstacle.boundingRadius() * 2));
 }
コード例 #8
0
ファイル: GameRenderer.java プロジェクト: mjerkovic/shooter
  public void render(Miner miner) {
    Vector adjustedPosition = miner.position().add(viewPoint);
    int x = (int) adjustedPosition.x();
    int y = (int) adjustedPosition.y();

    AffineTransform orig = graphics.getTransform();
    AffineTransform rot =
        AffineTransform.getRotateInstance(miner.heading().x(), miner.heading().y(), x, y);
    graphics.transform(rot);
    graphics.drawRect(
        x - (int) miner.boundingRadius(),
        y - ((int) miner.boundingRadius() / 2),
        (int) miner.boundingRadius() * 2,
        (int) miner.boundingRadius());
    graphics.setTransform(orig);
    renderHealthBar(miner, x, y);
    renderEnergyBar(miner, x, y);
  }
コード例 #9
0
ファイル: GameRenderer.java プロジェクト: mjerkovic/shooter
  public void render(Wall wall) {
    Stroke stroke = graphics.getStroke();
    graphics.setStroke(new BasicStroke(10));
    Vector from = wall.from().add(viewPoint);
    Vector to = wall.to().add(viewPoint);
    graphics.drawLine((int) from.x(), (int) from.y(), (int) to.x(), (int) to.y());
    graphics.setStroke(stroke);

    if (showWallNormals) {
      Vector centre = wall.centre().add(viewPoint);
      Vector normal = wall.normal();
      int x = (int) centre.x();
      int y = (int) centre.y();
      int toX = x + (int) (normal.x() * 10);
      int toY = y + (int) (normal.y() * 10);
      graphics.drawLine(x, y, toX, toY);
    }
  }
コード例 #10
0
ファイル: GameRenderer.java プロジェクト: mjerkovic/shooter
 public void render(Bullet bullet) {
   Vector adjustedPosition = bullet.position().add(viewPoint);
   int x1 = (int) adjustedPosition.x();
   int y1 = (int) adjustedPosition.y();
   Vector tail = bullet.heading().reverse();
   int x2 = x1 + (int) tail.x() * 10;
   int y2 = y1 + (int) tail.y() * 10;
   graphics.drawLine(x1, y1, x2, y2);
 }
コード例 #11
0
ファイル: GameRenderer.java プロジェクト: mjerkovic/shooter
 public void render(WatchTower watchTower) {
   Vector pos = watchTower.position().add(viewPoint);
   int x1 = (int) pos.x();
   int y1 = (int) pos.y();
   graphics.drawOval(x1 - 5, y1 - 5, 10, 10);
   /*
           Vector heading = watchTower.heading();
           int x2 = x1 + (int) (heading.x() * 20);
           int y2 = y1 + (int) (heading.y() * 20);
           graphics.drawLine(x1 + (int) (heading.x() * 5), y1 + (int) (heading.y() * 5), x2, y2);
   */
 }
コード例 #12
0
ファイル: GameRenderer.java プロジェクト: mjerkovic/shooter
 public void render(Signpost signpost) {
   Vector pos = signpost.position().add(viewPoint);
   graphics.drawString(signpost.getLabel(), (int) pos.x(), (int) pos.y());
 }