SFML community forums

General => SFML projects => Topic started by: Futochu on August 20, 2013, 06:43:33 pm

Title: Serpent - A simple snake clone
Post by: Futochu on August 20, 2013, 06:43:33 pm
SERPENT:

Though it seems I've been beaten to the punch by another snake cloner, here's my rendition of the game.  It's my first real project in C++ coming in with not much more knowhow than TI-BASIC can provide, but I think that it turned out rather well.  I apologise for any code looking unpolished, or any parts of the overall game feeling sloppy. 

Controls are the usual arrow keys, and the enter/return key will help you leave the "menu".

Unlike others, mine barely has any music, just an annoying 8-bit loop of around 6 seconds.

Unlike others, mine does eat fruit.  Apples in fact.

Unlike others, I do not have an "excellent fail screen".

I hope you enjoy it anyway.

(http://i.imgur.com/QRODvoe.png?1)

(http://i.imgur.com/zZ6PtHN.png)

Download link:
https://www.dropbox.com/sh/wu8vg4a6dtdk8y0/zj9DafPIdg (https://www.dropbox.com/sh/wu8vg4a6dtdk8y0/zj9DafPIdg)

Source code:
https://github.com/Futochu/Serpent (https://github.com/Futochu/Serpent)

Also, please bear with the 33/16 time signature music.  I can't seem to fix the music.
Title: Re: Serpent - A simple snake clone
Post by: Engineer on August 20, 2013, 08:49:26 pm
Haha, I was joking about the features of my game, at least yours prevent the snake from moving in the menu screen and you can restart it without launching the .exe again. :)

I enjoyed your snake through I noticed one minor problem :

- You can go left when your current direction is right, or up if your current direction is down, etc etc but ONLY if the size of the snake is equal to 2. Maybe you need to find some way to prevent the snake from going left if your current direction is right, or move the snake in the left direction nonetheless.

"Also, please bear with the 33/16 time signature music.  I can't seem to fix the music."
I don't see what you are talking about, but just know if you want to add more music it is very easy to do so and manage them with SFML. :)

By the way, even if you say your code is unpolished, your organization looks very nice and is separate in multiple files which is easy to read, which is good for a beginner (you don't want to read my snake made in one file). :)
Title: Re: Serpent - A simple snake clone
Post by: eXpl0it3r on August 20, 2013, 08:54:14 pm
Nice another Snake clone! :)

I really like the graphic style, although the snake could need a different tile for its head. :P

The game machanics need a bit more tweaking, because fast movement is currently not possible, e.g. pressing Up and Left very quickly one after the other, will result in the Snake going Up.
I quickly took a peak at the code, but didn't analyze it that much. What I saw (https://github.com/Futochu/Serpent/blob/master/main.cpp#L97) is wrong; you should not mix the realtime input class sf::Keyboard and mix it with events. Use on or the other, but not both at the same time for one task. See the official tutorial (http://www.sfml-dev.org/tutorials/2.1/window-events.php#the-keypressed-and-keyreleased-events) in how to correctly handle Event inputs, maybe that will already solve the issue, maybe not - we'll see. ;)

Uhm yeah "music"? :P

Anyways good job for your first project! :)
Title: Re: Serpent - A simple snake clone
Post by: Futochu on August 20, 2013, 10:11:35 pm
Nice another Snake clone! :)

I really like the graphic style, although the snake could need a different tile for its head. :P

The game machanics need a bit more tweaking, because fast movement is currently not possible, e.g. pressing Up and Left very quickly one after the other, will result in the Snake going Up.
I quickly took a peak at the code, but didn't analyze it that much. What I saw (https://github.com/Futochu/Serpent/blob/master/main.cpp#L97) is wrong; you should not mix the realtime input class sf::Keyboard and mix it with events. Use on or the other, but not both at the same time for one task. See the official tutorial (http://www.sfml-dev.org/tutorials/2.1/window-events.php#the-keypressed-and-keyreleased-events) in how to correctly handle Event inputs, maybe that will already solve the issue, maybe not - we'll see. ;)

Uhm yeah "music"? :P

Anyways good job for your first project! :)

So basically, instead of

case (sf::Event::KeyPressed):
 if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
  presskey = 1;
 else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
  presskey = 2;
 else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
  presskey = 3;
 else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
  presskey = 4;
 break;

You want

case (sf::Event::KeyPressed):
 if(event.key.code == sf::Keyboard::Up)
  presskey = 1;
 else if(event.key.code == sf::Keyboard::Down)
  presskey = 2;
 else if(event.key.code == sf::Keyboard::Right)
  presskey = 3;
 else if(event.key.code == sf::Keyboard::Left))
  presskey = 4;
 break;

?

Also, what do you mean by "fast movement"?

Anyway, all your critiques have been noted and rectified.

New executable Serpent v0.2:
https://www.dropbox.com/s/va74qwwgluha20w/Serpent.exe (https://www.dropbox.com/s/va74qwwgluha20w/Serpent.exe)

New assets:
https://www.dropbox.com/s/zv6d70r8n4uptod/loop.wav (https://www.dropbox.com/s/zv6d70r8n4uptod/loop.wav)
Replaces old loop.wav

https://www.dropbox.com/s/ym2kn0b0ijnjtb3/snakehead.png (https://www.dropbox.com/s/ym2kn0b0ijnjtb3/snakehead.png)
New snake head texture
Title: Re: Serpent - A simple snake clone
Post by: Engineer on August 20, 2013, 10:41:16 pm
When I launch your .exe I cannot see any snake, maybe a render problem ? But I see the main screen and the background
Title: Re: Serpent - A simple snake clone
Post by: eXpl0it3r on August 21, 2013, 12:10:38 am
So basically, instead of
[old code]
[new code]

Also, what do you mean by "fast movement"?

Anyway, all your critiques have been noted and rectified.
Yay! :D
Works really good now!

"fast movement" is, when you press Up and Left very quickly (only a few ms) one after the other. The issue with the old setup was, that while the key pressing was registered it was possible, that in the mean time (e.g. while processing other events) the player already let the key go, thus never registering the direction change. By using events only, you guarantee that the triggered event will get processed and applied correctly. ;)

I've found one small issue yet again, the apple can spawn underneath the snake. Apples should only be able to spawn on empty grid cells.
Title: Re: Serpent - A simple snake clone
Post by: Engineer on August 21, 2013, 01:56:38 am
Dunno why but there is no more snake appearing on my screen with the last build.
Title: Re: Serpent - A simple snake clone
Post by: eXpl0it3r on August 21, 2013, 02:07:17 am
Dunno why but there is no more snake appearing on my screen with the last build.
I think you already said that... ::)

The given information isn't that helpful though. What's your OS? Is your driver uptodate? What graphics card do you have? Do you have a screenshot of the issue? :)
Title: Re: Serpent - A simple snake clone
Post by: Futochu on August 21, 2013, 03:13:47 am
Make sure you didn't remove any necessary assets!

Alphabetically, your asset folder should look like this:

Apple2.png
eat.wav
loop.wav
MANZANIT.ttf
menuback.jpg
pattern.jpg
snake.png
snakebody.png
snakehead.png

I've found one small issue yet again, the apple can spawn underneath the snake. Apples should only be able to spawn on empty grid cells.

Actually, this is programmed in as an acceptable occurrence due to the additive nature of the gamemap.  It's not a bug, it's a feature!

____________________________________________________________________________

UPDATE:

Serpent v1.0 released I guess.

Now with:

Death sound
Green apples (Ew!)
Red apples don't spawn beneath you (but green ones do.  Suck it, Trebek.)

(http://i.imgur.com/mA1liDB.png)

_________________________________________________________________
NEW UPDATE:

Serpent v1.1 released

Now with:

Score

New executable Serpent v1.0:

New executable Serpent v1.1:

Serpent.exe (https://www.dropbox.com/s/va74qwwgluha20w/Serpent.exe)

New assets:

Green apple (or rotten apple if you wish) (https://www.dropbox.com/s/4n7np8lljsgiy9x/greenapple.gif)

Death chime (https://www.dropbox.com/s/fxxa64ab2h3bw78/beep-3.wav)

Scorefont (https://www.dropbox.com/s/92ryewcg19svs62/Velocette.ttf)

Maybe up to date sourcecode:

Link (https://github.com/Futochu/Serpent)
Title: Re: Serpent - A simple snake clone
Post by: Dreded on September 01, 2013, 01:37:06 am
While I think the base of this game is excellent what the heck is with the poison apples? For me this absolutely ruins the game. also the initial skill level is to high, there is no feeling of I can do better!

As I said though as far as snake clones go the base game is great just needs tweaking :p
Title: Re: Serpent - A simple snake clone
Post by: eXpl0it3r on September 01, 2013, 01:48:05 am
Dude, if you make an update make a new post on your thread! :o

Like the new added rotten apples + the counter. Something to dodge and keep track of the current success rate.
You might want to think about reducing the speed a bit, or let it ramp up from slower to fast. ;)