Building 16 Games in C++ (SFML) Сборка 16 игр на C++ (SFML)

Following the classic tutorial series by FamTrinli. По мотивам классической серии уроков от FamTrinli.

Prerequisite: Ensure you have followed my Environment Setup Guide (MinGW 13.1 & CMake). Предварительное условие: Убедитесь, что вы выполнили инструкции из руководства по настройке среды (MinGW 13.1 и CMake).

1. Project Organization 1. Организация проекта

For each game (e.g., 04 Snake), copy your source files (main.cpp and the images/ folder) into a directory and add the following three scripts: Для каждой игры (например, 04 Snake) скопируйте исходные файлы (main.cpp и папку images/) в директорию и добавьте следующие три скрипта:

CMakeLists.txt
cmake_minimum_required(VERSION 3.20)
project(FamTrinliGames)

add_executable(app main.cpp)

find_package(SFML 2.6 COMPONENTS system window graphics REQUIRED)
target_link_libraries(app sfml-system sfml-window sfml-graphics)

target_compile_features(app PRIVATE cxx_std_20)
target_link_options(app PRIVATE -static)

# Copy images to build folder automatically
add_custom_command(TARGET app POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_directory
    ${CMAKE_SOURCE_DIR}/images $<TARGET_FILE_DIR:app>/images)
Automation ScriptsСкрипты автоматизации

config.bat

cmake -G "MinGW Makefiles" -S . -B dist -DSFML_DIR=E:/libs/sfml-2.6.2-mingw/release/lib/cmake/SFML

build.bat

cmake --build dist

run-exe.bat

dist\app.exe

2. Method A: Sublime Text 4 + CMD 2. Способ А: Sublime Text 4 + CMD

  1. Open the project folder in Sublime Text 4 to edit the code.Откройте папку проекта в Sublime Text 4 для редактирования кода.
  2. Open CMD in the folder and run the scripts in order:Откройте CMD в папке и запустите скрипты по порядку:
config.bat   # Only needs to be run once
build.bat    # Run this every time you change the code
run-exe.bat  # Launch the game

3. Method B: Qt Creator 3. Способ Б: Qt Creator

-DSFML_DIR=E:/libs/sfml-2.6.2-mingw/release/lib/cmake/SFML

Press Ctrl+R to build and run.Нажмите Ctrl+R для сборки и запуска.

4. Method C: CLion (Free Non-Commercial) 4. Способ В: CLion (Бесплатно)

  1. Open CLion and select Open, then choose the project folder.Откройте CLion, нажмите Open и выберите папку проекта.
  2. Go to Settings > Build, Execution, Deployment > CMake.Перейдите в Settings > Build, Execution, Deployment > CMake.
  3. In "CMake options", paste:В поле "CMake options" вставьте:
-DSFML_DIR=E:/libs/sfml-2.6.2-mingw/release/lib/cmake/SFML

Click the Green Play Button at the top right.Нажмите зеленую кнопку Play в правом верхнем углу.

Tip: Since we used -static in the CMake file, you don't need to copy SFML .dll files into your folder! Совет: Так как мы использовали -static в файле CMake, вам не нужно копировать .dll файлы SFML в папку с игрой!

Support My Work Поддержать проект

If these tutorials helped you, consider buying me a coffee! Если эти туториалы вам помогли, вы можете поддержать автора.

Sberbank

Sberbank SBP QR Code

Direct transfer via phone number Перевод по номеру телефона

+7 (917) 212-29-59

Bybit (USDT TRC20)

Bybit USDT TRC20 QR Code

Support via Cryptocurrency Поддержка криптовалютой

TMtY1YifNf6FKvgeFmqKGQR4NStKr3csGp