That sounds good and not too hard! Thanks for the advice!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).
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?