Пример #1
0
  // Use the movement margins to move the view window
  public void moveView() {

    // Init the screen movement timer
    if (screenMovementTimer == null) {
      screenMovementTimer = new Timer();
    }

    // The x and y displacement of the margin
    int deltaX = 0;
    int deltaY = 0;

    GamePanel gp = GamePanel.getInstance();
    int marWidth = Settings.MOVEMENT_MARGIN_WIDTH;
    float moveDist = Settings.SCREEN_MOVEMENT_SPEED * screenMovementTimer.secsElapsed();
    screenMovementTimer.restart();

    // Top margin
    if (mouseLocal.y() < marWidth || KeyTracker.isPressed(KeyEvent.VK_UP)) {
      deltaY += moveDist;
    }

    // Bottom margin
    if (gp.getHeight() - marWidth < mouseLocal.y() || KeyTracker.isPressed(KeyEvent.VK_DOWN)) {
      deltaY -= moveDist;
    }

    // Left margin
    if (mouseLocal.x() < marWidth || KeyTracker.isPressed(KeyEvent.VK_LEFT)) {
      deltaX += moveDist;
    }

    // Right margin
    if (gp.getWidth() - marWidth < mouseLocal.x() || KeyTracker.isPressed(KeyEvent.VK_RIGHT)) {
      deltaX -= moveDist;
    }

    // Change the location of the j-panel
    globalOffset.add(new Pt(deltaX, deltaY));

    // Limit the position of the global offset
    GamePanel myPanel = GamePanel.getInstance();
    globalOffset.constrain(
        -Settings.FIELD_WIDTH + myPanel.getWidth(),
        -Settings.FIELD_HEIGHT - Settings.MINI_MAP_HEIGHT + myPanel.getHeight(),
        0,
        0);
  }
Пример #2
0
  private void drawElapsedTime(Graphics2D g2d, float x, float y) {

    int totalSecsElapsed = (int) matchTimer.secsElapsed();

    int minsElapsed = totalSecsElapsed / 60;
    int secsElapsed = totalSecsElapsed % 60;

    g2d.setColor(Color.BLACK);
    g2d.drawString("mins: " + minsElapsed, x, y);
    g2d.drawString("secs: " + secsElapsed, x, y + 15);
  }