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
|
#include <SDL/SDL.h>
#include <stdlib.h>
#include "st_sprite.h"
int main(int argc, char *argv[])
{
SDL_Rect rect[12][20];
SDL_Surface *ecran;
st_sprite *sprite[12][20];
int i,j,s,a;
if (SDL_Init (SDL_INIT_VIDEO) < 0) {
fprintf (stderr, "Impossible d'initialiser SDL : %s\n", SDL_GetError ());
exit (1);
}
atexit (SDL_Quit);
ecran = SDL_SetVideoMode (640, 480, 16, SDL_SWSURFACE | SDL_DOUBLEBUF /*| SDL_FULLSCREEN*/);
if (ecran == NULL) {
fprintf (stderr, "Impossible d'initialiser le mode video : %s\n", SDL_GetError ());
exit (2);
}
for(i=0;i<12;i=i+1)
{
for(j=0;j<20;j=j+1)
{
sprite[i][j]=(st_sprite*)malloc(sizeof(st_sprite));
if(sprite[i][j]==NULL)
exit (3);
sprite[i][j]->image=SDL_LoadBMP("./herbe.bmp");
}
}
a = 0;
s = 0;
for(i=0;i<12;i=i+1)
{
for(j=0;j<20;j=j+1)
{
rect[i][j].x = s;
rect[i][j].y = a;
rect[i][j].w = 32;
rect[i][j].h = 40;
s = s + 32;
}
s = 0;
a = a + 40;
}
SDL_WM_SetCaption ("Je dédie ce programme à ma chère soeur Hasna", NULL);
//////////////////////////////////////////////////////////////////////////////////
while (1) //////////////////////////////////////////////////////////
{
SDL_Event event;
if(SDL_PollEvent (&event) && event.type==SDL_QUIT)break;
//if(SDL_PollEvent (&event) && event.type==SDL_KEYDOWN)
{
if(event.key.state == SDL_PRESSED)
{
if(event.key.keysym.sym == SDLK_ESCAPE)break;
}
}
SDL_FillRect(ecran,NULL,SDL_MapRGB(ecran->format,255,0,255));
for(i=0;i<12;i=i+1)
{
for(j=0;j<20;j=j+1)
{
SDL_BlitSurface(sprite[i][j]->image,NULL,ecran,&rect[i][j]);
}
}
SDL_Flip(ecran);
} /////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
SDL_FreeSurface(ecran);
for(i=0;i<12;i=i+1)
{
for(j=0;j<20;j=j+1)
{
SDL_FreeSurface(sprite[i][j]->image);
}
}
for(i=0;i<12;i=i+1)
{
for(j=0;j<20;j=j+1)
{
free(sprite[i][j]);
}
}
///////////////////////////////////////////////////////////////////////////////////
return 0;
} |
Partager