Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

soundsystem

My version of snake, download link avail, win32/*nix (SDL).. one bug...

This topic is 5222 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay, I am almost done with this. I have two versions, the one on my computer uses SDL_TTF to write/blit the score, and it doesn't close the game when you lose.. this one does not use SDL_TTF, just removed it so more people can compile it. It's written in C89. the graphics are included, I did not include SDL.dll, there is no binaries, so if you can compile it, then I'm sure you have sdl.dll. Anyway, there is a bug, let's say you are going right, if you press down left really quick, it registers too fast and he ends up moving left and hitting himself.. try it out. You'll see what I mean. Also, please comment on my code, and how I can optimize this. Try: http://24.90.109.143/snake-1.0src.tar.gz or: http://wordbirdturd.tripod.com/snake-1.0src.tar.gz whoops, I left the Makefile in there.. you can use it, just remove '-lSDL_ttf' from $(LDFLAGS). [edited by - soundsystem on June 5, 2004 2:45:12 AM]

Share this post


Link to post
Share on other sites
Advertisement
I haven''t tried it, but regarding the bug with the snake moving back into himself, why not just check when processing the commands that the direction pressed isn''t the opposite of the current direction?

Share this post


Link to post
Share on other sites
This might be better suited to "My Announcements" but I''m going to download it and see if I can compile it.

I''ve never worked with SDL and I don''t know what SDL_TFF is but hopefully I can create a nice executable.

Share this post


Link to post
Share on other sites
SDL_tff is a library for working with text in SDL, by default it doesn''t have anything to write text to the screen (in this version I wrote the score on the window caption bar).

Taharez: I do, if you''re moving up, you can not go down, nothing happens. but the bug is.. when you are moving up.. you can press right and the snake faces right, then you can pess down.. and it will go down. This happens if you press the two keys really quick.

I have this:
case_ SDLK_d:
case SDLK_RIGHT:
if (snakefacing!=DIR_LEFT&&!paused)
snakefacing=DIR_RIGHT;

Share this post


Link to post
Share on other sites
you could make a queue...
make it so that when you press a key, say right, it doesnt change the snake''s direction to right. Instead it adds a CHANGE_SNAKE_DIR_TO_RIGHT thingy to a list of events. Then every frame you take the first item from the list and check if its OK( like not the opposite direction) If it is OK then you move it and continue with game logic. If its not you discard it and get the next event. This way if they are moving up, then press right, then down, you get a queue with a RIGHT action then a DOWN action. The next frame the snake turns right, then the frame after that it turns down. You could make it more challenging by clearing the queue every frame after reading from it, so you can''t stack clicks.

--------------------------------------------------------
Life would be so much easier if we could just get the source code.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!