diff options
Diffstat (limited to 'map.c')
-rw-r--r-- | map.c | 130 |
1 files changed, 130 insertions, 0 deletions
@@ -0,0 +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);
+}
|