SFML community forums

Help => General => Topic started by: paupav on July 05, 2014, 12:29:00 pm

Title: player speed
Post by: paupav on July 05, 2014, 12:29:00 pm
Ok, I wanna create simple snake game, and I'm stuck.
And I've wanted to ask you how do you create variable that defines player's speed.
E.g I wanna make my snake moves 15 blocks every second. Do you use clock somehow?

This is how I did it before, but that's messy way of doing that:
http://en.sfml-dev.org/forums/index.php?topic=15009.msg105920#msg105920
Title: Re: player speed
Post by: Jesper Juhl on July 05, 2014, 01:10:03 pm
The answer to your question can be found in every basic physics textbook. Speed is distance travelled per unit time.
And yes, you would use a clock to keep track of time passed.

Edit: I recently made a simple example of  a bouncing ball (http://en.sfml-dev.org/forums/index.php?topic=15613.msg111341#msg111341). Take a look - maybe it'll help you :)