LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-28-2012, 01:48 AM   #1
Nabeel
Member
 
Registered: Nov 2009
Location: Pakistan
Distribution: Ubuntu
Posts: 294

Rep: Reputation: 17
Making a Snakes(Clone)


Well I'm making a snakes clone. And this is what i've done so far. The language i'm using is python and as you can see i have laid down the basic idea of the game BUT I can't understand the basic logic of making it MOVE like an actual snake. So Please If an one can explain how that is achieved and how to implement it!
 
Old 12-28-2012, 10:39 PM   #2
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
Treat each segment of the snake as its own physics entity (that is, position+velocity you update each tick). Maintain a list of points where the snake turns, and the direction it turned to. When a segment reaches a turn point (equality with some fudge factor because of floating point), change the velocity to what the turn point indicates in the list. When the tail of your snake gets to a turn point, remove that turn point from the list.
 
Old 12-29-2012, 10:48 AM   #3
Nabeel
Member
 
Registered: Nov 2009
Location: Pakistan
Distribution: Ubuntu
Posts: 294

Original Poster
Rep: Reputation: 17
What I understand from your advice, This is how I precieve it.

* each part of the snake is to be drawn as a seperate entity.
* The player will control the direction of the snake's head and its velocity will be passed to the next part with each tick.
* The turn should be applied to each part seperately.

Please provide a suggestion if you find a flaw among the above. I might as well switch to classes to deal with specific parts of the snake.
 
Old 12-29-2012, 01:00 PM   #4
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
I don't know python and this might be a stupid idea, but I would probably implement the snake as a (cyclic) linked list of coordinates. You remember the pointer to the "head" segment, when you move, you replace the "tail" segment with the new position of the head ("head" + "velocity") and set the head pointer to this new segment. If the snake grows, instead of replacing the tail with the new segment, you will insert the new item before the "head" and set the "head" pointer there.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
FVWM: Making an accurate clone of the ALT+TAB function of WIN98/2000/XP frenchn00b Linux - Desktop 1 06-14-2011 01:48 PM
LXer: Snakes on a Couch! Using Python with CouchDB LXer Syndicated Linux News 0 09-24-2010 03:30 PM
making a clone of instillation lemtree Linux - Newbie 2 12-18-2009 03:18 AM
Snakes and Electromagnetic fields rjcrews General 27 12-26-2006 12:36 AM
Interested in making a Microsoft Console clone for Linux HGeneAnthony Linux - Software 5 11-06-2006 05:14 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration