当前位置: 首页>>代码示例>>C++>>正文


C++ Blob::calc_area方法代码示例

本文整理汇总了C++中Blob::calc_area方法的典型用法代码示例。如果您正苦于以下问题:C++ Blob::calc_area方法的具体用法?C++ Blob::calc_area怎么用?C++ Blob::calc_area使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Blob的用法示例。


在下文中一共展示了Blob::calc_area方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: collides_with

int Blob::collides_with (Blob* obj) {
  if (this->check_collide (obj)) {
    int xx = abs(this->x - obj->x);
    int yy = abs(this->y - obj->y);
    double d = (sqrt ((xx * xx) + (yy * yy))); // Pythagorean theorem
    Blob *giver = this;
    Blob *reciever = obj;
    if (this->radius > obj->radius) {
      giver = obj;
      reciever = this;
    }
    double oldArea = giver->Area;
    double overlap = (giver->radius + reciever->radius) - d;
    if (overlap < 0) overlap = 0; //-overlap;
    giver->radius -= overlap;
    if (giver->radius < 0.5) {
      giver->radius = 0.0;
      giver->Area = 0;
    } else giver->calc_area();
    reciever->Area += oldArea - giver->Area;
    reciever->calc_radius();
    return 1;
  }
  return 0;
}
开发者ID:Bencepapa,项目名称:CymonsGames,代码行数:25,代码来源:roverwars.cpp

示例2: gameloop

int gameloop () {
  //setup game
  mainmenu();

  blobs.clear();
  for (int p = 0; p < tot_players; p++) {
    blobs.push_back(Blob(players_start[p][0], players_start[p][1], player_radius));
    blobs.back().playerid = p + 1;
  }
  for (int rad = 10; rad >= 1; rad -= 2) { // 1 blob or radius 10 to 10 blobs of radius 1.
    for (int num = 0; num < 2 * (11 - rad); num++) {
      int tries = 3;
      Blob* newblob = new Blob();
      newblob->radius = 3 * rad;
      newblob->calc_area ();
      while (tries) {
        tries--;
        newblob->x = (rand() % (SCREENW - (2 * (int)newblob->radius))) + (int)newblob->radius;
        newblob->y = (rand() % (SCREENH - (2 * (int)newblob->radius))) + (int)newblob->radius;
        newblob->dx = (rand () % 5 - 2) / 2;
        newblob->dy = (rand () % 5 - 2) / 2;
        if (blobs.size()) {
          int c;
          for (c = 0; c < blobs.size() && !newblob->check_collide (&blobs[c]); c++);
          if (c == blobs.size()) {
            blobs.push_back(*newblob);
            tries = 0;
          }
        } else blobs.push_back (*newblob);
      }
      delete newblob;
    }
  }

  int numplayers = tot_players;
  tick = 0;
  while ((!key[KEY_ESC]) && (!key[KEY_F1]) && (numplayers > 1)) {
    while (!tick) rest(1);
    // main game goes here.
    while (tick) {
      tick--;

      numplayers = moveplayers ();

      for (int c = 0; c < blobs.size(); c++) {
        blobs[c].x += blobs[c].dx;
        blobs[c].y += blobs[c].dy;
        if ((blobs[c].x - blobs[c].radius) < 0) {
          blobs[c].x = blobs[c].radius;
          blobs[c].dx = -blobs[c].dx;
        }
        if ((blobs[c].y - blobs[c].radius) < 0) {
          blobs[c].y = blobs[c].radius;
          blobs[c].dy = -blobs[c].dy;
        }
        if ((blobs[c].x + blobs[c].radius) > SCREENW) {
          blobs[c].x = SCREENW - blobs[c].radius;
          blobs[c].dx = -blobs[c].dx;
        }
        if ((blobs[c].y + blobs[c].radius) > SCREENH) {
          blobs[c].y = SCREENH - blobs[c].radius;
          blobs[c].dy = -blobs[c].dy;
        }

        for (int d = c + 1; d < blobs.size(); d++) {
          if (blobs[c].radius < 0.5) continue;
          blobs[c].collides_with(&blobs[d]);
        }
        if (blobs[c].radius < 0.5) {
          blobs.erase(blobs.begin() + c);
          c--;
        }
      }

      // draw screen
      for (int c = 0; c < blobs.size(); c++) {
        int col = makecol (156, 128 - (c * (128.0 / blobs.size())), (c * (128.0 / blobs.size())));
        for (int p = 0; p < tot_players; p++) {
          if (blobs[c].playerid == p + 1)
            col = player_colors[p][0];
        }
        circlefill (buffer, blobs[c].x, blobs[c].y, (int)blobs[c].radius, col);
        col = makecol (255, 128 - (c * (128.0 / blobs.size())), (c * (128.0 / blobs.size())));
        for (int p = 0; p < tot_players; p++) {
          if (blobs[c].playerid == p + 1)
            col = player_colors[p][1];
        }
        circlefill (buffer, blobs[c].x + (blobs[c].radius / 6), blobs[c].y - (blobs[c].radius / 6), (int)(3 * blobs[c].radius / 4), col);
        if (blobs[c].radius > 10) {
//          textprintf_centre_ex(buffer, font, blobs[c].x + blobs[c].dx, blobs[c].y - 3 + blobs[c].dy, makecol(255,255,255), -1, "oo");
//          textprintf_centre_ex(buffer, font, blobs[c].x + blobs[c].dx - 1, blobs[c].y - 5 + blobs[c].dy, makecol(255,255,255), -1, "..");
          textprintf_centre_ex(buffer, font, blobs[c].x + blobs[c].dx, blobs[c].y - 5 + blobs[c].dy, makecol(0,0,0), -1, face);
        }
      }
      blit(buffer, screen, 0, 0, 0, 0, SCREENW, SCREENH);
      clear_to_color(buffer, makecol(0, 0, 0));
    }
  }

  if (numplayers == 2) return 0;
//.........这里部分代码省略.........
开发者ID:Bencepapa,项目名称:CymonsGames,代码行数:101,代码来源:roverwars.cpp


注:本文中的Blob::calc_area方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。