voila mon code source, je n'arrive pas a faire marcher la pause grâce à la touche p du clavier:
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#define TEMPSAFFICHAGEIMG 5
int main(int argc, char *argv[])
{
SDL_Surface *ecran = NULL, *zozor = NULL;
SDL_Rect positionZozor;
SDL_Event event;
long coul = 0;
int pause = 1;
int continuer = 1, versGauche = 0, versHaut = 1;
int tempsPrecedent = 0, tempsActuel = 0;
SDL_Init(SDL_INIT_VIDEO);
ecran = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_WM_SetCaption("Gestion du temps en SDL", NULL);
zozor = SDL_LoadBMP("zozor.bmp");
SDL_SetColorKey(zozor, SDL_SRCCOLORKEY, SDL_MapRGB(zozor->format, 0, 0, 255));
positionZozor.x = 0;
positionZozor.y = 50;
while (continuer)
{
SDL_PollEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer = 0;
break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
case SDLK_p:
if (pause == 1)
pause = 0;
else
pause = 1;
break;
case SDLK_ESCAPE:
continuer = 0;
break;
}
break;
}
if (pause)
{
tempsActuel = SDL_GetTicks();
if (tempsActuel - tempsPrecedent > TEMPSAFFICHAGEIMG)
{
tempsPrecedent = tempsActuel;
if (positionZozor.x <= 0)
{
versGauche = 0;
coul = 1;
}
if (positionZozor.x >= 556)
{
versGauche = 1;
coul = 2;
}
if (positionZozor.y <= 0)
{
versHaut = 0;
coul = 3;
}
if (positionZozor.y >= 385)
{
versHaut = 1;
coul = 4;
}
if (versHaut)
positionZozor.y--;
else
positionZozor.y++;
if (versGauche)
positionZozor.x--;
else
positionZozor.x++;
}
else
{
SDL_Delay(TEMPSAFFICHAGEIMG - (tempsActuel - tempsPrecedent));
}
if (coul == 0)
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
else if (coul == 1)
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 255));
else if (coul == 2)
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 0, 0));
else if (coul == 3)
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 255, 0));
else
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 0));
SDL_BlitSurface(zozor, NULL, ecran, &positionZozor);
SDL_Flip(ecran);
}
}
SDL_FreeSurface(zozor);
SDL_Quit();
return EXIT_SUCCESS;
}
Merci de me repondre a++
