Hello all,
i am at my wits end with this one, i am trying to generate a maze for a battle
city game remake.
I am reading in the following from a text file "map.txt"
####################
#******************#
#******************#
#******************#
#******************#
#******************#
#******************#
#******************#
#******************# //Length and height is 20, square size is 32 therefore 32*20 = screen dimensions(640)
#******************#
#******************#
#******************#
#******************#
#******************#
#******************#
#******************#
#******************#
#******************#
#******************#
####################
This is the code i am using to generate co-ordinates for my maze: A '#' represents a square block
void Maze::readObstacleCoordinates()
{
int x_pos = 0; //Where to begin drawing
int y_pos = 0;
_obstacles.clear(); //init _obstacles vector
std::ifstream input("map.txt");
std::string line;
while(input>>line)
{
for(unsigned int i = 0; i < line.size(); i++)
{
if(line.at(i) == '#')
{
Vector2F Position(x_pos, y_pos);
Obstacle obstacle(Position);
_obstacles.push_back(obstacle); //create a vector of obstacles - which make up a maze
}
x_pos += 32; //squares separated by distance of 32, i.e each square is 32 in size
}
x_pos = 0;
y_pos += 32; //Square dimensions is 32
}
}
Interface of the obstacle class
class Obstacle
{
public:
Obstacle(const Vector2F& obstaclePos);
Vector2F getPosition() const;
int getSize() const;
Vertices getVertices() const;
private:
Vertices _vertices;
Vector2F _obstaclePos;
const int _obstacleSize = 32;
};
Interface of the maze class
class Maze
{
public:
Maze();
vector<Obstacle> getObstacles() const;
private:
vector<Obstacle> _obstacles;
void readObstacleCoordinates();
};
Draw obstacles using sfml rectangular shape
for (unsigned int i = 0; i < _maze.getObstacles().size(); i++)
{
sf::RectangleShape pixel;
pixel.setPosition(_maze.getObstacles().at(i).getPosition().x, _maze.getObstacles().at(i).getPosition().y);
pixel.setTexture(&_wallTexture);
pixel.setSize(sf::Vector2f(32, 32));
_gameWindow.draw(pixel);
}
My problem now arises when i try to do collision detection for all this, SFML draws everything on screen and it looks perfect:
Note A,B,C,D are the vertices of a square, My collision detection ( Horizontal Collision detection)
bool CollisionDetection::hasCollided(Vertices box1,Vertices box2) const
{
if(box1.A.x - box2.B.x == 0 && box1.C.x - box2.D.x == 0)
{
return true;
}
return false;
}
The problem now is that sfml says there is a collision with the path that im supposed to move on, i.e the black spaces
shown on the picture below
http:// = [url]http://i1307.photobucket.com/albums/s582/ozwurld/Maze_zps507a6b9a.pngDOES ANYONE HAVE AN IDEA WHY THIS MAY BE??
-Thanks, sorry for the long question i am just trying to make sure i communicate the problem correctly!