Added a lot of sound and music.

This commit is contained in:
Linus_Probert 2018-02-15 14:00:59 +01:00
parent 2a24c6528e
commit f4867551a1
25 changed files with 92 additions and 19 deletions

View File

@ -37,6 +37,7 @@ x Fix crash when clicking menu items with pointer
- A different license perhaps? - A different license perhaps?
- Credit screen showing music and graphics guys: - Credit screen showing music and graphics guys:
- Music: http://soundimage.org/ (Eric Matyas) - Music: http://soundimage.org/ (Eric Matyas)
- SFX (Eric Matyas & https://opengameart.org/users/artisticdude)
- Graphics: (see README) - Graphics: (see README)
Legend: ( '-' = future) ( 'x' = completed ) ( 'o' = begun ) Legend: ( '-' = future) ( 'x' = completed ) ( 'o' = begun )

BIN
assets/Sounds/FX/bonk.wav Normal file

Binary file not shown.

BIN
assets/Sounds/FX/bottle.wav Normal file

Binary file not shown.

BIN
assets/Sounds/FX/bubble.wav Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
assets/Sounds/FX/coin.wav Normal file

Binary file not shown.

BIN
assets/Sounds/FX/death.wav Normal file

Binary file not shown.

BIN
assets/Sounds/FX/eat.wav Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
assets/Sounds/FX/splat.wav Normal file

Binary file not shown.

BIN
assets/Sounds/FX/swing.wav Normal file

Binary file not shown.

BIN
assets/Sounds/FX/swing2.wav Normal file

Binary file not shown.

BIN
assets/Sounds/FX/swing3.wav Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -198,13 +198,13 @@ set_max_health(Gui *gui, int max, SDL_Renderer *renderer)
static void static void
set_current_health(Gui *gui, int current) set_current_health(Gui *gui, int current)
{ {
if (current < 0)
current = 0;
int partial = current % 3; int partial = current % 3;
int full = (current - partial)/3; int full = (current - partial)/3;
int count = 0; int count = 0;
if (current < 0)
current = 0;
LinkedList *item = gui->health; LinkedList *item = gui->health;
while (item != NULL) { while (item != NULL) {
Sprite *sprite = (Sprite*) item->data; Sprite *sprite = (Sprite*) item->data;

View File

@ -5,6 +5,7 @@
#include "texture.h" #include "texture.h"
#include "util.h" #include "util.h"
#include "gui.h" #include "gui.h"
#include "mixer.h"
static ItemBuilder *builder = NULL; static ItemBuilder *builder = NULL;
@ -44,6 +45,7 @@ eat_flesh(Item *item, Player *player)
if (player->stats.hp > player->stats.maxhp) if (player->stats.hp > player->stats.maxhp)
player->stats.hp = player->stats.maxhp; player->stats.hp = player->stats.maxhp;
mixer_play_effect(EAT);
gui_log("You eat some foul meat and gain %d health", gui_log("You eat some foul meat and gain %d health",
player->stats.hp - original_hp); player->stats.hp - original_hp);
} }
@ -53,6 +55,7 @@ drink_health(Item *item, Player *player)
{ {
player->potion_sips += (int) item->value; player->potion_sips += (int) item->value;
mixer_play_effect(BOTTLE);
gui_log("You collect %u sips of health", (unsigned int) item->value); gui_log("You collect %u sips of health", (unsigned int) item->value);
} }
@ -77,6 +80,7 @@ static void
pickup_gold(Item *item, Player *player) pickup_gold(Item *item, Player *player)
{ {
player->gold += item->value; player->gold += item->value;
mixer_play_effect(COIN);
gui_log("You pick up %s", &item->label); gui_log("You pick up %s", &item->label);
} }

View File

@ -167,7 +167,7 @@ startGame(void *unused)
if (gPlayer) if (gPlayer)
player_destroy(gPlayer); player_destroy(gPlayer);
gPlayer = player_create(WARRIOR, gRenderer); gPlayer = player_create(WARRIOR, gRenderer);
mixer_stop_music(); mixer_play_music(GAME_MUSIC0 + (rand() % 3));
resetGame(); resetGame();
} }
@ -259,7 +259,7 @@ initMainMenu(void)
gMap = map_lua_generator_single_room__run(cLevel, gRenderer); gMap = map_lua_generator_single_room__run(cLevel, gRenderer);
createMenu(&mainMenu, menu_items, 2); createMenu(&mainMenu, menu_items, 2);
mixer_play_music(); mixer_play_music(MENU_MUSIC);
} }
static void static void
@ -380,6 +380,8 @@ check_next_level(void)
return; return;
} }
if (tile->levelExit) { if (tile->levelExit) {
mixer_play_effect(NEXT_LEVEL);
mixer_play_music(GAME_MUSIC0 + (rand() % 3));
++cLevel; ++cLevel;
resetGame(); resetGame();
} }
@ -444,6 +446,7 @@ run_game(void)
if (gGameState == PLAYING && is_player_dead()) { if (gGameState == PLAYING && is_player_dead()) {
gui_log("The dungeon consumed you"); gui_log("The dungeon consumed you");
mixer_play_effect(SPLAT);
gGameState = GAME_OVER; gGameState = GAME_OVER;
} }

View File

@ -2,9 +2,28 @@
#include "mixer.h" #include "mixer.h"
#include "util.h" #include "util.h"
static Mix_Music *music = NULL; static Mix_Music *music[LAST_MUSIC];
static Mix_Chunk *effects[LAST_EFFECT]; static Mix_Chunk *effects[LAST_EFFECT];
static Mix_Music*
load_song(char *path)
{
Mix_Music *m = Mix_LoadMUS(path);
if (m == NULL)
fatal("Failed to load music: %s", Mix_GetError());
return m;
}
static void
load_music(void)
{
music[GAME_MUSIC0] = load_song("assets/Sounds/Music/fantasy-game-background-looping.ogg");
music[GAME_MUSIC1] = load_song("assets/Sounds/Music/bog-creatures-on-the-move-looping.ogg");
music[GAME_MUSIC2] = load_song("assets/Sounds/Music/fantascape-looping.ogg");
music[MENU_MUSIC] = load_song("assets/Sounds/Music/fantasy-forest-battle.ogg");
}
static Mix_Chunk* static Mix_Chunk*
load_effect(char *path) load_effect(char *path)
{ {
@ -18,6 +37,21 @@ static void
load_effects(void) load_effects(void)
{ {
effects[CLICK] = load_effect("assets/Sounds/FX/click.wav"); effects[CLICK] = load_effect("assets/Sounds/FX/click.wav");
effects[SWING0] = load_effect("assets/Sounds/FX/swing.wav");
effects[SWING1] = load_effect("assets/Sounds/FX/swing2.wav");
effects[SWING2] = load_effect("assets/Sounds/FX/swing3.wav");
effects[SWORD_HIT] = load_effect("assets/Sounds/FX/sword_hit.wav");
effects[BONK] = load_effect("assets/Sounds/FX/bonk.wav");
effects[DEATH] = load_effect("assets/Sounds/FX/death.wav");
effects[COIN] = load_effect("assets/Sounds/FX/coin.wav");
effects[BOTTLE] = load_effect("assets/Sounds/FX/bottle.wav");
effects[BUBBLE0] = load_effect("assets/Sounds/FX/bubble.wav");
effects[BUBBLE1] = load_effect("assets/Sounds/FX/bubble2.wav");
effects[BUBBLE2] = load_effect("assets/Sounds/FX/bubble3.wav");
effects[EAT] = load_effect("assets/Sounds/FX/eat.wav");
effects[LEVEL_UP] = load_effect("assets/Sounds/FX/level_up.wav");
effects[NEXT_LEVEL] = load_effect("assets/Sounds/FX/next_level.wav");
effects[SPLAT] = load_effect("assets/Sounds/FX/splat.wav");
} }
void void
@ -27,9 +61,7 @@ mixer_init(void)
fatal("Failed to load sound: %s", Mix_GetError()); fatal("Failed to load sound: %s", Mix_GetError());
} }
load_effects(); load_effects();
music = Mix_LoadMUS("assets/Sounds/Music/fantasy-forest-battle.ogg"); load_music();
if (music == NULL)
fatal("Failed to load music: %s", Mix_GetError());
} }
void void
@ -40,12 +72,12 @@ mixer_play_effect(Fx fx)
} }
void void
mixer_play_music(void) mixer_play_music(Music mus)
{ {
if (Mix_PlayingMusic()) if (Mix_PlayingMusic())
return; mixer_stop_music();
if (Mix_PlayMusic(music, -1) == -1) if (Mix_PlayMusic(music[mus], -1) == -1)
fatal("Failed to play music"); fatal("Failed to play music");
} }
@ -59,10 +91,9 @@ mixer_stop_music(void)
void void
mixer_close(void) mixer_close(void)
{ {
for (size_t i = 0; i < LAST_EFFECT; ++i) { for (size_t i = 0; i < LAST_EFFECT; ++i)
Mix_FreeChunk(effects[i]); Mix_FreeChunk(effects[i]);
} for (size_t i = 0; i < LAST_MUSIC; ++i)
if (music) Mix_FreeMusic(music[i]);
Mix_FreeMusic(music);
Mix_CloseAudio(); Mix_CloseAudio();
} }

View File

@ -3,8 +3,31 @@
#include <stdbool.h> #include <stdbool.h>
typedef enum Music_t {
MENU_MUSIC,
GAME_MUSIC0,
GAME_MUSIC1,
GAME_MUSIC2,
LAST_MUSIC
} Music;
typedef enum Fx_t { typedef enum Fx_t {
CLICK, CLICK,
SWING0,
SWING1,
SWING2,
SWORD_HIT,
BONK,
DEATH,
COIN,
BOTTLE,
BUBBLE0,
BUBBLE1,
BUBBLE2,
EAT,
LEVEL_UP,
NEXT_LEVEL,
SPLAT,
LAST_EFFECT LAST_EFFECT
} Fx; } Fx;
@ -15,7 +38,7 @@ void
mixer_play_effect(Fx fx); mixer_play_effect(Fx fx);
void void
mixer_play_music(void); mixer_play_music(Music);
void void
mixer_stop_music(void); mixer_stop_music(void);

View File

@ -9,6 +9,7 @@
#include "item.h" #include "item.h"
#include "particle_engine.h" #include "particle_engine.h"
#include "keyboard.h" #include "keyboard.h"
#include "mixer.h"
#define ENGINEER_STATS { 12, 12, 5, 7, 2, 1, 1 } #define ENGINEER_STATS { 12, 12, 5, 7, 2, 1, 1 }
#define MAGE_STATS { 12, 12, 5, 7, 2, 1, 1 } #define MAGE_STATS { 12, 12, 5, 7, 2, 1, 1 }
@ -19,6 +20,8 @@
static void static void
player_levelup(Player *player) player_levelup(Player *player)
{ {
mixer_play_effect(LEVEL_UP);
player->stats.lvl += 1; player->stats.lvl += 1;
player->stats.maxhp += 3; player->stats.maxhp += 3;
player->stats.dmg += 5; player->stats.dmg += 5;
@ -74,12 +77,17 @@ has_collided(Player *player, RoomMatrix *matrix)
if (space->monster != NULL) { if (space->monster != NULL) {
unsigned int hit = stats_fight(&player->stats, unsigned int hit = stats_fight(&player->stats,
&space->monster->stats); &space->monster->stats);
mixer_play_effect(SWING0 + (rand() % 3));
monster_hit(space->monster, hit); monster_hit(space->monster, hit);
if (hit > 0) if (hit > 0) {
player->hits += 1; player->hits += 1;
else mixer_play_effect(SWORD_HIT);
} else {
player->misses += 1; player->misses += 1;
}
if (hit > 0) if (hit > 0)
gui_log("You hit %s for %u damage", gui_log("You hit %s for %u damage",
@ -91,11 +99,13 @@ has_collided(Player *player, RoomMatrix *matrix)
unsigned int gained_xp = 5 * space->monster->stats.lvl; unsigned int gained_xp = 5 * space->monster->stats.lvl;
player->kills += 1; player->kills += 1;
mixer_play_effect(DEATH);
gui_log("You killed %s and gained %d xp", gui_log("You killed %s and gained %d xp",
space->monster->lclabel, gained_xp); space->monster->lclabel, gained_xp);
player_gain_xp(player, gained_xp); player_gain_xp(player, gained_xp);
} }
} else if (collided) { } else if (collided) {
mixer_play_effect(BONK);
gui_log("Ouch! There is something in the way"); gui_log("Ouch! There is something in the way");
} }
@ -170,6 +180,7 @@ sip_health(Player *player)
if (player->potion_sips > 0) { if (player->potion_sips > 0) {
--player->potion_sips; --player->potion_sips;
++player->stats.hp; ++player->stats.hp;
mixer_play_effect(BUBBLE0 + (rand() % 3));
gui_log("You take a sip of health potion"); gui_log("You take a sip of health potion");
} else { } else {
gui_log("You have nothing to sip"); gui_log("You have nothing to sip");