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 / Making a 3D snake game need help with tail creation

Author
Message
Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 9th Dec 2008 23:06
so the problem im having is how to get the tail follow exactly what the "head" does and follow it around
this is the code i've been working with

i cant see why that wouldn't work, so if anyone knows what im doing wrong or even of a better way i can go about doing it then thank you
and im also having a problem with showing the score to the screen if anyone wants to help with that also.
the rest fo the code is just as i want it to be and its a work in progress

I was therefore I can be.
DsarchyUK
16
Years of Service
User Offline
Joined: 21st Nov 2008
Location: UK
Posted: 10th Dec 2008 11:55
I cant compile your code.
"Compilation Failed. Could not determine parameter type of 'Object Count()' at line 39."

Wouldn't it be easier to use an Array. So using 2D as an example. You would have the Xpos and Ypos Coords stored into an array. The snakes head would then be plotted on these Coords. Using these Coords you can then move the Snakes head through them and you would then be able to get the heads previous movements for use with the tail by looking at the Coord Value stored in the previous item of the array.

so for example the snakes head could start at Coords(0,0) which would have the values of Xpos as 0 and Ypos as 0

It would then move to Coords(1,0) with a Xpos of say 10 and Ypos of 0. The tail of the snake would then have to move from its current position to Coords of the Heads previous position, being Coord(0,0) or Xpos 0 and Ypos 0.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 10th Dec 2008 14:09
@Phantom 2590,
It's usually helpful to specify any plug-ins you are using.

@DsarchyUK,
Download the plug-ins pack by following the first link in my signature, then unzip it into your DBPro installation folder.

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 10th Dec 2008 16:03
Follow this link, it is the 2004 Programming Competition. One of the categories was a snake game, and most of the entries include the source code.

Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 10th Dec 2008 21:49 Edited at: 10th Dec 2008 22:52
ohh sry u can actually just delete that line as its not required right now, its not being applied yet
i completely forgot sry
and ill take a look at those entries thankyou

i actually had an idea earlier today of how i might make it work so im going to try that first

Edit:
my idea didnt work im going to start looking through those source codes. in the mean time DsarchyUK can you explain the method using arrays a little better?

I was therefore I can be.
DsarchyUK
16
Years of Service
User Offline
Joined: 21st Nov 2008
Location: UK
Posted: 11th Dec 2008 00:09
Yeah reading back at my post its not very clear.

Here is an example in 2D of what I mean:


This isn't a game, as the snake has nothing to eat and cant die, but it simple and shows you how movement on arrays works.
Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 13th Dec 2008 01:05 Edited at: 13th Dec 2008 01:14
If any one is wondering I figured out how to achieve the tail movement for my game.This is the snippet from my project of the code that makes the tail work.


And if you want to compare it to my who code then here is what I have so far.

There's some obvious bugs I need to iron out. Which I will do in time. There's a lot I want to do with this project. And I hope it all works out.

Thank you DsarchyUK for the array idea and thank you IanM for the great plugin!!! And BatVink thank you for the link to the snake game entries. It helped a lot going through some of those source codes.

P.S. I have Matrix1Utils plugins collection installed so I can use the Object Count() command. If you don't want to install the plug in just delete the line for coloring the spheres. It's not needed to make the program run. But, his plugin is a great addition and has a lot of useful features so I do recommend it. Here's the link for it http://forum.thegamecreators.com/?m=forum_view&t=85209&b=18

I was therefore I can be.
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 13th Dec 2008 01:53
That's weird I never thought of a snake game as the tail doing what the head did, or anything like that. I guess I always thought of them more like draw the snake wherever the player moves, and remove a certain length at the end.

I'll have to look at your code later to see what is going on.

~Zenassem
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 13th Dec 2008 17:49
Thanks for posting your final solution. It certainly beats "I got it now, delete this post"

Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 13th Dec 2008 23:46
@BatVink
haha yeah i hate when i'm looking for a problem and i see those things. I'm like I was so close. SO I decided I should let people know what I did in case anyone else has the same problem.

@zenassem
I honestly don't understand what you mean one bit sorry. Can you explain.

I was therefore I can be.
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 14th Dec 2008 00:17 Edited at: 14th Dec 2008 00:25
I'll try. The way I always viewed a snake type game, is...

rather than the pieces or tail of the snake "following" (which means they must move, and follow the pattern) of the head...

I envision adding on a piece to the head (making a new head), and taking one off the end and the new end becomes the Tail.

This would create the illusion that the tail pieces are following the head, when in fact they aren't moving at all. So you just add a piece to the head (wherever the next position the player is moving to) and you remove that unit of lenght from the end (if the snake isn't growing or shrinking).

Visually.... Let's say this is the snake.
[T] is the tail
[H] is the head
[ ] is the body
[t] is the old tail
[h] is the old head

So we have the snake

Now say the player's move is to move down and the snake is staying the same size. We create a new Head, and we move the pointer of the Tail to the second to last node.

So now that we have the "new" Head, and the "new" Tail, we just delete the old tail and the old head becomes part of the body.


If we keep doing this, it gives the illusion that the body is follwing the head.

~Zenassem
Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 14th Dec 2008 02:25
Is there a reason for doing it that way? Like, is it easier or faster in the long run? Or, is it just another method you could use?

I was therefore I can be.
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 14th Dec 2008 02:33 Edited at: 14th Dec 2008 02:34
I guess it would depend on what the snake actually looks like, and how it moves. If it can be done this way I would think it's easier and faster. I'll have to check though. Can you post a pic of what your snake looks like? (And for any of the comedians around the forum... you know what I mean! So don't go there)

~Zenassem
Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 14th Dec 2008 02:50 Edited at: 14th Dec 2008 02:51
Haha I didn't event think of that until you said it. But why don't you just run my code and see. Just delete lines 36 through 38 if you don't have IanM's plugin. All it is, is just green spheres.

I understand what you mean. If I had an actual model I was using for the snake than your way would work better since I would need a tail and a head model and one body model that could be coppied.

I was therefore I can be.
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 14th Dec 2008 03:25
I'll run it now. I couldn't run it before because I was at work.

~Zenassem
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 14th Dec 2008 03:44
Well since yours are made of spheres, your way will probabaly be better. If you used the method I was talking about, the animation would move one sphere length every iteration (which is kind of what yours does right now), but later on you could make yours smoother.

If you look at my method another way, it's sort of akin to having the playfield like a bunch of lightbulbs stacked into a 3d cube to make the entire playefield. Then you would just be turning on or turning off bulbs. In this way, you keep the snake in a 3d array, and it's very easy to manipulate the snake.

The only other way my method works is if the snake was an extruded shape all along it's body. Like a tube, a cube, etc...

If you are interested in an example i could code one up in about an hour.

~Zenassem
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 14th Dec 2008 04:51 Edited at: 14th Dec 2008 04:55
Heres a real quick example of what I mean. Right now I didn't code the snake nodes, but it does demonstrate how I can "turn on the bulbs" to create animation. I'll go back and make the actual snake movement if your interested.



~Zenassem
Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 14th Dec 2008 16:35 Edited at: 14th Dec 2008 16:49
To be honest I don't understand what you mean with the lightbulb effect to create animation. If you want to code the snake so I can understand than that'ld be nice and I'ld take a look at it. But, you don't have to do it if you don't want of course.

Do you mean like you have a large cube comprised of smaller cubes and to make the snake look like it's moving you simply change the color or some of the smaller cubes?

Can you check the part of the code where it's supposed to hide the snake while the cube is rotating? I don't understand why that isn't working. I'm kinda stuck on that.

Edit:
Figured out what I did wrong for the hiding the snake part. It was a stupid mistake. I just stared at that part of the code for a couple minutes and wen DUH!!!! I was using the wrong variable name. I wasn't using the variable name I created with the For.. Next loop.

I was therefore I can be.
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 14th Dec 2008 16:58
Quote: "
Do you mean like you have a large cube comprised of smaller cubes and to make the snake look like it's moving you simply change the color or some of the smaller cubes?"


Exactly! I will code the rest tonight, just to illustrate the concept.

~Zenassem
Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 14th Dec 2008 17:33 Edited at: 14th Dec 2008 19:35
Alright thank you!

Right now I'm trying to get the show object part to work the way i want. It hides itself right. But, now i want each part of the tail to only show once its in the cube field again. Since its supposed to look like the snake came from another face the tail can't show on the opposite side once its done rotating. So any ideas for that would be helpful. I'll let you know if I figure anything out.

Edit:
Figured it out. Here's what I did. I added the following code to show the object when needed.

I added that to each of the four rotating sub routines editing them as needed for each.

I've added collision checking for the tail and it does what it supposed to for the most part. If I have the check just print out you loose it does that. But, I'm trying to make it go to a function gameover() and clear the screen and print out Sorry You loose then wait and end the program. But it's not printing what I want it to. Please help with that.
Here's what I have so far.


I've tried using both the text command and Print.

Edit2:
Man I should really try things thoroughly first before I start asking on the forum. I figured out the game over problem and printing You loose and such.
I simply made these changes to the gameover() function.

Turns out the sync goes after your print your text...should have known.

Anyways from now on I'm going to try to fix a problem as much as I possibly can before I as for help. It probably gets annoying to others.

On to making the movement smoother...

I was therefore I can be.
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 14th Dec 2008 20:06
I'm also working on a 3D snake clone.

I used a type and a Dim'd array to store the snake segments individual x, y and angle.

To make the movement smoother I used Spooky's Timer based movement thing from the code snippets.

Without Music or Love the world would be a very empty place... Thank god I still have music.. --'-<@
Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 15th Dec 2008 00:49 Edited at: 15th Dec 2008 00:50
I still have to look into types and how they work with arrays. I know what they but I still don't have a full understanding of them. The reason my movement isn't smooth is because the method I used you have to use the same move step as the size of the each individual sphere or or more. So I can't have move object SnakeHead,1 with the sphere being 20 in diameter. If that makes sense

I was therefore I can be.
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 15th Dec 2008 13:57
types are easy



And as for smoothness, my grid (for turning/collision detection) works on multiples of 10. But I use spookys TBM to take smaller steps, depending on how fast the pc is.

I'd post u an example, but I'm not at my Pc atm.

Without Music or Love the world would be a very empty place... Thank god I still have music.. --'-<@
Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 15th Dec 2008 16:55 Edited at: 15th Dec 2008 16:56
Yea after I posted that yesterday I decided to take it upon myself to go learn types. Anything I don't know I try to learn. I even helped someone else yesterday with types after I had learned. But thank you. And if you get a chance to post that example at anytime that would be appreciated.

I was therefore I can be.
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 15th Dec 2008 23:17
Ok, its only rough (It was easier to write it from scratch than to rip the relevent bits out of my game), but I hope it points you in the right direction.



Good luck with it, and don't be afraid to ask if it makes no sense

Without Music or Love the world would be a very empty place... Thank god I still have music.. --'-<@
Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 16th Dec 2008 03:11 Edited at: 16th Dec 2008 03:15
I get an error on line 75 saying variable player doesn't exist.

Edit:
Found the problem you wrote the variable name wrong. Its supposed to be player1 because that's what you declared the array name as.

I was therefore I can be.
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 16th Dec 2008 11:12 Edited at: 16th Dec 2008 11:14
Sorry, I made some changes when I was posting it, and didn't check it.

Hope it helped tho

Without Music or Love the world would be a very empty place... Thank god I still have music.. --'-<@
Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 16th Dec 2008 22:49
I'm gona have to take a closer look at it when I get the chance. I usually only have free time in the weekend. But, I'll def let you know what I get from it. and thankyou

I was therefore I can be.

Login to post a reply

Server time is: 2024-11-24 17:03:52
Your offset time is: 2024-11-24 17:03:52