Commit a6972650 authored by Paul GEORGES's avatar Paul GEORGES
Browse files

Grosse Update

parent c80ee729
......@@ -10,6 +10,25 @@ Effet nouvel_effet_bloodHit(SDL_Texture **sprites, SDL_Rect pos, int angle){
e.image = sprites[3];
e.angle = angle - 90;
e.yMax = 1920;
e.id = 1;
return e;
}
Effet nouvel_effet_bloodSplatter(SDL_Texture **sprites, SDL_Rect pos, int angle){
Effet e;
e.pos = pos;
e.pos.x -= 20;
e.pos.y -= 20;
e.pos.w = 70;
e.pos.h = 70;
e.srcrect.x = 0;
e.srcrect.y = 0;
e.srcrect.w = 100;
e.srcrect.h = 100;
e.image = sprites[4];
e.angle = angle - 90;
e.yMax = 800;
e.id = 2;
return e;
}
......
#include <SDL2/SDL.h>
#include <stdio.h>
typedef struct s_Effet Effet, s_Effet;
struct s_Effet
......@@ -9,8 +9,10 @@ struct s_Effet
SDL_Texture *image;
float angle;
int yMax;
int id;
};
Effet nouvel_effet_bloodHit(SDL_Texture **sprites, SDL_Rect pos, int angle);
Effet nouvel_effet_bloodSplatter(SDL_Texture **sprites, SDL_Rect pos, int angle);
void afficher_effet(SDL_Renderer *renderer, Effet e);
#include "image.h"
SDL_Texture* charger_image(const char* cheminFichier, SDL_Renderer* renderer, int r, int g, int b)
{
SDL_Texture* charger_image(const char* cheminFichier, SDL_Renderer* renderer, int r, int g, int b){
SDL_Surface* surface = IMG_Load(cheminFichier);
if(r >= 0 && g >= 0 && b >= 0){
SDL_SetColorKey(surface, SDL_TRUE, SDL_MapRGB(surface->format, r, g, b ));
......@@ -15,14 +15,23 @@ SDL_Texture* charger_image(const char* cheminFichier, SDL_Renderer* renderer, in
void afficher_niveau(char *tab, SDL_Renderer *renderer, SDL_Texture **spriteMap, int xCamera, int yCamera){
SDL_Rect destrect;
destrect.h = 50;
destrect.w = 50;
int tabVal;
//affichage routes & murs
for(int j = 0; j < 60; j++){
for(int i = 0; i < 60; i++){
destrect.x = i * 50 - xCamera;
destrect.y = j * 50 - yCamera;
SDL_RenderCopy(renderer, spriteMap[0], NULL, &destrect);
switch(tab[60*j+i]){
destrect.h = 50;
destrect.w = 50;
tabVal = tab[60*j+i];
if(tabVal != '.' && tabVal != 'A' && tabVal != 'P'){
SDL_RenderCopy(renderer, spriteMap[0], NULL, &destrect);
}
switch(tabVal){
case '0':
SDL_RenderCopy(renderer, spriteMap[0], NULL, &destrect);
break;
case '1':
SDL_RenderCopy(renderer, spriteMap[1], NULL, &destrect);
break;
......@@ -47,10 +56,80 @@ void afficher_niveau(char *tab, SDL_Renderer *renderer, SDL_Texture **spriteMap,
case '8':
SDL_RenderCopy(renderer, spriteMap[8], NULL, &destrect);
break;
case 'R':
destrect.w = 200;
destrect.h = 200;
SDL_RenderCopy(renderer, spriteMap[10], NULL, &destrect);
break;
case 'S':
destrect.w = 200;
destrect.h = 200;
SDL_RenderCopy(renderer, spriteMap[9], NULL, &destrect);
break;
case 'E':
SDL_RenderCopy(renderer, spriteMap[13], NULL, &destrect);
break;
case 'H':
SDL_RenderCopy(renderer, spriteMap[17], NULL, &destrect);
break;
case 'M':
destrect.w = 550;
destrect.h = 400;
SDL_RenderCopy(renderer, spriteMap[15], NULL, &destrect);
break;
case 'N':
destrect.w = 500;
destrect.h = 600;
SDL_RenderCopy(renderer, spriteMap[16], NULL, &destrect);
break;
case 'L':
destrect.w = 800;
destrect.h = 600;
SDL_RenderCopy(renderer, spriteMap[18], NULL, &destrect);
break;
default:
break;
}
}
}
//voitures
for(int j = 0; j < 60; j++){
for(int i = 0; i < 60; i++){
destrect.x = i * 50 - xCamera;
destrect.y = j * 50 - yCamera;
destrect.h = 50;
destrect.w = 50;
switch(tab[60*j+i]){
case 'P':
destrect.w = 200;
destrect.h = 100;
SDL_RenderCopy(renderer, spriteMap[11], NULL, &destrect);
break;
case 'A':
destrect.w = 100;
destrect.h = 200;
SDL_RenderCopy(renderer, spriteMap[12], NULL, &destrect);
break;
case 'C' :
destrect.w = 150;
destrect.h = 250;
SDL_RenderCopy(renderer, spriteMap[14], NULL, &destrect);
break;
case 'F':
destrect.w = 300;
destrect.h = 300;
SDL_RenderCopy(renderer, spriteMap[19], NULL, &destrect);
break;
default :
break;
}
}
}
return;
}
......@@ -35,12 +35,13 @@ ListeB incrementer_balles(ListeB LB, ListeP LP, ListeR LR, ListeE *LE, int v, in
return incrementer_balles(LB, LP, LR, LE, v, xCamera, yCamera, sprites);
}
ballePos.w = 6;
ballePos.h = 6;
ballePos.x = LB->data.ballePos.x - 3;
ballePos.y = LB->data.ballePos.y - 3;
ballePos.w = 2;
ballePos.h = 2;
ballePos.x = LB->data.ballePos.x;
ballePos.y = LB->data.ballePos.y;
if(detecter_collision_perso(LP, LE, ballePos, LB->data.degats ,xCamera, yCamera, sprites)) {
if(detecter_collision_perso(LP, LE, ballePos, LB->data.angle, LB->data.degats, xCamera, yCamera, sprites)) {
LB = LB->next;
return incrementer_balles(LB, LP, LR, LE, v, xCamera, yCamera, sprites);
}
......@@ -67,7 +68,7 @@ ListeB tir_update(ListeB LB, ListeP LP, ListeR LR, ListeE *LE, int time, SDL_Tex
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 + 50) {
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;
......
......@@ -12,18 +12,25 @@ void cons_listeE(ListeE *L, Effet data){
void animer_effets(ListeE L){
ListeE tmp;
while(L != NULL){
L->data.srcrect.y += L->data.srcrect.h;
if(L->data.srcrect.y >= L->data.yMax){
if(L->next == NULL){
tmp = NULL;
L = tmp;
if(L->data.id == 1){
L->data.srcrect.y += L->data.srcrect.h;
if(L->data.srcrect.y >= L->data.yMax){
if(L->next == NULL){
tmp = NULL;
L = tmp;
} else {
tmp = malloc(sizeof(s_ListeE));
tmp->data = L->next->data;
tmp->next = L->next->next;
*L = *tmp;
}
} else {
tmp = malloc(sizeof(s_ListeE));
tmp->data = L->next->data;
tmp->next = L->next->next;
*L = *tmp;
L = L->next;
}
} else {
if(L->data.srcrect.y < L->data.yMax){
L->data.srcrect.y += L->data.srcrect.h;
}
L = L->next;
}
}
......@@ -33,7 +40,9 @@ void animer_effets(ListeE L){
void afficher_listeE(SDL_Renderer *renderer, ListeE L, int dxCamera, int dyCamera){
ListeE tmp = L;
int i = 0;
while(tmp != NULL) {
i++;
tmp->data.pos.x -= dxCamera;
tmp->data.pos.y -= dyCamera;
afficher_effet(renderer, tmp->data);
......
#include "effets.h"
#include <stdio.h>
#include <stdlib.h>
......
......@@ -42,59 +42,94 @@ Perso* joueur(ListeP L){
return NULL;
}
void deplacement_ennemi(Perso *p, Perso *joueur, int xCamera, int yCamera, int dxCamera, int dyCamera){
int dX = 0;
int dY = 0;
void deplacement_ennemi(Perso *p, ListeR LR, Perso *joueur, int xCamera, int yCamera, int dxCamera, int dyCamera){
if(p != NULL){
if(p->ennemi){
//Mj de la direction du perso
angle_ennemi(p);
//Compensation du dcalage de la camra + ajout du dplacement
dX = p->pos.x + round(-dxCamera + cos(p->angle) * p->vitesse);
dY = p->pos.y + round(-dyCamera + sin(p->angle) * p->vitesse);
//if(!detecter_collision_avec_joueur(p, joueur)){
detecter_collision_avec_joueur(p, joueur);
p->pos.x = dX;
p->pos.y = dY;
// }
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);
p->pos.y = p->pos.y + round(-dyCamera + sin(p->angle) * p->vitesse);
} if(p->collision == 1){
if(joueur->pos.y - p->pos.y < 0){
p->pos.y -= p->vitesse;
} else{
p->pos.y += p->vitesse;
}
p->pos.x -= dxCamera;
p->pos.y -= dyCamera;
if(!detecter_collision_murs(LR, p->pos, xCamera, yCamera)){
p->collision = 0;
}
} if(p->collision == 2){
if(joueur->pos.x - p->pos.x < 0){
p->pos.x -= p->vitesse;
} else{
p->pos.x += p->vitesse;
}
p->pos.x -= dxCamera;
p->pos.y -= dyCamera;
if(!detecter_collision_murs(LR, p->pos, xCamera, yCamera)){
p->collision = 0;
}
}
detecter_collision_avec_joueur(p, joueur);
p->angle = (p->angle * 180.0000)/PI;
}
}
return;
}
void deplacement_ennemis(ListeP L, int xCamera, int yCamera, int dxCamera, int dyCamera){
Perso *joueur_ptr = joueur(L);
while(L != NULL){
if(L->data.vie <= 0 && L->data.ennemi){
*L = *L->next;
L = L->next;
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(&L->data, joueur_ptr, xCamera, yCamera, dxCamera, dyCamera);
L = L->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 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, 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 ;
bx1 = L->data.pos.x - 0.3 * L->data.pos.w;
bx2 = L->data.pos.x + 0.6 * L->data.pos.w;
ax2 = rect.x + rect.w;
bx1 = L->data.pos.x ;
bx2 = L->data.pos.x + L->data.pos.w;
ay1 = rect.y;
ay2 = rect.y;
by1 = L->data.pos.y - 0.3 * L->data.pos.h;
by2 = L->data.pos.y + 0.6 * L->data.pos.h;
ay2 = rect.y + rect.h;
by1 = L->data.pos.y;
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;
} 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;
} else {
by1 -= 0.1 * L->data.pos.h;
by2 -= 0.3 * L->data.pos.h;
bx2 -= 0.5 * L->data.pos.w;
}
if(ax1 < bx2 && ax2 > bx1 && ay1 < by2 && ay2 > by1 && L->data.ennemi){
L->data.vie -= degats;
......@@ -142,9 +177,9 @@ 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, SDL_Texture **sprites){
void charger_vague_ennemis(SDL_Renderer *renderer, bool *b, int *vaguesEnnemis, int vagueNum, int xCamera, int yCamera, ListeP *LP, ListeR LR,SDL_Texture **sprites){
if(vaguesEnnemis[vagueNum] > 0){
cons_listeP(LP, nouvel_ennemi_1(renderer, sprites, xCamera, yCamera));
cons_listeP(LP, nouvel_ennemi_1(renderer, LR, sprites, xCamera, yCamera));
vaguesEnnemis[vagueNum] -= 1;
} else {
*b = true;
......
......@@ -18,10 +18,10 @@ bool vague_terminee(ListeP L);
void afficher_listeP(SDL_Renderer *renderer, ListeP L);
Perso* joueur(ListeP L);
void supprimer_ennemi(ListeP L);
void deplacement_ennemi(Perso *p, Perso *joueur, int xCamera, int yCamera, int dxCamera, int dyCamera);
void deplacement_ennemis(ListeP L, int xCamera, int yCamera, int dxCamera, int dyCamera);
bool detecter_collision_perso(ListeP L, ListeE *LE, SDL_Rect rect, int degats, int xCamera, int yCamera, SDL_Texture **sprites);
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);
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, SDL_Texture **sprites);
void charger_vague_ennemis(SDL_Renderer *renderer, bool *b, int *vaguesEnnemis, int vagueNum,int xCamera, int yCamera, ListeP *LP, ListeR LR, SDL_Texture **sprites);
......@@ -22,22 +22,21 @@ void charger_niveau(char *tab, ListeR *L){
for(int i = 0; i < 61; i++){
if(j < 61){
if(i==0){
caractereActuel = fgetc(fichier);
char tmp = caractereActuel;
caractereActuel = tmp;
tab[60*j+i] = caractereActuel;
printf("%c", tab[60*j+i]);
caractereActuel = fgetc(fichier);
char tmp = caractereActuel;
caractereActuel = tmp;
tab[60*j+i] = caractereActuel;
printf("%c", tab[60*j+i]);
}
else{
caractereActuel = fgetc(fichier);
tab[60*j+i] = caractereActuel;
printf("%c", tab[60*j+i]);
caractereActuel = fgetc(fichier);
tab[60*j+i] = caractereActuel;
printf("%c", tab[60*j+i]);
}
}
}
}
fclose(fichier);
}
......@@ -94,6 +93,79 @@ void charger_niveau(char *tab, ListeR *L){
rect.w = 50;
cons_listeR(L, rect);
break;
case 'A':
//ambulance
rect.x = i * 50;
rect.y = j * 50;
rect.h = 200;
rect.w = 100;
cons_listeR(L, rect);
break;
case 'P':
//police
rect.x = i * 50;
rect.y = j * 50;
rect.h = 100;
rect.w = 200;
cons_listeR(L, rect);
break;
case 'E':
rect.x = i * 50;
rect.y = j * 50;
rect.h = 50;
rect.w = 50;
cons_listeR(L, rect);
break;
case 'C':
rect.x = i * 50 ;
rect.y = j * 50;
rect.h = 250;
rect.w = 150;
cons_listeR(L, rect);
break;
case 'M':
rect.x = i * 50 + 25;
rect.y = j * 50 + 100;
rect.h = 280;
rect.w = 410;
cons_listeR(L, rect);
rect.x = i * 50 + 220;
rect.y = j * 50 + 30;
rect.h = 250;
rect.w = 300;
cons_listeR(L, rect);
break;
case 'N':
rect.x = i * 50;
rect.y = j * 50 + 38;
rect.h = 325;
rect.w = 500;
cons_listeR(L, rect);
rect.x = i * 50 ;
rect.y = j * 50 + 325;
rect.h = 260;
rect.w = 380;
cons_listeR(L, rect);
break;
case 'L':
rect.x = i * 50 + 30;
rect.y = j * 50 + 215;
rect.h = 360;
rect.w = 210;
cons_listeR(L, rect);
rect.x = i * 50 + 205 ;
rect.y = j * 50 + 40;
rect.h = 425;
rect.w = 570;
cons_listeR(L, rect);
break;
case 'F':
rect.x = i * 50 + 25;
rect.y = j * 50 + 25;
rect.h = 245;
rect.w = 245;
cons_listeR(L, rect);
break;
}
}
}
......@@ -112,6 +184,7 @@ bool detecter_collision_murs(ListeR L, SDL_Rect rect, int xCamera, int yCamera){
ay2 = rect.y + rect.h + yCamera;
by1 = L->data.y;
by2 = L->data.y + L->data.h;
if(ax1 < bx2 && ax2 > bx1 && ay1 < by2 && ay2 > by1){
return true;
}
......@@ -119,3 +192,4 @@ bool detecter_collision_murs(ListeR L, SDL_Rect rect, int xCamera, int yCamera){
}
return false;
}
......@@ -2,6 +2,7 @@
#include <stdlib.h>
#include <stdbool.h>
typedef struct s_ListeR *ListeR, s_ListeR;
struct s_ListeR
{
......@@ -13,3 +14,4 @@ struct s_ListeR
void cons_listeR(ListeR *L, SDL_Rect data);
void charger_niveau(char *tab, ListeR *L);
bool detecter_collision_murs(ListeR L, SDL_Rect rect, int xCamera, int yCamera);
......@@ -9,7 +9,7 @@ int main(int argc, char *argv[])
SDL_Window *fenetre;
SDL_Event evenements;
SDL_Renderer *ecran;
SDL_Texture *tmp, *balleSprite, *sprites[4], *spritesMap[9];
SDL_Texture *tmp, *balleSprite, *sprites[5], *spritesMap[20];
float mouseX, mouseY;
int vitesse, vagueNum, tempsActuel, tempsPrecedent, tempsActuelTir, tempsActuelVague, tempsPrecedentVague,
tempsActuelAnim, tempsPrecedentAnim, xCamera, yCamera, dxCamera, dyCamera, vaguesEnnemis[100];
......@@ -62,9 +62,20 @@ int main(int argc, char *argv[])
spritesMap[6] = charger_image("sprites/map/mur_hd.png", ecran, 255, 255, 255);
spritesMap[7] = charger_image("sprites/map/mur_bg.png", ecran, 255, 255, 255);
spritesMap[8] = charger_image("sprites/map/mur_bd.png", ecran, 255, 255, 255);
spritesMap[9] = charger_image("sprites/map/route_ver.png", ecran, 0, 0, -1);
spritesMap[10] = charger_image("sprites/map/route_hor.png", ecran, 0, 0, -1);
spritesMap[11] = charger_image("sprites/map/police_car.png", ecran, 0, 0, -1);
spritesMap[12] = charger_image("sprites/map/ambulance.png", ecran, 0, 0, -1);
spritesMap[13] = charger_image("sprites/map/eau.png", ecran, 0, 0, -1);
spritesMap[14] = charger_image("sprites/map/conteneurs.png", ecran, 0, 0, -1);
spritesMap[15] = charger_image("sprites/map/maison2.png", ecran, 0, 0, -1);
spritesMap[16] = charger_image("sprites/map/maison.png", ecran, 0, 0, -1);
spritesMap[17] = charger_image("sprites/map/herbe.png", ecran, 0, 0, -1);
spritesMap[18] = charger_image("sprites/map/maison3.png", ecran, 0, 0, -1);
spritesMap[19] = charger_image("sprites/map/fontaine.png", ecran, 0, 0, -1);
//Personnages + Effets
tmp = charger_image("sprites/perso/handgun/idle/survivor_idle.png", ecran, 255, 255, 255);
tmp = charger_image("sprites/perso/survivor_rifle.png", ecran, 255, 255, 255);
sprites[0] = tmp;
tmp = charger_image("sprites/ennemis/zombie/move/zombie_moveV2.png", ecran, 0, 0, -1);
sprites[1] = tmp;
......@@ -72,6 +83,8 @@ int main(int argc, char *argv[])
sprites[2] = tmp;
tmp = charger_image("sprites/effets/blood/blood_hitv3.png", ecran, 0, 0, -1);
sprites[3] = tmp;
tmp = charger_image("sprites/effets/blood/blood_splatter.png", ecran, 255, 255, 255);
sprites[4] = tmp;
//Sons
......@@ -164,7 +177,7 @@ int main(int argc, char *argv[])
}
if(Mix_PlayingMusic() == 0) {
Mix_VolumeMusic(10);
Mix_VolumeMusic(20);
Mix_FadeInMusic(musique, 1, 1000);
}
......@@ -172,7 +185,7 @@ int main(int argc, char *argv[])
tempsActuelVague = SDL_GetTicks();
if(!vagueTerminee){
if(tempsActuelVague > tempsPrecedentVague + 250){
charger_vague_ennemis(ecran, &vagueTerminee, vaguesEnnemis, vagueNum, xCamera, yCamera, &persosListe, sprites);
charger_vague_ennemis(ecran, &vagueTerminee, vaguesEnnemis, vagueNum, xCamera, yCamera, &persosListe, mursListe, sprites);
tempsPrecedentVague = tempsActuelVague;
}
} else {
......@@ -187,7 +200,7 @@ int main(int argc, char *argv[])
}
}
// printf("vague %d\n",vagueNum);
joueur_ptr = joueur(persosListe);
if(joueur_ptr != NULL){
......@@ -212,7 +225,7 @@ int main(int argc, char *argv[])
//Dplacement/angle de tir ennemis
deplacement_ennemis(persosListe, xCamera, yCamera, dxCamera, dyCamera);
deplacement_ennemis(persosListe, mursListe, &effetsListe, sprites, xCamera, yCamera, dxCamera, dyCamera);
//Tir
tempsActuelTir = SDL_GetTicks();
......@@ -238,7 +251,7 @@ int main(int argc, char *argv[])