使用Imgui和SDL2做的一个弹球小游戏-Bounze
使用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
加载资源文件报错,因为找不到资源文件所在目录。