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

Author Topic: Collision detection doesn't work  (Read 1537 times)

0 Members and 1 Guest are viewing this topic.

reDo

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Collision detection doesn't work
« on: February 04, 2011, 12:16:26 pm »
I am trying to test collision detection from SFML sources but it doesnt work.
When they colliding, it doesnt write the message but it had to.
I edited collision.h, so I move Collision(); from the private to public because it doesnt work before.
Where did I do a mistake please?
Here is my source
Code: [Select]
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include "Collision.h"

int main()
{

    // Create the main rendering window
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Collision Detection Test");

    Collision o;

    sf::String Text;
    Text.SetText("they are colliding");
    Text.SetFont(sf::Font::GetDefaultFont());
    Text.SetPosition(0.f,0.f);


    // Load the sprite image from a file
    sf::Image Image;
    Image.LoadFromFile("A.png");
    sf::Image Image2;
    Image2.LoadFromFile("B.png");

    Image.SetSmooth(false);
    Image2.SetSmooth(false);

    // Create the sprite
    sf::Sprite A(Image);
    sf::Sprite B(Image2);


    // Change its properties

    A.SetPosition(200.f, 100.f);
    B.SetPosition(100.f,200.f);

    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

        // Get elapsed time
        float ElapsedTime = App.GetFrameTime();

        // Move the sprite
        if (App.GetInput().IsKeyDown(sf::Key::Left))  A.Move(-100 * ElapsedTime, 0);
        if (App.GetInput().IsKeyDown(sf::Key::Right)) A.Move( 100 * ElapsedTime, 0);
        if (App.GetInput().IsKeyDown(sf::Key::Up))    A.Move(0, -100 * ElapsedTime);
        if (App.GetInput().IsKeyDown(sf::Key::Down))  A.Move(0,  100 * ElapsedTime);

        // Rotate the sprite
        if (App.GetInput().IsKeyDown(sf::Key::Add))      A.Rotate(- 100 * ElapsedTime);
        if (App.GetInput().IsKeyDown(sf::Key::Subtract)) A.Rotate(+ 100 * ElapsedTime);

        // Clear screen
        App.Clear();

        // Display sprite in our window
        App.Draw(A);
        App.Draw(B);

        if(o.BoundingBoxTest(A,B)==true)
        App.Draw(Text);


        // Display window contents on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}

:roll:

reDo

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Collision detection doesn't work
« Reply #1 on: February 04, 2011, 12:52:11 pm »
Here is full project in zip http://www.megaupload.com/?d=RBTLWNIY  :roll: