summaryrefslogtreecommitdiff
path: root/map.c
blob: ff0d61aef893d2f3d5ac740e24f398a2554bc795 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#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:
                case SDLK_f:
                continuer=Fjouer(surfaces,positions,persos,ennemis);
                break;
                case SDLK_ESCAPE:
                case SDLK_a:
                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);
}