Compare commits

..

No commits in common. "e318c65135e3fe166038405de4de7d25decf99fb" and "0a4c700bf6941efe44d004c82b5518649fbfa39c" have entirely different histories.

7 changed files with 16 additions and 136 deletions

View File

@ -8,8 +8,6 @@
#include <emscripten/emscripten.h> #include <emscripten/emscripten.h>
#endif #endif
static SFX_t sfx_buffer[N_SFX] = {0};
static uint32_t sfx_counts[N_SFX] = {0};
Scene_t* scenes[1]; Scene_t* scenes[1];
static GameEngine_t engine = static GameEngine_t engine =
@ -17,13 +15,7 @@ static GameEngine_t engine =
.scenes = scenes, .scenes = scenes,
.max_scenes = 1, .max_scenes = 1,
.curr_scene = 0, .curr_scene = 0,
.assets = {0}, .assets = {0}
.sfx_list = {
.sfx = sfx_buffer,
.n_sfx = N_SFX,
.sfx_queue = sfx_counts,
.played_sfx = 0,
}
}; };
void update_loop(void) void update_loop(void)
@ -39,11 +31,9 @@ void update_loop(void)
int main(void) int main(void)
{ {
init_engine(&engine);
InitWindow(1280, 640, "raylib"); InitWindow(1280, 640, "raylib");
SetTargetFPS(60); SetTargetFPS(60);
InitAudioDevice();
init_engine(&engine);
init_memory_pools(); init_memory_pools();
init_assets(&engine.assets); init_assets(&engine.assets);
@ -57,17 +47,6 @@ int main(void)
#endif #endif
init_item_creation(&engine.assets); init_item_creation(&engine.assets);
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; LevelScene_t scene;
scene.scene.engine = &engine; scene.scene.engine = &engine;
init_sandbox_scene(&scene); init_sandbox_scene(&scene);
@ -96,7 +75,6 @@ int main(void)
update_entity_manager(&scene.scene.ent_manager); update_entity_manager(&scene.scene.ent_manager);
// This is needed to advance time delta // This is needed to advance time delta
render_scene(&scene.scene); render_scene(&scene.scene);
update_sfx_list(&engine);
if (WindowShouldClose()) break; if (WindowShouldClose()) break;
} }
#endif #endif

View File

@ -1,36 +0,0 @@
#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

View File

@ -65,12 +65,4 @@ Font* get_font(Assets_t* assets, const char* name);
LevelPack_t* get_level_pack(Assets_t* assets, const char* name); LevelPack_t* get_level_pack(Assets_t* assets, const char* name);
void draw_sprite(Sprite_t* spr, Vector2 pos, bool flip_x); void draw_sprite(Sprite_t* spr, Vector2 pos, bool flip_x);
typedef struct SFX
{
Sound* snd;
uint8_t plays;
uint8_t cooldown;
} SFX_t;
#endif // __ASSETS_H #endif // __ASSETS_H

View File

@ -3,7 +3,6 @@
void init_engine(GameEngine_t* engine) void init_engine(GameEngine_t* engine)
{ {
sc_queue_init(&engine->key_buffer); sc_queue_init(&engine->key_buffer);
memset(engine->sfx_list.sfx, 0, engine->sfx_list.n_sfx * sizeof(SFX_t));
} }
void deinit_engine(GameEngine_t* engine) void deinit_engine(GameEngine_t* engine)
@ -49,38 +48,6 @@ void change_scene(GameEngine_t* engine, unsigned int idx)
engine->scenes[engine->curr_scene]->state = SCENE_PLAYING; engine->scenes[engine->curr_scene]->state = SCENE_PLAYING;
} }
bool load_sfx(GameEngine_t* engine, const char* snd_name, uint32_t tag_idx)
{
if (tag_idx >= engine->sfx_list.n_sfx) return false;
Sound* snd = get_sound(&engine->assets, snd_name);
if (snd == NULL) return false;
engine->sfx_list.sfx[tag_idx].snd = snd;
engine->sfx_list.sfx[tag_idx].cooldown = 0;
engine->sfx_list.sfx[tag_idx].plays = 0;
}
void play_sfx(GameEngine_t* engine, unsigned int tag_idx)
{
if (tag_idx >= engine->sfx_list.n_sfx) return;
SFX_t* sfx = engine->sfx_list.sfx + tag_idx;
if (sfx->plays == 0 && sfx->snd != NULL)
{
PlaySound(*sfx->snd);
sfx->plays++;
engine->sfx_list.sfx_queue[engine->sfx_list.played_sfx++] = tag_idx;
}
}
void update_sfx_list(GameEngine_t* engine)
{
for (uint32_t i = 0; i< engine->sfx_list.played_sfx; ++i)
{
uint32_t tag_idx = engine->sfx_list.sfx_queue[i];
engine->sfx_list.sfx[tag_idx].plays = 0;
}
engine->sfx_list.played_sfx = 0;
}
//void init_scene(Scene_t* scene, SceneType_t scene_type, system_func_t render_func, action_func_t action_func) //void init_scene(Scene_t* scene, SceneType_t scene_type, system_func_t render_func, action_func_t action_func)
void init_scene(Scene_t* scene, system_func_t render_func, action_func_t action_func) void init_scene(Scene_t* scene, system_func_t render_func, action_func_t action_func)
{ {

View File

@ -7,23 +7,15 @@
typedef struct Scene Scene_t; typedef struct Scene Scene_t;
typedef struct SFXList
{
SFX_t* sfx;
uint32_t* sfx_queue;
uint32_t n_sfx;
uint32_t played_sfx;
} SFXList_t;
typedef struct GameEngine { typedef struct GameEngine {
Scene_t **scenes; Scene_t **scenes;
unsigned int max_scenes; unsigned int max_scenes;
unsigned int curr_scene; unsigned int curr_scene;
Assets_t assets; Assets_t assets;
SFXList_t sfx_list;
// Maintain own queue to handle key presses // Maintain own queue to handle key presses
struct sc_queue_32 key_buffer; struct sc_queue_32 key_buffer;
} GameEngine_t; } GameEngine_t;
void change_scene(GameEngine_t* engine, unsigned int idx);
//typedef enum SceneType { //typedef enum SceneType {
// LEVEL_SCENE = 0, // LEVEL_SCENE = 0,
@ -55,11 +47,6 @@ void init_engine(GameEngine_t* engine);
void deinit_engine(GameEngine_t* engine); void deinit_engine(GameEngine_t* engine);
void process_inputs(GameEngine_t* engine, Scene_t* scene); void process_inputs(GameEngine_t* engine, Scene_t* scene);
void change_scene(GameEngine_t* engine, unsigned int idx);
bool load_sfx(GameEngine_t* engine, const char* snd_name, uint32_t tag_idx);
void play_sfx(GameEngine_t* engine, unsigned int tag_idx);
void update_sfx_list(GameEngine_t* engine);
// Inline functions, for convenience // Inline functions, for convenience
extern void update_scene(Scene_t* scene); extern void update_scene(Scene_t* scene);
extern void render_scene(Scene_t* scene); extern void render_scene(Scene_t* scene);

View File

@ -1,7 +1,19 @@
#ifndef __ENT_IMPL_H #ifndef __ENT_IMPL_H
#define __ENT_IMPL_H #define __ENT_IMPL_H
#include "assets.h" #include "assets.h"
#include "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;
bool init_player_creation(const char* info_file, Assets_t* assets); 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); bool init_player_creation_rres(const char* rres_file, const char* file, Assets_t* assets);

View File

@ -362,7 +362,6 @@ void player_movement_input_system(Scene_t* scene)
// Check if possible to jump when jump is pressed // 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) if (p_cjump->jump_released && p_pstate->jump_pressed && p_cjump->jumps > 0 && p_cjump->jump_ready)
{ {
play_sfx(scene->engine, PLAYER_JMP_SFX);
p_cjump->jumps--; p_cjump->jumps--;
if (!in_water) if (!in_water)
{ {
@ -386,12 +385,6 @@ void player_movement_input_system(Scene_t* scene)
p_cjump->jump_ready = false; p_cjump->jump_ready = false;
p_cjump->jump_released = 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);
}
} }
} }
@ -905,7 +898,6 @@ void moveable_update_system(Scene_t* scene)
p_moveable->gridmove = false; p_moveable->gridmove = false;
p_bbox->solid = true; p_bbox->solid = true;
p_ctransform->movement_mode = REGULAR_MOVEMENT; p_ctransform->movement_mode = REGULAR_MOVEMENT;
play_sfx(scene->engine, BOULDER_LAND_SFX);
} }
else if (remaining_distance > 0.1) else if (remaining_distance > 0.1)
{ {
@ -1353,17 +1345,6 @@ void state_transition_update_system(Scene_t* scene)
{ {
p_ctransform->active = true; 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);
}
} }
} }
@ -1760,7 +1741,6 @@ void airtimer_update_system(Scene_t* scene)
{ {
p_air->curr_count--; p_air->curr_count--;
p_air->curr_ftimer = p_air->max_ftimer; p_air->curr_ftimer = p_air->max_ftimer;
play_sfx(scene->engine, BUBBLE_SFX);
} }
else else
{ {