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
| #include <cstdlib>
#include <iostream>
#include <fstream>
#include <SDL.h>
#include <SDL_image.h>
#define BLOCK_LARGEUR 107
#define BLOCK_HAUTEUR 80
#define NB_BLOCS_LARGEUR 6
#define NB_BLOCS_HAUTEUR 6
#define LARGEUR_FENETRE BLOCK_LARGEUR * NB_BLOCS_LARGEUR
#define HAUTEUR_FENETRE BLOCK_HAUTEUR* NB_BLOCS_HAUTEUR
using namespace std;
int main(int argc,char** argv)
{
SDL_Surface *ecran = NULL, *Terre = NULL, *Vide =NULL;
SDL_Rect position;
SDL_Event event;
int Map[6][6];
bool continuer = true;
char caractere;
SDL_Init(SDL_INIT_VIDEO);
ecran = SDL_SetVideoMode(LARGEUR_FENETRE, HAUTEUR_FENETRE, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_WM_SetCaption("Map", NULL);
SDL_EnableKeyRepeat(10, 10);
SDL_ShowCursor(SDL_DISABLE);
Terre = IMG_Load("Terre.bmp");
Vide = IMG_Load("Vide.bmp");
ifstream FichierMap("Map1.txt", ios::in);
while (FichierMap.get(caractere))
{
for (int x=0;x<NB_BLOCS_LARGEUR;x++)
{
for (int y=0;y<NB_BLOCS_HAUTEUR;y++)
{
if (caractere == '0')
{
Map[x][y] = 0;
}
else if (caractere == '1')
{
Map[x][y] = 1;
}
}
}
}
while (continuer)
{
for (int i = 0 ; i < NB_BLOCS_LARGEUR ; i++)
{
for (int j = 0 ; j < NB_BLOCS_HAUTEUR ; j++)
{
position.x = i * BLOCK_LARGEUR;
position.y = j * BLOCK_HAUTEUR;
switch (Map[i][j])
{
case 1:
SDL_BlitSurface(Terre, NULL, ecran, &position);
break;
case 0:
SDL_BlitSurface(Vide, NULL, ecran, &position);
break;
}
}
}
SDL_Flip(ecran);
SDL_WaitEvent(&event);
switch (event.type)
{
case SDL_QUIT:
SDL_Quit();
exit(0);
break;
}
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
}
FichierMap.close();
SDL_FreeSurface(ecran);
SDL_Quit();
return 0;
} |
Partager