Commit 06928e8b authored by Paul GEORGES's avatar Paul GEORGES
Browse files

vagues ennemis, amélioration map

parent fdc1fe46
......@@ -17,22 +17,36 @@ void afficher_niveau(char *tab, SDL_Renderer *renderer, SDL_Texture **spriteMap,
SDL_Rect destrect;
destrect.h = 50;
destrect.w = 50;
for(int j = 0; j < 30; j++){
for(int i = 0; i < 30; i++){
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[30*j+i]){
case 'H':
switch(tab[60*j+i]){
case '1':
SDL_RenderCopy(renderer, spriteMap[1], NULL, &destrect);
break;
case 'Q':
case '2':
SDL_RenderCopy(renderer, spriteMap[2], NULL, &destrect);
break;
case 'V':
case '3':
SDL_RenderCopy(renderer, spriteMap[3], NULL, &destrect);
break;
case '4':
SDL_RenderCopy(renderer, spriteMap[4], NULL, &destrect);
break;
case '5':
SDL_RenderCopy(renderer, spriteMap[5], NULL, &destrect);
break;
case '6':
SDL_RenderCopy(renderer, spriteMap[6], NULL, &destrect);
break;
case '7':
SDL_RenderCopy(renderer, spriteMap[7], NULL, &destrect);
break;
case '8':
SDL_RenderCopy(renderer, spriteMap[8], NULL, &destrect);
break;
}
......
......@@ -67,7 +67,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 + 400) {
if(time > tmp->data.tempsTirPrecedent + 50) {
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;
......
......@@ -11,8 +11,15 @@ void cons_listeP(ListeP *L, Perso data){
bool est_vide_listeP(ListeP L){
return (L == NULL);
bool vague_terminee(ListeP L){
ListeP tmp = L;
while(tmp != NULL){
if(tmp->data.ennemi){
return false;
}
tmp = tmp->next;
}
return true;
}
void afficher_listeP(SDL_Renderer *renderer, ListeP L){
......@@ -135,3 +142,13 @@ 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){
if(vaguesEnnemis[vagueNum] > 0){
cons_listeP(LP, nouvel_ennemi_1(renderer, sprites, xCamera, yCamera));
vaguesEnnemis[vagueNum] -= 1;
} else {
*b = true;
}
return;
}
......@@ -14,7 +14,7 @@ struct s_ListeP
void cons_listeP(ListeP *L, Perso data);
bool est_vide_listeP(ListeP L);
bool vague_terminee(ListeP L);
void afficher_listeP(SDL_Renderer *renderer, ListeP L);
Perso* joueur(ListeP L);
void supprimer_ennemi(ListeP L);
......@@ -23,5 +23,5 @@ void deplacement_ennemis(ListeP L, int xCamera, int yCamera, int dxCamera, int d
bool detecter_collision_perso(ListeP L, ListeE *LE, SDL_Rect rect, 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);
......@@ -18,97 +18,82 @@ void charger_niveau(char *tab, ListeR *L){
int caractereActuel;
if (fichier != NULL){
for(int j = 0; j < 33; j++){
for(int i = 0; i < 31; i++){
if(j < 31){
if(i==0){
//caractereActuel = fgetc(fichier);
caractereActuel = fgetc(fichier);
char tmp = caractereActuel;
// caractereActuel = fgetc(fichier);
caractereActuel = tmp;
tab[30*j+i] = caractereActuel;
printf("%c", tab[30*j+i]);
}
else{
caractereActuel = fgetc(fichier);
tab[30*j+i] = caractereActuel;
printf("%c", tab[30*j+i]);
}
}
}
for(int j = 0; j < 63; j++){
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]);
}
else{
caractereActuel = fgetc(fichier);
tab[60*j+i] = caractereActuel;
printf("%c", tab[60*j+i]);
}
}
}
}
}
fclose(fichier);
fclose(fichier);
}
//Remplir la liste de murs
SDL_Rect rect;
for(int j = 0; j < 30; j++){
for(int i = 0; i < 30; i++){
switch(tab[30*j+i]){
case 'S':
for(int j = 0; j < 60; j++){
for(int i = 0; i < 60; i++){
switch(tab[60*j+i]){
case '0':
break;
case 'H':
case '1':
//mur du haut
rect.x = i * 50;
rect.y = j * 50;
rect.h = 25;
rect.w = 50;
cons_listeR(L, rect);
//tab[30*j+i] = 1;
break;
case 'V':
rect.x = i * 50;
rect.y = j * 50;
rect.h = 50;
rect.w = 25;
cons_listeR(L, rect);
//tab[30*j+i] = 3;
break;
/**
//mur du bas
case '2':
rect.x = i * 50;
rect.y = j * 50 + 25;
rect.h = 25;
rect.w = 50;
L = cons_listeR(L, rect);
cons_listeR(L, rect);
break;
case '3':
//mur de gauche
rect.x = i * 50;
rect.y = j * 50;
rect.h = 50;
rect.w = 25;
L = cons_listeR(L, rect);
cons_listeR(L, rect);
break;
case '4':
//mur de droite
rect.x = i * 50 + 25;
rect.y = j * 50;
rect.h = 50;
rect.w = 25;
L = cons_listeR(L, rect);
cons_listeR(L, rect);
break;
case '5':
//coin haut gauche
case '6':
//coin haut droit
case '7':
//coin bas gauche
case '8':
//coin bas droit
rect.x = i * 50;
rect.y = j * 50;
rect.h = 50;
rect.w = 50;
L = cons_listeR(L, rect);
break;
case '0':
cons_listeR(L, rect);
break;
*/
}
}
}
......
......@@ -5,15 +5,15 @@
int main(int argc, char *argv[])
{
srand(time(NULL));
bool gameover, tir, exit;
bool gameover, tir, exit, vagueTerminee;
SDL_Window *fenetre;
SDL_Event evenements;
SDL_Renderer *ecran;
SDL_Texture *tmp, *balleSprite, *sprites[4], *spritesMap[9];
float mouseX, mouseY;
int vitesse, tempsActuel, tempsPrecedent, tempsActuelTir, tempsActuelAnim, tempsPrecedentAnim,
xCamera, yCamera, dxCamera, dyCamera;
char map[32][30]; ;
int vitesse, vagueNum, tempsActuel, tempsPrecedent, tempsActuelTir, tempsActuelVague, tempsPrecedentVague,
tempsActuelAnim, tempsPrecedentAnim, xCamera, yCamera, dxCamera, dyCamera, vaguesEnnemis[100];
char map[62][60];
ListeB ballesTirees;
ListeP persosListe;
ListeR mursListe;
......@@ -31,9 +31,8 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
//Mix_Init(MIX_INIT_MP3);
if( Mix_OpenAudio(44100, AUDIO_S16, 1, 4096) < 0 )
if(Mix_OpenAudio(44100, AUDIO_S16, 1, 4096) < 0)
{
printf("Erreur d'initialisation de la SDL %s", Mix_GetError() );
SDL_Quit();
......@@ -74,44 +73,6 @@ int main(int argc, char *argv[])
tmp = charger_image("sprites/effets/blood/blood_hitv3.png", ecran, 0, 0, -1);
sprites[3] = tmp;
/**
FILE* fichier = NULL;
fichier = fopen("map.txt", "r");
int caractereActuel;
if (fichier != NULL){
for(int j = 0; j < 33; j++){
for(int i = 0; i < 31; i++){
if(j < 31){
if(i==0){
//caractereActuel = fgetc(fichier);
caractereActuel = fgetc(fichier);
char tmp = caractereActuel;
// caractereActuel = fgetc(fichier);
caractereActuel = tmp;
map[j][i] = caractereActuel;
printf("%c", map[j][i]);
}
else{
caractereActuel = fgetc(fichier);
map[j][i] = caractereActuel;
printf("%c", map[j][i]);
}
}
}
}
fclose(fichier);
}
*/
//Sons
musique = NULL;
......@@ -124,11 +85,15 @@ int main(int argc, char *argv[])
gameover = false;
tir = false;
vagueTerminee = false;
vitesse = 25;
vagueNum = 0;
tempsActuel = 0;
tempsPrecedent = 0;
tempsActuelTir = 0;
tempsActuelVague = 0;
tempsPrecedentVague = 0;
tempsActuelAnim = 0;
tempsPrecedentAnim = 0;
xCamera = 0;
......@@ -146,23 +111,15 @@ int main(int argc, char *argv[])
p = nouveau_joueur(ecran, sprites);
cons_listeP(&persosListe, p);
p = nouvel_ennemi_1(ecran, sprites);
cons_listeP(&persosListe, p);
p = nouvel_ennemi_1(ecran, sprites);
cons_listeP(&persosListe, p);
p = nouvel_ennemi_1(ecran, sprites);
cons_listeP(&persosListe, p);
p = nouvel_ennemi_1(ecran, sprites);
cons_listeP(&persosListe, p);
charger_vagues_ennemis(vaguesEnnemis);
//Boucle de jeu
while(!gameover)
{
tempsActuel = SDL_GetTicks();
if (tempsActuel > tempsPrecedent + 16)
{
if (tempsActuel > tempsPrecedent + 16) {
//Dtection vnements
while(SDL_PollEvent(&evenements))
{
......@@ -206,12 +163,32 @@ int main(int argc, char *argv[])
}
}
if( Mix_PlayingMusic() == 0 ) {
if(Mix_PlayingMusic() == 0) {
Mix_VolumeMusic(10);
Mix_FadeInMusic(musique, 1, 1000);
}
tempsActuelVague = SDL_GetTicks();
if(!vagueTerminee){
if(tempsActuelVague > tempsPrecedentVague + 250){
charger_vague_ennemis(ecran, &vagueTerminee, vaguesEnnemis, vagueNum, xCamera, yCamera, &persosListe, sprites);
tempsPrecedentVague = tempsActuelVague;
}
} else {
if(vague_terminee(persosListe)){
if(tempsActuelVague > tempsPrecedentVague + 2000){
vagueNum ++;
tempsPrecedentVague = tempsActuelVague;
vagueTerminee = false;
}
} else {
tempsPrecedentVague = tempsActuelVague;
}
}
// printf("vague %d\n",vagueNum);
joueur_ptr = joueur(persosListe);
if(joueur_ptr != NULL){
//Gestion dplacement/angle de tir
......
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHV
HHHHHHHHHHHHHHHHHHHHHHHHHHHHVH
VHSSSSSSSSSSSSSSSSSSHHHHHHHHVV
VSSSSSSSSSSSSSSSSSSSSVSSSSSSSH
VSSSSSSSSSSSSSSSSSSSSVSSSSSSSV
VSSSSSSSSSSSSSSSSSSSSVSSSSSSSH
VSSSSSSSSSSSSSSSSSSSSSSSSSSSSV
VSSSSSSSSSSSSSSSSSSSSSSSSSSSSH
VSSSSSSSSSSSSSSSSSSSSSSSSSSSVV
VSSSSSSSSSSSSSSSSSSSSSSSSSSSVH
VSSSSSSSSSSSSSSSSSSSSSSSSSSVVV
VSSSSSSSSSSSSSSSSSSSSSSSSSSSVH
VSSSSSSSSSSSSSSSSSSSSSSSSSSSVV
VSSSSSSSSSSSSSSSSSSSSSSSSSSSVH
VSSSSSSSSSSSSSSSSSSSSSSSSSSSVV
VSSSSSSSSSSSSSSSSSSSSSSSSSSSSH
VSSSSSSSSSSSSSSSSSSSSSSSSSSSSV
VSSSSSSSSSSSSSSSSSSSSSSSSSSSSH
VSSSSSSSSSSSSSSSSSSSSSSSSSSSSV
VSSSSSSSSSSSSSSSSSSSSSSSSSSSSH
VSSSSSSSSSSSSSSSSSSSSSSSSSSSSV
VSSSSSSSSSSSSSSSSSSSSSSSSSSSSH
VSSSSSSSSSSSSSSSSSSSSSSSSSSSSV
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSH
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSV
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSH
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSV
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSH
VVSSSSSSSSSSSSSSSSSSSSSSSSSHHV
VVSSSSSSSSSSSSSSSSSSSSSSSSSHHV
QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ
QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ
\ No newline at end of file
511111111111111111111111111111111111111111111111111111111116
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
300000000000000000000000000000000000000000000000000000000004
722222222222222222222222222222222222222222222222222222222228
QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ
QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ
\ No newline at end of file
......@@ -15,7 +15,7 @@ Perso nouveau_joueur(SDL_Renderer *renderer, SDL_Texture **sprites){
p.srcrect.h = 220;
p.angle = 0;
p.vie = 100;
p.degats = 25;
p.degats = 100;
p.vitesse = 4;
p.yMax = 0;
p.tir = false;
......@@ -24,13 +24,20 @@ Perso nouveau_joueur(SDL_Renderer *renderer, SDL_Texture **sprites){
return p;
}
Perso nouvel_ennemi_1(SDL_Renderer *renderer, SDL_Texture **sprites){
Perso nouvel_ennemi_1(SDL_Renderer *renderer, SDL_Texture **sprites, int xCamera, int yCamera){
Perso p;
p.tempsTirPrecedent = 0;
p.image = sprites[1];
//gnre des coordonnes de spawn alatoires(provisoire)
p.pos.x = rand()%100 + 0;
p.pos.y = rand()%700 + 0;
//gnre des coordonnes de spawn alatoires hors du champ de vision du joueur
int x, y;
do {
x = (rand()%1424 + 26) - xCamera;
} while(x > 0 && x < 1000);
do {
y = (rand()%1424 + 26) - yCamera;
} while(y > 0 && y < 700);
p.pos.x = x;
p.pos.y = y;
p.pos.w = 50;
p.pos.h = 50;
p.srcrect.x = 0;
......@@ -48,11 +55,21 @@ Perso nouvel_ennemi_1(SDL_Renderer *renderer, SDL_Texture **sprites){
return p;
}
void afficher_perso(SDL_Renderer *renderer, Perso p)
{
void afficher_perso(SDL_Renderer *renderer, Perso p) {
SDL_RenderCopyEx(renderer, p.image, &p.srcrect, &p.pos, p.angle, NULL, SDL_FLIP_NONE);
return;
}
void charger_vagues_ennemis(int *tab){
for(int j = 0; j < 100; j++){
tab[j] = 3*j + 1;
}
return;
}
void deplacement_joueur(Perso *p, ListeR L, int *xCamera, int *yCamera, int *dxCamera, int *dyCamera)
{
int dX = 0;
......
......@@ -27,8 +27,9 @@ struct s_Personnage
Perso nouveau_joueur(SDL_Renderer *renderer, SDL_Texture **sprites);
Perso nouvel_ennemi_1(SDL_Renderer *renderer, SDL_Texture **sprites);
Perso nouvel_ennemi_1(SDL_Renderer *renderer, SDL_Texture **sprites, int xCamera, int yCamera);
void afficher_perso(SDL_Renderer *renderer, Perso p);
void charger_vagues_ennemis(int *tab);
void deplacement_joueur(Perso *p, ListeR L, int *xCamera, int *yCamera, int *dxCamera, int *dyCamera);
void angle_ennemi(Perso *p);
void angle_joueur(Perso *p, float mouseX, float mouseY);
......
......@@ -12,7 +12,7 @@ balle nouvelle_balle(SDL_Texture *image, float angle, int degats, SDL_Rect perso
return b;
}
//v = vitesse de la balle (provisoire)
void incrementer_balle(balle *b, int v)
{
b->ballePos.x += round(cos(b->angle * PI / 180) * v);
......
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