Skip to content
Snippets Groups Projects
Commit 6eed3fcd authored by Paul GEORGES's avatar Paul GEORGES
Browse files

Ajout armes

parent bc88b261
Branches
No related tags found
No related merge requests found
Showing
with 120 additions and 74 deletions
......@@ -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 coordonnes des balles dj tires, dpop si ncssaire
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;
}
......
......@@ -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);
......@@ -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;
......
......@@ -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);
......
......@@ -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;
//gnre des coordonnes de spawn alatoires 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;
}
......@@ -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);
#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);
}
......
......@@ -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;
}
File moved
File moved
sprites/perso/survivor_handgun.png

12.3 KiB

sprites/perso/survivor_idle.png

34.6 KiB

sprites/perso/survivor_rifle - Copie.png

13 KiB

sprites/perso/survivor_rifle.png

13 KiB | W: | H:

sprites/perso/survivor_rifle.png

30.7 KiB | W: | H:

sprites/perso/survivor_rifle.png
sprites/perso/survivor_rifle.png
sprites/perso/survivor_rifle.png
sprites/perso/survivor_rifle.png
  • 2-up
  • Swipe
  • Onion skin
sprites/perso/survivor_shotgun.png

38.1 KiB | W: | H:

sprites/perso/survivor_shotgun.png

12.7 KiB | W: | H:

sprites/perso/survivor_shotgun.png
sprites/perso/survivor_shotgun.png
sprites/perso/survivor_shotgun.png
sprites/perso/survivor_shotgun.png
  • 2-up
  • Swipe
  • Onion skin
sprites/projectiles/balle/balle_handgun.png

329 B

sprites/projectiles/balle/balle_longue_jaune - Copie.png

762 B

sprites/projectiles/balle/balle_longue_jaune.png

758 B

sprites/projectiles/balle/balle_rifle.png

327 B

sprites/projectiles/balle/balle_shotgun.png

327 B

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment