Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Snake game - block positions  (Read 2334 times)

0 Members and 3 Guests are viewing this topic.

Stormboy

  • Newbie
  • *
  • Posts: 10
  • Don't let anything stop you in life. Just move on.
    • View Profile
Snake game - block positions
« on: April 04, 2014, 06:01:16 pm »
Hi,
I'm planning to make a snake game and I've pretty much figured out most of the game except one thing: updating the snake's body blocks' position.

Take this scenario for example:
The snake is moving left. User presses the UP key and now the head block starts moving up. Now how should the body blocks' positions (x & y) be updated?

Thanks. :D

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Snake game - block positions
« Reply #1 on: April 04, 2014, 06:09:22 pm »
The head is the only thing that will move to a new position depending on user input. All body segments simply move to the position of the segment that is in front of them.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Stormboy

  • Newbie
  • *
  • Posts: 10
  • Don't let anything stop you in life. Just move on.
    • View Profile
Re: Snake game - block positions
« Reply #2 on: April 04, 2014, 06:13:04 pm »
The head is the only thing that will move to a new position depending on user input. All body segments simply move to the position of the segment that is in front of them.

Oh never thought of it that way. Thanks again :D

Another question if you don't mind: Which would be the best container for the blocks?

dabbertorres

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • website/blog
Re: Snake game - block positions
« Reply #3 on: April 05, 2014, 05:04:57 am »
Check this out whenever you have to decide what kind of container you need:
http://i.imgur.com/OxUhWfm.png

Stormboy

  • Newbie
  • *
  • Posts: 10
  • Don't let anything stop you in life. Just move on.
    • View Profile
Re: Snake game - block positions
« Reply #4 on: April 05, 2014, 09:45:20 am »
Check this out whenever you have to decide what kind of container you need:
http://i.imgur.com/OxUhWfm.png

Thanks for that :).

didii

  • Full Member
  • ***
  • Posts: 122
    • View Profile
Re: Snake game - block positions
« Reply #5 on: April 06, 2014, 01:08:19 pm »
Also this, if you wan't more detailed information about the different container of STL.