使用Imgui和SDL2做的一個彈球小游戲-Bounze
油管上面TheCherno博主分享的一個視頻FIRST GAME in C++! Did He Do a Good Job? // Code Review (C++/SDL2)里面分享了一個Github項目:
https://github.com/staticaron/Bounze
使用了Imgui和SDL2,并且可以設置音樂播放,修改音量等,玩家可以得分等,目前游戲支持Windows和Linux。
Bounze
How to Play.
- The ball bounces off the bat randomly in normal mode.
- If boost is active, the ball bounces off according to where it collides with the bat.
- Balancing the ball on bat and destroying the diamonds using the boosted ball gives points.
- Get the highscore.
- I left the debug imgui in the game where you can modify the volumes etc. Press
TAB
to access.
How to build.
Windows + Visual Studio
- Open the folder in visual studio as Cmake Project.
Ctrl + S
on the CMakeLists.txt file to build the project.- Run
bounze.exe
.
NOTE : Copy the /resources
folder in same directory as the .exe
file.
LINUX
- Create a folder
/build
- Enter the folder
cd build
- Run the cmake command
cmake ..
- Make the build file
make
NOTE : Copy the /resources
folder in same directory as the .exe
file.
參考上述https://github.com/staticaron/Bounze的README.md
文件,下載上述項目后,在Window11中使用VS2022打開下載的目錄,以CMake工程打開;
接著打開CMakeLists.txt
,執行Ctrl+S
編譯,生成Makefile等工程文件;最后將代碼根目錄下的resources
資源文件夾拷貝到和bounze.exe
同級目錄,運行bounze.exe
可執行程序
然后鼠標雙擊bounze.exe
可執行程序,
如果不拷貝resources
資源文件夾,直接鼠標雙擊bounze.exe
可執行程序,會報如下的錯誤:
ERROR loading the font at : ./resources/fonts/mightysouly.ttf Couldn't open ./resources/fonts/mightysouly.ttf
加載資源文件報錯,因為找不到資源文件所在目錄。