예제 #1
0
Platform* MapGenerator::generatePlatform(Vector2d* startVector)
{
	// 1. get possible set
	// 2. get allowed set
	// 3. modify chance (using buffer & deltaY)
	// 4. select GeneratedBlock
	// 5. add platformblock to platform
	// 6. add used GeneratedBlock to buffer

	Platform* platform = new Platform();

	set<GeneratedBlock> possibleSet = allZeroes;
	set<GeneratedBlock> allowedSet = getAllowedSet(possibleSet, startVector);
	modifyChances(allowedSet, startVector);
	GeneratedBlock* selectedBlock = selectBlock(allowedSet);

	PlatformBlock* block = new PlatformBlock(selectedBlock->type, startVector);
	platform->addPlatformBlock(block);

	Vector2d* newStartVector = block->getEndVector();

	addToBuffer(*selectedBlock);

	int length = (PLATFORM_LENGTH_MIN - 1) + (rand() % (2 + PLATFORM_LENGTH_MAX - PLATFORM_LENGTH_MIN));

	for (int i = 0; i < length; i++) {

		possibleSet = getPossibleSet(selectedBlock);
		allowedSet = getAllowedSet(possibleSet, newStartVector);
		modifyChances(allowedSet, newStartVector);
		selectedBlock = selectBlock(allowedSet);

		*newStartVector+=Vector2d(0.f, selectedBlock->dy);

		block = new PlatformBlock(selectedBlock->type, newStartVector);
		platform->addPlatformBlock(block);

		newStartVector = block->getEndVector();

		addToBuffer(*selectedBlock);
	}

	return platform;
}
예제 #2
0
Platform* MapGenerator::generateFlatPlatform(Vector2d* startVector, int length)
{
	Platform* platform = new Platform();
	for (int i = 0; i < length; i++) {
		PlatformBlock* block = new PlatformBlock(HORIZONTAL, startVector);
		platform->addPlatformBlock(block);
		startVector = block->getEndVector();
	}
	return platform;
}