SFML community forums

Help => General => Topic started by: Helios101 on August 12, 2014, 11:28:53 am

Title: .
Post by: Helios101 on August 12, 2014, 11:28:53 am
.
Title: Re: Giving the snake the bending effect
Post by: eXpl0it3r on August 12, 2014, 11:54:34 am
The genius thing about Snake is, that you don't have to move all the blocks every time. It really doesn't matter whether block 4 remains block 4 or if it will be block 5 later on.

All you essentially need to care about when moving the snake is, removing the tail (last block), moving the head and adding a new element behind the head. All the in-between parts never need to move. ;)

To change direction, you simply move the head in the given direction and add a new block where the head was before, it's very simple. But it's best to use a std::deque so you can work on both ends.
Title: Re: Giving the snake the bending effect
Post by: Nexus on August 13, 2014, 08:34:40 am
Exactly. Every segment except for the first and the last remain the same when you update the snake. Essentially, the update step then becomes:
And you should iterate with iterators and not indices, because it's more generic and faster (http://en.sfml-dev.org/forums/index.php?topic=10084) (for std::deque).