예제 #1
0
  public void updateRunning(List<TouchEvent> event, float AccelX, float AccelY, float deltaTime) {
    for (int i = 0; i < event.size(); i++) {
      if (event.get(i).type == TouchEvent.TOUCH_UP) {
        if (GameUtil.inBounds(
            event.get(i),
            AppConst.ORIGIN_X,
            AppConst.ORIGIN_Y,
            AppConst.RUNNING_PAUSE_WIDTH,
            AppConst.RUNNING_PAUSE_HEIGHT)) {
          if (Settings.soundEnabled) Assets.click.play(1);
          state = GameState.PAUSED;
        } else {
          if (Settings.soundEnabled) Assets.rotate.play(1);
          arena.rotate();
        }
      }
    }

    // For each more turn it will fired at higher acceleration
    if (AccelX >= AppConst.ACCELERATIONCONST[leftA]) {
      arena.moveLeft();
      rightA = 0;
      if (leftA < (AppConst.ACCELERATIONCONST.length - 1)) leftA++;
    } else if (AccelX <= -AppConst.ACCELERATIONCONST[rightA]) {
      arena.moveRight();
      leftA = 0;
      if (rightA < (AppConst.ACCELERATIONCONST.length - 1)) rightA++;
    }

    if (AccelY > MOVE_DOWN_ACCELERATION_CONST) {
      if (!arena.shapePlaced) {
        MOVE_DOWN_ACCELERATION = AccelY;
        deltaTime += 0.5f;
        arena.update(deltaTime);
      }
    }
    if (arena.shapePlaced && AccelY < (MOVE_DOWN_ACCELERATION - RESUME_MOVE_DOWN)) {
      arena.shapePlaced = false;
    }

    arena.update(deltaTime);

    if (arena.gameOver()) {
      state = GameState.STOPPED;
      Settings.addScore(arena.score);
      Settings.save(game.getFileIO());
    }
  }
예제 #2
0
  void commonPresent(Graphics g) {

    // Filing the lower base
    for (int i = 0;
        i
            <= ((AppConst.FRAMEBUFFER_HEIGHT - (AppConst.ARENA_GRID_HEIGHT * AppConst.BLOCK_HEIGHT))
                / FileName.FILING_BLOCK_HOR_HT);
        i++) {
      for (int j = 0;
          j < ((AppConst.ARENA_GRID_WIDTH * AppConst.BLOCK_WIDTH) / FileName.FILING_BLOCK_HOR_WH);
          j++) {
        g.drawPixmap(
            Assets.filing_block_hor,
            AppConst.ORIGIN_X + (j * FileName.FILING_BLOCK_HOR_WH),
            AppConst.HORIZONTAL_LINE_Y + (i * FileName.FILING_BLOCK_HOR_HT));
      }
    }

    for (int i = 0; i < AppConst.FRAMEBUFFER_HEIGHT; i += FileName.FILING_BLOCK_VER_HT) {
      g.drawPixmap(Assets.filing_block_ver, AppConst.VERTICAL_LINE_X, i);
    }

    // Shape in the Next Box
    int[][] nsCoordinate = arena.getNextShapeCoordinate();
    for (int i = 0; i < nsCoordinate.length; i++) {
      g.drawPixmap(
          Assets.block,
          nsCoordinate[i][0],
          nsCoordinate[i][1],
          AppConst.ORIGIN_X,
          AppConst.ORIGIN_Y
              + arena.nextShape.colour * (AppConst.ATLASING_OFFSET + AppConst.BLOCK_HEIGHT),
          AppConst.BLOCK_WIDTH,
          AppConst.BLOCK_HEIGHT);
    }

    // Score Update
    String score = Integer.toString(arena.score);
    int startX =
        ScreenConst.SCORE_VALUE_X
            + ((FileName.TEXT_SCORE_WH / 2) - ((score.length() * AppConst.SMALL_DIGIT_WIDTH) / 2));
    for (int i = 0; i < score.length(); i++) {
      g.drawPixmap(
          Assets.small_digits,
          startX + (i * AppConst.SMALL_DIGIT_WIDTH),
          ScreenConst.SCORE_VALUE_Y,
          AppConst.ORIGIN_X,
          ((score.charAt(i) - '0') + 1)
              * (AppConst.SMALL_DIGIT_HEIGHT + AppConst.SMALL_DIGIT_OFFSET),
          AppConst.SMALL_DIGIT_WIDTH,
          AppConst.SMALL_DIGIT_HEIGHT);
    }

    // level update
    String level = Integer.toString(arena.level);
    int levelStartX =
        ScreenConst.LEVEL_VALUE_X
            + ((FileName.TEXT_LEVEL_WH / 2) - ((level.length() * AppConst.SMALL_DIGIT_WIDTH) / 2));
    for (int i = 0; i < level.length(); i++) {
      g.drawPixmap(
          Assets.small_digits,
          levelStartX + (i * AppConst.SMALL_DIGIT_WIDTH),
          ScreenConst.LEVEL_VALUE_Y,
          AppConst.ORIGIN_X,
          ((level.charAt(i) - '0') + 1)
              * (AppConst.SMALL_DIGIT_HEIGHT + AppConst.SMALL_DIGIT_OFFSET),
          AppConst.SMALL_DIGIT_WIDTH,
          AppConst.SMALL_DIGIT_HEIGHT);
    }

    // Lines update
    String lines = Integer.toString(arena.lines);
    int linesStartX =
        ScreenConst.LINES_VALUE_X
            + ((FileName.TEXT_LINES_WH / 2) - ((lines.length() * AppConst.SMALL_DIGIT_WIDTH) / 2));
    for (int i = 0; i < lines.length(); i++) {
      g.drawPixmap(
          Assets.small_digits,
          linesStartX + (i * AppConst.SMALL_DIGIT_WIDTH),
          ScreenConst.LINES_VALUE_Y,
          AppConst.ORIGIN_X,
          ((lines.charAt(i) - '0') + 1)
              * (AppConst.SMALL_DIGIT_HEIGHT + AppConst.SMALL_DIGIT_OFFSET),
          AppConst.SMALL_DIGIT_WIDTH,
          AppConst.SMALL_DIGIT_HEIGHT);
    }

    g.drawPixmap(Assets.text_next, ScreenConst.NEXT_X, ScreenConst.NEXT_Y);
    g.drawPixmap(Assets.text_level, ScreenConst.LEVEL_X, ScreenConst.LEVEL_Y);
    g.drawPixmap(Assets.text_score, ScreenConst.SCORE_X, ScreenConst.SCORE_Y);
    g.drawPixmap(Assets.text_lines, ScreenConst.LINES_X, ScreenConst.LINES_Y);
  }