diff --git a/listeB.c b/listeB.c index 24650716c27ebad6324db7698a9cc4113be2641c..dbdbc9e464597bad730bac10df1099e68f254ab0 100644 --- a/listeB.c +++ b/listeB.c @@ -15,7 +15,7 @@ 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) +ListeB incrementer_balles(ListeB LB, ListeP LP, ListeR LR, ListeE *LE, int v, int xCamera, int yCamera, int *nbTues, SDL_Texture **sprites) { if(LB == NULL){ return LB; @@ -26,13 +26,24 @@ ListeB incrementer_balles(ListeB LB, ListeP LP, ListeR LR, ListeE *LE, int v, in SDL_Rect ballePos; ballePos.w = 1; ballePos.h = 1; - ballePos.x = LB->data.ballePos.x + 20; - ballePos.y = LB->data.ballePos.y + 20; + if(LB->data.angle >= -45 && LB->data.angle < 45){ + ballePos.x = LB->data.ballePos.x + 50; + ballePos.y = LB->data.ballePos.y + 15; + } else if(LB->data.angle >= 45 && LB->data.angle < 135){ + ballePos.x = LB->data.ballePos.x + 30; + ballePos.y = LB->data.ballePos.y + 30; + } else if(LB->data.angle >= -135 && LB->data.angle < -45){ + ballePos.x = LB->data.ballePos.x + 35; + ballePos.y = LB->data.ballePos.y; + } else { + ballePos.x = LB->data.ballePos.x + 15; + ballePos.y = LB->data.ballePos.y; + } if(ballePos.x < 0 || ballePos.x >= 1000 || ballePos.y <= 0 || ballePos.y >= 700 || detecter_collision_murs(LR, ballePos, xCamera, yCamera)){ LB = LB->next; - return incrementer_balles(LB, LP, LR, LE, v, xCamera, yCamera, sprites); + return incrementer_balles(LB, LP, LR, LE, v, xCamera, yCamera, nbTues, sprites); } ballePos.w = 2; @@ -40,17 +51,14 @@ ListeB incrementer_balles(ListeB LB, ListeP LP, ListeR LR, ListeE *LE, int v, in ballePos.x = LB->data.ballePos.x; ballePos.y = LB->data.ballePos.y; - - if(detecter_collision_perso(LP, LE, ballePos, LB->data.angle, LB->data.degats, xCamera, yCamera, sprites)) { + if(detecter_collision_perso(LP, LE, ballePos, LB->data.angle, LB->data.degats, xCamera, yCamera, nbTues, sprites)) { LB = LB->next; - return incrementer_balles(LB, LP, LR, LE, v, xCamera, yCamera, sprites); + return incrementer_balles(LB, LP, LR, LE, v, xCamera, yCamera, nbTues, sprites); } - - LB->next = incrementer_balles(LB->next, LP, LR, LE, v, xCamera, yCamera, sprites); + LB->next = incrementer_balles(LB->next, LP, LR, LE, v, xCamera, yCamera, nbTues, sprites); return LB; - return NULL; } @@ -62,23 +70,43 @@ 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, Mix_Chunk **sons){ - //Si perso en train de tirer +ListeB tir_update(ListeB LB, ListeP LP, ListeR LR, ListeE *LE, int time, int v, int xCamera, int yCamera, int *nbTues, SDL_Texture **sprites, Mix_Chunk **sons){ 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 + 80) { - 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; + int arme; + arme = tmp->data.arme; + switch(arme){ + case 0: + if(time > tmp->data.tempsTirPrecedent + 250){ + cons_listeB(&LB, nouvelle_balle(sprites[7], tmp->data.angle, 25, tmp->data.pos)); + Mix_PlayChannel(1, sons[0], 0); + tmp->data.tempsTirPrecedent = time; + } + break; + case 1: + if(time > tmp->data.tempsTirPrecedent + 1500){ + cons_listeB(&LB, nouvelle_balle(sprites[8], tmp->data.angle - 1.5, 100, tmp->data.pos)); + cons_listeB(&LB, nouvelle_balle(sprites[8], tmp->data.angle + 1.5, 100, tmp->data.pos)); + cons_listeB(&LB, nouvelle_balle(sprites[8], tmp->data.angle - 3, 100, tmp->data.pos)); + cons_listeB(&LB, nouvelle_balle(sprites[8], tmp->data.angle + 3, 100, tmp->data.pos)); + Mix_PlayChannel(1, sons[1], 0); + tmp->data.tempsTirPrecedent = time; + } + break; + case 2: + if(time > tmp->data.tempsTirPrecedent + 80){ + cons_listeB(&LB, nouvelle_balle(sprites[9], tmp->data.angle, 25, tmp->data.pos)); + Mix_PlayChannel(1, sons[2], 0); + tmp->data.tempsTirPrecedent = time; + } + break; } } tmp = tmp->next; } - //On met a jour les coordonn�es des balles d�j� tir�es, d�pop si n�c�ssaire - LB = incrementer_balles(LB, LP, LR, LE, v, xCamera, yCamera, sprites); + LB = incrementer_balles(LB, LP, LR, LE, v, xCamera, yCamera, nbTues, sprites); return LB; } diff --git a/listeB.h b/listeB.h index ab28f4b3c2c7b06edb23209a016962150529d220..a5771570897597a0901d0f8391b1e9ad827b77e1 100644 --- a/listeB.h +++ b/listeB.h @@ -14,8 +14,8 @@ struct s_ListeB 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); +ListeB incrementer_balles(ListeB LB, ListeP LP, ListeR LR, ListeE *LE, int v, int xCamera, int yCamera, int *nbTues, 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, Mix_Chunk **sons); +ListeB tir_update(ListeB LB, ListeP LP, ListeR LR, ListeE *LE, int time, int v, int xCamera, int yCamera, int *nbTues, SDL_Texture **sprites, Mix_Chunk **sons); diff --git a/listeP.c b/listeP.c index c2bc49d754d5a777f5811d2cceb097bab20d6180..9811d014456c8749f93d079e43c57c3af1f116dc 100644 --- a/listeP.c +++ b/listeP.c @@ -47,7 +47,6 @@ void deplacement_ennemi(Perso *p, ListeR LR, Perso *joueur, int xCamera, int yCa if(p != NULL){ if(p->ennemi){ angle_ennemi(p); - if(p->collision == 0){ detecter_collision_murs_ennemis(LR, p, xCamera, yCamera); p->pos.x = p->pos.x + round(-dxCamera + cos(p->angle) * p->vitesse); @@ -86,25 +85,15 @@ void deplacement_ennemi(Perso *p, ListeR LR, Perso *joueur, int xCamera, int yCa void deplacement_ennemis(ListeP LP, ListeR LR, ListeE *LE, SDL_Texture **sprites, int xCamera, int yCamera, int dxCamera, int dyCamera){ Perso *joueur_ptr = joueur(LP); while(LP != NULL){ - if(LP->data.vie <= 0 && LP->data.ennemi){ - Effet e; - e = nouvel_effet_bloodSplatter(sprites, LP->data.pos, LP->data.angle); - cons_listeE(LE, e); - *LP = *LP->next; - LP = LP->next; - } else { - deplacement_ennemi(&LP->data, LR, joueur_ptr, xCamera, yCamera, dxCamera, dyCamera); - LP = LP->next; - } + deplacement_ennemi(&LP->data, LR, joueur_ptr, xCamera, yCamera, dxCamera, dyCamera); + LP = LP->next; } return; } -bool detecter_collision_perso(ListeP L, ListeE *LE, SDL_Rect rect, int angle, int degats, int xCamera, int yCamera, SDL_Texture **sprites){ - +bool detecter_collision_perso(ListeP L, ListeE *LE, SDL_Rect rect, int angle, int degats, int xCamera, int yCamera, int *nbTues, SDL_Texture **sprites){ int ax1, ax2, bx1, bx2, ay1, ay2, by1, by2; Effet e; - while(L != NULL){ ax1 = rect.x; ax2 = rect.x + rect.w; @@ -116,25 +105,34 @@ bool detecter_collision_perso(ListeP L, ListeE *LE, SDL_Rect rect, int angle, in by2 = L->data.pos.y + L->data.pos.h; //correction hitbox if(angle >= -45 && angle < 45){ - by1 -= 0.6 * L->data.pos.h; - by2 -= 0.6 * L->data.pos.h; + by1 -= 0.4 * L->data.pos.h; + by2 -= 0.4 * L->data.pos.h; + bx1 -= 0.8 * L->data.pos.w; } else if(angle >= 45 && angle < 135){ - bx1 -= 0.1 * L->data.pos.w; - bx2 -= 0.2 * L->data.pos.w; - } else if(angle >= -135 && angle < -45){ bx1 -= 0.4 * L->data.pos.w; bx2 -= 0.6 * L->data.pos.w; - by2 -= 0.5 * L->data.pos.h; + by1 -= 0.5 * L->data.pos.h; + } else if(angle >= -135 && angle < -45){ + bx1 -= 0.7 * L->data.pos.w; + bx2 -= 0.9 * L->data.pos.w; } else { by1 -= 0.1 * L->data.pos.h; by2 -= 0.3 * L->data.pos.h; bx2 -= 0.5 * L->data.pos.w; + bx1 -= 0.5 * L->data.pos.w; } if(ax1 < bx2 && ax2 > bx1 && ay1 < by2 && ay2 > by1 && L->data.ennemi){ L->data.vie -= degats; e = nouvel_effet_bloodHit(sprites, L->data.pos, L->data.angle); cons_listeE(LE, e); + + if(L->data.vie <= 0){ + e = nouvel_effet_bloodSplatter(sprites, L->data.pos, L->data.angle); + cons_listeE(LE, e); + *nbTues += 1; + *L = *L->next; + } return true; } L = L->next; @@ -149,12 +147,12 @@ void detecter_collision_avec_joueur(Perso *p, Perso *joueur){ ax1 = p->pos.x; ax2 = p->pos.x + p->pos.w ; - bx1 = joueur->pos.x + 0.3 * joueur->pos.w; - bx2 = joueur->pos.x + 0.7 * joueur->pos.w; + bx1 = joueur->pos.x + round(0.24 * joueur->pos.w); + bx2 = joueur->pos.x + round(0.75 * joueur->pos.w); ay1 = p->pos.y; ay2 = p->pos.y + p->pos.h; - by1 = joueur->pos.y + 0.3 * joueur->pos.h; - by2 = joueur->pos.y + 0.7 * joueur->pos.h; + by1 = joueur->pos.y; + by2 = joueur->pos.y + joueur->pos.h; if(ax1 < bx2 && ax2 > bx1 && ay1 < by2 && ay2 > by1){ p->tir = true; diff --git a/listeP.h b/listeP.h index dcb67a1e9af25555c3381ddd75093c7454adfc15..24b17b8217a4e12c8bdbbf09f8ddaa45f12ecade 100644 --- a/listeP.h +++ b/listeP.h @@ -20,7 +20,7 @@ Perso* joueur(ListeP L); void supprimer_ennemi(ListeP L); void deplacement_ennemi(Perso *p, ListeR LR, Perso *joueur, int xCamera, int yCamera, int dxCamera, int dyCamera); void deplacement_ennemis(ListeP LP, ListeR LR, ListeE *LE, SDL_Texture **sprites, int xCamera, int yCamera, int dxCamera, int dyCamera); -bool detecter_collision_perso(ListeP L, ListeE *LE, SDL_Rect rect, int angle, int degats, int xCamera, int yCamera, SDL_Texture **sprites); +bool detecter_collision_perso(ListeP L, ListeE *LE, SDL_Rect rect, int angle, int degats, int xCamera, int yCamera, int *nbTues, SDL_Texture **sprites); void detecter_collision_avec_joueur(Perso *p, Perso *joueur); void animer_persos(ListeP L, SDL_Texture **sprites, Perso *joueur); void charger_vague_ennemis(SDL_Renderer *renderer, bool *b, int *vaguesEnnemis, int vagueNum,int xCamera, int yCamera, ListeP *LP, ListeR LR, SDL_Texture **sprites); diff --git a/personnage.c b/personnage.c index cc5cfa9f60db101c724631b07a6618bd69ead0be..8ad05d51e1cd178cd3f26784b28e68d3e9cb1bc5 100644 --- a/personnage.c +++ b/personnage.c @@ -5,19 +5,19 @@ Perso nouveau_joueur(SDL_Renderer *renderer, SDL_Texture **sprites){ Perso p; p.tempsTirPrecedent = 0; p.image = sprites[0]; - p.pos.x = 480; - p.pos.y = 330; - p.pos.w = 50; - p.pos.h = 35; + p.pos.x = 465; + p.pos.y = 335; + p.pos.w = 70; + p.pos.h = 30; p.srcrect.x = 0; p.srcrect.y = 0; - p.srcrect.w = 258; - p.srcrect.h = 220; + p.srcrect.w = 395; + p.srcrect.h = 151; p.angle = 0; p.vie = 100; - p.degats = 25; p.vitesse = 4; p.yMax = 0; + p.arme = 0; p.tir = false; p.ennemi = false; p.collision = 0; @@ -31,7 +31,6 @@ Perso nouvel_ennemi_1(SDL_Renderer *renderer, ListeR LR, SDL_Texture **sprites, p.image = sprites[1]; p.pos.w = 50; p.pos.h = 50; - //g�n�re des coordonn�es de spawn al�atoires hors du champ de vision du joueur et hors des hitbox int x, y; do { do { @@ -44,8 +43,6 @@ Perso nouvel_ennemi_1(SDL_Renderer *renderer, ListeR LR, SDL_Texture **sprites, p.pos.y = y; } while(detecter_collision_murs(LR, p.pos, xCamera, yCamera)); - - p.srcrect.x = 0; p.srcrect.y = 0; p.srcrect.w = 229; @@ -55,6 +52,7 @@ Perso nouvel_ennemi_1(SDL_Renderer *renderer, ListeR LR, SDL_Texture **sprites, p.degats = 10; p.vitesse = 2; p.yMax = 4403; + p.arme = -1; p.tir = false; p.ennemi = true; p.collision = 0; @@ -115,16 +113,20 @@ void deplacement_joueur(Perso *p, ListeR L, int *xCamera, int *yCamera, int *dxC *dxCamera = dX; *dyCamera = dY; - - if(detecter_collision_murs(L, p->pos, *xCamera, *yCamera)){ + SDL_Rect pos = p->pos; + pos.x += 15; + pos.w -= 30; + pos.y -= 3; + pos.h += 10; + if(detecter_collision_murs(L, pos, *xCamera, *yCamera)){ *xCamera -= dX; *dxCamera = 0; - if(detecter_collision_murs(L, p->pos, *xCamera, *yCamera)){ + if(detecter_collision_murs(L, pos, *xCamera, *yCamera)){ *xCamera += dX; *dxCamera = dX; *yCamera -= dY; *dyCamera = 0; - if(detecter_collision_murs(L, p->pos, *xCamera, *yCamera)){ + if(detecter_collision_murs(L, pos, *xCamera, *yCamera)){ *xCamera -= dX; *dxCamera = 0; } @@ -137,16 +139,16 @@ void deplacement_joueur(Perso *p, ListeR L, int *xCamera, int *yCamera, int *dxC void angle_joueur(Perso *p, float mouseX, float mouseY){ float angle; - angle = atan2(mouseY - (p->pos.y + 20), mouseX - (p->pos.x + 20)); + angle = atan2(mouseY - (p->pos.y + p->pos.h/2), mouseX - (p->pos.x + p->pos.w/2)); angle = (angle * 180.0000)/PI; - angle -= 1; + angle -= 2; p->angle = angle; return; } void angle_ennemi(Perso *p){ float angle; - angle = atan2(350 - (p->pos.y + 20), 500 - (p->pos.x + 20)); + angle = atan2(350 - (p->pos.y + 25), 500 - (p->pos.x + 25)); p->angle = angle; return; } @@ -224,4 +226,20 @@ void detecter_collision_murs_ennemis(ListeR L, Perso *p, int xCamera, int yCamer } - +void changer_arme_joueur(Perso *p, int arme, SDL_Texture **sprites){ + switch(arme){ + case 0: + p->image = sprites[0]; + p->tempsTirPrecedent = 0; + break; + case 1: + p->image = sprites[10]; + p->tempsTirPrecedent = 0; + break; + case 2: + p->image = sprites[11]; + p->tempsTirPrecedent = 0; + break; + } + return; +} diff --git a/personnage.h b/personnage.h index 7947b73c70b56ab607a72f6c8986ba1fe1c347de..ee5c867631e0e064f1cfe78ede803134f59f3041 100644 --- a/personnage.h +++ b/personnage.h @@ -7,7 +7,6 @@ #define PI 3.14159265359 - typedef struct s_Personnage Perso; struct s_Personnage { @@ -21,9 +20,10 @@ struct s_Personnage int vitesse; int animFlip; int yMax; + int arme; + int collision; bool tir; bool ennemi; - int collision; }; @@ -36,3 +36,4 @@ void angle_ennemi(Perso *p); void angle_joueur(Perso *p, float mouseX, float mouseY); void animer_perso(Perso *p, Perso *joueur, SDL_Texture **sprites); void detecter_collision_murs_ennemis(ListeR L, Perso *p, int xCamera, int yCamera); +void changer_arme_joueur(Perso *p, int arme, SDL_Texture **sprites); diff --git a/projectile.c b/projectile.c index 56292f2f4dd417efe2824ac8978e45446f1c4150..19322075397e9f49a57e96dae9eae770003e89ff 100644 --- a/projectile.c +++ b/projectile.c @@ -1,8 +1,8 @@ #include "projectile.h" -balle nouvelle_balle(SDL_Texture *image, float angle, int degats, SDL_Rect persoPos) -{ + +balle nouvelle_balle(SDL_Texture *image, float angle, int degats, SDL_Rect persoPos){ balle b; b.angle = angle; b.collision = false; @@ -12,16 +12,13 @@ balle nouvelle_balle(SDL_Texture *image, float angle, int degats, SDL_Rect perso return b; } - -void incrementer_balle(balle *b, int v) -{ +void incrementer_balle(balle *b, int v){ b->ballePos.x += round(cos(b->angle * PI / 180) * v); b->ballePos.y += round(sin(b->angle * PI / 180) * v); } -void afficher_balle(SDL_Renderer *renderer, balle b) -{ +void afficher_balle(SDL_Renderer *renderer, balle b){ SDL_RenderCopyEx(renderer, b.image, NULL, &b.ballePos, b.angle, NULL, SDL_FLIP_NONE); } diff --git a/son.c b/son.c index e72a4fffd2672ff54a9089c44ead01e1bdac3dc5..91616e2752c2c86909109695f269b2f70375fcef 100644 --- a/son.c +++ b/son.c @@ -3,8 +3,12 @@ void charger_sons(Mix_Music **musique, Mix_Chunk **sons){ *musique = Mix_LoadMUS("son/musique.mp3"); - sons[0] = Mix_LoadWAV("son/machinegun.mp3"); + sons[0] = Mix_LoadWAV("son/handgun.mp3"); + sons[1] = Mix_LoadWAV("son/shotgun.mp3"); + sons[2] = Mix_LoadWAV("son/rifle.mp3"); Mix_VolumeChunk(sons[0], 40); + Mix_VolumeChunk(sons[1], 20); + Mix_VolumeChunk(sons[2], 40); return; } diff --git a/son/tir.mp3 b/son/handgun.mp3 similarity index 100% rename from son/tir.mp3 rename to son/handgun.mp3 diff --git a/son/machinegun.mp3 b/son/rifle.mp3 similarity index 100% rename from son/machinegun.mp3 rename to son/rifle.mp3 diff --git a/sprites/perso/survivor_handgun.png b/sprites/perso/survivor_handgun.png new file mode 100644 index 0000000000000000000000000000000000000000..df9c811d8a19ff8c2bd936439ca7bef91206dd75 Binary files /dev/null and b/sprites/perso/survivor_handgun.png differ diff --git a/sprites/perso/survivor_idle.png b/sprites/perso/survivor_idle.png deleted file mode 100644 index fa290f62b80ffdd875e57ce5168b89a468351675..0000000000000000000000000000000000000000 Binary files a/sprites/perso/survivor_idle.png and /dev/null differ diff --git a/sprites/perso/survivor_rifle - Copie.png b/sprites/perso/survivor_rifle - Copie.png deleted file mode 100644 index b25528834c1d6a094c229201d33dfb63c56d09d2..0000000000000000000000000000000000000000 Binary files a/sprites/perso/survivor_rifle - Copie.png and /dev/null differ diff --git a/sprites/perso/survivor_rifle.png b/sprites/perso/survivor_rifle.png index b25528834c1d6a094c229201d33dfb63c56d09d2..9d2a926dcc40e2c53d789093ac0d290f30b5ba93 100644 Binary files a/sprites/perso/survivor_rifle.png and b/sprites/perso/survivor_rifle.png differ diff --git a/sprites/perso/survivor_shotgun.png b/sprites/perso/survivor_shotgun.png index 77f9104ff599c10f87b83a18dae535e83a4537d3..7811f7976703dfff02c780dcb48d16c6bad04602 100644 Binary files a/sprites/perso/survivor_shotgun.png and b/sprites/perso/survivor_shotgun.png differ diff --git a/sprites/projectiles/balle/balle_handgun.png b/sprites/projectiles/balle/balle_handgun.png new file mode 100644 index 0000000000000000000000000000000000000000..cc554bf88aad0012752acae8f6007a31e97d47b3 Binary files /dev/null and b/sprites/projectiles/balle/balle_handgun.png differ diff --git a/sprites/projectiles/balle/balle_longue_jaune - Copie.png b/sprites/projectiles/balle/balle_longue_jaune - Copie.png deleted file mode 100644 index 4319282e5b3431ffb34da6b59e6c93242e188ca9..0000000000000000000000000000000000000000 Binary files a/sprites/projectiles/balle/balle_longue_jaune - Copie.png and /dev/null differ diff --git a/sprites/projectiles/balle/balle_longue_jaune.png b/sprites/projectiles/balle/balle_longue_jaune.png deleted file mode 100644 index 9a4b9ce8c5c1554054803a80ebe380b301a03c99..0000000000000000000000000000000000000000 Binary files a/sprites/projectiles/balle/balle_longue_jaune.png and /dev/null differ diff --git a/sprites/projectiles/balle/balle_rifle.png b/sprites/projectiles/balle/balle_rifle.png new file mode 100644 index 0000000000000000000000000000000000000000..e1801d1c5bc4db29b656aef87c5b92fb650a8986 Binary files /dev/null and b/sprites/projectiles/balle/balle_rifle.png differ diff --git a/sprites/projectiles/balle/balle_shotgun.png b/sprites/projectiles/balle/balle_shotgun.png new file mode 100644 index 0000000000000000000000000000000000000000..e1801d1c5bc4db29b656aef87c5b92fb650a8986 Binary files /dev/null and b/sprites/projectiles/balle/balle_shotgun.png differ