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
|
#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
// Permet de pouvoir sortir du programme en appuyant sur la croix
class SystemManager {
public:
// Here we will just have a couple public members for example purposes.
bool running;
SDL_Event events;
void inputManager(); // Handle input.
void renderingManager(); // Handle drawing pretty pictures.
};
void SystemManager::inputManager() {
while(SDL_PollEvent(&events)) {
if(events.type == SDL_QUIT)
running = false;
}
}
void SystemManager::renderingManager() {
// Draw pretty pictures...
}
int main( int argc, char *argv[ ] )
{
SDL_Surface *screen;
SystemManager sysMgr;
sysMgr.running = true;
int lastrender = 0;
int dirX = 1;
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( 1280, 800, 16, SDL_HWSURFACE| SDL_FULLSCREEN | SDL_DOUBLEBUF ); // initialisation de l'ecran
if( !screen)
{
printf( "Can't set video mode: %s\n", SDL_GetError( ) );
return EXIT_FAILURE;
}
SDL_Rect position; // creation du point (rectangle)
SDL_Surface *rectangle = NULL;
rectangle = SDL_CreateRGBSurface(SDL_HWSURFACE, 12, 12, 16, 0, 1, 0, 0); // taille et couleur
position.x = screen->w/2; //structure pour placer le point au centre
position.y = screen->h/2;
int dirx = 1;
SDL_Event event;
while(sysMgr.running) // boucle qui travaille tant qu'on appuye pas sur la croix pour quitter
{
sysMgr.inputManager();
sysMgr.renderingManager();
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 += dirx;
if ((position.x >= screen->w) || (position.x <= 0))
dirx = -dirx;
SDL_Delay(100);
}
return EXIT_SUCCESS;
} |
Partager