Exemplo n.º 1
0
  /*
   * A super messy way to initiate the camera position without gameplay-input (meant to be run exactly once,
   * at the beginning of the loading of a level).
   */
  public void findPlayer() {
    boolean lockNS =
        ResourceManager.MANAGER.playerFocusEntity.cameraLockNS(
            GameMap.MAP, GraphicsManager.MANAGER);
    boolean lockEW =
        ResourceManager.MANAGER.playerFocusEntity.cameraLockEW(
            GameMap.MAP, GraphicsManager.MANAGER);

    int mapHeight =
        GameMap.MAP.mapCanvas.get(ResourceManager.MANAGER.playerFocusEntity.mapLevel).mapHeight
            * GameMap.MAP.tileDimensions;
    int mapWidth =
        GameMap.MAP.mapCanvas.get(ResourceManager.MANAGER.playerFocusEntity.mapLevel).mapWidth
            * GameMap.MAP.tileDimensions;

    int screenHeight = GraphicsManager.MANAGER.getHeight();
    int screenWidth = GraphicsManager.MANAGER.getWidth();

    int top = mapHeight - screenHeight + (GraphicsManager.MANAGER.border * 2); // excess height!
    int right = mapWidth - screenWidth + (GraphicsManager.MANAGER.border * 2);

    setPosition(0, 0, 0);

    if (lockNS) position.y = ResourceManager.MANAGER.playerFocusEntity.position.y;
    else {
      if (ResourceManager.MANAGER.playerFocusEntity.position.y > ((mapHeight / 2) - top / 2))
        position.y = mapHeight / 2 + top / 2;
      else position.y = mapHeight / 2 - top / 2;
    }

    if (lockEW) position.x = ResourceManager.MANAGER.playerFocusEntity.position.x;
    else {
      if (ResourceManager.MANAGER.playerFocusEntity.position.x > ((mapWidth / 2) - right / 2))
        position.x = mapWidth / 2 + right / 2;
      else position.x = mapWidth / 2 - right / 2;
    }
  }
Exemplo n.º 2
0
  public void pollMouse() {

    int mouseWheelDelta = Mouse.getDWheel();

    for (String b : buttons.keySet()) {
      buttons.get(b).checkHover(Mouse.getX(), GraphicsManager.MANAGER.getHeight() - Mouse.getY());
    }
    for (MessageBox mb : messageBoxes) {
      mb.checkHover(Mouse.getX(), GraphicsManager.MANAGER.getHeight() - Mouse.getY());
    }

    while (Mouse.next()) {
      if (Mouse.getEventButtonState()) {
        switch (Mouse.getEventButton()) {
          case 0: // Left click
            for (Button b : buttons.values()) {
              if (b.hovering) {
                b.onClick();
              }
            }
            for (MessageBox mb : messageBoxes) {
              if (mb.hovering) mb.onClick();
            }
            break;
          case 1: // Right click
            break;
        }
      }
      if (mouseWheelDelta != 0)
        for (MessageBox mb : messageBoxes) {
          if (mb.hovering) {
            mb.onScroll(mouseWheelDelta);
          }
        }
    }
  }