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
| #include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include <stdio.h>
#include <stdlib.h>
#define HEIGHT 780
#define WIDTH 1280
#include <pthread.h>
SDL_Surface *ecran=SDL_SetVideoMode(WIDTH,HEIGHT, 32, SDL_HWSURFACE);
void* affichage( void*);
int main(int narg, char **args)
{
SDL_Init(SDL_INIT_VIDEO);
pthread_t* aff;
// La position de la pomme
SDL_Rect *position_pomme= new SDL_Rect;
pthread_create(aff,NULL,affichage,position_pomme);
//On centre a peu pres la pomme
position_pomme->x=HEIGHT/2;
//On place la pomme en haut
position_pomme->y=0;
double y=0;
double vitesse=10.9;
/* Tant que la pomme n'est pas en bas*/
while(y < HEIGHT)
{
//Calcul de la nouvelle position
y+=vitesse;
// Mise à jour de la position
position_pomme->y=(int)y;
usleep(1e5);
}
pthread_cancel(*aff);
SDL_Quit();
}
void* affichage( void* position){
SDL_Rect* position_pomme=(SDL_Rect *) position;
static SDL_Surface * pomme=IMG_Load("pomme.jpg");
while(1){
// On efface l'écran
SDL_FillRect(ecran,NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
// On affiche la pomme à sa position
SDL_BlitSurface(pomme,NULL,ecran,position_pomme);
SDL_Flip(ecran);
usleep(10000);
}
} |
Partager