Ejemplo n.º 1
0
  public boolean isColliding(int x, int y) {
    for (Block b : blocks)
      // if the block is a down block.
      if (b.getX() < x && x - b.getX() < b.getWidth() && b.getY() < y) return true;

    return false;
  }
Ejemplo n.º 2
0
  @Override
  public void paint(BufferedImage buf) {
    Graphics g = buf.getGraphics();
    g.setColor(Color.green);

    for (Block b : blocks)
      g.fillRoundRect(b.getX(), b.getY(), b.getWidth(), b.getHeight() + 10, 5, 5);
  }
Ejemplo n.º 3
0
  @Override
  public void update(int shiftX, int shiftY) {

    if (blocks.isEmpty()) return;

    for (Block b : blocks) {
      b.setX(b.getX() + shiftX);

      // removes the block and instantly adds a new one.
      if (b.getX() < 0 - b.getWidth()) {
        blocks.remove(b);
        int rand = (int) (Math.random() * BLOCK_HEIGHT_MAX + 1);

        if (auto) {
          // if( change)
          createBlockDown(BLOCK_HEIGHT_BASE + rand, 30);
          // else
          // createBlockUp( BLOCK_HEIGHT_BASE + rand, 30);
        }

        change = !change;
      }
    }
  }
Ejemplo n.º 4
0
 public Block(Block block) {
   this(block.getX(), block.getY(), block.getColor());
 }