本文整理汇总了C++中Planet::addShips方法的典型用法代码示例。如果您正苦于以下问题:C++ Planet::addShips方法的具体用法?C++ Planet::addShips怎么用?C++ Planet::addShips使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Planet
的用法示例。
在下文中一共展示了Planet::addShips方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
bi->setRange(200);
bi->setCD(1000);
//Building images are now in rotation caches
SDL_FreeSurface(b01);
SDL_FreeSurface(bc01);
SDL_FreeSurface(b02);
SDL_FreeSurface(bc02);
//Create a list of planets
std::list<Planet> planets;
//The standard rate of production of basic ship 0
float ship0rate = 1.0;
//The array of indicators
SDL_Surface* indicator[3];
indicator[1] = loadImage("selectorb.png");
indicator[2] = loadImage("selectorr.png");
SDL_Surface* planet0img = loadImage("planet0.png");
SDL_Surface* planet1img = loadImage("planet1.png");
SDL_Surface* planet1_1img = loadImage("planet1-1.png");
//Create the planets at random
//First, create two home planets
std::vector<int> homestart;
homestart.resize(1,3);
planets.push_back(Planet(planet0img, 1.0,
Vec2f(rand()%100, 100 + rand()%(LEVEL_HEIGHT-200)), 0));
planets.back().setOwner(1, indicator);
planets.back().setShipRate(0, ship0rate);
planets.back().setRotSpeed(M_PI/20);
planets.back().addShips(3, 0);
planets.push_back(Planet(planet0img, 1.0,
Vec2f(LEVEL_WIDTH-(2*UNSCALED_PLANET_RADIUS)-(rand()%100),
100 + rand()%(LEVEL_HEIGHT-200)), 0));
planets.back().setOwner(2, indicator);
planets.back().setShipRate(0, ship0rate);
planets.back().setRotSpeed(M_PI/20);
planets.back().addShips(3, 0);
//Now repeatedly create planets until either a target density is reached
//or we go too many tries without finding a spot for a new planet.
char tries = 0;
char maxTries = 10;
double density = 0.13;
double totalSize = LEVEL_WIDTH*LEVEL_HEIGHT;
double currentSize = M_PI*UNSCALED_PLANET_RADIUS*UNSCALED_PLANET_RADIUS*2;
double spacing = 23;
while (currentSize/totalSize < density && tries < maxTries)
{
//Create a new planet at a completely random location with a random size
//For now, make half normal and half volcanic
float psize = (double(rand())/double(RAND_MAX))*0.7 + 0.5;
Planet p(planet0img, psize,
Vec2f(rand()%(LEVEL_WIDTH-int(2*UNSCALED_PLANET_RADIUS*psize)),
rand()%(LEVEL_HEIGHT-int(2*UNSCALED_PLANET_RADIUS*psize))), 0);;
if (rand()%2 == 0)
{
p.setType(0);
p.setImage(planet0img);
}
else
{