Building 16 Games in C++ (SFML) Сборка 16 игр на C++ (SFML)
Following the classic tutorial series by FamTrinli. По мотивам классической серии уроков от FamTrinli.
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
- Open the project folder in Sublime Text 4 to edit the code.Откройте папку проекта в Sublime Text 4 для редактирования кода.
- 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
- File > Open File or Project > Select
CMakeLists.txt.Файл > Открыть файл или проект > ВыберитеCMakeLists.txt. - In Projects tab, add the SFML path to CMake configuration:Вкладка Проекты, добавьте путь к SFML в конфигурацию CMake:
-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 (Бесплатно)
- Open CLion and select Open, then choose the project folder.Откройте CLion, нажмите Open и выберите папку проекта.
- Go to Settings > Build, Execution, Deployment > CMake.Перейдите в Settings > Build, Execution, Deployment > CMake.
- 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 в правом верхнем углу.
-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
Direct transfer via phone number Перевод по номеру телефона
Bybit (USDT TRC20)
Support via Cryptocurrency Поддержка криптовалютой