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

Pages: 1 [2]
16
General / How to use "Simple Collision Detection?"
« on: April 30, 2011, 12:37:48 pm »
Quote from: "Dimple"
Quote from: "Girby2K11"

For some reason i can't see my character and ball. Actually i can see the objects now but the program quickly starts then ends when i add if(Collision::BoundingBoxTest(Object1, Object2))
         return EXIT_FAILURE;

Are the objects on top of each other in the beginning? I added that part only to test if the detection worked. It causes the program to exit if the sprites are on top of each other.


No, i just deleted if(Collision::BoundingBoxTest(Object1, Object2))
         return EXIT_FAILURE; and when i compiled the objects were not touching.

17
General / How to use "Simple Collision Detection?"
« on: April 30, 2011, 12:15:00 pm »
Quote from: "Dimple"
This works for me:
Code: [Select]

#include <SFML/Graphics.hpp>
#include "Collision.h"

int main()
{

     sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Failing");

     sf::Image iCharacter;
     if (!iCharacter.LoadFromFile("character.png"))
     return EXIT_FAILURE;
     sf::Sprite Object1(iCharacter);

     Object1.SetPosition(100.f,100.f);

     sf::Image iBall;
     if (!iBall.LoadFromFile("Ball.png"))
     return EXIT_FAILURE;

     sf::Sprite Object2(iBall);

     Object2.SetPosition(300.f,300.f);

     while (App.IsOpened())
     {
         sf::Event Event;

         while (App.GetEvent(Event))
         {
             if (Event.Type == sf::Event::Closed)
             App.Close();

             if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
             App.Close();
         }


         float ElapsedTime = App.GetFrameTime();

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

         if(Collision::BoundingBoxTest(Object1, Object2)) {

             return EXIT_SUCCESS;
         }

         App.Clear(sf::Color::Red);
         App.Draw(Object2);

         App.Draw(Object1);
        App.Display();
     }


    return EXIT_SUCCESS;
}

Copy and paste the exact error messages.


For some reason i can't see my character and ball. Actually i can see the objects now but the program quickly starts then ends when i add if(Collision::BoundingBoxTest(Object1, Object2))
         return EXIT_FAILURE;

18
General / How to use "Simple Collision Detection?"
« on: April 30, 2011, 01:26:44 am »
Hi, i am am so new to sfml, i can make my sprites move but i now need collision detection but i can't figure out how to use it. heres the code in my project, but i get a bunch of errors which is very frustrating.

Code: [Select]
#include <SFML\Graphics.hpp>
#include <Collision.h>

int main()
{

     sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Failing");

     sf::Image iCharacter;
     if (!iCharacter.LoadFromFile("character.png"))
     return EXIT_FAILURE;
     sf::Sprite Object1(iCharacter);

     sf::Image iBall;
     if (!iBall.LoadFromFile("Ball.png"))
     return EXIT_FAILURE;

     sf::Sprite Object2(iBall);


     while (App.IsOpened())
     {
         sf::Event Event;

         while (App.GetEvent(Event))
         {
             if (Event.Type == sf::Event::Closed)
             App.Close();

             if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
             App.Close();
         }


         float ElapsedTime = App.GetFrameTime();

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

         Collision::BoundingBoxTest(Object1, Object2);

         App.Clear(sf::Color::Red);
         App.Draw(Object2);

         App.Draw(Object1);
        App.Display();
     }


    return EXIT_SUCCESS;
}


I have added collision.cpp to my project, but still get errors saying "Expected primary expression before &.

Please can someone help /  :?

19
General / I need help with this game i am trying to make.
« on: April 26, 2011, 05:48:59 pm »
Quote from: "Dimple"
Yes, if you downloaded the full SDK or the SFML 2.0 snapshot.


I have just been looking at the code and i don't think i will be able to know all of that stuff. I only wanted simple collision detection for boxes.

20
General / I need help with this game i am trying to make.
« on: April 26, 2011, 05:01:29 pm »
Quote from: "Dimple"
Then I would advice you to take a really good look at the Pong example that comes with the library and ask here if there's something that you don't understand. It has pretty much everything you need for basic physics (at least for a start).


Where can  find this Pong example it comes with the sfml download?

21
General / I need help with this game i am trying to make.
« on: April 25, 2011, 09:18:26 pm »
Quote from: "Dimple"
Quote from: "Girby2K11"
Thanks for your help I'm going to try it. Also do you know collision detection?

Yes, I know something about collision detection, too.

First it would be useful to know which collisions you would exactly want to detect and how would you want to react to them. You could start by telling what kind of game you are making. :)

It would also be  useful to know how familiar you are with vectors and trigonometric functions. Vectors can sometimes provide really nice solutions.

In the Pong example the collision with the edges of the screen is very simple: when the ball reaches the edge of the screen, either the game ends or the ball's direction is negated. For example, this is the code what happens when the ball hits the top:L
Code: [Select]

if (ball.GetPosition().y < 0.f)  // This checks if the ball has reached the top
            {
                ballSound.Play();   // Play the sound
                ballAngle = -ballAngle;   // negate the ball's angle to make it appear as if it bounces off the wall
                ball.SetY(0.1f);  // I'm guessing this is needed to make sure that the ball can't get stuck outside the game area. I tested without it and it appeared to work without it (at least with this setup).
            }


The collision between the paddle and the ball, on the other hand, is a simple box-to-box collision detection. You know the coordinates of the objects and you know their sizes so you can just compare the coordinates taking the sizes into account, and determine whether those objects are on top of each other. In semi-pseudo code it would be lsomething like this (assuming that the images are drawn so that the coordinates are on the upper left corner):
Code: [Select]

If object1.x + object1.width > object2.x And object1.x < object2.x + object2.width And object1.y + object1.height > object2.y And object1.y < object2.y + object2.height Then
    Objects_1_and_2_are_on_top_of_each_other
EndIf

So the detection is basically just comparing x and y coordinates taking the sizes of the objects into account.

I really can't help you more than that before you tell me what you actually want to do. :)


I want to make a pong game and under stand bounding box collisions. I get really confused with things but after awhile I understand them.

22
General / I need help with this game i am trying to make.
« on: April 25, 2011, 04:20:15 pm »
Thanks for your help I'm going to try it. Also do you know collision detection?

23
General / I need help with this game i am trying to make.
« on: April 25, 2011, 12:33:50 am »
Hi guys, i have only recently started SFML C++ C::B and i know how to control things, create windows,views but i am getting really confused. i have no idea when it comes to collision detection and physics.

all i have got is my background a wall and a ball loaded to the center, i don't know how i can make collision detection or make the ball move on the certain angle, Help me please i have read all the simplest collision detection pages and i don't understand it. i will post my code here and can some one tell me what i need to do please i will learn off that code you post me.

Code: [Select]

#include<SFML/Graphics.hpp>

int main()
{

    sf::RenderWindow App(sf::VideoMode(1000, 600, 32), "SFML/Graphics");

    sf::Image bPong;
    if (!bPong.LoadFromFile("bPong.png"))
    return EXIT_FAILURE;

    sf::Sprite sbPong(bPong);

    sf::Image iBall;
    if (!iBall.LoadFromFile("Ball.png"))
    return EXIT_FAILURE;

    sf::Sprite sBall(iBall);

    sf::Image Wall;
    if (!Wall.LoadFromFile("Wall.png"))
    return EXIT_FAILURE;

    sf::Sprite sWall(Wall);

    while (App.IsOpened())
    {
        sf::Event Event;

        while (App.GetEvent(Event))
        {

            if (Event.Type == sf::Event::Closed)
            App.Close();

            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
            App.Close();
        }

        float ElapsedTime = App.GetFrameTime();

        if (App.GetInput().IsKeyDown(sf::Key::Up)) sWall.Move(0, -100 * ElapsedTime);
       
       
        App.Clear();
        App.Draw(sbPong);
        App.Draw(sBall);
        App.Draw(sWall);
        App.Display();
    }



    return EXIT_SUCCESS;
}


i currently can only pull the wall up but i am not finishing until i understand.[/code]

24
General / Error loading sprite.
« on: April 10, 2011, 09:17:53 pm »
Hi, i am new to this forum and currently TRYING to learn SFML.

Anyway when i type in the code for loading a sprite, and then tell teh program where to find the picture sf::Image Image;
if (!Image.LoadFromFile("gun.png")) when i compile and run it says this error failed to load image "gun.png". reason unable to open file? can anyone help me with this. Thanks  :evil:

Pages: 1 [2]