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
| #include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
int main( int argc, char *argv[ ] )
{
SDL_Surface *screen;
int lastrender = 0;
if( SDL_Init( SDL_INIT_JOYSTICK | SDL_INIT_VIDEO ) == -1 )
{
printf( "Can't init SDL: %s\n", SDL_GetError( ) );
return EXIT_FAILURE;
}
atexit( SDL_Quit );
screen = SDL_SetVideoMode( 640, 480, 16, SDL_HWSURFACE );
if( !screen)
{
printf( "Can't set video mode: %s\n", SDL_GetError( ) );
return EXIT_FAILURE;
}
SDL_Rect position;
SDL_Surface *rectangle = NULL;
rectangle = SDL_CreateRGBSurface(SDL_HWSURFACE, 10, 10, 16, 0, 0, 0, 0);
position.x = screen->w/2;
position.y = screen->h/2;
bool jeu = false;
SDL_Event event;
while(!jeu)
{
SDL_FillRect(rectangle, NULL, SDL_MapRGB(screen->format, 255, 255, 255));
SDL_BlitSurface(rectangle, NULL, screen, &position); // Collage de la surface sur l'écran
SDL_Flip(screen); // Mise à jour de l'écran
// SDL_Delay( 100 );
SDL_FillRect(rectangle, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
SDL_BlitSurface(rectangle, NULL, screen, &position); // Collage de la surface sur l'écran
position.x = rand()%screen->w;
position.y = rand()%screen->h;
SDL_Delay( 2000 );
}
exit(0)
return EXIT_SUCCESS;
} |
Partager