Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - ozwurld

Pages: [1]
1
General / Collision Detection Not Working Right
« on: September 25, 2014, 07:22:41 pm »
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"

Code: [Select]
####################
#******************#
#******************#
#******************#
#******************#
#******************#
#******************#
#******************#
#******************# //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

Code: [Select]
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

Code: [Select]
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

Code: [Select]
class Maze
{
public:
    Maze();
    vector<Obstacle> getObstacles() const;

private:
    vector<Obstacle> _obstacles;
    void readObstacleCoordinates();
};

Draw obstacles using sfml rectangular shape
Code: [Select]
    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)

Code: [Select]
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.png

DOES 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!

2
General / Re: Drawing a maze from a text file on sfml 2.1
« on: August 28, 2014, 12:34:25 am »
Thanks for the hint, I really appreciate it everyone.  :)

3
General / Drawing a maze from a text file on sfml 2.1
« on: August 27, 2014, 03:42:19 pm »
Good day all,

I need to draw a really complex maze for a game that im making and would like to find out if it is possible to draw the maze based on a mapping that i have in a .txt file

-Thanks!

4
Window / Re: Implementation of Keyboard.hpp
« on: July 21, 2014, 09:19:49 pm »
~Thanks a million! ;D

5
Window / Implementation of Keyboard.hpp
« on: July 21, 2014, 09:11:44 pm »
Hey all,

Dont know if im posting this in the right place, but im looking for the implementation of the header file
Keyboard.hpp
i reckon it should be
Keyboard.cpp
but cant find such a file anywhere, i just need to know how
isKeyPressed(Key key)
has been implemented.

Thanks!  :)

6
General / Making sense of pong example
« on: June 27, 2014, 04:39:45 pm »
Hello all,

I noticed that on the examples that come with sfml 2.0 , when a key event is been coded for the following line is used:
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Space))
{
}
 

What is the significant of this part, it doesnt look like its doing anything to me since the game still runs if i remove it, so am guessing the must be a reason its there.

(event.type == sf::Event::KeyPressed)
 

Thanks!

Pages: [1]