Results 1 to 6 of 6

Thread: Snake Help

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    86

    Snake Help

    So I followed NoteMe's BitBlt Snake tutorial, by the way its great and easy to follow. Anyway, I'm trying to do what you suggested at the bottom of that page by adding the head and tail and whatnot. I have the walls, head, tail and where if the snake hits its own body.

    I need help on the part were if the snake is going up, it cant go down. if its going left it cant go right etc. Is there a way to disable keys like if the snake is going up, then the down key is disabled?

    Thanks in advance.

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Are you using my movement method from the tutorial? Then check the facing of the head in an inner If test in the code....


    Algorithm:

    - The user pressed left
    - Check to see if the snake head is facing right

    - If then do nothing
    - If NOT then face left


    Do the same with all directions..


    DId you get it? If not I can make you a code sample...but it's great learning for you, if you figgure it out after reading my Algorithm...

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    86
    Originally posted by NoteMe
    Are you using my movement method from the tutorial? Then check the facing of the head in an inner If test in the code....

    Algorithm:

    - The user pressed left
    - Check to see if the snake head is facing right

    - If then do nothing
    - If NOT then face left

    Do the same with all directions..

    DId you get it? If not I can make you a code sample...but it's great learning for you, if you figgure it out after reading my Algorithm...
    I am using the movement from the tutorial. SO owuld it be something like this:
    VB Code:
    1. if keycode=37 and facing=3 then      'check if left is pressed and facing right
    2.      'do nothin
    3. else if
    4.      Snake(0).facing=1     'goes left
    5. end if

    im just not sure what to do for the "do nothing" part. Or would it be better to use a boolean variable?

  4. #4
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    you could do it something like this:

    VB Code:
    1. If KeyCode = vbKeyLeft And facing <> 3 Then 'check if left is pressed and facing anything but right
    2.         Snake(0).facing = 1   'goes left
    3.     End If
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  5. #5
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Both ways are fine....just do it the way you feel most comfortable with...

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    86
    Thanks alot for the help. I used cyborg's code and worked perfectly. Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width