示例#1
0
  @Override
  public void update(int tick) {
    sortEntities();

    @SuppressWarnings("unchecked")
    List<Entity> sorted = (List<Entity>) entities.clone();
    Collections.reverse(sorted);
    for (Entity entity : sorted) {
      entity.update(tick);
      if (entity.isDead()) {
        if (entity.equals(selectedEntity)) selectedEntity = null;
        entities.remove(entity);
      }
    }

    for (Projectile p : projectiles) {
      p.update(tick);
      if (p.isDead()) projectiles.remove(p);
    }

    for (Animation a : animations) {
      a.update(tick);
      if (a.isDead()) animations.remove(a);
    }
  }
示例#2
0
  @Override
  public void draw(Graphics2D g) {
    AffineTransform old = g.getTransform();
    AffineTransform at = g.getTransform();
    at.translate(x, y);
    g.setTransform(at);

    Rectangle visible = new Rectangle(-x, -y, Game.getWidth(), Game.getHeight());
    try {
      for (int i = 0; i < chunks.length; i++) {
        for (int j = 0; j < chunks[0].length; j++) {
          if (new Rectangle(
                  i * Chunk.SIZE * Tile.SIZE,
                  j * Chunk.SIZE * Tile.SIZE,
                  Chunk.SIZE * Tile.SIZE,
                  Chunk.SIZE * Tile.SIZE)
              .intersects(visible)) chunks[i][j].draw(g);
        }
      }
    } catch (NullPointerException e) {
      return;
    }

    for (Entity e : entities) {
      if (e.getArea(false).intersects(visible)) e.drawEntity(g);
    }

    for (Projectile p : projectiles) p.draw(g);

    for (Animation a : animations) a.draw(g);

    // try
    // {
    // if (AStar.openList != null)
    // {
    // for (Node n : AStar.openList)
    // n.draw(Tile.SIZE, Color.white, g);
    // for (Node n : AStar.closedList)
    // n.draw(Tile.SIZE, Color.blue, g);
    // }
    // }
    // catch (ConcurrentModificationException e)
    // {}
    //
    // for (Entity e : entities)
    // {
    // if (e instanceof Creature)
    // {
    // if (((Creature) e).path != null) ((Creature) e).path.draw(g);
    // }
    // }

    // Color c = g.getColor();
    // g.setColor(Color.darkGray);
    // g.drawRect(Math.round((Game.currentGame.mouse.x - x - Tile.SIZE / 2) / (float) Tile.SIZE) *
    // Tile.SIZE, Math.round((Game.currentGame.mouse.y - y - Tile.SIZE / 2) / (float) Tile.SIZE) *
    // Tile.SIZE, Tile.SIZE, Tile.SIZE);
    // g.setColor(c);

    g.setTransform(old);
  }