Page 2 of 2

Re: Collision detection, how is it done? (SFML, if that matters)

Posted: Sun Oct 10, 2010 5:47 am
by myInt
EccentricDuck wrote:To the OP, don't worry about collision detection for now. Play around with moving something around and keeping track of it's position. Try this:
- Make a class called ball with two public fields - "x" and "y". Give them default values of 0 in the constructor.
- Write a function called DisplayPosition() in that class that writes x and y to the console window (probably using "cout"). // I'm assuming you don't know how to draw to the screen yet
- Make a game class with three fields - "finished" (boolean), "input"(Input class from SFML***), and "ball" (Ball class you just wrote). Give finished a default value of false and create objects of Input and Ball in the constructor. // *** go to this link and read about input: http://www.sfml-dev.org/documentation/1 ... 1Input.htm
- In your game class, write a while loop with the parameter being "finished == false". Inside that while loop, write six if statements with the condition being Input.IsKeyDown(// your key code in here //). To the first four, write the key codes for the up, down, left, and right arrows. Inside them, write code that increases or decreases the ball object's x or y values. To the fifth, make it whatever key you want. Inside it's going to call the ball's DisplayPosition() function. To the sixth, do the same but make it something like "x", "q", or "esc". To this one, you're going to make it change the value of finished to true. It'll quit your game by ending the while loop (and taking you to the end of the main() function).

Save, compile, and run. Assuming I didn't forget something (which is very well possible), you should be able to increase or decrease the ball's x or y values with the arrow keys, check them with whatever key you set for that, and quit the game with "x", "q", or "esc". That should give you a good starting point to play around with whatever you want to do next (probably using a rect struct to instead of x and y position coordinates).
That sounds good and not too hard! Thanks for the advice!

I'm trying to code it right now but I have some questions. What is a "field"?

And I assume that "GetInput" is equal to the "Input" you're talking about. I use "GetInput" for inputs. When I tried to write "Input" It didn't work.

And the while loop in the "Game" class. Is that my main loop?

I'm trying to make it display the positions of x and y. It doesn't work. I have to choose: I can make it display them after I've pressed esc, I can make it display them in the console window but with the game window blank, or I can make it display them with the game freezed... I've tried to display them at several different places in the code and those three seems to be my options. Do you know how to make it display with the game running?

Re: Collision detection, how is it done? (SFML, if that matters)

Posted: Sun Oct 10, 2010 7:12 pm
by EccentricDuck
myInt wrote:
EccentricDuck wrote:To the OP, don't worry about collision detection for now. Play around with moving something around and keeping track of it's position. Try this:
- Make a class called ball with two public fields - "x" and "y". Give them default values of 0 in the constructor.
- Write a function called DisplayPosition() in that class that writes x and y to the console window (probably using "cout"). // I'm assuming you don't know how to draw to the screen yet
- Make a game class with three fields - "finished" (boolean), "input"(Input class from SFML***), and "ball" (Ball class you just wrote). Give finished a default value of false and create objects of Input and Ball in the constructor. // *** go to this link and read about input: http://www.sfml-dev.org/documentation/1 ... 1Input.htm
- In your game class, write a while loop with the parameter being "finished == false". Inside that while loop, write six if statements with the condition being Input.IsKeyDown(// your key code in here //). To the first four, write the key codes for the up, down, left, and right arrows. Inside them, write code that increases or decreases the ball object's x or y values. To the fifth, make it whatever key you want. Inside it's going to call the ball's DisplayPosition() function. To the sixth, do the same but make it something like "x", "q", or "esc". To this one, you're going to make it change the value of finished to true. It'll quit your game by ending the while loop (and taking you to the end of the main() function).

Save, compile, and run. Assuming I didn't forget something (which is very well possible), you should be able to increase or decrease the ball's x or y values with the arrow keys, check them with whatever key you set for that, and quit the game with "x", "q", or "esc". That should give you a good starting point to play around with whatever you want to do next (probably using a rect struct to instead of x and y position coordinates).
That sounds good and not too hard! Thanks for the advice!

I'm trying to code it right now but I have some questions. What is a "field"?

And I assume that "GetInput" is equal to the "Input" you're talking about. I use "GetInput" for inputs. When I tried to write "Input" It didn't work.

And the while loop in the "Game" class. Is that my main loop?

I'm trying to make it display the positions of x and y. It doesn't work. I have to choose: I can make it display them after I've pressed esc, I can make it display them in the console window but with the game window blank, or I can make it display them with the game freezed... I've tried to display them at several different places in the code and those three seems to be my options. Do you know how to make it display with the game running?
A field is a variable - I'm used to using the C# and Java terminology (not sure why they use their own terms).

Yeah, if you're using GetInput and it works then I'd use that. I'm not entirely familiar with SFML so a lot of what I suggested in generic stuff that is a way to get a game going in with any library (minor variations in naming aside).

The while loop is a very simple main game loop. If you already have one then what I suggested if perhaps simpler than you need (since mine doesn't limit itself to 30 fps or anything like that - it'll take all the resources it can get while it's running). I was trying to suggest the simplest way for you to get up and running with something interactive.

Regarding displaying the positions of x and y, I did do it in a way as to just get them to print to the console window. I didn't realize that you had a game window up and running. The cout function inherently prints to the console window if I understand correctly (as a note, I print to the console window frequently for debugging purposes). To get text to display in the game window you'll need to render font to the screen. A method I used in C# rendered it in the same way as it did sprites, but I'm not sure what the best way would be to get that to render in SFML.

You could try to get the font to render in the game window - I'm sure there's some SFML documentation on that. You could also try to get a sprite rendered to the screen from what I gave you (though you'd want to use a rectangle most likely for doing that instead of just x and y coordinates).

Re: Collision detection, how is it done? (SFML, if that matters)

Posted: Mon Oct 11, 2010 11:49 am
by myInt
EccentricDuck wrote: A field is a variable - I'm used to using the C# and Java terminology (not sure why they use their own terms).

Yeah, if you're using GetInput and it works then I'd use that. I'm not entirely familiar with SFML so a lot of what I suggested in generic stuff that is a way to get a game going in with any library (minor variations in naming aside).

The while loop is a very simple main game loop. If you already have one then what I suggested if perhaps simpler than you need (since mine doesn't limit itself to 30 fps or anything like that - it'll take all the resources it can get while it's running). I was trying to suggest the simplest way for you to get up and running with something interactive.

Regarding displaying the positions of x and y, I did do it in a way as to just get them to print to the console window. I didn't realize that you had a game window up and running. The cout function inherently prints to the console window if I understand correctly (as a note, I print to the console window frequently for debugging purposes). To get text to display in the game window you'll need to render font to the screen. A method I used in C# rendered it in the same way as it did sprites, but I'm not sure what the best way would be to get that to render in SFML.

You could try to get the font to render in the game window - I'm sure there's some SFML documentation on that. You could also try to get a sprite rendered to the screen from what I gave you (though you'd want to use a rectangle most likely for doing that instead of just x and y coordinates).
Ok, I think I get it now. But do I render the numbers (the positions) as sprites that I have made in Paint or something? Sprites like "1", "2", "3", "4"... "416", "417"... ... Wouldn't that be hundreds of lines of code? Or is there some kind some of "shortcut"? I know that I can make numbers 1-9 and just put them together but that seems way to complicated.

Edit: I see now that you have written of some kind of shortcut (or have I misunderstood something?) and I'm lost again. I don't know what a font is. (I've tried to search for it but I don't really understand what it is)

Re: Collision detection, how is it done? (SFML, if that matters)

Posted: Mon Oct 11, 2010 7:33 pm
by wearymemory
myInt wrote:
EccentricDuck wrote: A field is a variable - I'm used to using the C# and Java terminology (not sure why they use their own terms).

Yeah, if you're using GetInput and it works then I'd use that. I'm not entirely familiar with SFML so a lot of what I suggested in generic stuff that is a way to get a game going in with any library (minor variations in naming aside).

The while loop is a very simple main game loop. If you already have one then what I suggested if perhaps simpler than you need (since mine doesn't limit itself to 30 fps or anything like that - it'll take all the resources it can get while it's running). I was trying to suggest the simplest way for you to get up and running with something interactive.

Regarding displaying the positions of x and y, I did do it in a way as to just get them to print to the console window. I didn't realize that you had a game window up and running. The cout function inherently prints to the console window if I understand correctly (as a note, I print to the console window frequently for debugging purposes). To get text to display in the game window you'll need to render font to the screen. A method I used in C# rendered it in the same way as it did sprites, but I'm not sure what the best way would be to get that to render in SFML.

You could try to get the font to render in the game window - I'm sure there's some SFML documentation on that. You could also try to get a sprite rendered to the screen from what I gave you (though you'd want to use a rectangle most likely for doing that instead of just x and y coordinates).
Ok, I think I get it now. But do I render the numbers (the positions) as sprites that I have made in Paint or something? Sprites like "1", "2", "3", "4"... "416", "417"... ... Wouldn't that be hundreds of lines of code? Or is there some kind some of "shortcut"? I know that I can make numbers 1-9 and just put them together but that seems way to complicated.

Edit: I see now that you have written of some kind of shortcut (or have I misunderstood something?) and I'm lost again. I don't know what a font is. (I've tried to search for it but I don't really understand what it is)
It's apparent that you're having a difficult time understanding some of the fundamental concepts of C++. Perhaps you should start by learning how to program in C++ without GUIs or SFML, or have you already spent a sufficient amount of time doing this? Drawing text to the screen is not complicated, and it does not require that you create your own numbers as sprites. You can, however, make your own in the future if you decide that there are no other fonts that suit your needs, but doing it in the way you've described is questionable. The first example program listed on the SFML Documentation page displays a String on the window. The SFML Docs are minimal, but they are useful nonetheless. Here is the documentation for the sf::String class: http://www.sfml-dev.org/documentation/1 ... String.htm. In order to display the changing coordinates on the window, you will need to repeatedly draw the new coordinates to the screen (by use of the sf::String class).

Re: Collision detection, how is it done? (SFML, if that matters)

Posted: Mon Oct 11, 2010 10:32 pm
by EccentricDuck
myInt wrote:
EccentricDuck wrote: A field is a variable - I'm used to using the C# and Java terminology (not sure why they use their own terms).

Yeah, if you're using GetInput and it works then I'd use that. I'm not entirely familiar with SFML so a lot of what I suggested in generic stuff that is a way to get a game going in with any library (minor variations in naming aside).

The while loop is a very simple main game loop. If you already have one then what I suggested if perhaps simpler than you need (since mine doesn't limit itself to 30 fps or anything like that - it'll take all the resources it can get while it's running). I was trying to suggest the simplest way for you to get up and running with something interactive.

Regarding displaying the positions of x and y, I did do it in a way as to just get them to print to the console window. I didn't realize that you had a game window up and running. The cout function inherently prints to the console window if I understand correctly (as a note, I print to the console window frequently for debugging purposes). To get text to display in the game window you'll need to render font to the screen. A method I used in C# rendered it in the same way as it did sprites, but I'm not sure what the best way would be to get that to render in SFML.

You could try to get the font to render in the game window - I'm sure there's some SFML documentation on that. You could also try to get a sprite rendered to the screen from what I gave you (though you'd want to use a rectangle most likely for doing that instead of just x and y coordinates).
Ok, I think I get it now. But do I render the numbers (the positions) as sprites that I have made in Paint or something? Sprites like "1", "2", "3", "4"... "416", "417"... ... Wouldn't that be hundreds of lines of code? Or is there some kind some of "shortcut"? I know that I can make numbers 1-9 and just put them together but that seems way to complicated.

Edit: I see now that you have written of some kind of shortcut (or have I misunderstood something?) and I'm lost again. I don't know what a font is. (I've tried to search for it but I don't really understand what it is)
Sorry, maybe I shouldn't have mixed those two. I was suggesting that you could work on rendering text to the screen OR rendering sprites. Rendering sprites would be if you want to display a sprite that represents those position coordinates you have. It would be an "entity" that you're drawing to the screen.

For now though, ignore what I said about sprites. You want to work on getting text drawn to the game screen. What you were talking about IS something that can be done (so congrats for having that solution come to your head), but for now there's a much simpler way that you'd probably be better off working on (what wearymemory mentioned).

Re: Collision detection, how is it done? (SFML, if that matters)

Posted: Tue Oct 12, 2010 11:07 am
by myInt
wearymemory wrote: It's apparent that you're having a difficult time understanding some of the fundamental concepts of C++. Perhaps you should start by learning how to program in C++ without GUIs or SFML, or have you already spent a sufficient amount of time doing this? Drawing text to the screen is not complicated, and it does not require that you create your own numbers as sprites. You can, however, make your own in the future if you decide that there are no other fonts that suit your needs, but doing it in the way you've described is questionable. The first example program listed on the SFML Documentation page displays a String on the window. The SFML Docs are minimal, but they are useful nonetheless. Here is the documentation for the sf::String class: http://www.sfml-dev.org/documentation/1 ... String.htm. In order to display the changing coordinates on the window, you will need to repeatedly draw the new coordinates to the screen (by use of the sf::String class).
I don't think that I am having a difficult time understanding the fundamentals of C++. It's just the terminology used (and sometimes the logic) that confuses me. I'm really not some kind of genius and I don't have enough time to make time for hours just to figure out small things that I don't even know are there somewhere. I don't know how I'm supposed to know that there is an SFML class "String" that renders text to the game screen.

The only thing that I know that I have problems with is passing variables and right now I don't seem to need it. [EDIT:] Ok, after a while of thinking (and trying to program) I realize that I have some troubles with the basics of C++. I need to get a book on it, or something. Youtube is not my friend anymore (thanks to "anti-RTFM", though, for doing as much as youtube is capable of).[/EDIT]

I'm in high school right now and I have extremely little time for anything other than school. I want to do something fun with that little time. And fun = cool results.

I know, now I don't only seem like an idiot. I seem like a lazy idiot.

Anyways, thanks for telling me about strings!
EccentricDuck wrote: Sorry, maybe I shouldn't have mixed those two. I was suggesting that you could work on rendering text to the screen OR rendering sprites. Rendering sprites would be if you want to display a sprite that represents those position coordinates you have. It would be an "entity" that you're drawing to the screen.

For now though, ignore what I said about sprites. You want to work on getting text drawn to the game screen. What you were talking about IS something that can be done (so congrats for having that solution come to your head), but for now there's a much simpler way that you'd probably be better off working on (what wearymemory mentioned).
Thanks for your help!

Re: Collision detection, how is it done? (SFML, if that matters)

Posted: Tue Oct 12, 2010 1:27 pm
by short
straight up the best book for c++ you can read it, or use the index and look things up. It was written by the designer/implementer of C++ http://www.amazon.com/Programming-Langu ... 0201889544

Re: Collision detection, how is it done? (SFML, if that matters)

Posted: Tue Oct 12, 2010 8:45 pm
by wearymemory
myInt wrote:I don't think that I am having a difficult time understanding the fundamentals of C++. It's just the terminology used (and sometimes the logic) that confuses me. I'm really not some kind of genius and I don't have enough time to make time for hours just to figure out small things that I don't even know are there somewhere. I don't know how I'm supposed to know that there is an SFML class "String" that renders text to the game screen.
Absolutely don't spend hours on problems with terminology or logic, but perhaps you should set some time aside to familiarizing yourself with programming terminology because, as of you've witnessed, it plays a crucial role in communication. As for logic, this will come easier to you if you devote more time to learning the structure and flow of a program, along with problem solving, which might be easier if you started with simpler problems, unlike collision detection, which may take time to fully comprehend. Furthermore, you should also devote some of your time to learning the API of whichever technology you choose to utilize. Unfortunately, SFML's Docs are, as I've said, rather limited; however, it is crucial that programmers can refer to and use this information because it allows us to program more efficiently. The API isn't very large, so you could technically read through most of the classes listed on this page. You may even be able to find what you need by searching for simple keywords like "text," and you may be able to find what you are looking for (sf::String) within a few tries. If you want to know what the SFML library allows you to draw on the window, you can view the inheritance diagram for the sf::Drawable class. Also, passing variables (formally: arguments) to functions or c'tors (read: constructors) is important, and you do need that understanding and that knowledge because you're doing it frequently, whether you know it or not.

Re: Collision detection, how is it done? (SFML, if that matters)

Posted: Sun Oct 17, 2010 7:58 am
by myInt
short wrote:straight up the best book for c++ you can read it, or use the index and look things up. It was written by the designer/implementer of C++ http://www.amazon.com/Programming-Langu ... 0201889544
Thanks! I'll consider it. Hefty price though... ;)
wearymemory wrote:Absolutely don't spend hours on problems with terminology or logic, but perhaps you should set some time aside to familiarizing yourself with programming terminology because, as of you've witnessed, it plays a crucial role in communication. As for logic, this will come easier to you if you devote more time to learning the structure and flow of a program, along with problem solving, which might be easier if you started with simpler problems, unlike collision detection, which may take time to fully comprehend. Furthermore, you should also devote some of your time to learning the API of whichever technology you choose to utilize. Unfortunately, SFML's Docs are, as I've said, rather limited; however, it is crucial that programmers can refer to and use this information because it allows us to program more efficiently. The API isn't very large, so you could technically read through most of the classes listed on this page. You may even be able to find what you need by searching for simple keywords like "text," and you may be able to find what you are looking for (sf::String) within a few tries. If you want to know what the SFML library allows you to draw on the window, you can view the inheritance diagram for the sf::Drawable class. Also, passing variables (formally: arguments) to functions or c'tors (read: constructors) is important, and you do need that understanding and that knowledge because you're doing it frequently, whether you know it or not.
Thanks for your help!

Re: Collision detection, how is it done? (SFML, if that matters)

Posted: Tue Oct 19, 2010 5:38 am
by short
myInt wrote:
short wrote:straight up the best book for c++ you can read it, or use the index and look things up. It was written by the designer/implementer of C++ http://www.amazon.com/Programming-Langu ... 0201889544
Thanks! I'll consider it. Hefty price though... ;)
89 used from $4.23

Re: Collision detection, how is it done? (SFML, if that matters)

Posted: Tue Oct 19, 2010 5:03 pm
by myInt
short wrote:
myInt wrote:
short wrote:straight up the best book for c++ you can read it, or use the index and look things up. It was written by the designer/implementer of C++ http://www.amazon.com/Programming-Langu ... 0201889544
Thanks! I'll consider it. Hefty price though... ;)
89 used from $4.23
Seems like a good price. I think I'm going to look at the local library first, though.