Пример #1
0
Polygon * Factory::getRandPolygon() {
	int N = iRand(3, 9);
	Point * * points = new Point * [N+1];
	for (int i = 0; i < N; i++) {
		Point * p = getRandPoint();
		points[i] = p;
		if (points[i]->getX() < points[0]->getX())
			std::swap(points[i], points[0]);
	}
	for (int i = 2; i < N; i++) {
		int j = i;
		while (j > 1 && (points[0]->rotate(*points[j - 1], *points[j]) < 0)) {
			std::swap(points[j - 1], points[j]);
			j -= 1;
		}
	}
	points[N] = new Point(points[0]->getX(), points[0]->getY());
	Container<Point> pl;
	for (int i = 0; i < N+1; i++) {
		pl.pushBack(*points[i]);
		delete points[i];
	}
	delete points;
	return new Polygon(pl);
}
Пример #2
0
void StarSystem::GenerateContents()
{
	int numPlanets = 1 + iRand(5);
	for(int curPlanetNum = 0; curPlanetNum < numPlanets; ++curPlanetNum)
	{
		//create random planet type
		if(fRand() < 0.001)
		{
			// 0.01%
			mContents.push_back(new Planet(this, HabitableObject::PLANET_TERRAN));
		}
		else if(fRand() < 0.199)
		{
			// 19.9%
			mContents.push_back(new Planet(this, HabitableObject::PLANET_ICE));
		}
		else if(fRand() < 0.2)
		{
			// 20%
			mContents.push_back(new Planet(this, HabitableObject::PLANET_GASGIANT));
		}
		else
		{
			// 60%
			mContents.push_back(new Planet(this, HabitableObject::PLANET_DEAD));
		}

		GameManager::GetSingleton().AddHabitableObject((Planet*)mContents.back());
		GameManager::AddSettletPlanet((Planet*)mContents.back());
	}
	//create the star
	mContents.push_back(new Star(this));
	//
	mGeneratedContents = true;
}
Пример #3
0
void
ReadPixSanityTest::checkIndex(ReadPixSanityResult& r, Window& w) {
	DrawingSurfaceConfig& config = *r.config;
	RandomBits iRand(config.bufSize, 2);

	r.passIndex = true;
	for (int i = 0; i < 100 && r.passIndex; ++i) {
		GLuint expected = iRand.next();
		glClearIndex(expected);
		glClear(GL_COLOR_BUFFER_BIT);

		GLuint buf[READPIX_SANITY_WIN_SIZE][READPIX_SANITY_WIN_SIZE];
		glReadPixels(0, 0, READPIX_SANITY_WIN_SIZE,
			READPIX_SANITY_WIN_SIZE, GL_COLOR_INDEX,
			GL_UNSIGNED_INT, buf);

		for (int y = 0; y < READPIX_SANITY_WIN_SIZE && r.passIndex; ++y)
			for (int x = 0; x < READPIX_SANITY_WIN_SIZE; ++x)
				if (buf[y][x] != expected) {
					r.passIndex = false;
					r.xIndex = x;
					r.yIndex = y;
					r.expectedIndex = expected;
					r.actualIndex = buf[y][x];
					break;
				}

		w.swap();
	}
} // ReadPixSanityTest::checkIndex
Пример #4
0
PlayerSpawn* MapSuite::GetRandomPlayerSpawn()
{
	if(m_LoadedSpawns.size())
	{
		return m_LoadedSpawns[iRand(m_LoadedSpawns.size())];
	}
	return NULL;
}
Пример #5
0
void Background::init(BattleFieldLayout& bfl) {
	Coord w = bfl.width_  * 4;
	Coord h = bfl.height_ * 4;

	for(size_t i = 0; i < 300; i++) {
		Star s;
		s.z_ = 4;
		s.x = fRand(-w,w * 1.5);
		s.y = fRand(-h,h * 1.5);
		s.radius = fRand(1,3);
		s.r = 255 - iRand(0,20);
		s.g = 255 - iRand(0,20);
		s.b = 255 - iRand(0,20);
		s.alpha = fRand(100,255);
		s.step = 0.7;
		s.discontinuity = std::max(1.0, round(s.radius / 8));
		buffers_.push_back(s);
	}

	for(size_t i = 0; i < 600; i++) {
		Star s;
		s.z_ = 8;
		s.x = fRand(-w,w * 1.5);
		s.y = fRand(-h,h * 1.5);
		s.radius = fRand(1,3);
		s.r = 255 - iRand(0,20);
		s.g = 255 - iRand(0,20);
		s.b = 255 - iRand(0,20);
		s.alpha = fRand(100,255);
		s.step = 0.7;
		s.discontinuity = std::max(1.0, round(s.radius / 8));
		buffers_.push_back(s);
	}

	for(size_t i = 0; i < 1200; i++) {
		Star s;
		s.z_ = 12;
		s.x = fRand(-w,w * 1.5);
		s.y = fRand(-h,h * 1.5);
		s.radius = fRand(1,2);
		s.r = 255 - iRand(0,20);
		s.g = 255 - iRand(0,20);
		s.b = 255 - iRand(0,20);
		s.alpha = fRand(100,255);
		s.step = 0.7;
		s.discontinuity = std::max(1.0, round(s.radius / 8));
		buffers_.push_back(s);
	}
}
Пример #6
0
Polyline * Factory::getRandPolyline() {
	Polyline * pl = new Polyline();
	int N = iRand(1, 10);
	for (int i = 0; i < N; i++) {
		Point * p = getRandPoint();
		pl->addPoint(* p);
		delete p;
	}	
	return pl;
}
Пример #7
0
StarSystem::StarSystem(StellarGroup* a_pParent, bool a_IsHomeSystem)
:	DisplayableObject(DisplayableObject::STARSYSTEM, a_pParent)
,	mIsNebula(false)
//,	mAsteroidBelt(*new AsteroidBelt())
{
	m_ImageName = "../media/system.png";
	m_BGImageName = "../media/starsystem_bg.png";
	//
	m_Name = GetRandomName(DisplayableObject::STARSYSTEM);
	if(a_IsHomeSystem)
	{
		//create the starting planet
		mContents.push_back(new Planet(this, HabitableObject::PLANET_TERRAN));
		GameManager::SetHomePlanet((Planet*)mContents.back());
		GameManager::AddSettletPlanet((Planet*)mContents.back());

		//create this system's planets
		GenerateContents();
		ShowContents(false);

		//we're at the center of the entire playable area
		mRelPosition.x = 0.5f;
		mRelPosition.y = 0.5f;
	}
	else
	{
		GenerateContents();

		//5% chance of being a nebula
		mIsNebula = iRand() > 95 ? true : false;
		
		mRelPosition.x = fRand();
		mRelPosition.y = fRand();

		/*
		//calculate a random position for this group in the stellar group
		//calculate random coords with an even distribution across the internal volume of a sphere
		float phi = fRand() * PI;
		float costheta = fRand() * 2 - 1;
		float u = fRand();

		float theta = acos( costheta );
		float R = 1.f;		//distribution radius - just use 0-1 for easy distribution across screen space
		float r = R * curt( u );

		//as we're treating everything as 2D for now, just drop the zPos
		mRelPosition.x = r * sin( theta) * cos( phi );
		mRelPosition.y = r * sin( theta) * sin( phi );
		//mRelPosition.z = r * cos( theta );
		*/
	}
}
Пример #8
0
Shapes* Factory::getRandShape() {
	int k = iRand(1, 6);
	switch (k) {
	case 1:
		return getRandCircle();
	case 2:
		return getRandPoint();
	case 3:
		return getRandPolygon();
	case 4:
		return getRandPolyline();
	case 5:
		return getRandRect();
	case 6:
		return getRandSquare();
	default:
		return NULL;
	}
}
Пример #9
0
	/*!
	\brief Adds a player into the game and creates its slot in the Player Vector.
	
	\param PlayerID This is NOT the player's ID relative to the Player vector, but just a constant to define which player sprite is this one. For example, IT_PLAYER_SUSI (which is 1, as seen in players.h).
	\param x Player's X.
	\param y Player's Y.
	\param Mirror2 Which side is the player facing? you should use IT_PLAYER_FACE_LEFT or _RIGHT as seen in players.h.
	\param Scaling Player's size (in percents). Note: This DOES NOT modify its collision internal bounding box if its defined BEFORE the player's scaling here.
	*/	
	void AddPlayer(int PlayerID, GLfloat x, GLfloat y, bool Mirror2, GLfloat Scaling)
	{
		Player.push_back(PlayerObj());
		
		if(PlayerID == IT_PLAYER_SUSI) {
			Player[Player.size()-1].iterateSheets = true;
			Player[Player.size()-1].setAnimationSpeed(0.0f);			
			Player[Player.size()-1].animationTimer.Start();
			Player[Player.size()-1].Name="Susi";
			Player[Player.size()-1].Load("data/chars/susi_film_1of2.png", 8, 1); 
			Player[Player.size()-1].Load("data/chars/susi_film_2of2.png", 4, 1); 					
		}
		
		Player[Player.size()-1].Move(x,y);
		Player[Player.size()-1].Mirror=Mirror2;
		Player[Player.size()-1].Scale(Scaling);
		Player[Player.size()-1].CanMove=false;
		Player[Player.size()-1].CanJump=false;
		Player[Player.size()-1].Angle=iRand(0,360);
		Player[Player.size()-1].col_x[0]=(64/2)-10;
		Player[Player.size()-1].col_y[0]=8;
		Player[Player.size()-1].col_width[0]=20;
		Player[Player.size()-1].col_height[0]=60-8;
	}