Computer Science Canada I need help with snake game |
Author: | cpu_hacker4.0 [ Wed Oct 17, 2007 5:57 pm ] | ||
Post subject: | I need help with snake game | ||
Ok I am making a snake game for turing and this is what I have so far. Basically, you control one ball with the arrow keys and have to "eat" other circles that get added on to the tail. I'm trying to use collision detection (to "eat" other balls), but it doesn't seem to be working. I put the code that's causing problems in green, just so you can see what I am trying to do. Fiirst run it as is, then remove the /* and */ to see what the problem is. Help would be greatly appreciated.
|
Author: | Saad [ Wed Oct 17, 2007 6:26 pm ] |
Post subject: | RE:I need help with snake game |
The 'or's in if statement should be an "and" and that should be inside the for loop |
Author: | HeavenAgain [ Wed Oct 17, 2007 6:29 pm ] |
Post subject: | RE:I need help with snake game |
yea, forget the equal to, just change the or to and. ![]() |
Author: | cpu_hacker4.0 [ Wed Oct 17, 2007 6:42 pm ] | ||
Post subject: | Re: I need help with snake game | ||
Alright thanks! That seems to have worked...but why is it and? I know now that or doesn't work, but I used or because my ball can either be on the left or right side of the other ball...it can't be on both. Also, I need help with the next part. When I touch the other ball, I want it to act as a tail that follows my ball around, but I don't know how to use it. I know I need to make an array for the x and y values, but I'm not sure how to use it in the program. Thanks for helping! Here is the updated code:
|
Author: | Nick [ Thu Oct 18, 2007 6:56 am ] | ||||
Post subject: | RE:I need help with snake game | ||||
just make the x and y = the old x and y of ur snake and have each attaching part = the old x and y of the precedding part so:
i havent actually tried this nor made a snake game but i did make a trailing string bounce program ill post so u can see how this works
|
Author: | cpu_hacker4.0 [ Thu Oct 18, 2007 10:38 am ] |
Post subject: | Re: I need help with snake game |
Ok thanks...I think I understand how it works, but I'm using a variable for the last number of the array, because it depends on how many times the ball disappears. So I don't really know how to put that in my code...how would I do it?[/quote] |
Author: | HeavenAgain [ Thu Oct 18, 2007 11:40 am ] |
Post subject: | RE:I need help with snake game |
i cant rememebr who it was, but someone made a nice snake game a while back, and it was only a few lines (and it was great) like i said, go and search for it, its in the turing sections somewhere. and it seems like you dont know hwo does the array works? you can have a nice look at the tutorials section, here |
Author: | cpu_hacker4.0 [ Thu Oct 18, 2007 5:55 pm ] |
Post subject: | Re: I need help with snake game |
No I know how to use arrays, just don't know what to do with the code |
Author: | CodeMonkey2000 [ Thu Oct 18, 2007 9:07 pm ] | ||
Post subject: | Re: I need help with snake game | ||
There is a ridiculously easy way to make a snake game. I'm too lazy to explain it so meh. Ther a re a lot of ways you can optimize this though.
|