Commit 93a2ab6f authored by Paul GEORGES's avatar Paul GEORGES
Browse files

Son

parent 2450476c
File added
File added
File added
File added
File added
File added
File added
......@@ -61,14 +61,15 @@ void afficher_listeB(SDL_Renderer *renderer, ListeB L) {
}
}
ListeB tir_update(ListeB LB, ListeP LP, ListeR LR, ListeE *LE, int time, SDL_Texture *balleLongueJaune, int v, int xCamera, int yCamera, SDL_Texture **sprites){
ListeB tir_update(ListeB LB, ListeP LP, ListeR LR, ListeE *LE, int time, SDL_Texture *balleLongueJaune, int v, int xCamera, int yCamera, SDL_Texture **sprites, Mix_Chunk **sons){
//Si perso en train de tirer
s_ListeP *tmp = LP;
while(tmp != NULL){
if(tmp->data.tir && tmp->data.ennemi == false){
//On fait pop une nouvelle balle toutes les X ms
if(time > tmp->data.tempsTirPrecedent + 200) {
if(time > tmp->data.tempsTirPrecedent + 400) {
cons_listeB(&LB, nouvelle_balle(balleLongueJaune, tmp->data.angle, tmp->data.degats, tmp->data.pos));
Mix_PlayChannel(1, sons[0], 0);
tmp->data.tempsTirPrecedent = time;
}
}
......
......@@ -16,6 +16,6 @@ void cons_listeB(ListeB *L, balle data);
bool est_vide_listeB(ListeB L);
ListeB incrementer_balles(ListeB LB, ListeP LP, ListeR LR, ListeE *LE, int v, int xCamera, int yCamera, SDL_Texture **sprites);
void afficher_listeB(SDL_Renderer *renderer, ListeB L);
ListeB tir_update(ListeB LB, ListeP LP, ListeR LR, ListeE *LE, int time, SDL_Texture *balleLongueJaune, int v, int xCamera, int yCamera, SDL_Texture **sprites);
ListeB tir_update(ListeB LB, ListeP LP, ListeR LR, ListeE *LE, int time, SDL_Texture *balleLongueJaune, int v, int xCamera, int yCamera, SDL_Texture **sprites, Mix_Chunk **sons);
......@@ -18,19 +18,26 @@ int main(int argc, char *argv[])
ListeR mursListe;
ListeE effetsListe;
Perso p, *joueur_ptr;
Mix_Music *musique;
Mix_Chunk *sons[2];
//Initialisation SDL
if(SDL_Init(SDL_INIT_VIDEO < 0))
if(SDL_Init(SDL_INIT_EVERYTHING))
{
printf("Erreur d'initialisation de la SDL %s", SDL_GetError());
SDL_Quit();
return EXIT_FAILURE;
}
//Initialisation SDL_image (PNG)
IMG_Init(IMG_INIT_PNG);
//Mix_Init(MIX_INIT_MP3);
if( Mix_OpenAudio(44100, AUDIO_S16, 1, 4096) < 0 )
{
printf("Erreur d'initialisation de la SDL %s", Mix_GetError() );
SDL_Quit();
return EXIT_FAILURE;
}
//Cration fentre
fenetre = SDL_CreateWindow("gameName", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1000, 700, SDL_WINDOW_RESIZABLE);
......@@ -66,6 +73,11 @@ int main(int argc, char *argv[])
tmp = charger_image("sprites/effets/blood/blood_hitv3.png", ecran, 0, 0, -1);
sprites[3] = tmp;
//Sons
musique = NULL;
charger_sons(&musique, &sons[0]);
exit = false;
while(!exit){
......@@ -154,6 +166,11 @@ int main(int argc, char *argv[])
}
}
if( Mix_PlayingMusic() == 0 ) {
Mix_VolumeMusic(10);
Mix_FadeInMusic(musique, 1, 1000);
}
joueur_ptr = joueur(persosListe);
if(joueur_ptr != NULL){
......@@ -182,7 +199,7 @@ int main(int argc, char *argv[])
//Tir
tempsActuelTir = SDL_GetTicks();
ballesTirees = tir_update(ballesTirees, persosListe, mursListe, &effetsListe, tempsActuelTir, balleSprite, vitesse, xCamera, yCamera, sprites);
ballesTirees = tir_update(ballesTirees, persosListe, mursListe, &effetsListe, tempsActuelTir, balleSprite, vitesse, xCamera, yCamera, sprites, &sons[0]);
//Affichage
SDL_RenderClear(ecran);
......@@ -203,9 +220,11 @@ int main(int argc, char *argv[])
//Nettoyage
SDL_DestroyWindow(fenetre);
SDL_DestroyRenderer(ecran);
SDL_DestroyTexture(balleSprite);;
SDL_DestroyTexture(tmp);
IMG_Quit();
Mix_FreeMusic(musique);
Mix_CloseAudio();
SDL_Quit();
return EXIT_SUCCESS;
}
......@@ -2,8 +2,11 @@
#include <stdbool.h>
#include <math.h>
#include <stdlib.h>
#include "son.h"
#define PI 3.14159265359
typedef struct s_Balle balle, s_Balle;
struct s_Balle
{
......
#include "son.h"
void charger_sons(Mix_Music **musique, Mix_Chunk **sons){
*musique = Mix_LoadMUS("son/musique.mp3");
sons[0] = Mix_LoadWAV("son/pistolet.mp3");
Mix_VolumeChunk(sons[0], 50);
return;
}
#include <SDL2/SDL_mixer.h>
#include <stdlib.h>
void charger_sons(Mix_Music **musique, Mix_Chunk **sons);
No preview for this file type
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment