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

Author Topic: SFMLnake - Snake clone  (Read 6894 times)

0 Members and 1 Guest are viewing this topic.

Grenthal

  • Newbie
  • *
  • Posts: 20
    • View Profile
    • Email
SFMLnake - Snake clone
« on: June 24, 2018, 07:09:06 am »
Hello Community members,

As a part of my learning process I’ve created yet another snake clone… their pretty popular around here recently
What makes this project special?. As I’ve created some basic “clones” in the past like Pong, Arkanoid and Tetris but this one as only went all the way to actual final 1.0v :).
Yes, it’s my first fully finished project.

Any thoughts and feedback really appreciated.

Github project:
https://github.com/PawelWorwa/SFMLnake

Windows binaries:
https://github.com/PawelWorwa/SFMLnake/releases/tag/v1.0.0

Linux/Mac binaries:
Well I’m afraid it’s required to compile project using included cmake file.

Controls:
Arrows – movement
m key – turn music on/off

Screenshots from game:
(click to show/hide)

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: SFMLnake - Snake clone
« Reply #1 on: July 01, 2018, 01:16:01 pm »
I took just a quick 30 minute look.

No offense but for what it is it feels a bit too overengineered at 1300 lines, all the structure, separate folders for like 7 pngs and 4 oggs (it's good practice to do it of course but for such a small game it feels like an overkill). Plus the tools you've listed, it feels like you might have spent more on them than on that game?

I also don't get why you've included all the SFML headers in your repo. Does CMake somehow require that?

You also use classes full of static const members instead of more "normal" global consts.

It's a bit strange to put manager classes in Game, because it feels way more like 'Engine' part.

In SoundManager you copy SoundBuffer although you didn't need to and it's kinda heavy since it stores all the samples, and could do it in a single line, since [] does an insertion. Similar thing with Texture in TextureManager.

Style-ish stuff: a bit too little consts in various places like locals, getters, etc. Not using proper constant literals (like .f for float, etc.) in places, the =default could be put in the header in the class body itself.

Making all destructors is kinda unusual and kinda wrong.

There is an std::to_string since C++11 and you use C++11 features elsewhere in your code already, no need for stringstream.

There is no need for '48 means 0' comments, you can put a '0' in place of that 48 there to make the intention clearer. No need to iterate over a string with a char reference, just a normal (const) char would do.

You sometimes use this-> even though it's not needed (and you didn't make it your style to always use it).

Sometimes you use C style cast and sometimes a C++ static_cast.

isHoovered is a misspelling of hovered.
« Last Edit: July 01, 2018, 01:25:49 pm by FRex »
Back to C++ gamedev with SFML in May 2023

Grenthal

  • Newbie
  • *
  • Posts: 20
    • View Profile
    • Email
Re: SFMLnake - Snake clone
« Reply #2 on: July 02, 2018, 10:19:02 pm »
Hello FRex,

No offense taken as I was hoping for some constructive criticism - thank You very much for all the time You've taken for review.

About “overengineering” part… I’m aware of that as main part for this project was to learn couple of new things (cmake basic, trying out new patterns, learning new tools like Travis and SonarCloud). As it was easier for me to learn by doing, this project is somehow result of this process. Yet… it may went a little too far  :(.

Clarifying two things:
Quote
“I also don't get why you've included all the SFML headers in your repo. Does CMake somehow require that?”
It’s artifact from linking project with Sonar/Travis (which I disabled at the end realizing it was a little bit overkill) - it was easier to build project using included dependencies than creating script to download, extract and include library each time. Yet true, it’s unnecessary for source code.

Quote
“There is an std::to_string since C++11 and you use C++11…”
Got some issues with compiler and decided to use a walkaround.

For the rest of comments, point taken  :)

Once again thank You for You’re time.

Best regards
Grenthal

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: SFMLnake - Snake clone
« Reply #3 on: July 02, 2018, 10:39:46 pm »
What compiler issues with std::to_string?
Back to C++ gamedev with SFML in May 2023

Grenthal

  • Newbie
  • *
  • Posts: 20
    • View Profile
    • Email
Re: SFMLnake - Snake clone
« Reply #4 on: July 02, 2018, 11:37:23 pm »
Quote
What compiler issues with std::to_string?
error: 'to_string' is not a member of 'std'

Stopped fighting with it...

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: SFMLnake - Snake clone
« Reply #5 on: July 03, 2018, 02:26:46 pm »
error: 'to_string' is not a member of 'std'

Are you including the string header:
#include <string>
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Grenthal

  • Newbie
  • *
  • Posts: 20
    • View Profile
    • Email
Re: SFMLnake - Snake clone
« Reply #6 on: July 03, 2018, 10:28:14 pm »
Hello Hapax,

Thank You for hint… but I’m afraid it’s not so trivial :)

#include <string>

int main() {
    std::to_string(1);
    return 0;
}

(...)>g++ -std=c++11  main.cpp
main.cpp: In function 'int main()':
main.cpp:4:5: error: 'to_string' is not a member of 'std'
     std::to_string(0);
     ^

gcc version 4.9.2 (tdm-1) (Standard MinGW 32-bit Edition as I'm still using 2.4.2 SFML version)

But it’s not really important for this topic :)
« Last Edit: July 05, 2018, 06:30:14 am by Grenthal »

Grundkurs

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: SFMLnake - Snake clone
« Reply #7 on: August 13, 2018, 11:57:52 pm »
Maybe i misremember, but i think mingw does not support std::to_string for some odd reason.
Have you tried using mingw-w64 instead of mingw?
You can grab a gcc 8.1 compliant version here:
https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/installer/mingw-w64-install.exe/download
« Last Edit: August 13, 2018, 11:59:58 pm by Grundkurs »

Grenthal

  • Newbie
  • *
  • Posts: 20
    • View Profile
    • Email
Re: SFMLnake - Snake clone
« Reply #8 on: August 20, 2018, 11:45:59 am »
Hi Grundkurs,

No, I haven’t tried out mingw-w64 compiler yet - thanks for info :).

As I mentioned before, found out that but some odd reason got issues only with cpp11 std::to_string method, so used workaround without focusing too much on this issue.
But I’ll try out new compiler (if not with this project than with another  :))

 

anything