Skip to content
Snippets Groups Projects
Commit 661ababf authored by Denys's avatar Denys
Browse files

added functions working with music, updated documentation

parent 11b358ab
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@
/// @brief Main file responsible for game functionality
/// @author Mathieu Constant, Denys SHCHERBA, Ivan OSADTSIV
/// @version 1.0
/// @date 10.04.2023
/// @date 17.05.2023
#include "sdl2-light.h"
......@@ -97,13 +97,27 @@ void init_walls(world_t * world)
}
/// @brief initialisation de music
/// @param bgmsc background music
void init_music(Mix_Music * bgmsc)
{
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
Mix_Init(MIX_INIT_MP3 | MIX_INIT_OGG);
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 6, 4096);
bgmsc = Mix_LoadMUS("ressources/music/music_1.wav");
Mix_PlayMusic(bgmsc, 0);
}
/// @brief fonction qui initialise le jeu: initialisation de la partie graphique (SDL), chargement des textures, initialisation des données
/// @param window la fenêtre du jeu
/// @param renderer le renderer
/// @param textures les textures
/// @param world le monde
void init(SDL_Window **window, SDL_Renderer ** renderer, resources_t *textures, world_t * world)
/// @param bgmsc background music
void init(SDL_Window **window, SDL_Renderer ** renderer, resources_t *textures, world_t *world, Mix_Music *bgmsc)
{
init_music(bgmsc);
init_sdl(window, renderer, SCREEN_WIDTH, SCREEN_HEIGHT);
init_data(world);
init_ttf();
......@@ -113,26 +127,30 @@ void init(SDL_Window **window, SDL_Renderer ** renderer, resources_t *textures,
}
/// @brief close an open music file
/// @param bgmsc background music
void clean_music(Mix_Music *bgmsc)
{
Mix_FreeMusic(bgmsc);
Mix_CloseAudio();
Mix_HaltMusic();
Mix_Quit();
}
/// @brief programme principal qui implémente la boucle du jeu
int main( int argc, char* args[] )
{
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
Mix_Init(MIX_INIT_MP3 | MIX_INIT_OGG);
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 6, 4096);
Mix_Music * bgmsc = Mix_LoadMUS("ressources/music/music_1.wav");
Mix_PlayMusic(bgmsc, 0);
SDL_Event event;
world_t world;
resources_t textures;
SDL_Renderer *renderer;
SDL_Window *window;
Mix_Music * bgmsc;
//initialisation du jeu
init(&window,&renderer,&textures,&world);
Mix_PlayMusic(bgmsc, 0);
init(&window,&renderer,&textures,&world, bgmsc);
while(!is_game_over(&world)){ //tant que le jeu n'est pas fini
//gestion des évènements
......@@ -151,14 +169,6 @@ int main( int argc, char* args[] )
//nettoyage final
clean(window,renderer,&textures,&world);
if(Mix_PlayMusic(bgmsc, -1)==-1) {
printf("Mix_PlayMusic: %s\n", Mix_GetError());
// well, there's no music, but most games don't break without music...
}
Mix_FreeMusic(bgmsc);
Mix_CloseAudio();
Mix_HaltMusic();
Mix_Quit();
clean_music(bgmsc);
return 0;
}
/// @file space_graphics.h
/// @author SHCHERBA Denys, OSADTSIV Ivan
/// @brief File with classes and methods responsible for game graphics
/// @brief File with methods responsible for game graphics
#include "sdl2-light.h"
#include "space_logics.h"
......@@ -41,10 +41,10 @@ void apply_sprite(SDL_Renderer *renderer, SDL_Texture *texture, sprite_t *sprite
/// @param sprite sprite to apply
void apply_wall(SDL_Renderer *renderer, SDL_Texture *texture, sprite_t *sprite);
/// @brief no
/// @param renderer no
/// @param texture no
/// @param sprite no
/// @brief Applies all the walls
/// @param renderer renderer
/// @param texture texture
/// @param sprite sprite to apply
void apply_walls(SDL_Renderer *renderer, SDL_Texture *texture, world_t *world);
......
......@@ -5,7 +5,6 @@
#include "space_logics.h"
#include "space_const.h"
#include "space_graphics.h"
#include "sdl2-light.h"
int is_game_over(world_t *world)
......
/// @file test.c
/// @author SHCHERBA Denys, OSADTSIV Ivan
/// @brief file to test some important mechanics
#include "sdl2-light.h"
#include <stdio.h>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment