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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
#include <SDL.h>
#include <stdio.h>
#include <stdlib.h>
#include <SDL_audio.h>
#include <SDL_mixer.h>
#include <SDL_image.h>
SDL_Event event;
SDL_Rect rect,rect2,rect3,rect4,back;
SDL_Surface *screen,*rectangle,*rectangle4;
SDL_Surface *background = NULL;
//fonction d'affichage
void apply_surface (int x,int y, SDL_Surface* source, SDL_Surface* destination);
void inputInit(void)
{
// Traduction unicode
SDL_EnableUNICODE(1);
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,
SDL_DEFAULT_REPEAT_INTERVAL+50);
}
void apply_surface (int x,int y, SDL_Surface* source, SDL_Surface* destination)
{ SDL_Rect offset;
offset.x = x;
offset.y = y;
// blit de la surface
SDL_BlitSurface (source, NULL, destination, &offset);
SDL_Flip(screen);
}
void affichage()
{ //coloration des surfaces
/* SDL_FillRect(rectangle, NULL,
SDL_MapRGB(screen->format, 255, 0, 0));*/
SDL_FillRect(screen, NULL, 0);
//defintion de la zone a l'ecran
rect.x= (screen->w /2) -(rect.w/ 2);
rect.y= (screen->h /2) -(rect.h/ 2);
rect.w= screen ->w /2;
rect.h= screen -> h /2;
//definition pour positionner rect2
rect.x =rect.x - 50;
rect.y =rect.y - 100;
rect4.x =rect.x +200;
rect4.y =rect.y;
SDL_BlitSurface(rectangle,NULL,screen,&rect);
SDL_BlitSurface(rectangle4,NULL,screen,&rect4);
SDL_Flip(screen);
}
int main(int argc,char **argv)
{ // initialisation de la SDL
if (SDL_Init (SDL_INIT_EVERYTHING) == -1)
{ return 1;
}
screen = SDL_SetVideoMode (640,480,32, SDL_SWSURFACE | SDL_DOUBLEBUF);
if (screen ==NULL) {
fprintf(stderr, "erreur d'initialisation du mode video: %s\n",SDL_GetError ());
return 2;
}
bool quit= false;
//Allocation de la memoire
rectangle=SDL_LoadBMP("./fab.bmp");
background = IMG_Load("back.bmp");
apply_surface(0,0,background,screen);
// titre de la fenetre
SDL_WM_SetCaption ("jeu fab", NULL);
Mix_Music* myMus;
SDL_Init(SDL_INIT_AUDIO);
/* code à exécuter en cas de pression sur une touche du clavier */
Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT, 2, 1024);
do
{
SDL_Event event; // fermer la fenetre
switch (event.type)
{
case SDL_KEYUP :
// On charge un fichier audio
myMus = Mix_LoadMUS ("concentr.wav");
//on lance la musique
Mix_PlayMusic(myMus, 1);
while (Mix_PlayingMusic() ==1)
{ /* Tant que la musique ne s'est pas termine on fait quelquechose car sinon le programme
s 'eteint et la musique aussi*/
SDL_Delay(10);}
Mix_FreeMusic (myMus);
Mix_CloseAudio();
//rectangle=SDL_LoadBMP("./fab.bmp");
default: ;
}
if (SDL_PollEvent (&event) &&event.type ==SDL_QUIT)
break;
affichage();
// c'est peut etre ici qu'il ya une erreur
apply_surface (0,0,background,screen);
}
while (event.type !=SDL_QUIT);
//Update the screen
// liberation de la memoire
SDL_FreeSurface(rectangle);
SDL_FreeSurface(background);
// SDL_FreeWav();
return 0;
} |
Partager