void generate_coin_to_the_right()

in coinrun/coinrun.cpp [710:833]


  void generate_coin_to_the_right(int game_type)
  {
    maze->spawnpos[0] = 1;
    maze->spawnpos[1] = 1;
    maze->coins = 1;

    dif = choose_difficulty(MAX_COINRUN_DIFFICULTY);
    int num_sections = randn(dif) + dif;
    int curr_x = 5;
    int curr_y = 1;

    int pit_threshold = dif;
    int danger_type = randn(3);

    char secondary_monster_type = WALKING_MONSTER;
    int max_dy = (maze->max_dy - .5); 
    int max_dx = (maze->max_dx - .5);

    for (int i = 0; i < num_sections; i++) {
      if (curr_x + 15 >= maze->w) {
        break;
      }

      int dy = randn(4) + 1 + int(dif / 3);

      if (dy > max_dy) {
        dy = max_dy;
      }

      if (curr_y >= 20) {
        dy *= -1;
      } else if (curr_y >= 5 and randn(2) == 1) {
        dy *= -1;
      }

      int dx = randn(2 * dif) + 3 + int(dif / 3);

      curr_y += dy;

      if (curr_y < 1) {
        curr_y = 1;
      }

      bool use_pit = (dx > 7) && (curr_y > 3) && (randn(20) >= pit_threshold);

      if (use_pit) {
        int x1 = randn(3) + 1;
        int x2 = randn(3) + 1;
        int pit_width = dx - x1 - x2;

        if (pit_width > max_dx) {
          pit_width = max_dx;
          x2 = dx - x1 - pit_width;
        }

        fill_ground_block(curr_x, 0, x1, curr_y);
        fill_ground_block(curr_x + dx - x2, 0, x2, curr_y);

        int lava_height = randn(curr_y - 3) + 1;

        if (danger_type == 0) {
          fill_lava_block(curr_x + x1, 1, pit_width, lava_height);
        } else if (danger_type == 1) {
          maze->fill_elem(curr_x + x1, 1, pit_width, 1, SAW_MONSTER);
        } else if (danger_type == 2) {
          maze->fill_elem(curr_x + x1, 1, pit_width, 1, secondary_monster_type);
        }

        if (pit_width > 4) {
          int x3, w1;
          if (pit_width == 5) {
            x3 = 1 + randn(2);
            w1 = 1 + randn(2);
          } else if (pit_width == 6) {
            x3 = 2 + randn(2);
            w1 = 1 + randn(2);
          } else {
            x3 = 2 + randn(2);
            int x4 = 2 + randn(2);
            w1 = pit_width - x3 - x4;
          }

          fill_ground_block(curr_x + x1 + x3, curr_y - 1, w1, 1);
        }

      } else {
        fill_ground_block(curr_x, 0, dx, curr_y);

        int ob1_x = -1;
        int ob2_x = -1;

        if (randn(10) < (2 * dif) && dx > 3) {
          ob1_x = curr_x + randn(dx - 2) + 1;
          maze->set_elem(ob1_x, curr_y, SAW_MONSTER);
        }

        if (randn(10) < dif && dx > 3 && (max_dx >= 4)) {
          ob2_x = curr_x + randn(dx - 2) + 1;
          maze->set_elem(ob2_x, curr_y, secondary_monster_type);
        }

        for (int i = 0; i < 2; i++) {
          int crate_x = curr_x + randn(dx - 1) + 1;

          if (randn(2) == 1 && ob1_x != crate_x && ob2_x != crate_x) {
            int pile_height = randn(3) + 1;

            for (int j = 0; j < pile_height; j++) {
              maze->set_elem(crate_x, curr_y + j, choose_crate());
            }
          }
        }
      }

      curr_x += dx;
    }

    maze->set_elem(curr_x, curr_y, COIN_OBJ1);

    fill_ground_block(curr_x, 0, 1, curr_y);
    maze->fill_elem(curr_x + 1, 0, 1, maze->h, WALL_MIDDLE);

    remove_traces_add_monsters();
  }