Bonjour/Bonsoir tout le monde !
Je ne vais pas y passer par 4 chemins, voici mon problème:
1er : Je charge mon image de balle d'AK47, qui doit apparaître et avancer lorsque qu'on appuie sur le bouton gauche de la souris. Or, elle apparaît déjà lorsque qu'on lance le jeu.
2ème: Non seulement, la balle d'AK 47 apparaît au début du programme, mais en plus, elle apparaît 2 fois à l'écran ! (En bas et en haut)
3ème: Je ne peux tirer qu'une seule balle.
4ème: Dès que je bouge ma souris, la balle se fige.
Auriez-vous une solution s'il vous plait ?
Code:
- include <stdlib.h>
- include <stdio.h>
- include <SDL/SDL.h>
int main(int argc, char *argv[])
{
SDL_Surface *ecran = NULL, *perso = NULL, *ImageDeFond = NULL, *balle = NULL;
SDL_Rect positionPerso, positionFond, positionBalle;
SDL_Event event;
int continuer = 1;
int tempsPrecedent = 0, tempsActuel = 0;
positionFond.x = 0;
positionFond.y = 0;
SDL_Init(SDL_INIT_VIDEO);
ecran = SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_WM_SetCaption("Gestion du temps en SDL", NULL);
ImageDeFond = SDL_LoadBMP("Nuit.bmp");
balle = SDL_LoadBMP("Balle.bmp");
SDL_SetColorKey(balle, SDL_SRCCOLORKEY, SDL_MapRGB(balle->format, 0, 0, 0));
perso = SDL_LoadBMP("CNAK.bmp");
SDL_SetColorKey(perso, SDL_SRCCOLORKEY, SDL_MapRGB(perso->format, 0, 0, 0));
positionPerso.x = ecran->w / 2 - perso->w / 2;
positionPerso.y = ecran->h / 2 - perso->h / 2;
positionBalle.x = ecran->w / 2 - perso->w / 2;
positionBalle.y = ecran->h / 2 - perso->h / 2;
SDL_EnableKeyRepeat(1000, 1000);
while (continuer)
{
SDL_PollEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer = 0;
break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
case SDLK_ESCAPE:
continuer = 0;
break;
case SDLK_LEFT:
positionPerso.x--;
break;
case SDLK_RIGHT:
positionPerso.x++;
break;
}
break;
case SDL_MOUSEBUTTONUP:
if(event.button.button == SDL_BUTTON_LEFT)
{
tempsActuel = SDL_GetTicks();
if (tempsActuel - tempsPrecedent > 0)
{
positionBalle.x++;
tempsPrecedent = tempsActuel;
}
}
break;
}
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
SDL_BlitSurface(ImageDeFond, NULL, ecran, &positionFond);
SDL_BlitSurface(balle, NULL, ecran, &positionBalle);
SDL_BlitSurface(perso, NULL, ecran, &positionPerso);
SDL_Flip(ecran);
}
SDL_FreeSurface(perso);
SDL_FreeSurface(ImageDeFond);
SDL_Quit();
return EXIT_SUCCESS;
}
Merci d'avance !
Coucou, tu veux voir mon argent ?
¯¯\/¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
