A lot of people use fairly slow techniques in snake games - eg, moving an entire array down one space when the snake moves one square, using linked lists, etc. Personally, I''ve been able to make a snake clone that runs happily on a TI-83 calculator - which runs at a few mHz and uses an interpreting language. For a snake game on the PC, none of this is needed - but would you rather have a snake game which takes 20% or 8% cpu time?
There were two minor and two major speed boosts I used.
The first major one was to start with two lists (1-dimensional arrays) of sufficient size to hold the entire length of the snake once it''s reached full size. (One list was the x coordinates, the second was the y coordinates.) Then there are two variables which hold the snake''s head and tail position. These can be incremented by one, and set back to the beginning if they reach the end of the list. No shifting an entire array down one space - no manipulating and dereferencing pointers in linked lists.
The second major one was a lot simpler, but some friends of mine who attempted to make snake clones failed to do this, so anyway - the map data is stored in an array. 1''s mean you can move there. 0''s mean you can''t. When the snake moves, these values can be changed to simplify detection of the snake running into itself.
The first minor one was improved input processing speed (which took 9/10ths the time of the regular method... woohoo!). The other one was to hold the amounts that the snake''s head moves in the x and y directions, eg left = (-1 ,0). It''s common for people to hold a direction (0..3) and use array indicies/if statements to move the snake''s head.
Great, Beer Hunter!
Thanks I try the two linked list for head and tail. This was realy some pice of info, once I''m done with the ASCII snake of my I go for some graphics, then two players, some levels, music, editor, ..........Somebody stop me!!
---------------------------
MasterBlaster(CodeFighters)
---------------------------
Thanks I try the two linked list for head and tail. This was realy some pice of info, once I''m done with the ASCII snake of my I go for some graphics, then two players, some levels, music, editor, ..........Somebody stop me!!
---------------------------
MasterBlaster(CodeFighters)
---------------------------
---------------------------MasterBlaster(CodeFighters)---------------------------
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement