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
|
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <time.h>
typedef struct surfaces{
SDL_Surface* surface1;
SDL_Surface* surface2;
SDL_Surface* surface3;
SDL_Rect* position;
}SURFACES;
Uint32 mouvement(Uint32 intervalle, void* param){
SDL_Rect* pos = param;
pos->x+=5;
pos->y+=5;
return intervalle;
}
Uint32 afficher(Uint32 intervalle, void* param){
SURFACES* surface = param;
SDL_Rect p;
p.x=0;
p.y=0;
SDL_BlitSurface(surface->surface1,NULL,surface->surface2,&p);
SDL_BlitSurface(surface->surface3,NULL,surface->surface2,surface->position);
SDL_Flip(surface->surface2);
return intervalle;
}
int main(int argc, char *argv[]){
SDL_Surface* ecran=NULL;
SDL_Surface* fond=NULL;
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
ecran=SDL_SetVideoMode(750,500,32,SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_Rect position, posi;
position.x=200;
position.y=100;
posi.x=0;
posi.y=0;
SDL_WM_SetCaption("Test timer",NULL);
fond=SDL_LoadBMP("fond.bmp");
SDL_BlitSurface(fond,NULL,ecran,&posi);
SDL_Flip(ecran);
SDL_Surface* piques;
piques = SDL_LoadBMP("boulepique.bmp");
SURFACES* surfaces;
surfaces->surface1=fond;
surfaces->surface2=ecran;
surfaces->surface3=piques;
SDL_TimerID timer = SDL_AddTimer(500, mouvement, &position);
SDL_TimerID frame = SDL_AddTimer(400, afficher, surfaces);
SDL_Delay(10000);
SDL_RemoveTimer(timer);
SDL_RemoveTimer(frame);
SDL_FreeSurface(piques);
SDL_FreeSurface(fond);
SDL_FreeSurface(ecran);
SDL_Quit();
return EXIT_SUCCESS;
} |
Partager