コード例 #1
0
void CentipedeSegment::updateDirection()
{
	Direction newDirection;
	
	switch (direction)
	{
	case LEFT:
		if ((GLuint)Position.y1 < FIELDSIZE - 1) newDirection = DOWN;
		else newDirection = UP;
		break;

	case RIGHT:
		if ((GLuint)Position.y1 < FIELDSIZE - 1) newDirection = DOWN;
		else newDirection = UP;
		break;

	case DOWN:
		newDirection = getOppositeDirection(oldDirection);
		Position.y1 = (GLfloat)((GLuint)getCenter().y); //Align to y axis
		Position.y2 = Position.y1 + CENTISEGMENT_HEIGHT;
		break;

	case UP:
		newDirection = getOppositeDirection(oldDirection);
		Position.y1 = (GLfloat)((GLuint)getCenter().y); //Align to y axis
		Position.y2 = Position.y1 + CENTISEGMENT_HEIGHT;
		break;

	default:
		break;
	}

	changeDirection(newDirection);
}
コード例 #2
0
CentipedeSegment::CentipedeSegment(Vec position, CentipedeSegment *previous, CentipedeManager *centipedeManager, Direction direction)
{
	Position.x1 = position.x;
	Position.y1 = position.y;
	Position.x2 = Position.x1 + CENTISEGMENT_WIDTH;
	Position.y2 = Position.y1 + CENTISEGMENT_HEIGHT;

	AABB = Position;

	isStatic = GL_FALSE;
	isAlive = GL_TRUE;
	isVisible = GL_TRUE;
	colliders.mushroom = GL_TRUE;
	colliders.centipede = GL_TRUE;
	colliders.player = GL_TRUE;
	colliders.bullet = GL_TRUE;
	ID = 2;

	this->direction = DOWN;
	oldDirection = getOppositeDirection(direction);
	this->previous = previous;
	this->centipedeManager = centipedeManager;

	if (previous == nullptr) type = HEAD;
	else type = BODY;

	updateTexCoord();
}
コード例 #3
0
ファイル: MazeSolver.cpp プロジェクト: DDoS/Maze-Challenge
std::vector<int> MazeSolver::SolveMaze2(std::vector<std::vector<int> > walls) {
	/*
		1. Find a dead end, ignoring the start and end cells
		2. Close all of the cells in the dead end path with walls (4 walls for the closed cells)
		3. Repeat over the entire maze, ignoring the start and end cells
		4. The solution is the only path left
		5. Place solution in path collection
	*/

	int mazeSize = std::sqrt(walls.size());
	int mazeStart = 0;
	int mazeEnd = mazeSize * mazeSize - 1;
	fillDeadEnds(&walls, mazeSize, mazeStart, mazeEnd);	

	std::vector<int> path;
	int current = mazeStart;
	int directionToLast = -1;
	int i = 0;
	while (current != mazeEnd) {
		path.push_back(current);
		int direction = getFreeDirection(walls[current], directionToLast);
		current = getRelative(current, direction, mazeSize);
		directionToLast = getOppositeDirection(direction);
	}
	path.push_back(current);

	return path;
}
コード例 #4
0
ファイル: MazeSolver.cpp プロジェクト: DDoS/Maze-Challenge
void fillDeadEnd(std::vector<std::vector<int> >* walls, int size, int start, int end, int index, int recurLevel = 0, int maxRecurLevel = -1) {
	std::vector<int>* cell = &(*walls)[index];
	if (index != start && index != end && isDeadEnd(*cell)) {
		int free = getFreeDirection(*cell);
		int next = getRelative(index, free, size);
		(*cell)[free] = 1;
		(*walls)[next][getOppositeDirection(free)] = 1;
		if (maxRecurLevel == -1 || recurLevel < maxRecurLevel) {
			fillDeadEnd(walls, size, start, end, next, recurLevel + 1, maxRecurLevel);
		}
	}
}