コード例 #1
0
ファイル: World.java プロジェクト: roby1995/VillageDefense
  public void init(int width, int height) {
    entities.clear();
    animations.clear();
    projectiles.clear();

    this.width = width;
    this.height = height;
    x = -(width - Game.getWidth()) / 2;
    y = -(height - Game.getHeight()) / 2;

    chunks =
        new Chunk[(int) Math.ceil(width / (float) (Chunk.SIZE * Tile.SIZE))]
            [(int) Math.ceil(height / (float) (Chunk.SIZE * Tile.SIZE))];
    for (int i = 0; i < chunks.length; i++)
      for (int j = 0; j < chunks[0].length; j++) chunks[i][j] = new Chunk(i, j);

    generate();
    render();
  }
コード例 #2
0
ファイル: World.java プロジェクト: roby1995/VillageDefense
  @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);
  }