Open w-A-L-L-e opened 3 years ago
And after some more digging. Also got sounds to work on macOS. Turns out the SDL2 libs on mac with brew doesn't support mp3 (you don't get any compiler or run errors but there's just no sounds). I converted the 3 samples to .wav files and then changed this code. Now the whole game works perfectly including sound:
Mix_Chunk* chargeSfx = Mix_LoadWAV("res/sfx/charge.wav");
Mix_Chunk* swingSfx = Mix_LoadWAV("res/sfx/swing.wav");
Mix_Chunk* holeSfx = Mix_LoadWAV("res/sfx/hole.wav");
Also a proper makefile would help a lot. Keeping with the 'minimalistic build scripts' This is what I used to install depencencies with homebrew:
brew install sdl2
brew install sdl2_ttf
brew install sdl2_mixer
compile_and_run.sh (to compile, place assets into right place and start game):
echo "cleaning up..."
rm -rf bin
rm -f *.o
echo "compiling..."
g++ -c src/*.cpp -std=c++14 -O3 -Wall -m64 -I include && mkdir -p bin/release && g++ *.o -o bin/release/main -lSDL2main -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_mixer
cp -r res bin/release/
echo "starting game..."
./bin/release/main
Future work: write a level generator and add more levels ;) Also maybe different obstacles like ramps that allow increasing/decreasing the velocity (basically positive and negative acceleration) that could even make velocity go negative so a ball runs up and down ramps. Your friction variable is already some kind of negative accel that stops when v=0 I guess ;).
Anyway hope this helps you spread it for macos. For me it was nice to see a completed game with gfx+sound in sdl2 (I dabbled a bit with sdl years ago and then randomly saw your youtube video and then tried to make it run on my macbook ;) ). I do see a lot of things I would have done differently c++ style wise but still it seems to work fine now and I really like how it looks and plays smoothly. So good job!
I've attached the macos binary that I compiled after above patches and it includes the wav files. macos_big_sur_binary.zip
I've opened a PR that makes building easier with a Makefile; I'd be a lot better if you opened a PR with your code changes rather that putting them in an issue.
So I compiled this on macos. And it immediately crashed after clicking to start a game. However after some debugging I found the issue is your getStrokeText and getLevelText functions return a pointer to a std::string that is destructed in the function. A quick hack/fix for this, was to define them as globals so they stay in memory. Then the game works also on my macbook on catelina ;)
Here's the patch:
Another smaller issue was I was always getting a ttf error because the check did not work correctly. This I patched as follows:
Ideally however you could better return a std::string or a smart pointer instead.
Now everything works except the sounds are not playing. But I do see its a nice game. Well done in 2 days ;).