From 4d73f71eb18f55dd9ab02cb1f1e895e0ae91ab98 Mon Sep 17 00:00:00 2001 From: Martin CHAUVELIERE Date: Thu, 20 Apr 2023 17:02:06 +0200 Subject: [PATCH] Principal du jeu terminé, beaucoup d'optimisations à venir --- Interactif/Interactif.c | 9 ++++++--- Interactif/Interactif.h | 2 +- Main/init.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- Main/init.h | 3 +++ Main/main.c | 56 +++++++++++++++++++++++++++++++++++++++++--------------- 5 files changed, 104 insertions(+), 22 deletions(-) diff --git a/Interactif/Interactif.c b/Interactif/Interactif.c index 100604d..5465d8b 100644 --- a/Interactif/Interactif.c +++ b/Interactif/Interactif.c @@ -80,7 +80,7 @@ struct liste_entite* CheckCollisionListeListe(struct liste_entite *Liste1,int L1 -void SupprimerEntitesEnCollision(struct liste_entite** Liste1, int L1, int H1, struct liste_entite** Liste2, int L2, int H2) +int SupprimerEntitesEnCollision(struct liste_entite** Liste1, int L1, int H1, struct liste_entite** Liste2, int L2, int H2) { struct liste_entite* collision = CheckCollisionListeListe(*Liste1, L1, H1, *Liste2, L2, H2); @@ -96,7 +96,10 @@ void SupprimerEntitesEnCollision(struct liste_entite** Liste1, int L1, int H1, s SupprimerEntite(Liste2, enti2); afficherLutin(bouillie, enti2->posx - hitboxbouillieL/2 + ErreurHitbox, enti2->posy - hitboxbouillieH/2 + ErreurHitbox); + + return 1; } + return 0; } @@ -208,7 +211,7 @@ void DeplacementBombe(int bombe, struct liste_entite** l) while (ml != NULL) { - if (ml->enti.posy + hitboxbombeH - ErreurHitbox >= Sol) + if (ml->enti.posy + hitboxbombeH/2 - ErreurHitbox >= Sol) { struct entite* a_supprimer = &ml->enti; ml = ml->suivant; @@ -217,7 +220,7 @@ void DeplacementBombe(int bombe, struct liste_entite** l) else { ml->enti.posy += 2; - afficherLutin(bombe, ml->enti.posx - hitboxbombeL/2 + ErreurHitbox, ml->enti.posy); + afficherLutin(bombe, ml->enti.posx - hitboxbombeL/2 + ErreurHitbox, ml->enti.posy - hitboxbombeH/2 + ErreurHitbox); precedent = ml; ml = ml->suivant; } diff --git a/Interactif/Interactif.h b/Interactif/Interactif.h index ed06c33..5f9cf2c 100644 --- a/Interactif/Interactif.h +++ b/Interactif/Interactif.h @@ -12,7 +12,7 @@ void Tirer(struct entite, struct liste_entite**); void DeplacementTire(int,struct liste_entite**); -void SupprimerEntitesEnCollision(struct liste_entite**,int,int,struct liste_entite**,int,int); +int SupprimerEntitesEnCollision(struct liste_entite**,int,int,struct liste_entite**,int,int); char touche(); diff --git a/Main/init.c b/Main/init.c index 9aada16..02b950c 100644 --- a/Main/init.c +++ b/Main/init.c @@ -7,11 +7,12 @@ #define TailleX 500 #define TailleY 500 +#define Sol 475 #define ErreurHitbox 2 #define JoueurX TailleX/2 #define JoueurY 9*TailleY/10 -struct entite joueur = {JoueurX,JoueurY,-1}; +struct entite joueur; int canon=0; int missile=0; @@ -19,8 +20,6 @@ int sbire=0; int bouillie=0; int bombe=0; - - char Nom[15]="Space Invader"; char input='\0'; @@ -53,6 +52,14 @@ void initialiser() } +void initialiserjoueur(struct entite* joueur) +{ + joueur->posx = JoueurX; + joueur->posy = JoueurY; + joueur->dropbombe = -1; +} + + char pagedemarrage() { @@ -86,3 +93,46 @@ char pagedemarrage() } return input; } + + +void pagemort(int vie) +{ + static const char policeDefaut[]="/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"; + int Largeur, Hauteur; + + rectanglePlein(0,0,TailleX,TailleY,COULEUR_NOIR); + char mort[16]="Vous etes mort"; + char nbr_vie[30]; + sprintf(nbr_vie, "Nombre de vie restante : %d", vie); + + + choisirPolice(policeDefaut,40); + + int M = lutinTexte(mort,COULEUR_ROUGE); + tailleLutin(M,&Largeur,&Hauteur); + afficherLutin(M,TailleX/2-Largeur/2,TailleY/4+Hauteur/2); + + choisirPolice(policeDefaut,20); + + int V = lutinTexte(nbr_vie,COULEUR_BLANC); + tailleLutin(V,&Largeur,&Hauteur); + afficherLutin(V,TailleX/2-Largeur/2,TailleY/2-Hauteur/2); +} + + +void pageGameOver() +{ + static const char policeDefaut[]="/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"; + int Largeur, Hauteur; + + rectanglePlein(0,0,TailleX,TailleY,COULEUR_NOIR); + char fin[11]="GAME OVER"; + + choisirPolice(policeDefaut,40); + + int F = lutinTexte(fin,COULEUR_ROUGE); + tailleLutin(F,&Largeur,&Hauteur); + afficherLutin(F,TailleX/2-Largeur/2,TailleY/2); + +} + diff --git a/Main/init.h b/Main/init.h index e001a61..52bafd8 100644 --- a/Main/init.h +++ b/Main/init.h @@ -23,4 +23,7 @@ extern int hitboxbombeL; extern int hitboxbombeH; void initialiser(); +void initialiserjoueur(struct entite*); char pagedemarrage(); +void pagemort(int); +void pageGameOver(); diff --git a/Main/main.c b/Main/main.c index fdd99e4..173261e 100644 --- a/Main/main.c +++ b/Main/main.c @@ -18,14 +18,14 @@ int main() creerSurface(TailleX,TailleY,Nom); initialiser(); - - + initialiserjoueur(&joueur); + struct liste_entite *enemies = NULL; struct liste_entite *tires = NULL; struct liste_entite *bombes = NULL; - - char texte[15]="SCORE : "; - int Score = lutinTexte(texte,COULEUR_BLANC); + //joueur est dans une liste pour que je puisse utiliser des fonctions deja créé + struct liste_entite* Ljoueur = NULL; + ajout_tete(&Ljoueur,joueur); LigneSbire(&enemies,8,3); @@ -34,22 +34,46 @@ int main() int compteur=0; int DropAlea=0; int CheckAlea=0; - + int mort = 0; + int nbr_vie = 3; + if (pagedemarrage() != 'j') { return 0; } - //Bouble principale while(input!='m') { + if (mort == 1) + { + nbr_vie-=1; + if (nbr_vie > 0) + { + pagemort(nbr_vie); + printf("%d \n",joueur.posx); + majSurface(); + SDL_Delay(2000); + mort = 0; + } + else + { + pageGameOver(); + majSurface(); + SDL_Delay(2000); + return 0; + } + ajout_tete(&Ljoueur,joueur); + tires = NULL; + bombes = NULL; + } + rectanglePlein(0,0,TailleX,TailleY,COULEUR_NOIR); rectanglePlein(0,Sol,TailleX,2,COULEUR_VERT); - afficherLutin(Score,0,Sol+ErreurHitbox); - - afficherLutin(canon,joueur.posx - hitboxcanonL/2 + ErreurHitbox,joueur.posy); + afficherLutin(canon,Ljoueur->enti.posx - hitboxcanonL/2 + ErreurHitbox,Ljoueur->enti.posy); + AfficherSbire(sbire,hitboxsbireL,hitboxsbireH,enemies); + if (DropAlea == 0) { DropAlea = rand() % 31 + 100; @@ -61,10 +85,8 @@ int main() CheckAlea=0; } - AfficherSbire(sbire,hitboxsbireL,hitboxsbireH,enemies); - input = touche(); - action(&joueur,input,&tires); + action(&Ljoueur->enti,input,&tires); if (compteur==10) { @@ -73,13 +95,17 @@ int main() } DeplacementTire(missile,&tires); - DeplacementBombe(bombe,&bombes); SupprimerEntitesEnCollision(&tires,hitboxmissileL,hitboxmissileH,&enemies,hitboxsbireL,hitboxsbireH); + if (SupprimerEntitesEnCollision(&bombes,hitboxbombeL,hitboxbombeH,&Ljoueur,hitboxcanonL,hitboxcanonH) == 1) + { + mort = 1; + majSurface(); + SDL_Delay(200); + } majSurface(); - SDL_Delay(20); compteur+=1; -- libgit2 0.21.2