Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Snake Game movement help


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 stein102   Members   -  Reputation: 485

Like
0Likes
Like

Posted 07 April 2013 - 08:06 PM

I'm working on a snake game and I've been stuck on the movement for the last half hour or so and figure it's time to get some assistance on this. I've gone through several possible solutions, but I keep getting the same result. When a new piece to the snake is added, it draws the new block in the correct spot to start with, but when the update method is run, all the snake parts are drawn in the same place. This is my code:

 

LinkedList<WormBlock> wormDataCopy = wormData;
			
			getFirst().setPosition(getFirst().getPosition().add(direction));
			for(int i = 1; i < wormData.size();i++){
				wormData.set(i, wormDataCopy.get(i-1));
			}

 

Any idea what I've done wrong?



Sponsor:

#2 ultramailman   Prime Members   -  Reputation: 1585

Like
1Likes
Like

Posted 07 April 2013 - 08:29 PM

Try removing the tail of the snake, if you are not already doing that in the code.

#3 stein102   Members   -  Reputation: 485

Like
0Likes
Like

Posted 07 April 2013 - 08:57 PM

Removing the tail of the snake? Why would I remove the tail of the snake?



#4 ultramailman   Prime Members   -  Reputation: 1585

Like
3Likes
Like

Posted 07 April 2013 - 09:31 PM

Ah, I meant remove the tail of the snake, and add it do the head. That will create the illusion of movement, wouldn't it?

And just to make sure I am not embarrassing myself, when you say snake game, you mean the one where the snake move around in 4 directions, and eat apple food to grow bigger, yes?


Edited by ultramailman, 07 April 2013 - 09:34 PM.


#5 stein102   Members   -  Reputation: 485

Like
0Likes
Like

Posted 07 April 2013 - 09:43 PM

Yes, that's the game I'm working on. That solution has never occurred to me though, very clever. I was making it much more complicated than I had to, I'll implement that right now.



#6 ultramailman   Prime Members   -  Reputation: 1585

Like
0Likes
Like

Posted 07 April 2013 - 10:09 PM

I hope it works out, because I've never made a snake game before, and therefore I don't know if it works. It was just one of those "light bulb" moments.



#7 stein102   Members   -  Reputation: 485

Like
0Likes
Like

Posted 07 April 2013 - 10:12 PM

It worked perfectly, very easy and simple to implement. A lot less clutter than my other solutions as well.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS