anisometropie  | pour info voici le code complet, merci d'avance
  Code :
 - #include <stdlib.h>
 - #include <stdio.h>
 - #include <SDL/SDL.h>
 - #include <SDL/SDL_image.h>
 - #include "main.h"
 - int main(int argc, char *argv[])
 - {
 - 	if (SDL_Init(SDL_INIT_VIDEO) == -1) // Démarrage de la SDL. Si erreur alors...
 - 	{
 -   fprintf(stderr, "Erreur d'initialisation de la SDL : %s\n", SDL_GetError()); // Ecriture de l'erreur
 -   exit(EXIT_FAILURE); // On quitte le programme
 - 	}
 - 	int i,j;
 - 	int continuer = 1;
 - 	char coordonnees[DIMENSIONS+1][DIMENSIONS+1];
 - 	SDL_Surface *surfaces[DIMENSIONS+1][DIMENSIONS+1];
 - 	SDL_Event event;
 - 	SDL_WM_SetCaption("Ma super fenêtre SDL !", NULL);
 - 	SDL_Surface *ecran = NULL;
 - 	SDL_Surface *mario = NULL;
 - 	SDL_Rect positionMario;
 - 	for (i=1;i<=DIMENSIONS;i++)
 - 	{
 -   for(j=1;j<=DIMENSIONS;j++)
 -   {
 -   	surfaces[i][j] = NULL;
 -   }
 - 	}
 - 	ecran = SDL_SetVideoMode(DIMENSIONS * 34, DIMENSIONS * 34, 32, SDL_HWSURFACE);
 - 	SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
 - 	lireNiveau (coordonnees,surfaces,&mario,&positionMario);
 - 	afficherNiveau(surfaces, &ecran);
 - 	SDL_BlitSurface(mario, NULL, ecran, &positionMario);
 - 	SDL_Flip(ecran);
 - 	while (continuer)
 - 	{
 -   SDL_WaitEvent(&event);
 -   switch(event.type)
 -   {
 -   	case SDL_QUIT:
 -     continuer = 0;
 -     break;
 -   	case SDL_KEYDOWN:
 -     switch(event.key.keysym.sym)
 -     {
 -     	case SDLK_UP: // Flèche haut
 -       positionMario.y-=34;
 -       mario = IMG_Load("mario_haut.gif" );
 -       SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
 -       SDL_BlitSurface(mario, NULL, ecran, &positionMario);
 -       SDL_Flip(ecran);
 -       break;
 -     	case SDLK_DOWN: // Flèche bas
 -       positionMario.y+=34;
 -       mario = IMG_Load("mario_bas.gif" );
 -       SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
 -       SDL_BlitSurface(mario, NULL, ecran, &positionMario);
 -       SDL_Flip(ecran);
 -       break;
 -     	case SDLK_RIGHT: // Flèche droite
 -       positionMario.x+=34;
 -       mario = IMG_Load("mario_droite.gif" );
 -       SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
 -       SDL_BlitSurface(mario, NULL, ecran, &positionMario);
 -       SDL_Flip(ecran);
 -       break;
 -     	case SDLK_LEFT: // Flèche gauche
 -       positionMario.x-=34;
 -       mario = IMG_Load("mario_gauche.gif" );
 -       SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
 -       SDL_BlitSurface(mario, NULL, ecran, &positionMario);
 -       SDL_Flip(ecran);
 -       break;
 -     }
 -     break;
 -   }
 - 	}
 - 	return EXIT_SUCCESS;
 - }
 - void lireNiveau (char coordonnees[DIMENSIONS+1][DIMENSIONS+1],SDL_Surface* surfaces[DIMENSIONS+1][DIMENSIONS+1], SDL_Surface **mario,SDL_Rect *positionMario)
 - {
 - 	printf("lire niveau " );
 - 	int i,j;
 - 	FILE* niveau = NULL;
 - 	niveau = fopen("niveau", "r" );
 - 	if (niveau != NULL)
 - 	{
 -   for (i=1;i<=DIMENSIONS;i++)
 -   {
 -   	for(j=1;j<=DIMENSIONS;j++)
 -   	{
 -     coordonnees[i][j] = fgetc(niveau);
 -     switch(coordonnees[i][j])
 -     {
 -     	case 'o':
 -       printf("%d %d ",i,j);
 -       printf("%c",coordonnees[i][j]);
 -       surfaces[i][j] = IMG_Load("objectif.png" );
 -       break;
 -     	case 'm':
 -       printf("%d %d ",i,j);
 -       printf("%c",coordonnees[i][j]);
 -       surfaces[i][j] = IMG_Load("mur.jpg" );
 -       break;
 -     	case 'c':
 -       printf("%d %d ",i,j);
 -       printf("%c",coordonnees[i][j]);
 -       surfaces[i][j] = IMG_Load("caisse.jpg" );
 -       break;
 -     	case 'M':
 -       printf("%d %d ",i,j);
 -       printf("%c",coordonnees[i][j]);
 -       *mario = IMG_Load("mario_bas.gif" );
 -       break;
 -     	default:
 -       printf("%d %d ",i,j);
 -       printf("%c",coordonnees[i][j]);
 -       break;
 -     }
 -   	}
 -   fclose(niveau); // On ferme le fichier qui a été ouvert
 -   }
 - 	}
 - }
 - void coordonneesVersPosition (int x, int y,SDL_Rect *position)
 - {
 - 	position->x = 12 * x;
 - 	position->y = 12 * y;
 - }
 - void positionVersCoordonnees (SDL_Rect position, int *x, int *y)
 - {
 - 	*x = position.x /12 ;
 - 	*y = position.y /12 ;
 - }
 - void afficherNiveau(SDL_Surface *surfaces[DIMENSIONS+1][DIMENSIONS+1], SDL_Surface **ecran)
 - {
 - 	printf("afficher niveau" );
 - 	SDL_FillRect(*ecran, NULL, SDL_MapRGB((*ecran)->format, 255, 255, 255));
 - 	SDL_Rect position;
 - 	int i;
 - 	int j;
 - 	for(i=1;i<=DIMENSIONS;i++)
 - 	{
 -   for(j=1;j<=DIMENSIONS;j++)
 -   {
 -   	coordonneesVersPosition (i, j,&position);
 -   	SDL_BlitSurface(surfaces[i][j], NULL, *ecran, &position);
 -   	SDL_Flip(*ecran);
 -   }
 - 	}
 - }
 
  |  
    Message édité par anisometropie le 18-01-2008 à 16:50:09  ---------------
			 I didn't mean you're useless. I only meant you never do anything of any use.
    |