Adjust Game UI + Add SFXs
parent
cb22cac6c3
commit
ce84014668
|
@ -118,7 +118,7 @@ void play_sfx_pitched(GameEngine_t* engine, unsigned int tag_idx, float pitch)
|
||||||
//if (sfx->snd != NULL)
|
//if (sfx->snd != NULL)
|
||||||
{
|
{
|
||||||
PlaySound(*sfx->snd);
|
PlaySound(*sfx->snd);
|
||||||
sfx->plays++;
|
//sfx->plays++;
|
||||||
}
|
}
|
||||||
//SetSoundPitch(*sfx->snd, 0.0f);
|
//SetSoundPitch(*sfx->snd, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,9 @@ int main(int argc, char** argv)
|
||||||
load_sfx(&engine, "snd_wdrop", WATER_IN_SFX);
|
load_sfx(&engine, "snd_wdrop", WATER_IN_SFX);
|
||||||
load_sfx(&engine, "snd_bland", BOULDER_LAND_SFX);
|
load_sfx(&engine, "snd_bland", BOULDER_LAND_SFX);
|
||||||
load_sfx(&engine, "snd_bubble", BUBBLE_SFX);
|
load_sfx(&engine, "snd_bubble", BUBBLE_SFX);
|
||||||
|
load_sfx(&engine, "snd_step", PLAYER_STEP_SFX);
|
||||||
|
load_sfx(&engine, "snd_dead", PLAYER_DEAD_SFX);
|
||||||
|
load_sfx(&engine, "snd_drwg", PLAYER_DROWNING_SFX);
|
||||||
load_sfx(&engine, "snd_mdestroy", METAL_DESTROY_SFX);
|
load_sfx(&engine, "snd_mdestroy", METAL_DESTROY_SFX);
|
||||||
load_sfx(&engine, "snd_wdestroy", WOOD_DESTROY_SFX);
|
load_sfx(&engine, "snd_wdestroy", WOOD_DESTROY_SFX);
|
||||||
load_sfx(&engine, "snd_cland", WOOD_LAND_SFX);
|
load_sfx(&engine, "snd_cland", WOOD_LAND_SFX);
|
||||||
|
|
|
@ -64,6 +64,9 @@ int main(void)
|
||||||
load_sfx(&engine, "snd_cland", WOOD_LAND_SFX);
|
load_sfx(&engine, "snd_cland", WOOD_LAND_SFX);
|
||||||
load_sfx(&engine, "snd_explsn", EXPLOSION_SFX);
|
load_sfx(&engine, "snd_explsn", EXPLOSION_SFX);
|
||||||
load_sfx(&engine, "snd_coin", COIN_SFX);
|
load_sfx(&engine, "snd_coin", COIN_SFX);
|
||||||
|
load_sfx(&engine, "snd_step", PLAYER_STEP_SFX);
|
||||||
|
load_sfx(&engine, "snd_dead", PLAYER_DEAD_SFX);
|
||||||
|
load_sfx(&engine, "snd_drwg", PLAYER_DROWNING_SFX);
|
||||||
load_sfx(&engine, "snd_arrhit", ARROW_DESTROY_SFX);
|
load_sfx(&engine, "snd_arrhit", ARROW_DESTROY_SFX);
|
||||||
load_sfx(&engine, "snd_launch", ARROW_RELEASE_SFX);
|
load_sfx(&engine, "snd_launch", ARROW_RELEASE_SFX);
|
||||||
load_sfx(&engine, "snd_launch", BOMB_RELEASE_SFX);
|
load_sfx(&engine, "snd_launch", BOMB_RELEASE_SFX);
|
||||||
|
|
|
@ -20,6 +20,9 @@ typedef enum SFXTag {
|
||||||
PLAYER_RUN_SFX,
|
PLAYER_RUN_SFX,
|
||||||
PLAYER_LADDER_SFX,
|
PLAYER_LADDER_SFX,
|
||||||
PLAYER_WATER_RUN_SFX,
|
PLAYER_WATER_RUN_SFX,
|
||||||
|
PLAYER_STEP_SFX,
|
||||||
|
PLAYER_DEAD_SFX,
|
||||||
|
PLAYER_DROWNING_SFX,
|
||||||
WATER_IN_SFX,
|
WATER_IN_SFX,
|
||||||
WATER_OUT_SFX,
|
WATER_OUT_SFX,
|
||||||
WOOD_LAND_SFX,
|
WOOD_LAND_SFX,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "EC.h"
|
#include "EC.h"
|
||||||
|
#include "engine.h"
|
||||||
#include "render_queue.h"
|
#include "render_queue.h"
|
||||||
#include "particle_sys.h" // includes assets
|
#include "particle_sys.h" // includes assets
|
||||||
|
|
||||||
|
@ -136,6 +137,7 @@ typedef struct _CWaterRunner {
|
||||||
}CWaterRunner_t;
|
}CWaterRunner_t;
|
||||||
|
|
||||||
typedef unsigned int (*sprite_transition_func_t)(Entity_t *ent); // Transition requires knowledge of the entity
|
typedef unsigned int (*sprite_transition_func_t)(Entity_t *ent); // Transition requires knowledge of the entity
|
||||||
|
typedef void (*sprite_sfx_func_t)(GameEngine_t*, Entity_t *ent); // Transition requires knowledge of the entity
|
||||||
|
|
||||||
typedef struct _SpriteRenderInfo
|
typedef struct _SpriteRenderInfo
|
||||||
{
|
{
|
||||||
|
@ -149,6 +151,7 @@ typedef struct _CSprite_t {
|
||||||
RenderInfoNode node;
|
RenderInfoNode node;
|
||||||
SpriteRenderInfo_t* sprites;
|
SpriteRenderInfo_t* sprites;
|
||||||
sprite_transition_func_t transition_func;
|
sprite_transition_func_t transition_func;
|
||||||
|
sprite_sfx_func_t sfx_func;
|
||||||
unsigned int current_idx;
|
unsigned int current_idx;
|
||||||
int current_frame;
|
int current_frame;
|
||||||
float fractional;
|
float fractional;
|
||||||
|
|
|
@ -67,15 +67,27 @@ static void level_scene_render_func(Scene_t* scene)
|
||||||
DrawText(buffer, gui_x, data->game_rec.height - 12, 12, WHITE);
|
DrawText(buffer, gui_x, data->game_rec.height - 12, 12, WHITE);
|
||||||
|
|
||||||
DrawRectangle(0, 0, data->game_rec.width, 32, (Color){0,0,0,128});
|
DrawRectangle(0, 0, data->game_rec.width, 32, (Color){0,0,0,128});
|
||||||
DrawText("Z", 300, 5, 24, RED);
|
|
||||||
if (data->camera.mode == CAMERA_RANGED_MOVEMENT)
|
|
||||||
{
|
{
|
||||||
DrawText("Eyes", 320, 5, 24, RED);
|
DrawText("Z", 300, 5, 24, RED);
|
||||||
|
Sprite_t* spr = get_sprite(&scene->engine->assets, "eye");
|
||||||
|
if (data->camera.mode == CAMERA_RANGED_MOVEMENT)
|
||||||
|
{
|
||||||
|
draw_sprite(spr, 1, (Vector2){332, 0}, 0, false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
draw_sprite(spr, 0, (Vector2){332, 0}, 0, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
DrawText(data->level_pack->levels[data->current_level].level_name, 5, 5, 24, WHITE);
|
DrawText(data->level_pack->levels[data->current_level].level_name, 5, 5, 24, WHITE);
|
||||||
sprintf(buffer, "Chests: %u / %u", data->coins.current, data->coins.total);
|
{
|
||||||
gui_x = data->game_rec.width - MeasureText(buffer, 24) - 5;
|
sprintf(buffer, "%u / %u", data->coins.current, data->coins.total);
|
||||||
DrawText(buffer, gui_x, 5, 24, RED);
|
gui_x = data->game_rec.width - MeasureText(buffer, 24) - 5;
|
||||||
|
// TODO: Use the chest sprite
|
||||||
|
Sprite_t* spr = get_sprite(&scene->engine->assets, "chest");
|
||||||
|
draw_sprite_pro(spr, 0, (Vector2){gui_x-32, 8}, 0, 0, (Vector2){0.5,0.5}, WHITE);
|
||||||
|
DrawText(buffer, gui_x, 5, 24, RED);
|
||||||
|
}
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -286,6 +286,7 @@ void check_player_dead_system(Scene_t* scene)
|
||||||
if (!p_player->m_alive)
|
if (!p_player->m_alive)
|
||||||
{
|
{
|
||||||
Entity_t* ent = create_dead_player(&scene->ent_manager);
|
Entity_t* ent = create_dead_player(&scene->ent_manager);
|
||||||
|
play_sfx(scene->engine, PLAYER_DEAD_SFX);
|
||||||
if (ent != NULL)
|
if (ent != NULL)
|
||||||
{
|
{
|
||||||
ent->position = p_player->position;
|
ent->position = p_player->position;
|
||||||
|
@ -2045,6 +2046,10 @@ void airtimer_update_system(Scene_t* scene)
|
||||||
};
|
};
|
||||||
play_particle_emitter(&scene->part_sys, &emitter);
|
play_particle_emitter(&scene->part_sys, &emitter);
|
||||||
play_sfx(scene->engine, BUBBLE_SFX);
|
play_sfx(scene->engine, BUBBLE_SFX);
|
||||||
|
if (p_air->curr_count < 2)
|
||||||
|
{
|
||||||
|
play_sfx(scene->engine, PLAYER_DROWNING_SFX);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -2106,6 +2111,9 @@ void sprite_animation_system(Scene_t* scene)
|
||||||
p_cspr->current_frame++;
|
p_cspr->current_frame++;
|
||||||
p_cspr->current_frame %= spr.sprite->frame_count;
|
p_cspr->current_frame %= spr.sprite->frame_count;
|
||||||
}
|
}
|
||||||
|
if (p_cspr->sfx_func != NULL) {
|
||||||
|
p_cspr->sfx_func(scene->engine, p_ent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include "engine.h"
|
||||||
#include "ent_impl.h"
|
#include "ent_impl.h"
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -67,6 +68,20 @@ static unsigned int player_sprite_transition_func(Entity_t* ent)
|
||||||
return (p_ctrans->velocity.y < 0) ? SPR_PLAYER_JUMP : SPR_PLAYER_FALL;
|
return (p_ctrans->velocity.y < 0) ? SPR_PLAYER_JUMP : SPR_PLAYER_FALL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void player_sfx_func(GameEngine_t* engine, Entity_t* ent) {
|
||||||
|
CSprite_t* p_spr = get_component(ent, CSPRITE_T);
|
||||||
|
if (p_spr->current_idx == SPR_PLAYER_RUN) {
|
||||||
|
if (p_spr->current_frame % 3 == 0) {
|
||||||
|
play_sfx_pitched(engine, PLAYER_STEP_SFX, p_spr->current_frame == 0?1.0f : 0.75f );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (p_spr->current_idx == SPR_PLAYER_CRMOVE) {
|
||||||
|
if (p_spr->current_frame % 2 == 0) {
|
||||||
|
play_sfx(engine, PLAYER_STEP_SFX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Entity_t* create_player(EntityManager_t* ent_manager)
|
Entity_t* create_player(EntityManager_t* ent_manager)
|
||||||
{
|
{
|
||||||
Entity_t* p_ent = add_entity(ent_manager, PLAYER_ENT_TAG);
|
Entity_t* p_ent = add_entity(ent_manager, PLAYER_ENT_TAG);
|
||||||
|
@ -116,6 +131,7 @@ Entity_t* create_player(EntityManager_t* ent_manager)
|
||||||
CSprite_t* p_cspr = add_component(p_ent, CSPRITE_T);
|
CSprite_t* p_cspr = add_component(p_ent, CSPRITE_T);
|
||||||
p_cspr->sprites = player_sprite_map;
|
p_cspr->sprites = player_sprite_map;
|
||||||
p_cspr->transition_func = &player_sprite_transition_func;
|
p_cspr->transition_func = &player_sprite_transition_func;
|
||||||
|
p_cspr->sfx_func = &player_sfx_func;
|
||||||
p_cspr->node.colour = WHITE;
|
p_cspr->node.colour = WHITE;
|
||||||
p_cspr->node.scale = (Vector2){1, 1};
|
p_cspr->node.scale = (Vector2){1, 1};
|
||||||
p_cspr->depth = 1;
|
p_cspr->depth = 1;
|
||||||
|
|
Loading…
Reference in New Issue