Esempio n. 1
0
/**
 * \brief Create the level.
 */
void rp::level_generator::create_level()
{
  bear::universe::position_type pos(get_top_left());
  bool previous_is_slope(false);
  unsigned int last_paint = 0;

  for(unsigned int i = 0; i != 100; i++ )
    {
      const double selector = (double)rand() / RAND_MAX;

      if ( ( ( selector < 0.9 ) && previous_is_slope ) ||
	   ( ( selector < 0.5 ) && ! previous_is_slope ) )
	{
	  previous_is_slope = true;
	  add_slope(pos);
	}
      else
	{
	  previous_is_slope = false;
	  add_ground(pos);
	}

      create_target(pos);
      
      if ( ( ((double)rand() / RAND_MAX) < 0.1 ) && 
	   ( i - last_paint > 50 ) )
	{
	  last_paint = i;
	  create_bonus(pos);
	}
    }  
} // rp::level_generator::create_level()
Esempio n. 2
0
void Model::init_map(){
    QJsonObject json_obj= read_json_file(":/map/map_1.json");
    QJsonArray ground_array = json_obj.value(QString("ground")).toArray();
    QJsonObject ground_obj;
    for(int i = 0; i < ground_array.size(); i++){
        ground_obj = ground_array[i].toObject();
        add_ground(ground_obj["line_beg"].toInt(), ground_obj["line_end"].toInt(),
                ground_obj["column_beg"].toInt(), ground_obj["colum_end"].toInt());
    }
}