diff options
author | Olivier Gayot <duskcoder@gmail.com> | 2014-10-26 18:20:28 +0000 |
---|---|---|
committer | Olivier Gayot <duskcoder@gmail.com> | 2014-10-26 18:20:54 +0000 |
commit | e816f16a5007798968f4c9003b3159a45485e88f (patch) | |
tree | 86be1ca571b383ba1d532fa655991d099903732a /map.c | |
parent | f290b8cd7e40ed8688175fba312697f7da96a34e (diff) |
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 <duskcoder@gmail.com>
Diffstat (limited to 'map.c')
-rw-r--r-- | map.c | 260 |
1 files changed, 130 insertions, 130 deletions
@@ -1,130 +1,130 @@ -#include <SDL/SDL.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include "constantes.h"
-#include "structures.h"
-#include "prototypes.h"
-#include <SDL/SDL_image.h>
-
-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 <SDL/SDL.h> +#include <stdio.h> +#include <stdlib.h> +#include "constantes.h" +#include "structures.h" +#include "prototypes.h" +#include <SDL/SDL_image.h> + +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); +} |