From e318c65135e3fe166038405de4de7d25decf99fb Mon Sep 17 00:00:00 2001 From: En Yi Date: Tue, 10 Oct 2023 21:57:45 +0800 Subject: [PATCH] Add some more sfx --- scene_test.c | 18 +++++++++++++----- scenes/assets_tag.h | 36 ++++++++++++++++++++++++++++++++++++ scenes/ent_impl.h | 14 +------------- scenes/game_systems.c | 21 ++++++++++++++++++++- 4 files changed, 70 insertions(+), 19 deletions(-) create mode 100644 scenes/assets_tag.h diff --git a/scene_test.c b/scene_test.c index 5e9b9b1..82f6be6 100644 --- a/scene_test.c +++ b/scene_test.c @@ -8,8 +8,8 @@ #include #endif -static SFX_t sfx_buffer[4] = {0}; -static uint32_t sfx_counts[4] = {0}; +static SFX_t sfx_buffer[N_SFX] = {0}; +static uint32_t sfx_counts[N_SFX] = {0}; Scene_t* scenes[1]; static GameEngine_t engine = @@ -20,7 +20,7 @@ static GameEngine_t engine = .assets = {0}, .sfx_list = { .sfx = sfx_buffer, - .n_sfx = 4, + .n_sfx = N_SFX, .sfx_queue = sfx_counts, .played_sfx = 0, } @@ -57,8 +57,16 @@ int main(void) #endif init_item_creation(&engine.assets); - add_sound(&engine.assets, "testsnd", "res/sound.ogg"); - load_sfx(&engine, "testsnd", 0); + add_sound(&engine.assets, "snd_jump", "res/jump.ogg"); + add_sound(&engine.assets, "snd_land", "res/land.ogg"); + add_sound(&engine.assets, "snd_wdrop", "res/water_land.ogg"); + add_sound(&engine.assets, "snd_bland", "res/boulder_move.ogg"); + add_sound(&engine.assets, "snd_bubble", "res/bubble.ogg"); + load_sfx(&engine, "snd_jump", PLAYER_JMP_SFX); + load_sfx(&engine, "snd_land", PLAYER_LAND_SFX); + load_sfx(&engine, "snd_wdrop", WATER_IN_SFX); + load_sfx(&engine, "snd_bland", BOULDER_LAND_SFX); + load_sfx(&engine, "snd_bubble", BUBBLE_SFX); LevelScene_t scene; scene.scene.engine = &engine; diff --git a/scenes/assets_tag.h b/scenes/assets_tag.h new file mode 100644 index 0000000..8560c28 --- /dev/null +++ b/scenes/assets_tag.h @@ -0,0 +1,36 @@ +#ifndef _ASSETS_TAG_H +#define _ASSETS_TAG_H +typedef enum EntityTag { + NO_ENT_TAG = 0, + PLAYER_ENT_TAG, + ENEMY_ENT_TAG, + CRATES_ENT_TAG, + CHEST_ENT_TAG, + BOULDER_ENT_TAG, + LEVEL_END_TAG, + DESTRUCTABLE_ENT_TAG, + DYNMEM_ENT_TAG, +} EntityTag_t; + +#define N_SFX 18 +typedef enum SFXTag { + PLAYER_JMP_SFX = 0, + PLAYER_LAND_SFX, + PLAYER_RUN_SFX, + PLAYER_LADDER_SFX, + PLAYER_WATER_RUN_SFX, + WATER_IN_SFX, + WATER_OUT_SFX, + WOOD_LAND_SFX, + WOOD_DESTROY_SFX, + METAL_LAND_SFX, + METAL_DESTROY_SFX, + BOULDER_LAND_SFX, + BOULDER_DESTROY_SFX, + ARROW_RELEASE_SFX, + ARROW_DESTROY_SFX, + BOMB_RELEASE_SFX, + EXPLOSION_SFX, + BUBBLE_SFX, +} SFXTag_t; +#endif diff --git a/scenes/ent_impl.h b/scenes/ent_impl.h index 5857eb8..5e4f7fe 100644 --- a/scenes/ent_impl.h +++ b/scenes/ent_impl.h @@ -1,19 +1,7 @@ #ifndef __ENT_IMPL_H #define __ENT_IMPL_H #include "assets.h" - -typedef enum EntityTag { - NO_ENT_TAG = 0, - PLAYER_ENT_TAG, - ENEMY_ENT_TAG, - CRATES_ENT_TAG, - CHEST_ENT_TAG, - BOULDER_ENT_TAG, - LEVEL_END_TAG, - DESTRUCTABLE_ENT_TAG, - DYNMEM_ENT_TAG, -} EntityTag_t; - +#include "assets_tag.h" bool init_player_creation(const char* info_file, Assets_t* assets); bool init_player_creation_rres(const char* rres_file, const char* file, Assets_t* assets); diff --git a/scenes/game_systems.c b/scenes/game_systems.c index 89afc37..538b07f 100644 --- a/scenes/game_systems.c +++ b/scenes/game_systems.c @@ -362,7 +362,7 @@ void player_movement_input_system(Scene_t* scene) // Check if possible to jump when jump is pressed if (p_cjump->jump_released && p_pstate->jump_pressed && p_cjump->jumps > 0 && p_cjump->jump_ready) { - play_sfx(scene->engine, 0); + play_sfx(scene->engine, PLAYER_JMP_SFX); p_cjump->jumps--; if (!in_water) { @@ -386,6 +386,12 @@ void player_movement_input_system(Scene_t* scene) p_cjump->jump_ready = false; p_cjump->jump_released = false; } + else if (p_mstate->ground_state == 0b01) + { + // the else if check is to prevent playing the landing sfx + // on first frame jumps + play_sfx(scene->engine, PLAYER_LAND_SFX); + } } } @@ -899,6 +905,7 @@ void moveable_update_system(Scene_t* scene) p_moveable->gridmove = false; p_bbox->solid = true; p_ctransform->movement_mode = REGULAR_MOVEMENT; + play_sfx(scene->engine, BOULDER_LAND_SFX); } else if (remaining_distance > 0.1) { @@ -1346,6 +1353,17 @@ void state_transition_update_system(Scene_t* scene) { p_ctransform->active = true; } + if (p_mstate->ground_state == 0b01) + { + if (p_ent->m_tag == BOULDER_ENT_TAG) + { + play_sfx(scene->engine, BOULDER_LAND_SFX); + } + } + if (p_mstate->water_state == 0b01) + { + play_sfx(scene->engine, WATER_IN_SFX); + } } } @@ -1742,6 +1760,7 @@ void airtimer_update_system(Scene_t* scene) { p_air->curr_count--; p_air->curr_ftimer = p_air->max_ftimer; + play_sfx(scene->engine, BUBBLE_SFX); } else {