summaryrefslogtreecommitdiff
path: root/map.c
diff options
context:
space:
mode:
authorOlivier Gayot <duskcoder@gmail.com>2014-10-26 18:15:21 +0000
committerOlivier Gayot <duskcoder@gmail.com>2014-10-26 18:15:21 +0000
commitf290b8cd7e40ed8688175fba312697f7da96a34e (patch)
treeb9671094c14db5cd26bf5578dd95e19803eb6560 /map.c
game: Add a buildable version of the agme
Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
Diffstat (limited to 'map.c')
-rw-r--r--map.c130
1 files changed, 130 insertions, 0 deletions
diff --git a/map.c b/map.c
new file mode 100644
index 0000000..04d0be4
--- /dev/null
+++ b/map.c
@@ -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);
+}