Added a lot of sound and music.
This commit is contained in:
parent
2a24c6528e
commit
f4867551a1
1
TODO.txt
1
TODO.txt
|
@ -37,6 +37,7 @@ x Fix crash when clicking menu items with pointer
|
|||
- A different license perhaps?
|
||||
- Credit screen showing music and graphics guys:
|
||||
- Music: http://soundimage.org/ (Eric Matyas)
|
||||
- SFX (Eric Matyas & https://opengameart.org/users/artisticdude)
|
||||
- Graphics: (see README)
|
||||
|
||||
Legend: ( '-' = future) ( 'x' = completed ) ( 'o' = begun )
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -198,13 +198,13 @@ set_max_health(Gui *gui, int max, SDL_Renderer *renderer)
|
|||
static void
|
||||
set_current_health(Gui *gui, int current)
|
||||
{
|
||||
if (current < 0)
|
||||
current = 0;
|
||||
|
||||
int partial = current % 3;
|
||||
int full = (current - partial)/3;
|
||||
int count = 0;
|
||||
|
||||
if (current < 0)
|
||||
current = 0;
|
||||
|
||||
LinkedList *item = gui->health;
|
||||
while (item != NULL) {
|
||||
Sprite *sprite = (Sprite*) item->data;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "texture.h"
|
||||
#include "util.h"
|
||||
#include "gui.h"
|
||||
#include "mixer.h"
|
||||
|
||||
static ItemBuilder *builder = NULL;
|
||||
|
||||
|
@ -44,6 +45,7 @@ eat_flesh(Item *item, Player *player)
|
|||
if (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",
|
||||
player->stats.hp - original_hp);
|
||||
}
|
||||
|
@ -53,6 +55,7 @@ drink_health(Item *item, Player *player)
|
|||
{
|
||||
player->potion_sips += (int) item->value;
|
||||
|
||||
mixer_play_effect(BOTTLE);
|
||||
gui_log("You collect %u sips of health", (unsigned int) item->value);
|
||||
}
|
||||
|
||||
|
@ -77,6 +80,7 @@ static void
|
|||
pickup_gold(Item *item, Player *player)
|
||||
{
|
||||
player->gold += item->value;
|
||||
mixer_play_effect(COIN);
|
||||
gui_log("You pick up %s", &item->label);
|
||||
}
|
||||
|
||||
|
|
|
@ -167,7 +167,7 @@ startGame(void *unused)
|
|||
if (gPlayer)
|
||||
player_destroy(gPlayer);
|
||||
gPlayer = player_create(WARRIOR, gRenderer);
|
||||
mixer_stop_music();
|
||||
mixer_play_music(GAME_MUSIC0 + (rand() % 3));
|
||||
resetGame();
|
||||
}
|
||||
|
||||
|
@ -259,7 +259,7 @@ initMainMenu(void)
|
|||
gMap = map_lua_generator_single_room__run(cLevel, gRenderer);
|
||||
|
||||
createMenu(&mainMenu, menu_items, 2);
|
||||
mixer_play_music();
|
||||
mixer_play_music(MENU_MUSIC);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -380,6 +380,8 @@ check_next_level(void)
|
|||
return;
|
||||
}
|
||||
if (tile->levelExit) {
|
||||
mixer_play_effect(NEXT_LEVEL);
|
||||
mixer_play_music(GAME_MUSIC0 + (rand() % 3));
|
||||
++cLevel;
|
||||
resetGame();
|
||||
}
|
||||
|
@ -444,6 +446,7 @@ run_game(void)
|
|||
|
||||
if (gGameState == PLAYING && is_player_dead()) {
|
||||
gui_log("The dungeon consumed you");
|
||||
mixer_play_effect(SPLAT);
|
||||
gGameState = GAME_OVER;
|
||||
}
|
||||
|
||||
|
|
53
src/mixer.c
53
src/mixer.c
|
@ -2,9 +2,28 @@
|
|||
#include "mixer.h"
|
||||
#include "util.h"
|
||||
|
||||
static Mix_Music *music = NULL;
|
||||
static Mix_Music *music[LAST_MUSIC];
|
||||
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*
|
||||
load_effect(char *path)
|
||||
{
|
||||
|
@ -18,6 +37,21 @@ static void
|
|||
load_effects(void)
|
||||
{
|
||||
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
|
||||
|
@ -27,9 +61,7 @@ mixer_init(void)
|
|||
fatal("Failed to load sound: %s", Mix_GetError());
|
||||
}
|
||||
load_effects();
|
||||
music = Mix_LoadMUS("assets/Sounds/Music/fantasy-forest-battle.ogg");
|
||||
if (music == NULL)
|
||||
fatal("Failed to load music: %s", Mix_GetError());
|
||||
load_music();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -40,12 +72,12 @@ mixer_play_effect(Fx fx)
|
|||
}
|
||||
|
||||
void
|
||||
mixer_play_music(void)
|
||||
mixer_play_music(Music mus)
|
||||
{
|
||||
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");
|
||||
}
|
||||
|
||||
|
@ -59,10 +91,9 @@ mixer_stop_music(void)
|
|||
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]);
|
||||
}
|
||||
if (music)
|
||||
Mix_FreeMusic(music);
|
||||
for (size_t i = 0; i < LAST_MUSIC; ++i)
|
||||
Mix_FreeMusic(music[i]);
|
||||
Mix_CloseAudio();
|
||||
}
|
||||
|
|
25
src/mixer.h
25
src/mixer.h
|
@ -3,8 +3,31 @@
|
|||
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef enum Music_t {
|
||||
MENU_MUSIC,
|
||||
GAME_MUSIC0,
|
||||
GAME_MUSIC1,
|
||||
GAME_MUSIC2,
|
||||
LAST_MUSIC
|
||||
} Music;
|
||||
|
||||
typedef enum Fx_t {
|
||||
CLICK,
|
||||
SWING0,
|
||||
SWING1,
|
||||
SWING2,
|
||||
SWORD_HIT,
|
||||
BONK,
|
||||
DEATH,
|
||||
COIN,
|
||||
BOTTLE,
|
||||
BUBBLE0,
|
||||
BUBBLE1,
|
||||
BUBBLE2,
|
||||
EAT,
|
||||
LEVEL_UP,
|
||||
NEXT_LEVEL,
|
||||
SPLAT,
|
||||
LAST_EFFECT
|
||||
} Fx;
|
||||
|
||||
|
@ -15,7 +38,7 @@ void
|
|||
mixer_play_effect(Fx fx);
|
||||
|
||||
void
|
||||
mixer_play_music(void);
|
||||
mixer_play_music(Music);
|
||||
|
||||
void
|
||||
mixer_stop_music(void);
|
||||
|
|
15
src/player.c
15
src/player.c
|
@ -9,6 +9,7 @@
|
|||
#include "item.h"
|
||||
#include "particle_engine.h"
|
||||
#include "keyboard.h"
|
||||
#include "mixer.h"
|
||||
|
||||
#define ENGINEER_STATS { 12, 12, 5, 7, 2, 1, 1 }
|
||||
#define MAGE_STATS { 12, 12, 5, 7, 2, 1, 1 }
|
||||
|
@ -19,6 +20,8 @@
|
|||
static void
|
||||
player_levelup(Player *player)
|
||||
{
|
||||
mixer_play_effect(LEVEL_UP);
|
||||
|
||||
player->stats.lvl += 1;
|
||||
player->stats.maxhp += 3;
|
||||
player->stats.dmg += 5;
|
||||
|
@ -74,12 +77,17 @@ has_collided(Player *player, RoomMatrix *matrix)
|
|||
if (space->monster != NULL) {
|
||||
unsigned int hit = stats_fight(&player->stats,
|
||||
&space->monster->stats);
|
||||
|
||||
mixer_play_effect(SWING0 + (rand() % 3));
|
||||
|
||||
monster_hit(space->monster, hit);
|
||||
|
||||
if (hit > 0)
|
||||
if (hit > 0) {
|
||||
player->hits += 1;
|
||||
else
|
||||
mixer_play_effect(SWORD_HIT);
|
||||
} else {
|
||||
player->misses += 1;
|
||||
}
|
||||
|
||||
if (hit > 0)
|
||||
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;
|
||||
player->kills += 1;
|
||||
|
||||
mixer_play_effect(DEATH);
|
||||
gui_log("You killed %s and gained %d xp",
|
||||
space->monster->lclabel, gained_xp);
|
||||
player_gain_xp(player, gained_xp);
|
||||
}
|
||||
} else if (collided) {
|
||||
mixer_play_effect(BONK);
|
||||
gui_log("Ouch! There is something in the way");
|
||||
}
|
||||
|
||||
|
@ -170,6 +180,7 @@ sip_health(Player *player)
|
|||
if (player->potion_sips > 0) {
|
||||
--player->potion_sips;
|
||||
++player->stats.hp;
|
||||
mixer_play_effect(BUBBLE0 + (rand() % 3));
|
||||
gui_log("You take a sip of health potion");
|
||||
} else {
|
||||
gui_log("You have nothing to sip");
|
||||
|
|
Loading…
Reference in New Issue