Sound effects
This commit is contained in:
Binary file not shown.
BIN
assets/sounds/hit.wav
Normal file
BIN
assets/sounds/hit.wav
Normal file
Binary file not shown.
BIN
assets/sounds/pickup.wav
Normal file
BIN
assets/sounds/pickup.wav
Normal file
Binary file not shown.
@@ -25,6 +25,14 @@ static constexpr uint8_t BACKGROUND_MUSIC_DATA[] = {
|
|||||||
#embed "../assets/sounds/JamaicanSunrise.wav"
|
#embed "../assets/sounds/JamaicanSunrise.wav"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static constexpr uint8_t PICKUP_SOUND_DATA[] = {
|
||||||
|
#embed "../assets/sounds/pickup.wav"
|
||||||
|
};
|
||||||
|
|
||||||
|
static constexpr uint8_t HIT_SOUND_DATA[] = {
|
||||||
|
#embed "../assets/sounds/hit.wav"
|
||||||
|
};
|
||||||
|
|
||||||
static constexpr uint8_t DEFAULT_FONT_DATA[] = {
|
static constexpr uint8_t DEFAULT_FONT_DATA[] = {
|
||||||
#embed "../assets/fonts/OpenTTD-Sans.ttf"
|
#embed "../assets/fonts/OpenTTD-Sans.ttf"
|
||||||
};
|
};
|
||||||
@@ -96,7 +104,11 @@ AssetModule::AssetModule(flecs::world& world)
|
|||||||
.basket = Texture{.sdl_texture = basket, .texture_atlas_layout = basket_layout}});
|
.basket = Texture{.sdl_texture = basket, .texture_atlas_layout = basket_layout}});
|
||||||
|
|
||||||
auto background_music = load_audio(BACKGROUND_MUSIC_DATA, sizeof(BACKGROUND_MUSIC_DATA));
|
auto background_music = load_audio(BACKGROUND_MUSIC_DATA, sizeof(BACKGROUND_MUSIC_DATA));
|
||||||
world.set<AudioAssets>(AudioAssets{.background_music = background_music});
|
auto pickup_sound = load_audio(PICKUP_SOUND_DATA, sizeof(PICKUP_SOUND_DATA));
|
||||||
|
auto hit_sound = load_audio(HIT_SOUND_DATA, sizeof(HIT_SOUND_DATA));
|
||||||
|
world.set<AudioAssets>(AudioAssets{.background_music = background_music,
|
||||||
|
.pickup_sound = pickup_sound,
|
||||||
|
.hit_sound = hit_sound});
|
||||||
|
|
||||||
auto font = load_font(DEFAULT_FONT_DATA, sizeof(DEFAULT_FONT_DATA));
|
auto font = load_font(DEFAULT_FONT_DATA, sizeof(DEFAULT_FONT_DATA));
|
||||||
world.set<FontAssets>(FontAssets{.default_font = font});
|
world.set<FontAssets>(FontAssets{.default_font = font});
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ struct TextureAssets
|
|||||||
struct AudioAssets
|
struct AudioAssets
|
||||||
{
|
{
|
||||||
AudioAsset background_music;
|
AudioAsset background_music;
|
||||||
|
AudioAsset pickup_sound;
|
||||||
|
AudioAsset hit_sound;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FontAsset
|
struct FontAsset
|
||||||
|
|||||||
@@ -7,9 +7,10 @@ AudioModule::AudioModule(flecs::world& world)
|
|||||||
auto* music_stream = SDL_OpenAudioDeviceStream(
|
auto* music_stream = SDL_OpenAudioDeviceStream(
|
||||||
SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &audio_assets->background_music.spec, NULL, NULL);
|
SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &audio_assets->background_music.spec, NULL, NULL);
|
||||||
auto* sound_stream = SDL_OpenAudioDeviceStream(
|
auto* sound_stream = SDL_OpenAudioDeviceStream(
|
||||||
SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &audio_assets->background_music.spec, NULL, NULL);
|
SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &audio_assets->pickup_sound.spec, NULL, NULL);
|
||||||
|
|
||||||
SDL_ResumeAudioStreamDevice(music_stream);
|
SDL_ResumeAudioStreamDevice(music_stream);
|
||||||
|
SDL_ResumeAudioStreamDevice(sound_stream);
|
||||||
|
|
||||||
world.set<AudioStreams>(
|
world.set<AudioStreams>(
|
||||||
AudioStreams{.music_stream = music_stream, .sound_stream = sound_stream});
|
AudioStreams{.music_stream = music_stream, .sound_stream = sound_stream});
|
||||||
|
|||||||
@@ -122,26 +122,54 @@ struct LevelModule
|
|||||||
// e.destruct();
|
// e.destruct();
|
||||||
// });
|
// });
|
||||||
|
|
||||||
world.system<Game, Position, Fruit, Collided>("CollectFruit")
|
world.system<Game, AudioStreams, AudioAssets, Position, Fruit, Collided>("CollectFruit")
|
||||||
.term_at(0)
|
.term_at(0)
|
||||||
.singleton()
|
.singleton()
|
||||||
|
.term_at(1)
|
||||||
|
.singleton()
|
||||||
|
.term_at(2)
|
||||||
|
.singleton()
|
||||||
.each(
|
.each(
|
||||||
[](flecs::entity e, Game& game, Position& pos, Fruit, Collided)
|
[](flecs::entity e,
|
||||||
|
Game& game,
|
||||||
|
AudioStreams& audio_streams,
|
||||||
|
AudioAssets& audio_assets,
|
||||||
|
Position& pos,
|
||||||
|
Fruit,
|
||||||
|
Collided)
|
||||||
{
|
{
|
||||||
game.score += 10;
|
game.score += 10;
|
||||||
pos.x += 1000;
|
pos.x += 1000;
|
||||||
// e.destruct();
|
// e.destruct();
|
||||||
|
|
||||||
|
SDL_PutAudioStreamData(audio_streams.sound_stream,
|
||||||
|
audio_assets.pickup_sound.buffer,
|
||||||
|
audio_assets.pickup_sound.buffer_length);
|
||||||
});
|
});
|
||||||
|
|
||||||
world.system<Game, Position, Spider, Collided>("CollectSpider")
|
world.system<Game, AudioStreams, AudioAssets, Position, Spider, Collided>("CollectSpider")
|
||||||
.term_at(0)
|
.term_at(0)
|
||||||
.singleton()
|
.singleton()
|
||||||
|
.term_at(1)
|
||||||
|
.singleton()
|
||||||
|
.term_at(2)
|
||||||
|
.singleton()
|
||||||
.each(
|
.each(
|
||||||
[](flecs::entity e, Game& game, Position& pos, Spider, Collided)
|
[](flecs::entity e,
|
||||||
|
Game& game,
|
||||||
|
AudioStreams& audio_streams,
|
||||||
|
AudioAssets& audio_assets,
|
||||||
|
Position& pos,
|
||||||
|
Spider,
|
||||||
|
Collided)
|
||||||
{
|
{
|
||||||
game.score -= 50;
|
game.score -= 50;
|
||||||
pos.x += 1000;
|
pos.x += 1000;
|
||||||
// e.destruct();
|
// e.destruct();
|
||||||
|
|
||||||
|
SDL_PutAudioStreamData(audio_streams.sound_stream,
|
||||||
|
audio_assets.hit_sound.buffer,
|
||||||
|
audio_assets.hit_sound.buffer_length);
|
||||||
});
|
});
|
||||||
|
|
||||||
world.system<ButtonInput const, Position, Size const, Sprite const, Basket>("MoveBasket")
|
world.system<ButtonInput const, Position, Size const, Sprite const, Basket>("MoveBasket")
|
||||||
|
|||||||
Reference in New Issue
Block a user