Sigurdhsson

Completely irrelevant

Snake game

This morning I made a snake game, console based, in C++. I was quite happy with it, and I’m planning on making it SDL instead of console next Wednesday, so I’ll let you see the source then. The problem with snake games usually is moving the tail, but I think I have a pretty neat solution to that problem.

Each snake peice is struct with two ints in it. The snake is also a struct, containing x and y coordinates and a vector of peices. Every step the coordinates change, and when they do the last element in the vector is inserted using vector.insert(vector.begin(), vector[vector.end()]);, and then it is deleted. This way I move the last peice of the snake to the first position, thus making the snake move. Adding a peice is simple. You just push_back() a copy of the last vector member. In the next step this newly added peice will be moved forward, while the old one stays, thus making the snake longer. As I said I will release the source code next week, I hope it makes more sense to you if you get to see it.

This post was written in english, and is categorized as Things I Made.
It was written March 1st, 2007 (20:49 CET) and has no comments.

« “Can you pronounce “element”?” “Vista rejected by U.S. Department of Transportation” »

No comments on this post

Use the comment form to post a comment, or get the trackback URI.

No more discussions!

I realize it might seem a bit fascist, but I have disabled commenting on this post.

About me

Simon Sigurdhsson

Simon Sigurdhsson is a swedish student at Chalmers Tekniska Högskola, aimimng for a master's degree in mathematics.

Email
Sigurdhsson{at}gmail.com
Jabber
Sigurdhsson{at}gmail.com
MSN
Sigurdhsson{at}gmail.com
Facebook
Simon Sigurdhsson
Twitter
urdh
dopplr
urdh
del.icio.us
urdh
last.fm
TinyGuy
flickr
TinyGuy

Search

Asides

  • I just read the best god damn article ever. #
  • Microsoft can't even make bug-free mp3 players. #
  • WordPress admin pages need to stop stealing focus when they reload. It's incredibly annoying. #
  • Check out Logospire - an elegantly crafted logo gallery. #
  • An Event Apart - <3 HTML5. #

del.icio.us

Twitter

  • Twitter is not responding...

last.fm

  1. cd cover
  2. cd cover
  3. cd cover
  4. cd cover
  5. cd cover

flickr