forked from NotAShelf/rogged
audio: refactor audio asset loading, add crit sound
This commit is contained in:
parent
23dead8c0d
commit
a315b14dd1
5 changed files with 66 additions and 44 deletions
33
src/main.c
33
src/main.c
|
|
@ -187,18 +187,18 @@ static void post_action(GameState *gs, Enemy *attacked_enemy) {
|
|||
|
||||
if (combat_was_dodged()) {
|
||||
spawn_floating_label(gs, ex, ey, "DODGE", EFFECT_NONE);
|
||||
audio_play_dodge();
|
||||
audio_play_dodge(gs);
|
||||
} else {
|
||||
if (combat_get_last_damage() > 0)
|
||||
spawn_floating_text(gs, ex, ey, combat_get_last_damage(), combat_was_critical());
|
||||
audio_play_attack();
|
||||
audio_play_attack(gs);
|
||||
if (combat_was_blocked()) {
|
||||
spawn_floating_label(gs, ex, ey - 10, "BLOCK", EFFECT_NONE);
|
||||
audio_play_block();
|
||||
audio_play_block(gs);
|
||||
}
|
||||
if (combat_was_critical()) {
|
||||
spawn_floating_label(gs, ex + 8, ey - 10, "CRIT!", EFFECT_NONE);
|
||||
audio_play_crit();
|
||||
audio_play_crit(gs);
|
||||
}
|
||||
StatusEffectType applied = combat_get_applied_effect();
|
||||
if (applied != EFFECT_NONE) {
|
||||
|
|
@ -207,7 +207,7 @@ static void post_action(GameState *gs, Enemy *attacked_enemy) {
|
|||
}
|
||||
if (!attacked_enemy->alive) {
|
||||
spawn_floating_label(gs, ex, ey - 20, "SLAIN", EFFECT_NONE);
|
||||
audio_play_enemy_death();
|
||||
audio_play_enemy_death(gs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -217,7 +217,7 @@ static void post_action(GameState *gs, Enemy *attacked_enemy) {
|
|||
|
||||
// Check if player took damage
|
||||
if (combat_was_player_damage() && combat_get_last_damage() > 0) {
|
||||
audio_play_player_damage();
|
||||
audio_play_player_damage(gs);
|
||||
gs->screen_shake = 8;
|
||||
spawn_floating_text(gs, gs->player.x * TILE_SIZE + 8, gs->player.y * TILE_SIZE, combat_get_last_damage(),
|
||||
combat_was_critical());
|
||||
|
|
@ -349,7 +349,7 @@ static int handle_inventory_input(GameState *gs) {
|
|||
static int handle_descend_input(GameState *gs) {
|
||||
if (IsKeyPressed(KEY_Y)) {
|
||||
if (gs->player.floor < NUM_FLOORS) {
|
||||
audio_play_stairs();
|
||||
audio_play_stairs(gs);
|
||||
init_floor(gs, gs->player.floor + 1);
|
||||
gs->last_message = "Descended to next floor!";
|
||||
gs->message_timer = 60;
|
||||
|
|
@ -388,7 +388,7 @@ static int handle_movement_input(GameState *gs) {
|
|||
add_log(gs, pickup_msg);
|
||||
gs->last_message = "Picked up item!";
|
||||
gs->message_timer = 60;
|
||||
audio_play_item_pickup();
|
||||
audio_play_item_pickup(gs);
|
||||
} else {
|
||||
gs->last_message = "Inventory full!";
|
||||
gs->message_timer = 60;
|
||||
|
|
@ -402,7 +402,7 @@ static int handle_movement_input(GameState *gs) {
|
|||
if (gs->player.inventory_count > 0 && player_use_first_item(&gs->player)) {
|
||||
gs->last_message = "Used potion!";
|
||||
gs->message_timer = 60;
|
||||
audio_play_item_pickup();
|
||||
audio_play_item_pickup(gs);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -468,11 +468,24 @@ static int handle_input(GameState *gs) {
|
|||
return handle_movement_input(gs);
|
||||
}
|
||||
|
||||
void load_audio_assets(GameState *gs) {
|
||||
gs->sounds.attack1 = LoadSound("./assets/sounds/sword1.wav");
|
||||
gs->sounds.attack2 = LoadSound("./assets/sounds/sword2.wav");
|
||||
gs->sounds.attack3 = LoadSound("./assets/sounds/sword3.wav");
|
||||
gs->sounds.pickup = LoadSound("./assets/sounds/itempickup.wav");
|
||||
gs->sounds.staircase = LoadSound("./assets/sounds/levelcomplete.wav");
|
||||
gs->sounds.dodge1 = LoadSound("./assets/sounds/dodge1.wav");
|
||||
gs->sounds.dodge2 = LoadSound("./assets/sounds/dodge2.wav");
|
||||
gs->sounds.dodge3 = LoadSound("./assets/sounds/dodge3.wav");
|
||||
gs->sounds.crit = LoadSound("./assets/sounds/crit.wav");
|
||||
return;
|
||||
}
|
||||
|
||||
// Main game loop
|
||||
static void game_loop(void) {
|
||||
GameState gs;
|
||||
memset(&gs, 0, sizeof(GameState));
|
||||
|
||||
load_audio_assets(&gs);
|
||||
// Initialize first floor
|
||||
rng_seed(12345);
|
||||
init_floor(&gs, 1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue