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
| #include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include <SDL_image.h>
#include "jeu.h"
enum {NORMAL,GAUCHE,DROITE};
void jeu()
{
SDL_Surface *ecran = NULL,*planemtn = NULL;
SDL_Surface *plane[3] = {NULL}; // pour stocker les 3 images pour les 3 positions
int i=0;
SDL_Rect position;
position.x = 100; //valeurs test
position.y = 100;
SDL_Init(SDL_INIT_VIDEO);
ecran = SDL_SetVideoMode(480, 640, 32, SDL_HWSURFACE | SDL_DOUBLEBUF); // | SDL_NOFRAME (pour virer les bordures)
SDL_WM_SetCaption("Flying Shark", NULL); // si on ne vire pas les bordures
plane[NORMAL] = IMG_Load("jeanpaul.png");
plane[GAUCHE] = IMG_Load("jeanpaulgauche.png");
plane[DROITE] = IMG_Load("jeanpauldroite.png");
planemtn = plane[NORMAL];
int continuer = 1;
while (continuer)
{
deplacement(continuer,plane,planemtn,ecran,position);
//affich(planemtn,ecran,tir,position);
}
// pause(); // a virer quand on aura fini
SDL_FreeSurface(planemtn);//retourne une erreur 3, voir
for (i = 0 ; i < 4 ; i++)
{
SDL_FreeSurface(plane[i]);
}
SDL_Quit();
}
void deplacement(int continuer, SDL_Surface *plane[3], SDL_Surface *planemtn, SDL_Surface *ecran, SDL_Rect position)
{
SDL_EnableKeyRepeat(10, 10);
SDL_Event event;
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer=0;
break;
case SDL_KEYDOWN:
switch (event.key.keysym.sym)
{
case SDLK_UP: // touche haut
position.y=position.y-2;
break;
case SDLK_DOWN: // touche bas
position.y=position.y+2;
break;
case SDLK_RIGHT: // touche droite
position.x=position.x+2;
planemtn = plane[DROITE];
break;
case SDLK_LEFT: // touche gauche
position.x=position.x-2;
planemtn = plane[GAUCHE];
break;
// case SDLK_SPACE: // tir, probablement à déplacer
// tirer (tir,ecran,position);
// break;
default: // pour le moment quitte si touche non correcte, changer pour ne rien faire
continuer=0;
break;
}
break;
}
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 0));
SDL_BlitSurface(planemtn, NULL, ecran, &position);
SDL_Flip(ecran);
SDL_EnableKeyRepeat(0, 0);
} |