コード例 #1
0
ファイル: GameState.java プロジェクト: mgriley/hive-wars
  public void mousePressed(MouseEvent e) {

    updateGlobalMouse();

    int mX = e.getX();
    int mY = e.getY();

    if (SwingUtilities.isLeftMouseButton(e)) {

      leftMousePressed = true;

      // Check for HUD panel presses
      if (hudPanel.contains(mX, mY) && showMiniMap) {

        if (miniMapRect.contains(mX, mY)) {

          startedInMiniMap = true;

          // Centre the camera to the field position of the mini-map click
          centreCamOnPt(getFieldPtFromMiniMapClick(mX, mY));
        }

        return;
      }

      // Check for Hive creation
      if (placingHive) {

        // TODO: check if the placement location is valid

        // Create a larvae pod out of the selected larvae
        myPlayer.spawnPod(mouseGlobal, myPlayer.getSelectedLarvae());

        placingHive = false;
        startedInHiveCreation = true;

        return;
      }

      // Default

      // Save the start point of the selection rectangle
      startSelect.set(mouseGlobal);

      startedInMiniMap = false;
      startedInHiveCreation = false;

    } else if (SwingUtilities.isRightMouseButton(e)) {

      if (!miniMapRect.contains(mX, mY) || !showMiniMap) {
        myPlayer.handleRightClick(mouseGlobal.x(), mouseGlobal.y());
      } else {
        Pt fieldPos = getFieldPtFromMiniMapClick(mX, mY);
        myPlayer.handleRightClick(fieldPos.x(), fieldPos.y());
      }
    }
  }