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.


Topics - lack

Pages: [1]
1
General / collision detection
« on: October 16, 2015, 02:21:45 pm »
Hi, when i run my program, the controllable rectangle is always blue although i want it to be red when it collides with tiles with the value 1.

 player.Update();
    for(int i = 0; i < colMap.size(); i++)
{
        for(int j = 0; j < colMap[i].size(); j++)
        {
            if(colMap[i][j] == 1)
            {
            int bottom, top, left, right;
            bottom = i * 40 + 40;
            top = i * 40;
            right = j * 40 + 40;
            left = j * 40;

                if(player.right < left || player.left > right || player.top > bottom || player.bottom < top)
                {
                    player.rect.setFillColor(sf::Color::Blue);
                }
                else
                {
                    player.rect.setFillColor(sf::Color::Red);
                    break;
                }
            }

        }
}

Stuff that might help you further:
(click to show/hide)

(click to show/hide)

(click to show/hide)

(click to show/hide)

thanks

Pages: [1]