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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
#include <SDL.h>
#include <stdio.h>
#include <stdlib.h>
#include <SDL_audio.h>
#include <SDL_mixer.h>
#include <SDL_image.h>
#include <string>
#include <SDL_ttf.h>
Mix_Music* myMus;
SDL_Event event;
SDL_Surface *message = NULL, *intro;
SDL_Surface *background = NULL;
SDL_Surface *screen = NULL;
SDL_Surface *back =NULL;
SDL_Surface *rectangle1=NULL;
SDL_Surface *rectangle;
SDL_Rect rect;
void clavier();
void clean_up();
void audio(void);
//The font that's going to be used
TTF_Font *font;
//The color of the font
SDL_Color TextColor = {0, 0, 255};
/*SDL_Surface *load_image ( std ::string filename)
{
SDL_Surface* loadedImage = NULL;
SDL_Surface* optimizedImage = NULL;
loadedImage = SDL_LoadBMP (filename.c_str() );
if ( loadedImage != NULL)
{ optimizedImage = SDL_DisplayFormat (loadedImage);
SDL_FreeSurface (loadedImage);
}
return optimizedImage;
}*/
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);
}
int main (int argc, char* args[])
{ if (SDL_Init(SDL_INIT_EVERYTHING) == -1)
{ return 1;
}
bool quit = false;
if( TTF_Init() == -1 )
{
return false; }
//Open the font
font = TTF_OpenFont( "police12.ttf", 30);
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);
screen= SDL_SetVideoMode (1024,768, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
if (screen == NULL)
{ return 1;
}
SDL_WM_SetCaption ("fab", NULL);
rectangle1 = IMG_Load ("fab.bmp");
background = IMG_Load ("fond.png");
//Render the text
message = TTF_RenderText_Solid( font, "Bienvenue au jeu de Basket", TextColor);
intro = TTF_RenderText_Solid( font, "appuyer sur entrée", TextColor);
//If there was an error in rendering the text
if( rectangle1 == NULL )
{
return 1;
}
apply_surface (0,0, background, screen);
apply_surface (10,100, message, screen);
//apply_surface( 10, 200, rectangle1, screen );
//rect=SDL_FillRect(rectangle,NULL,SDL_MapRGB(screen -> format, 100,10,30));
//SDL_BlitSurface(rectangle,NULL,screen,&rect);
if (SDL_Flip (screen) == -1)
{
return 1;
}
//While the user hasn't quit
while( quit == false )
{
//While there's events to handle
while ( SDL_PollEvent (&event ) )
{ clavier();
//If the user has Xed out the window
if (event.type == SDL_QUIT )
{
//Quit the program
quit = true;
}
}
}
clean_up();
return 0;
}
void audio (void)
{ // 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);
// on libere le materiel
Mix_CloseAudio();
}
void clean_up()
{
SDL_FreeSurface (message);
SDL_FreeSurface (background);
Mix_FreeMusic (myMus);
SDL_Quit();
}
void clavier()
{
SDL_Event event;
switch (event.type)
{ case SDL_KEYDOWN:
switch (event.key.keysym.sym)
{
case SDLK_ESCAPE: audio();
break;
default:;
}
}
} |
Partager