Snake Game
Author |
Message |
evogre3n
|
Posted: 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! |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
lyam_kaskade
![](http://www.linux-squad.com/albumphoto/linuxwallpapers/thumbnails/tn_born2frag.jpg)
|
Posted: Wed Jun 01, 2005 2:59 pm Post subject: (No 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] |
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Wed Jun 01, 2005 3:04 pm Post subject: (No 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. |
|
|
|
|
![](images/spacer.gif) |
evogre3n
|
Posted: Wed Jun 01, 2005 3:16 pm Post subject: (No subject) |
|
|
multple array? lol
i ment multiple array tutorials, as in lots od different array tutorials 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 ![Twisted Evil Twisted Evil](images/smiles/icon_twisted.gif) |
|
|
|
|
![](images/spacer.gif) |
evogre3n
|
Posted: Fri Jun 03, 2005 6:27 am Post subject: (No subject) |
|
|
Anymore help plz? ![Sad Sad](http://compsci.ca/v3/images/smiles/icon_sad.gif) |
|
|
|
|
![](images/spacer.gif) |
evogre3n
|
Posted: Fri Jun 03, 2005 8:15 am Post subject: (No 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 im so lost! |
|
|
|
|
![](images/spacer.gif) |
MysticVegeta
![](http://www.geocities.com/ohsoinsane/my_avatar.JPG)
|
Posted: Fri Jun 03, 2005 3:13 pm Post subject: (No subject) |
|
|
code: | var arr : flexible array 1..1 of type |
If you want to add dimensions
code: | new arr, upper(arr)+1 |
|
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Fri Jun 03, 2005 3:47 pm Post subject: (No subject) |
|
|
evogre3n wrote: I dont even understand how to make flexible array ![Sad Sad](http://compsci.ca/v3/images/smiles/icon_sad.gif) 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. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
MysticVegeta
![](http://www.geocities.com/ohsoinsane/my_avatar.JPG)
|
Posted: Fri Jun 03, 2005 6:38 pm Post subject: (No subject) |
|
|
yeah sry, i am gonna change it, i liked it when you said long and wrong lol they rhyme |
|
|
|
|
![](images/spacer.gif) |
evogre3n
|
Posted: Mon Jun 06, 2005 7:44 pm Post subject: (No 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 Very Happy](http://compsci.ca/v3/images/smiles/icon_biggrin.gif) |
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Mon Jun 06, 2005 8:53 pm Post subject: (No 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. |
|
|
|
|
![](images/spacer.gif) |
evogre3n
|
Posted: Mon Jun 06, 2005 8:56 pm Post subject: (No 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 Embarassed](http://compsci.ca/v3/images/smiles/icon_redface.gif) |
|
|
|
|
![](images/spacer.gif) |
evogre3n
|
Posted: Mon Jun 06, 2005 10:00 pm Post subject: (No 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 Sad](http://compsci.ca/v3/images/smiles/icon_sad.gif) |
|
|
|
|
![](images/spacer.gif) |
|
|