Computer Science Canada

Snake Game

Author:  evogre3n [ Wed Jun 01, 2005 2:26 pm ]
Post subject:  Snake Game

Well, i know that there have been a lot of posts on this, but as much as I search through the forum and read the multiple array tutorials available, I just dont understand how it works with snake, and how i would go about creating a snake game.

Its for a school assignment, and I would really appreciate it if anyone could help me out, not tell me the answers, but send me in the right direction or w/e.

would be really appreciated if someone could help.
Thanks a lot cheers!

Author:  lyam_kaskade [ Wed Jun 01, 2005 2:59 pm ]
Post subject: 

Ummm...these two made snake games. It might help you.

http://www.compsci.ca/v2/viewtopic.php?t=9050
[url]http://www.compsci.ca/v2/viewtopic.php?t=9035&start=0&postdays=0&postorder=asc&highlight=uncle+worm
[/url]

Author:  Cervantes [ Wed Jun 01, 2005 3:04 pm ]
Post subject: 

Multiple arrays? You mean, multi-dimensional arrays? If so, then yes, you will need those to store the environment that your snake interacts with. Generally, a 0 represents an open space. A 1 would represent a wall.
Your snake should be a flexible array (because he can grow!) of a record that records x and y components.
You'll also need to keep track of the snake's direction. Just use a global variable for that.

I think that should "send [you] in the right direction". On the other hand, you could have already gotten that and are wondering, say, about how to get the segments to follow each other. I don't know, because you haven't specified. If you want help, you're going to have to specify.

Author:  evogre3n [ Wed Jun 01, 2005 3:16 pm ]
Post subject: 

multple array? lol

i ment multiple array tutorials, as in lots od different array tutorials Razz lol


And i know everything you have told me, im just confused on how to use it, perhaps I should think about it some more Razz Twisted Evil

Author:  evogre3n [ Fri Jun 03, 2005 6:27 am ]
Post subject: 

Anymore help plz? Sad

Author:  evogre3n [ Fri Jun 03, 2005 8:15 am ]
Post subject: 

Cervantes wrote:
Multiple arrays? You mean, multi-dimensional arrays? If so, then yes, you will need those to store the environment that your snake interacts with. Generally, a 0 represents an open space. A 1 would represent a wall.
Your snake should be a flexible array (because he can grow!) of a record that records x and y components.
You'll also need to keep track of the snake's direction. Just use a global variable for that.

I think that should "send [you] in the right direction". On the other hand, you could have already gotten that and are wondering, say, about how to get the segments to follow each other. I don't know, because you haven't specified. If you want help, you're going to have to specify.


I dont even understand how to make flexible array Sad im so lost!

Author:  MysticVegeta [ Fri Jun 03, 2005 3:13 pm ]
Post subject: 

code:
var arr : flexible array 1..1 of type


If you want to add dimensions

code:
new arr, upper(arr)+1

Author:  Cervantes [ Fri Jun 03, 2005 3:47 pm ]
Post subject: 

evogre3n wrote:
I dont even understand how to make flexible array Sad im so lost!


You're in luck!

And Mystic, that does not add dimensions. That adds elements. 8)
Lastly, can you please tone down your sig? It's rather long.

Author:  MysticVegeta [ Fri Jun 03, 2005 6:38 pm ]
Post subject: 

yeah sry, i am gonna change it, i liked it when you said long and wrong lol they rhyme

Author:  evogre3n [ Mon Jun 06, 2005 7:44 pm ]
Post subject: 

Okay im making some progress with this game.

I finally understand this whole flexible array thing, and i got the outside collision detection, but the self collision is what I cant figure out.

code:
exit when whatdotcolour (snake (1).x, snake (1).y) = red


Ive looked at the Worm game posted in 1st reply, and it seems to work there, but its not working for me, and I even tried to duplicate that set of code, and it still doesnt seem to work, any help is appreciated Very Happy

Author:  Cervantes [ Mon Jun 06, 2005 8:53 pm ]
Post subject: 

For snake, you shouldn't be using whatdotcolour. It just complicates everything. Snake works on a grid system, so, you don't need to worry about checking ranges of values. It's just a single point comparison. Do you know how to use 2D arrays? (check the Tutorial section, if not!) I recommend you use one of those for your map, and fill it with integers (or strings, w/e) that represent different things. ie. 0 = empty, 1 = wall, 2 = apple. Then just take the x and y position of the snakes head, plop that into your grid array (like this:
code:
if grid (snake (1).x, snake (1).y) = "2" then  %you ate an apple!

) and voila, you've got your collision detection.

Author:  evogre3n [ Mon Jun 06, 2005 8:56 pm ]
Post subject: 

ive read through this tutorial several times, and I am just not understanding it one bit.

If you could, walk me through it, or something, I really am lost Embarassed

Author:  evogre3n [ Mon Jun 06, 2005 10:00 pm ]
Post subject: 

SOrry for the double post.

This is really starting to bug me. My teacher says i cant switch games and this assignment is due friday and worth 25% of my mark, and its just killing me that I cant even begin this, its really agravating.

If someone experienced could please help, i basically am a total noob at this. What we learned in tech this year was not enough for me to gain the ability to code this game, and i am just really lost.

anyone, plz help. thanks alot Sad


: