2014-04-10 14:33:33 +02:00
|
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
|
#include <SDL2/SDL_mixer.h>
|
|
|
|
|
#include <SDL2/SDL_main.h>
|
2014-04-05 10:34:16 +02:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
int continuer = 1;
|
2014-04-10 14:33:33 +02:00
|
|
|
|
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
|
2014-04-05 10:34:16 +02:00
|
|
|
|
SDL_Event event;
|
|
|
|
|
if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 1024) == -1) //Initialisation de l'API Mixer
|
|
|
|
|
{
|
|
|
|
|
printf("%s", Mix_GetError());
|
|
|
|
|
}
|
|
|
|
|
Mix_Music *musique; //Creation du pointeur de type Mix_Music
|
2014-04-10 14:33:33 +02:00
|
|
|
|
musique = Mix_LoadMUS("trigger.wav"); //Chargement de la musique
|
2014-04-05 10:34:16 +02:00
|
|
|
|
|
|
|
|
|
while(continuer)
|
|
|
|
|
{
|
|
|
|
|
SDL_WaitEvent(&event);
|
|
|
|
|
switch(event.type)
|
|
|
|
|
{
|
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
|
Mix_PlayMusic(musique, -1); //Jouer en boucle tant que la touche est enfoncee
|
|
|
|
|
SDL_WaitEvent(&event);
|
|
|
|
|
switch(event.type)
|
|
|
|
|
{
|
|
|
|
|
case SDL_KEYUP:
|
|
|
|
|
Mix_HaltMusic(); //Arreter la boucle si la touche est relachee
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
while(continuer)
|
|
|
|
|
{
|
|
|
|
|
SDL_WaitEvent(&event);
|
|
|
|
|
switch(event.type)
|
|
|
|
|
{
|
|
|
|
|
case SDL_QUIT:
|
|
|
|
|
continuer = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Mix_FreeMusic(musique); //Lib<69>ration de la musique
|
|
|
|
|
Mix_CloseAudio(); //Fermeture de l'API
|
|
|
|
|
SDL_Quit();
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
|
}
|