Пример #1
0
  @Override
  public void tick(MouseButtons mouseButtons) {
    super.tick(mouseButtons);

    // show/hide save menu buttons
    if (updateButtons) {
      updateSaveButtons();
      updateButtons = false;
    }

    // lock buttons when save menu is visible
    if (saveMenuVisible) return;

    // update pencil location
    pencilX = (mouseButtons.getX() / 2) - (TILE_WIDTH / 2);
    pencilY = (mouseButtons.getY() / 2) - (TILE_HEIGHT / 2);

    // move level x with mouse
    if (mouseButtons.getX() - MENU_WIDTH > MENU_WIDTH) {
      if (pencilX + TILE_WIDTH > MojamComponent.GAME_WIDTH
          && -(mapX - MENU_WIDTH) < mapW - (MojamComponent.GAME_WIDTH - MENU_WIDTH) + TILE_HEIGHT) {
        mapX -= TILE_WIDTH / 2;
      } else if (pencilX < MENU_WIDTH && mapX < MENU_WIDTH + 32) {
        mapX += TILE_WIDTH / 2;
      }
    }

    // move level y with mouse
    if (pencilY + TILE_HEIGHT > MojamComponent.GAME_HEIGHT
        && -mapY < mapH - MojamComponent.GAME_HEIGHT + TILE_HEIGHT) {
      mapY -= TILE_HEIGHT / 2;
    } else if (pencilY < 0 && mapY < TILE_HEIGHT) {
      mapY += TILE_HEIGHT / 2;
    }

    // draw
    if (drawing || editorComponent.isPressed()) {
      int x = (((pencilX + TILE_WIDTH / 2) - mapX) / TILE_WIDTH);
      int y = (((pencilY + TILE_HEIGHT / 2) - mapY) / TILE_HEIGHT);
      draw(selectedButton.getTile(), x, y);
    }
  }