Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / snake problems

Author
Message
GameMaker Jason
21
Years of Service
User Offline
Joined: 22nd Nov 2003
Location: UK
Posted: 5th Feb 2004 20:43
how can I make my snakes head move and the following segments follow? also how do i make an extra segment be added 8 pixels away from the last segment of the snake?

just code
the_winch
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 5th Feb 2004 22:20 Edited at: 5th Feb 2004 22:21
You can have a vairable with the number of segments in. Then have the head of the sprite as sprite 1 and the next segment no 2 etc.

Then to move the snake all you need to do is start at the highest numbered segment and move it to where the previous segment is until you get to the head sprite. Then just move the head sprite in the direction the snake is moving.

To add segments just have a variable with the number of segments waiting to be added to the snake. Then before you move the snake if there is a segment waiting create a sprite and increase the number of segments and it will be positioned at the end when you move the sprite.

Our civilization faces three great dangers. The first is destruction by a nuclear war, the second is being crippled with overpopulation and the third is the Age of Leisure.
GameMaker Jason
21
Years of Service
User Offline
Joined: 22nd Nov 2003
Location: UK
Posted: 5th Feb 2004 22:31
this might sound stupid or lazy but can you at some psuedo or real code so i can see how it actually knows where to place the next segment and to move then in order of there number?

just code
the_winch
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 5th Feb 2004 23:26


Our civilization faces three great dangers. The first is destruction by a nuclear war, the second is being crippled with overpopulation and the third is the Age of Leisure.
GameMaker Jason
21
Years of Service
User Offline
Joined: 22nd Nov 2003
Location: UK
Posted: 6th Feb 2004 00:00
could you go through the code please becuase i get what bit of it do but i don't get the rest.
like the get image and box commands what are they there for etc.

GameMaker Jason
21
Years of Service
User Offline
Joined: 22nd Nov 2003
Location: UK
Posted: 6th Feb 2004 20:05
i understand the moving head bit and the moving of the segments but dont know how create them at the end? you said to use a variable but how does that variable know to create the sprite a set distance away from the last one?

the_winch
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 6th Feb 2004 21:43 Edited at: 6th Feb 2004 21:51
In my code snippet seg_wait is the variable you need add the number of new segments you want to.

Then before all the segments are moved it checks if seg_wait is greater than 0 and if it is makes a new segment sprite.

You don't actually position the sprite a set difference from the end one, the part of the code that moves the segments does it for you.
The moving code works by starting at the last sprite in the chain and positioning it in the same place and the sprite infront of it. When a new segment is added the moving code positions it where the last segment of the snake is then moves the last segment of the snake to where the previous section is until it reaches the head sprite.

This code snippet adds a new segment when you press the spacebar


Our civilization faces three great dangers. The first is destruction by a nuclear war, the second is being crippled with overpopulation and the third is the Age of Leisure.
Ralen
21
Years of Service
User Offline
Joined: 22nd Jul 2003
Location:
Posted: 7th Feb 2004 02:33
Here is a 3d snake.

Pretty much what you do is Move that head, and put the segment at the end of the tail in place of the old location of the head.

like this:



Ralen
GameMaker Jason
21
Years of Service
User Offline
Joined: 22nd Nov 2003
Location: UK
Posted: 7th Feb 2004 11:18


This is my code i've added the bit that make the snake grow when it eats food but nothing happens. any help?

the_winch
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 7th Feb 2004 17:03
Proberly because the bit of code that adds new segments when seg_wait is greater than 0 has disapeared.
This bit of code should be in the move subroutine.


Our civilization faces three great dangers. The first is destruction by a nuclear war, the second is being crippled with overpopulation and the third is the Age of Leisure.
GameMaker Jason
21
Years of Service
User Offline
Joined: 22nd Nov 2003
Location: UK
Posted: 7th Feb 2004 18:04
sorry but it still does not add a section when i press the spacekey. Any more sudjections?

Login to post a reply

Server time is: 2024-11-26 04:24:17
Your offset time is: 2024-11-26 04:24:17