Bonjour a tous
je vien de faire un programme pour que quand box1 et box2 se rencontre le programme s’éteint (oui je sais c'est assez barbare ^^) le probleme et que sa ne marche pas et en plus sa ne me met pas de message d'erreur oO
le voici:
- include <stdlib.h>
- include <stdio.h>
- include <SDL/SDL.h>
- define true 1
- define false 0
void pause();
struct AABB
{
int x;
int y;
int w;
int h;
};
int Collision(SDL_Rect box2,SDL_Rect box1);
int main(int argc, char *argv[])
{
SDL_Surface *ecran = NULL , *box1 = NULL , *box2 = NULL;
SDL_Rect positionZozor;
SDL_Rect positionb;
SDL_Event event;
int continuer = 1;
SDL_Init (SDL_INIT_VIDEO);
ecran = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_WM_SetCaption("Gestion des évènements en SDL", NULL);
box2 = SDL_LoadBMP("icon.bmp");
box1 = SDL_LoadBMP("cb.bmp");
SDL_SetColorKey(box1, SDL_SRCCOLORKEY, SDL_MapRGB(box1->format, 0, 0, 255));
/* On centre Zozor à l'écran */
positionZozor.x = ecran->w / 2 - box1->w / 2;
positionZozor.y = ecran->h / 2 - box1->h / 2;
positionb.x = 0;
positionb.y = 0;
SDL_EnableKeyRepeat(10, 10);
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
positionZozor.y--;
break;
case SDLK_DOWN: // Flèche bas
positionZozor.y++;
break;
case SDLK_RIGHT: // Flèche droite
positionZozor.x++;
break;
case SDLK_LEFT: // Flèche gauche
positionZozor.x--;
break;
}
break;
}
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255)); /* On efface l'écran */
SDL_BlitSurface(box1, NULL, ecran, &positionZozor);
SDL_BlitSurface(box2, NULL, ecran, &positionb);
SDL_Flip(ecran); /* On met à jour l'affichage */
}
if (Collision(positionb , positionZozor))
{
SDL_Quit();
}
SDL_FreeSurface(box1);
SDL_FreeSurface(box2);
pause();
SDL_Quit();
return EXIT_SUCCESS;
return 0;}
int Collision(SDL_Rect box2,SDL_Rect box1)
{
if((box2.x >= box1.x + box1.w) // trop à droite
|| (box2.x + box2.w <= box1.x) // trop à gauche
|| (box2.y >= box1.y + box1.h) // trop en bas
|| (box2.y + box2.h <= box1.y)) // trop en haut
{
return false;
}
else
{
return true;
}
}
void pause()
{
int continuer = 1;
SDL_Event event;
while (continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer = 0;
}
}
}