Exemple #1
0
Section* Section_new(double x, double y, double z,
	double width, double height, double length, int enemies) {
	Section* inst = (Section*) malloc(sizeof(Section));
	int i;
	Vector spawn;
	double spacing;

	inst->pos[0] = x, inst->pos[1] = y, inst->pos[2] = z;
	inst->size[0] = width, inst->size[1] = height, inst->size[2] = length;
	inst->entities = List_new();

	for(i = 0, spacing = 0; i < enemies; ++i) {
		spawn[0] = randomInterval(x, x + width - Enemy_DEF_SIZE[0]);
		spawn[1] = randomInterval(y, y + height - Enemy_DEF_SIZE[1]);
		spawn[2] = randomInterval(z + spacing, z + length);

		List_pushBack(inst->entities, Enemy_new(
			spawn[0], spawn[1], spawn[2], random(),
			random() * 5 + 1, 800));

		spacing += Enemy_DEF_SIZE[2] + length/enemies;
	}

	return inst;
}
Exemple #2
0
void CTrack::genCenterline(b2Vec2 *points)
{
	
	b2Vec2 centerOfTrack = b2Vec2(SCREEN_SIZE_WIDTH / 2.0f, SCREEN_SIZE_HEIGHT / 2.0f);
	// generate first important points 
	// with a low sample rate (given by the downstep)
	int i;
	for (i = 0; i < m_trackSize; i += m_downStep)
	{
		float randomRadius = randomInterval(m_radiusCurvature[0], m_radiusCurvature[1]);
		float randomValue =  randomInterval(m_hardCurvatureProbability[0], m_hardCurvatureProbability[1]);
		float offsetconst = (randomValue >= m_hardCurvatureProbability[2]) ? (float)m_hardCurvatureValue : (float)m_radiusOffsetCurvature;
		float radius	  = offsetconst + randomRadius;

		float alpha = glm::radians(((360.0f / (m_trackSize - 1)) * i));
		// control point
		points[i] = centerOfTrack + radius * b2Vec2(sin(alpha), cos(alpha));

		// fill in the rest of the interval
		const int startIntervalIdx = i - m_downStep;
		if (startIntervalIdx >= 0)
		{
			const int endIntervalIdx = i;
			lerpInterval(startIntervalIdx, endIntervalIdx, points, m_trackSize);
		}
	}
	//Make the end point be the start point
	points[m_trackSize - 1] = points[0];
	//lerp last part if track_size is not a multiple of downstep
	if (i >= m_trackSize)
	{
		lerpInterval(i - m_downStep, m_trackSize - 1, points, m_trackSize);
	}

	//apply a simple smooth filter (moving average 3, centered)
	for (int i = 0; i < m_smoothIterations; i++)
	{
		for (int k = 0; k <  m_trackSize; k++)
		{
			// wrap around index
			int prev_idx = ((k - 1) < 0) ? (m_trackSize - 1) : (k - 1);
			int next_idx = ((k + 1) >= m_trackSize) ? 0: (k + 1);
			
			// moving average
			points[k] = 1/3.f *(points[prev_idx] + points[k] + points[next_idx]);
		}
	}

}