mapcreator git · master
SDL3 2.5D game and engine using assets, with map editor
C++ 99.3%git clone https://git.christianimmanuel.de/sdl-graphics/mapcreator.gitwget https://git.christianimmanuel.de/sdl-graphics/mapcreator/archive/mapcreator.tar.gzinit
music/bird.sing.wav | Bin 0 -> 526926 bytes music/character.attack.wav | Bin 0 -> 262222 bytes music/character.collect.wav | Bin 0 -> 351310 bytes music/character.cultivate.wav | Bin 0 -> 351310 bytes music/character.hit.wav | Bin 0 -> 196686 bytes music/character.plant.wav | Bin 0 -> 351310 bytes music/character.walk.wav | Bin 0 -> 117326 bytes src/audio/audio.cpp | 93 ++++++++++++++++++++++++++++++++++++++++++ src/audio/audio.hpp | 34 +++++++++++++++ src/music/border.wav | Bin 73806 -> 0 bytes src/music/buuuh.wav | Bin 158182 -> 0 bytes src/music/jubel.wav | Bin 100838 -> 0 bytes src/music/music.cpp | 0 src/music/music.cpp.old | 53 ------------------------ src/music/music.h.old | 18 -------- src/music/music.hpp | 0 src/music/orig_border.wav | Bin 264644 -> 0 bytes src/music/orig_buuuh.wav | Bin 264644 -> 0 bytes src/music/orig_jubel.wav | Bin 264644 -> 0 bytes src/music/orig_ping.wav | Bin 264644 -> 0 bytes src/music/orig_pong.wav | Bin 264644 -> 0 bytes src/music/ping.wav | Bin 149990 -> 0 bytes src/music/pong.wav | Bin 158182 -> 0 bytes 23 files changed, 127 insertions(+), 71 deletions(-) diff --git a/music/bird.sing.wav b/music/bird.sing.wav new file mode 100644 index 0000000..a5402c2 Binary files /dev/null and b/music/bird.sing.wav differ diff --git a/music/character.attack.wav b/music/character.attack.wav new file mode 100644 index 0000000..ca8b16e Binary files /dev/null and b/music/character.attack.wav differ diff --git a/music/character.collect.wav b/music/character.collect.wav new file mode 100644 index 0000000..810cfa7 Binary files /dev/null and b/music/character.collect.wav differ diff --git a/music/character.cultivate.wav b/music/character.cultivate.wav new file mode 100644 index 0000000..f9cdcf8 Binary files /dev/null and b/music/character.cultivate.wav differ diff --git a/music/character.hit.wav b/music/character.hit.wav new file mode 100644 index 0000000..f4f1943 Binary files /dev/null and b/music/character.hit.wav differ diff --git a/music/character.plant.wav b/music/character.plant.wav new file mode 100644 index 0000000..aa91dcc Binary files /dev/null and b/music/character.plant.wav differ diff --git a/music/character.walk.wav b/music/character.walk.wav new file mode 100644 index 0000000..ccbccb8 Binary files /dev/null and b/music/character.walk.wav differ diff --git a/src/audio/audio.cpp b/src/audio/audio.cpp new file mode 100644 index 0000000..4d5bd20 --- /dev/null +++ b/src/audio/audio.cpp @@ -0,0 +1,93 @@ +#include "audio.hpp" +#include <SDL3/SDL.h> +#include <stdio.h> +#include <string.h> + +Audio::Audio() + : mixer(nullptr), sound_count(0) +{ + if (!MIX_Init()) { + printf("MIX_Init failed: %s\n", SDL_GetError()); + return; + } + + mixer = MIX_CreateMixerDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, nullptr); + if (!mixer) { + printf("MIX_CreateMixerDevice failed: %s\n", SDL_GetError()); + MIX_Quit(); + return; + } +} + +void Audio::Quit() { + MIX_Quit(); + mixer=nullptr; +} + +bool Audio::RegisterSound(const char* id, const char* filename) { + if (!mixer || sound_count >= AUDIO_MAX_SOUNDS) { + return false; + } + + if (Find(id)) { + return false; // duplicate ID + } + + AudioSound& s = sounds[sound_count]; + + strncpy(s.id, id, AUDIO_ID_LEN - 1); + s.id[AUDIO_ID_LEN - 1] = '\0'; + + s.audio = MIX_LoadAudio(mixer, filename, false); + if (!s.audio) { + printf("MIX_LoadAudio failed (%s): %s\n", filename, SDL_GetError()); + return false; + } + + s.track = MIX_CreateTrack(mixer); + if (!s.track) { + MIX_DestroyAudio(s.audio); + return false; + } + + MIX_SetTrackAudio(s.track, s.audio); + + sound_count++; + return true; +} + +bool Audio::Play(const char* id, SDL_PropertiesID options) { + AudioSound* s = Find(id); + if (!s) { + return false; + } + + return MIX_PlayTrack(s->track, options); +} + +bool Audio::Stop(const char* id, SDL_PropertiesID options) { + AudioSound* s = Find(id); + if (!s) { + return false; + } + + return MIX_StopTrack(s->track, options); +} + +bool Audio::is_Playing(const char* id) { + AudioSound* s = Find(id); + if (!s) { + return false; + } + + return MIX_TrackPlaying(s->track); +} + +AudioSound* Audio::Find(const char* id) { + for (int i = 0; i < sound_count; ++i) { + if (strcmp(sounds[i].id, id) == 0) { + return &sounds[i]; + } + } + return nullptr; +} diff --git a/src/audio/audio.hpp b/src/audio/audio.hpp new file mode 100644 index 0000000..ef7be75 --- /dev/null +++ b/src/audio/audio.hpp @@ -0,0 +1,34 @@ +#pragma once + +#include <SDL3_mixer/SDL_mixer.h> + +#define AUDIO_MAX_SOUNDS 64 +#define AUDIO_ID_LEN 64 + +struct AudioSound { + char id[AUDIO_ID_LEN]; + MIX_Audio* audio; + MIX_Track* track; +}; + +class Audio { +public: + Audio(); + + bool RegisterSound(const char* id, const char* filename); + bool Play(const char* id, SDL_PropertiesID options = 0); + bool Stop(const char* id, SDL_PropertiesID options = 0); + bool is_Playing(const char* id); + void Quit(); + +private: + MIX_Mixer* mixer; + AudioSound sounds[AUDIO_MAX_SOUNDS]; + int sound_count; + + AudioSound* Find(const char* id); + + Audio(const Audio&) = delete; + Audio& operator=(const Audio&) = delete; +}; + diff --git a/src/music/border.wav b/src/music/border.wav deleted file mode 100644 index 12f52c6..0000000 Binary files a/src/music/border.wav and /dev/null differ diff --git a/src/music/buuuh.wav b/src/music/buuuh.wav deleted file mode 100644 index 53c1538..0000000 Binary files a/src/music/buuuh.wav and /dev/null differ diff --git a/src/music/jubel.wav b/src/music/jubel.wav deleted file mode 100644 index 1d6ce8c..0000000 Binary files a/src/music/jubel.wav and /dev/null differ diff --git a/src/music/music.cpp b/src/music/music.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/music/music.cpp.old b/src/music/music.cpp.old deleted file mode 100644 index b966ab8..0000000 --- a/src/music/music.cpp.old +++ /dev/null @@ -1,53 +0,0 @@ -#include "music.h" - - -MIX_Mixer* init_Music( ) { - if ( !MIX_Init() ) { - printf("MIX_Init failed: %s\n", SDL_GetError()); - return NULL; - } - - MIX_Mixer* mixer = MIX_CreateMixerDevice( SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, NULL ); - if ( !mixer ) { - printf("MIX_CreateMixerDevice failed: %s\n", SDL_GetError()); - MIX_Quit(); - SDL_Quit(); - return NULL; - } - return mixer; -} - -bool set_Music( sound_t* sound, MIX_Mixer* mixer, const char* title ) { - sound->audio = MIX_LoadAudio( mixer, title, false ); - if (!sound->audio) { - printf( "MIX_LoadAudio failed: %s\n", SDL_GetError() ); - MIX_DestroyMixer( mixer ); - MIX_Quit(); - SDL_Quit(); - return false; - } - - sound->track = MIX_CreateTrack( mixer ); - if (!sound->track) { - printf("MIX_CreateTrack failed: %s\n", SDL_GetError()); - MIX_DestroyAudio( sound->audio ); - MIX_DestroyMixer( mixer ); - MIX_Quit(); - SDL_Quit(); - return false; - } - - MIX_SetTrackAudio(sound->track, sound->audio); - - return true; -} - -void free_Sound( sound_t* sound ) { - MIX_DestroyAudio( sound->audio ); - MIX_DestroyTrack( sound->track ); -} - -void delete_Music( MIX_Mixer* mixer ) { - MIX_DestroyMixer( mixer ); - MIX_Quit(); -} diff --git a/src/music/music.h.old b/src/music/music.h.old deleted file mode 100644 index 45793a9..0000000 --- a/src/music/music.h.old +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef MUSIC_H -#define MUSIC_H - -#include <SDL3_mixer/SDL_mixer.h> -#include <stdio.h> - -typedef struct { - MIX_Audio* audio; - MIX_Track* track; -} sound_t; - - -MIX_Mixer* init_Music( ); -bool set_Music( sound_t* sound, MIX_Mixer* mixer, const char* title ); -void free_Sound( sound_t* sound ); -void delete_Music( MIX_Mixer* mixer ); - -#endif diff --git a/src/music/music.hpp b/src/music/music.hpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/music/orig_border.wav b/src/music/orig_border.wav deleted file mode 100644 index b82258b..0000000 Binary files a/src/music/orig_border.wav and /dev/null differ diff --git a/src/music/orig_buuuh.wav b/src/music/orig_buuuh.wav deleted file mode 100644 index fafa4bd..0000000 Binary files a/src/music/orig_buuuh.wav and /dev/null differ diff --git a/src/music/orig_jubel.wav b/src/music/orig_jubel.wav deleted file mode 100644 index 41ca41b..0000000 Binary files a/src/music/orig_jubel.wav and /dev/null differ diff --git a/src/music/orig_ping.wav b/src/music/orig_ping.wav deleted file mode 100644 index dd240bf..0000000 Binary files a/src/music/orig_ping.wav and /dev/null differ diff --git a/src/music/orig_pong.wav b/src/music/orig_pong.wav deleted file mode 100644 index afeae84..0000000 Binary files a/src/music/orig_pong.wav and /dev/null differ diff --git a/src/music/ping.wav b/src/music/ping.wav deleted file mode 100644 index 66a1813..0000000 Binary files a/src/music/ping.wav and /dev/null differ diff --git a/src/music/pong.wav b/src/music/pong.wav deleted file mode 100644 index de30f3a..0000000 Binary files a/src/music/pong.wav and /dev/null differ