Clion, SFML2 and an old school project

Posted on Apr 10, 2021

This week and for some time I planned to dust off some of my oldest projects that I still think are interesting not only because I spent ungodly amount of time on them but also because they represent relics of a knowledge and hard skills that are still buried deep in my memory.

I think it’s a nice exercise to wander in the past and dig out things that made you who you are today and wonder if you would make things differently today, for better or worse.

The context of the project

This project was completed in may or june 2017 during my first year of University.

At this time I had only about 7 to 9 months of school experience in C++, the main language they used to teach us object oriented programming.

This project represents the culmination of my C++ skills, it lacks any kind of design pattern and was made with little planification.

I say it was the culmination of my skills because in the second year we practiced a lot more Java for object oriented programming.

We were two on the project, my talented friend Lucas Dumartin and myself.

The project is a game in the style of the game lightbot.

The twist was to replace the original shapes of the square platforms to hexagonal platforms. Thus the name of the project without much originality boiled down to Hexalightbot.

We had to make the whole game and a level editor in about three months.

The final project

You can download the project from github here.

We were pretty proud of the results and obtained a 17,5/20 in the end, not bad.

Here is how it looked :

The main menu

Main menu

The little girl you see is derived from an asset by Kenney.

The Game menu

Game menu

We had to design a point system to tell the player if he did good or not. It’s indicated by the number of stars awarded at the end of each level.

The Editor menu

Editor menu

This one is very similar to the game menu except with no stars.

Level One

Editor menu

Here we are in the middle of the subject, from top to bottom we have:

  • a visual of the level in an isometric perspective,
  • the different programs in which the instructions to play will be placed,
  • the different instructions playable at the bottom of the screen, forward, light out an hexagon, both rotations, forward jump and both programs.
  • the start button to launch your instructions (replaced with a stop button while the program is running)
  • back button with an obvious function

It’s the part that I worked the most on, the editor was made by my coworker.

Editor level one

Editor menu

It’s the part that my coworker worked the most on, much less by me.

The editor is in a top down view, much more convenient for edition.

  • The number represents the height of the hexagon.
  • The blue hexagon represents the ones that will we lit up.
  • The little triangle in the center represents the player and its orientation.
  • All the other functionalities are pretty obvious, test, save and delete options.

What I did to make it work

I already tried to run this project multiple times from my current system but I never succeeded. I tried to make my own makefile, compile in different manners with make, qtcreator…

At the time of making the project we used an IDE called QtCreator with ubuntu which was very nice at the time of making the project but nowadays I’m using windows 10 and the newer versions of QtCreator would only make things worse.

I made the decision of using CLion the JetBrains IDE for C++, I always wanted to try it and now was the occasion.

This time I payed extra attention to the compatibility of each elements and the correct installation of the compilers. I also realized I wouldn’t be able to compile my project with make and gcc alone (not with my inexistant skills anyway), I needed something more versatile and powerful, CMake is the tool I needed.

I found a youtube tutorial for a minimal installation that let me compile a project with the latest SFML 2.5.1 library. It needed a bit of tweaking but helped me a lot.

Here’s step by step what I did :

  1. Install MinGW version 7.3 (version 7.5 may work but not above or below, the version is very important to make it compatible with SFML), the official website is down so you’ll have to find a trustworthy mirror, like this one or this one. You should now have gcc, to verify this, open a terminal and type
gcc --version

You should see something like this:

gcc (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

If not, verify that the path to mingw was correctly added to your PATH variable and restart your terminal to apply the changes.

  1. Install Clion, should be easy if you have the Jetbrains Toolbox and a subscription to their services (free for students).

  2. Download SFML 2.5.1 from the official website, it’s recommended to download the 32 bits version to make your programs compatible with a maximum of devices.

  3. create the folders for your project, you should have the following (tree example from my project) :

  • Hexalightbot
    • include
      • all of your .h files
    • libs
      • where you unzip the SFML-2.5.1 and other libraries
    • ressources
      • all of your images, fonts, songs, ressources…
    • src
      • all of your .cpp files
    • .gitignore
    • CMakeLists.txt -> I’ll give you the content of this file
    • main.cpp -> very important that this file is here, it’s your entry point to your app

You can download my project from github here.

CMakeLists.txt

cmake_minimum_required(VERSION 3.14)
set(PROJECT_NAME "HexalightBot")
project(${PROJECT_NAME})

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
set(SFML_STATIC_LIBRARIES TRUE)
set(SFML_DIR "${CMAKE_CURRENT_LIST_DIR}/libs/SFML-2.5.1/lib/cmake/SFML")

file(GLOB_RECURSE SOURCES "src/*.cpp" "include/*.hpp") #glob all the source files into one place
file(COPY libs/SFML-2.5.1/bin/openal32.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ressources DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

set(CMAKE_CXX_STANDARD 17)

link_libraries(stdc++fs) #link the filesystem
file(GLOB_RECURSE SCRF "src/*.cpp" "include/*.hpp")
include_directories("libs/")

add_executable(${PROJECT_NAME} ${SCRF} main.cpp)
find_package(SFML 2.5.1 COMPONENTS system window graphics network audio REQUIRED)
target_link_libraries(${PROJECT_NAME} sfml-audio sfml-graphics sfml-window sfml-system)
  1. Config CLion to compile your project

For this part you’ll have to open your Clion and open the settings through File > settings > Build, Execution, Deployment > Toolchains. There select the mingw folder (typically at the root C:\mingw32) for your compilation environment.

Everything should fill like in the screenshot bellow.

mingw config clion

  1. Compile your project and debug

If I explained everything accurately you should be able to compile your project like bellow.

clion compilation