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 - Viperz012

Pages: [1]
1
General / Collision
« on: February 13, 2015, 05:07:43 am »
I have a collision map with 0 for no collision and 1 for collision I go through the file find 1 and get its position such as

0 1 0
top = 0
bottom = 32
left = 32
right = 64

    for ( int i = 0; i < mapCollision.size(); i++ )
    {
        for ( int j = 0; j < mapCollision.size(); j++ )
        {
            if ( mapCollision[j] == 1)
            {
                sf::Vector2i findSquarePosition = sf::Vector2i ( 1 * j, 1 * i );
                int topOfTile, bottomOfTile, leftOfTile, rightOfTile;
                topOfTile    = findSquarePosition.y * 32;
                bottomOfTile = findSquarePosition.y * 32 + 32;
                leftOfTile   = findSquarePosition.x * 32;
                rightOfTile  = findSquarePosition.x * 32 + 32;

                int playerTopOfBox, playerBottomOfBox, playerLeftOfBox, playerRightOfBox;
                playerTopOfBox = player.getPosition().y;
                playerBottomOfBox = player.getPosition().y + player.getSize().y;
                playerLeftOfBox = player.getPosition().x;
                playerRightOfBox = player.getPosition().x + player.getSize().x;

                if ( playerRightOfBox < leftOfTile || playerLeftOfBox > rightOfTile || playerTopOfBox > bottomOfTile || playerBottomOfBox < topOfTile )
                {
                }
                else
                {
                    if ( playerTopOfBox < bottomOfTile )
                    {
                        cout << "Collision!" << endl;
                    }
                }

            }
        }
    }

issue I am having is that I hit the block however if I move over to go around it I get blocked also.
I am trying to make a collision detection that knows if I hit the left side of the block or top or bottom or right and pushing away accordingly to that detection.
Say my left side of my player hits the right wall I want to push him right
Say my right side of my player hits the left wall I want to push him left

Can anyone help thank you!

2
SFML projects / fallahn sfml-tmxloader
« on: February 11, 2015, 03:42:00 am »
I was curious if anyone has used this and if so would anyone want to post example of collision control? Even source code from project I could examine we be so helpful!

Pages: [1]
anything