Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Serpent - A simple snake clone  (Read 8107 times)

0 Members and 1 Guest are viewing this topic.

Futochu

  • Newbie
  • *
  • Posts: 7
  • Now with 50% more gelatin
    • View Profile
    • Email
Serpent - A simple snake clone
« 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.





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

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

Also, please bear with the 33/16 time signature music.  I can't seem to fix the music.
« Last Edit: August 20, 2013, 09:59:57 pm by Futochu »

Engineer

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: Serpent - A simple snake clone
« Reply #1 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). :)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Serpent - A simple snake clone
« Reply #2 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 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 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! :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Futochu

  • Newbie
  • *
  • Posts: 7
  • Now with 50% more gelatin
    • View Profile
    • Email
Re: Serpent - A simple snake clone
« Reply #3 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 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 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

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

https://www.dropbox.com/s/ym2kn0b0ijnjtb3/snakehead.png
New snake head texture

Engineer

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: Serpent - A simple snake clone
« Reply #4 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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Serpent - A simple snake clone
« Reply #5 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Engineer

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: Serpent - A simple snake clone
« Reply #6 on: August 21, 2013, 01:56:38 am »
Dunno why but there is no more snake appearing on my screen with the last build.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Serpent - A simple snake clone
« Reply #7 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? :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Futochu

  • Newbie
  • *
  • Posts: 7
  • Now with 50% more gelatin
    • View Profile
    • Email
Re: Serpent - A simple snake clone
« Reply #8 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.)



_________________________________________________________________
NEW UPDATE:

Serpent v1.1 released

Now with:

Score

New executable Serpent v1.0:

New executable Serpent v1.1:

Serpent.exe

New assets:

Green apple (or rotten apple if you wish)

Death chime

Scorefont

Maybe up to date sourcecode:

Link
« Last Edit: August 21, 2013, 08:28:17 am by Futochu »

Dreded

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Serpent - A simple snake clone
« Reply #9 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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Serpent - A simple snake clone
« Reply #10 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. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/