How to start a snake game?

Blitz3D Forums/Blitz3D Beginners Area/How to start a snake game?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

1) what do you mean with swallow ?

2) Basically, you can think at your snake like a collection of type elements.

Start for example with three elements, which represents an head, the body, and the tail.

Each element should have a direction field, and when the snake walks, each element should take the new direction from the next one, while the first one (the head), changes its direction with the player control.

;snake structure example
type t_snake
   field direction ;an integer indicating the direction
   field x ;x pos
   field y ;y pos
end type


In other words, suppose the snake goes up. At this moment, the head, the body and the tail have the same direction.

Now you turn left; the head direction changes, so in the next loop:
- the tail will move towards its direction, and takes the body's position and direction

- the body will move toward its direction, and takes the head's position and direction

- the head will move toward its direction, and takes the new direction from the player

And so on. When you want to make the snake longer, just add a new element to the list, and manage its movement as well.

This is a very rough example, but should put you in the right path; plus, if you try this on paper, drawing some simple square with an arrow which indicates the direction, you will get what I mean..

Sergio.