From e816f16a5007798968f4c9003b3159a45485e88f Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Sun, 26 Oct 2014 18:20:28 +0000 Subject: game: remove useless checks it is safe to pass a null pointer to SDL_FreeSurface() BTW: change the format of the files from dos to unix Signed-off-by: Olivier Gayot --- map.c | 260 +++++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 130 insertions(+), 130 deletions(-) (limited to 'map.c') diff --git a/map.c b/map.c index 04d0be4..5c341a1 100644 --- a/map.c +++ b/map.c @@ -1,130 +1,130 @@ -#include -#include -#include -#include "constantes.h" -#include "structures.h" -#include "prototypes.h" -#include - -void Fmap (SURFACES*surfaces, POSITIONS* positions,PERSONNAGES persos[],ENNEMIS ennemis[]) -{ - int map[15][11]; - int continuer=1; - SDL_Event event; - Fchargersurfaces_map(surfaces,positions); - Fgetmap (map); - Fblittermap(surfaces,positions,map); - while(continuer) - { - SDL_WaitEvent (&event); - switch (event.type) - { - case SDL_KEYDOWN: - switch (event.key.keysym.sym) - { - case SDLK_RETURN: - continuer=Fjouer(surfaces,positions,persos,ennemis); - break; - case SDLK_ESCAPE: - continuer=0; - break; - } - break; - } - } -//une fois le jeu quitté ! - Fdechargersurfaces_map(surfaces); -} - -void Fgetmap (int map[][11]) -{ - FILE* fichier=NULL; - char chaine[165]; - int i,j,k=0; - - fichier=fopen("map.war","r"); - if(fichier==NULL) - fprintf(stderr, "Impossible d'ouvrir le fichier map.war"); - fgets(chaine,166,fichier); - fclose(fichier); - for(j=0;j<11;j++) - { - for(i=0;i<15;i++) - { - switch (chaine[k]) - { - case '0': - map[i][j]=SOL; - break; - case '1': - map[i][j]=MUR; - break; - case '2': - map[i][j]=COFFRE; - break; - case '3': - map[i][j]=GUS; - break; - } - k++; - } - } -} - -void Fchargersurfaces_map (SURFACES *surfaces,POSITIONS*positions) -{ - int i,j; - for(j=0;j<11;j++) - { - for(i=0;i<15;i++) - { - positions->Vpositionmap_item[i][j].x=i*64+32; - positions->Vpositionmap_item[i][j].y=j*64+32; - } - } - surfaces->Pmap_sol=NULL; - surfaces->Pmap_sol=IMG_Load("images/map/sol.bmp"); - surfaces->Pmap_mur=NULL; - surfaces->Pmap_mur=IMG_Load("images/map/mur.bmp"); - surfaces->Pmap_coffre=NULL; - surfaces->Pmap_coffre=IMG_Load("images/map/coffre.bmp"); - surfaces->Pmap_perso=NULL; - surfaces->Pmap_perso=IMG_Load("images/map/perso.bmp"); -} - -void Fdechargersurfaces_map(SURFACES*surfaces) -{ - SDL_FreeSurface(surfaces->Pmap_sol); - SDL_FreeSurface(surfaces->Pmap_mur); - SDL_FreeSurface(surfaces->Pmap_coffre); - SDL_FreeSurface(surfaces->Pmap_perso); -} - - -void Fblittermap (SURFACES*surfaces,POSITIONS*positions,int map[][11]) -{ - int i,j; - - for(j=0;j<11;j++) - { - for(i=0;i<15;i++) - { - switch (map[i][j]) - { - case SOL: - SDL_BlitSurface(surfaces->Pmap_sol,NULL,surfaces->Pecran,&positions->Vpositionmap_item[i][j]); - break; - case MUR: - SDL_BlitSurface(surfaces->Pmap_mur,NULL,surfaces->Pecran,&positions->Vpositionmap_item[i][j]); - break; - case COFFRE: - SDL_BlitSurface(surfaces->Pmap_coffre,NULL,surfaces->Pecran,&positions->Vpositionmap_item[i][j]); - break; - case GUS: - SDL_BlitSurface(surfaces->Pmap_perso,NULL,surfaces->Pecran,&positions->Vpositionmap_item[i][j]); - break; - } - } - } - SDL_Flip(surfaces->Pecran); -} +#include +#include +#include +#include "constantes.h" +#include "structures.h" +#include "prototypes.h" +#include + +void Fmap (SURFACES*surfaces, POSITIONS* positions,PERSONNAGES persos[],ENNEMIS ennemis[]) +{ + int map[15][11]; + int continuer=1; + SDL_Event event; + Fchargersurfaces_map(surfaces,positions); + Fgetmap (map); + Fblittermap(surfaces,positions,map); + while(continuer) + { + SDL_WaitEvent (&event); + switch (event.type) + { + case SDL_KEYDOWN: + switch (event.key.keysym.sym) + { + case SDLK_RETURN: + continuer=Fjouer(surfaces,positions,persos,ennemis); + break; + case SDLK_ESCAPE: + continuer=0; + break; + } + break; + } + } +//une fois le jeu quitté ! + Fdechargersurfaces_map(surfaces); +} + +void Fgetmap (int map[][11]) +{ + FILE* fichier=NULL; + char chaine[165]; + int i,j,k=0; + + fichier=fopen("map.war","r"); + if(fichier==NULL) + fprintf(stderr, "Impossible d'ouvrir le fichier map.war"); + fgets(chaine,166,fichier); + fclose(fichier); + for(j=0;j<11;j++) + { + for(i=0;i<15;i++) + { + switch (chaine[k]) + { + case '0': + map[i][j]=SOL; + break; + case '1': + map[i][j]=MUR; + break; + case '2': + map[i][j]=COFFRE; + break; + case '3': + map[i][j]=GUS; + break; + } + k++; + } + } +} + +void Fchargersurfaces_map (SURFACES *surfaces,POSITIONS*positions) +{ + int i,j; + for(j=0;j<11;j++) + { + for(i=0;i<15;i++) + { + positions->Vpositionmap_item[i][j].x=i*64+32; + positions->Vpositionmap_item[i][j].y=j*64+32; + } + } + surfaces->Pmap_sol=NULL; + surfaces->Pmap_sol=IMG_Load("images/map/sol.bmp"); + surfaces->Pmap_mur=NULL; + surfaces->Pmap_mur=IMG_Load("images/map/mur.bmp"); + surfaces->Pmap_coffre=NULL; + surfaces->Pmap_coffre=IMG_Load("images/map/coffre.bmp"); + surfaces->Pmap_perso=NULL; + surfaces->Pmap_perso=IMG_Load("images/map/perso.bmp"); +} + +void Fdechargersurfaces_map(SURFACES*surfaces) +{ + SDL_FreeSurface(surfaces->Pmap_sol); + SDL_FreeSurface(surfaces->Pmap_mur); + SDL_FreeSurface(surfaces->Pmap_coffre); + SDL_FreeSurface(surfaces->Pmap_perso); +} + + +void Fblittermap (SURFACES*surfaces,POSITIONS*positions,int map[][11]) +{ + int i,j; + + for(j=0;j<11;j++) + { + for(i=0;i<15;i++) + { + switch (map[i][j]) + { + case SOL: + SDL_BlitSurface(surfaces->Pmap_sol,NULL,surfaces->Pecran,&positions->Vpositionmap_item[i][j]); + break; + case MUR: + SDL_BlitSurface(surfaces->Pmap_mur,NULL,surfaces->Pecran,&positions->Vpositionmap_item[i][j]); + break; + case COFFRE: + SDL_BlitSurface(surfaces->Pmap_coffre,NULL,surfaces->Pecran,&positions->Vpositionmap_item[i][j]); + break; + case GUS: + SDL_BlitSurface(surfaces->Pmap_perso,NULL,surfaces->Pecran,&positions->Vpositionmap_item[i][j]); + break; + } + } + } + SDL_Flip(surfaces->Pecran); +} -- cgit v1.2.3