view trix/src/menu.c @ 24:c7e131ce2f14

makefile rm
author Przemyslaw <prymula76@outlook.com>
date Mon, 01 Apr 2024 07:16:40 +0200
parents 2787f5e749ae
children
line wrap: on
line source

#include "trix.h"
/* 
 * Trix - klikanie po klockach
 * Przemysław R. Pietraszczyk
 * 
 * paźdżiernik 2006 r.
 * 
 * licencja: Public Domain
 */
 /*
#if WINDOWS
//#include "img\\about.xpm"
#include "xpm//about.xpm"
#elif LINUX
#include "xpm//about.xpm"
#endif
*/
#define Y_RETURN 400


#define X_START X_CENTER(white_start_inscription->w)
#define X_HISCORES X_CENTER(white_hiscores_inscription->w)
#define X_ABOUT X_CENTER(white_about_inscription->w)
#define X_OPTIONS X_CENTER(white_options_inscription->w)

#define X_RETURN X_CENTER(white_return_inscription->w)

#define X_START_LEVEL X_CENTER(start_level_inscription->w)
#define X_TOPICAL_LEVEL 150
#define X_MINUS 165
#define X_PLUS 250
#define X_NET 165

#define Y_START_LEVEL 100
#define Y_TOPICAL_LEVEL 150
#define Y_NET 250

// z trix.h begin
SDL_Surface * block[8];
SDL_Surface * explode;
SDL_Surface * bomb;
SDL_Surface * wall;
SDL_Surface * smoke;

SDL_Surface * net;
SDL_Surface * banner;
SDL_Surface * bg;
SDL_Surface * screen;
TTF_Font* font;

SDL_Renderer * renderer;
SDL_Texture * tex_screen;

SDL_Rect source, dest;
//int use_net;        // zmienna wyswietlania siatki
//int start_level;    // start gry od poziomu ...
//int score;
//int bonus;          // nalicza premie

//char * hifile;		// path do hiscore


int use_net;        // zmienna wyswietlania siatki
int start_level;    // start gry od poziomu ...
int score;
int bonus;          // nalicza premie

char * hifile;		// path do hiscore
struct tab tab_hiscores[5];
char catalogue[N_PIC][40];
struct FIELD field[23][26];
// z trix.h end


SDL_Surface * prepare_text(int r, int b, int g, char *buffer);
void draw_text (int x, int y, SDL_Surface * image);
void save_settings(void);
void print_inscription(char * buffor, int desx, int desy);
void save_hiscores_to_file (void);

/* sortuje tabele wynikiow i umieszcza
   nowy wpis na odpowiednim miejscu */
void prepare_new_place(char *new_name) {
   
   int i, j, hi = -1;
   
   /* szukamy miejsca na wpis */
   for (i=4; i>=0; --i) {
      if (tab_hiscores[i].score < score)hi = i;    
   }   
 
   /* przesowamy gorsze wyniki o miejsce w dol */
   for (i=4; i>hi; --i) {
     tab_hiscores[i].score = tab_hiscores[i-1].score;
     strcpy(tab_hiscores[i].name, tab_hiscores[i-1].name);  
   }    
   
   /* nowy wpis */
   tab_hiscores[hi].score = score; 
   strcpy(tab_hiscores[hi].name, new_name);  
   
   
   /* zapamietanie wpisu */
   save_hiscores_to_file();
      
}
   

/* pobiera imie gracza */
void  get_name_of_player(void) {
   
   int i, done, p;
   SDL_Rect srcrect, destrect;
   SDL_Surface * enter = NULL;
   SDL_Surface * enter_name_inscription;
   char buffor[20];
   
   destrect = set_rect(0,0,screen->w,screen->h);
   SDL_FillRect(screen,&destrect,0);    
   
#define MAX 20 
   
   /* wypisanie informacji o wprowadzeniu danych */
   enter_name_inscription = (SDL_Surface *) prepare_text(255, 255, 255, "ENTER YOUR NAME");
   draw_text(X_CENTER(enter_name_inscription->w) , 100, enter_name_inscription);
   
   //SDL_Flip(screen);   
   
   p = done = 0;
   while (!done)
   {
      SDL_Event event;

      /* Check for events */
      while (SDL_PollEvent (&event))
      {
         switch (event.type)   
         {
            case SDL_KEYDOWN:
//               printf("Nacini�o klawisz: %s\n",
//               SDL_GetKeyName(event.key.keysym.sym));
               
               if (event.key.keysym.sym==SDLK_ESCAPE)
                  done = 1;
            
               /* kasowanie ostatniej litery */
               if (event.key.keysym.sym==SDLK_BACKSPACE)
               {
                  if (p) {
                     /* skracamy bufor */
                     --p;
                     buffor[p] = '\0';
                     
                     /* najperw czyscimy miejsce wpisu */
                     destrect = set_rect(0, 150, screen->w,enter->h);
                     SDL_FillRect(screen,&destrect,0);  
                     //SDL_UpdateRect(screen, 0, 150, screen->w, enter->h);

                     SDL_FreeSurface(enter);

                     if (strlen(buffor)) { 
                        enter = (SDL_Surface *) prepare_text(255, 255, 255, buffor);
                        draw_text(X_CENTER(enter->w), 150, enter);
                       // SDL_UpdateRect(screen, X_CENTER(enter->w), 150,
                       //     enter->w, enter->h);
                     }
                     /* jesli bufor jest pusty to koniecznie */
                     else enter = NULL;                                     
                  }
                  break;
               }
               /* zatwierdzanie */
               if (event.key.keysym.sym==SDLK_RETURN)
               {
                  /* tylko wtedy gdy jest jakis podpis */
                  if (p)
                     prepare_new_place(buffor);
                  
                  done = 1;
                  break;
               }
               /* dopisywanie litery na koncu */
               if (p < 20 &&  event.key.keysym.sym >= 97 && 
                  event.key.keysym.sym <= 122) {
                  
                  /* najperw czyscimy miejsce wpisu */
                  destrect = set_rect(0, 150, screen->w,32);
                  SDL_FillRect(screen,&destrect,0);  
                  //SDL_UpdateRect(screen, 0, 150, screen->w, 32);

                  SDL_FreeSurface(enter);
                  sprintf(&buffor[p], "%s", SDL_GetKeyName(event.key.keysym.sym));
                  ++p;
                  enter = (SDL_Surface *) prepare_text(255, 255, 255, buffor);
                  draw_text(X_CENTER(enter->w), 150, enter);
                  //SDL_UpdateRect(screen, X_CENTER(enter->w), 150, 
                  //   enter->w, enter->h);
               }
                  
               break;
            case SDL_QUIT:
                exit(0);
                break;      
         }
      }
      
		dest = set_rect(0, 0, screen->w, screen->h);
		//SDL_FillRect(screen, &dest, SDL_MapRGB(screen->format, 255, 255, 255));

		source = set_rect(0, 0, screen->w, screen->h);

		tex_screen = SDL_CreateTextureFromSurface(renderer, screen);
		SDL_RenderClear ( renderer );
		SDL_RenderCopy(renderer, tex_screen,&source,&dest);
		SDL_RenderPresent(renderer);
		SDL_DestroyTexture(tex_screen);
      
   }

   SDL_FreeSurface(enter);
   SDL_FreeSurface(enter_name_inscription);

}   

/* opcje */
void options (void) {
   
   SDL_Surface * start_level_inscription;
   SDL_Surface * white_net_inscription;
   SDL_Surface * yellow_net_inscription;
   SDL_Surface * white_minus_inscription;
   SDL_Surface * yellow_minus_inscription;
   SDL_Surface * white_plus_inscription;
   SDL_Surface * yellow_plus_inscription;
   SDL_Surface * yes_inscription;
   SDL_Surface * no_inscription; 
   SDL_Surface * white_return_inscription;
   SDL_Surface * yellow_return_inscription;
   
   
   int done;
   SDL_Rect srcrect, destrect;
   char buffor[10];
   
   start_level_inscription = (SDL_Surface *) prepare_text(255, 255, 255, "START LEVEL");
   white_net_inscription = (SDL_Surface *) prepare_text(255, 255, 255, "NET:");
   yellow_net_inscription = (SDL_Surface *) prepare_text(237, 0, 255, "NET:");
   white_minus_inscription = (SDL_Surface *) prepare_text(255, 255, 255, "<<");
   yellow_minus_inscription = (SDL_Surface *) prepare_text(237, 0, 255, "<<");
   white_plus_inscription = (SDL_Surface *) prepare_text(255, 255, 255, ">>");
   yellow_plus_inscription = (SDL_Surface *) prepare_text(237, 0, 255, ">>");
   yes_inscription = (SDL_Surface *) prepare_text(255, 255, 255, "YES");   
   no_inscription = (SDL_Surface *) prepare_text(255, 255, 255, "NO ");
   
   white_return_inscription = (SDL_Surface *) prepare_text(255, 255, 255, "RETURN TO MENU");
   yellow_return_inscription = (SDL_Surface *) prepare_text(237, 0, 255, "RETURN TO MENU");

   /* czysci ekran */
   destrect = set_rect(0,0,screen->w,screen->h);
   SDL_FillRect(screen,&destrect,0);

   draw_text(X_START_LEVEL, Y_START_LEVEL, start_level_inscription);
   draw_text(X_MINUS, Y_TOPICAL_LEVEL, white_minus_inscription);
   draw_text(X_PLUS, Y_TOPICAL_LEVEL, white_plus_inscription);

   sprintf(buffor, "%2d", start_level);
   print_inscription(buffor, X_MINUS+47, Y_TOPICAL_LEVEL);
   
   draw_text(X_NET, Y_NET, white_net_inscription);

   if (!use_net) draw_text(X_NET+60, Y_NET, no_inscription); 
   else draw_text(X_NET+60, Y_NET, yes_inscription);
      
   draw_text(X_RETURN, Y_RETURN, white_return_inscription);
   
   ////SDL_Flip(screen);
   
   done = 0;
   while (!done)
   {
      SDL_Event event;

      /* Check for events */
      while (SDL_PollEvent (&event))
      {
         switch (event.type)   
         {
            case SDL_KEYDOWN:
//               printf("Nacini�o klawisz: %s\n",
//               SDL_GetKeyName(event.key.keysym.sym));
               
               if (event.key.keysym.sym==SDLK_ESCAPE)
                  done = 1;        
               break;
            case SDL_QUIT:
                 exit(0);
                break;   
            case SDL_MOUSEMOTION:  
               
            case SDL_MOUSEBUTTONDOWN:
//                printf("Nacini�o przycisk o numerze %d na "
//                "punkcie o wsp�rz�nych %d,%d\n", event.button.button, 
//                event.button.x, event.button.y);  
                /* Kursor na << */
                if (!event.button.button && event.button.x >= X_MINUS &&
                   event.button.y >= Y_TOPICAL_LEVEL && 
                   event.button.x <= X_MINUS + yellow_minus_inscription->w &&
                   event.button.y <= Y_TOPICAL_LEVEL + yellow_minus_inscription->h) {

                   draw_text(X_MINUS, Y_TOPICAL_LEVEL, yellow_minus_inscription);
                  // SDL_UpdateRect(screen, X_MINUS, Y_TOPICAL_LEVEL, 
                 //    yellow_minus_inscription->w, yellow_minus_inscription->h); 
 
                }
                /* gdy wcisnieto << */
                else if (event.button.button && event.button.x >= X_MINUS &&
                   event.button.y >= Y_TOPICAL_LEVEL &&
                   event.button.x <= X_MINUS + yellow_minus_inscription->w &&
                   event.button.y <= Y_TOPICAL_LEVEL + yellow_minus_inscription->h) {

                   if (start_level > 1) start_level -= 1;
                   
                   /* wymazuje wpis */ 
                   destrect = set_rect(212,Y_TOPICAL_LEVEL, 28, 32);             
                   SDL_FillRect(screen,&destrect,0);
                  // SDL_UpdateRect(screen, 212, Y_TOPICAL_LEVEL, 28, 32);
                   
                   /* nowy wpis */                
                   sprintf(buffor, "%2d", start_level);
                   print_inscription(buffor, X_MINUS+47, Y_TOPICAL_LEVEL);
                   //SDL_UpdateRect(screen, X_MINUS+47, Y_TOPICAL_LEVEL, 28, 32);
                   
                   /* << na zolto */                                   
                   draw_text(X_MINUS, Y_TOPICAL_LEVEL, yellow_minus_inscription);
                   //SDL_UpdateRect(screen, X_MINUS, Y_TOPICAL_LEVEL,
                   //  yellow_minus_inscription->w, yellow_minus_inscription->h);                               
                }                      
                else {              
                   /* << na bialo */
                   draw_text(X_MINUS, Y_TOPICAL_LEVEL, white_minus_inscription);
                 //  SDL_UpdateRect(screen, X_MINUS, Y_TOPICAL_LEVEL, 
                //     white_minus_inscription->w, white_minus_inscription->h);
                } 
                /* kursor na >> */
                if (!event.button.button && event.button.x >= X_PLUS &&
                   event.button.y >= Y_TOPICAL_LEVEL && 
                   event.button.x <= X_PLUS + yellow_plus_inscription->w &&
                   event.button.y <= Y_TOPICAL_LEVEL + yellow_plus_inscription->h) {

                   draw_text(X_PLUS, Y_TOPICAL_LEVEL, yellow_plus_inscription);
                   //SDL_UpdateRect(screen, X_PLUS, Y_TOPICAL_LEVEL, 
                  //   yellow_plus_inscription->w, yellow_plus_inscription->h); 
 
                }
                /* gdy wcisnieto >> */
                else if (event.button.button && event.button.x >= X_PLUS &&
                   event.button.y >= Y_TOPICAL_LEVEL &&
                   event.button.x <= X_PLUS + yellow_plus_inscription->w &&
                   event.button.y <= Y_TOPICAL_LEVEL + yellow_plus_inscription->h) {

                   if (start_level<10) start_level += 1;
                   
                   /* wymazuje wpis */
                   destrect = set_rect(212,Y_TOPICAL_LEVEL, 28, 32);              
                   SDL_FillRect(screen,&destrect,0);                
                   //SDL_UpdateRect(screen, 212, Y_TOPICAL_LEVEL, 28, 32);   
                   
                   /* nowy wpis */
                   sprintf(buffor, "%2d", start_level);
                   print_inscription(buffor, X_MINUS+47, Y_TOPICAL_LEVEL);
                  //SDL_UpdateRect(screen, X_MINUS+47, Y_TOPICAL_LEVEL, 28, 32);
                   
                   /* >> na zolto */                               
                   draw_text(X_PLUS, Y_TOPICAL_LEVEL, yellow_plus_inscription);
                  // SDL_UpdateRect(screen, X_PLUS, Y_TOPICAL_LEVEL,
                   //  yellow_plus_inscription->w, yellow_plus_inscription->h);                               
                }                      
                else {              
                   /* >> na bialo */
                   draw_text(X_PLUS, Y_TOPICAL_LEVEL, white_plus_inscription);
                  // SDL_UpdateRect(screen, X_PLUS, Y_TOPICAL_LEVEL, 
                   //  white_plus_inscription->w, white_plus_inscription->h);
//                  printf ("nie wcisnieto \n");
                } 
                /* kursor na NET */
                if (!event.button.button && event.button.x >= X_NET &&
                   event.button.y >= Y_NET && 
                   event.button.x <= X_NET + yellow_net_inscription->w &&
                   event.button.y <= Y_NET + yellow_net_inscription->h) {

                   draw_text(X_NET, Y_NET, yellow_net_inscription);
                   //SDL_UpdateRect(screen, X_NET, Y_NET, 
                   //  yellow_net_inscription->w, yellow_net_inscription->h); 
 
                }
                /* gdy wcisnieto NET */
                else if (event.button.button && event.button.x >= X_NET &&
                   event.button.y >= Y_NET &&
                   event.button.x <= X_NET + yellow_net_inscription->w &&
                   event.button.y <= Y_NET + yellow_net_inscription->h) {

                   if (use_net) use_net =0;
                   else use_net =1;
                   
                   /* wymazuje wpis */
                   destrect = set_rect(X_NET+60,Y_NET,
                     yes_inscription->w,yes_inscription->h);
                   SDL_FillRect(screen,&destrect,0);
                  
                   /* ustawia odpowiedni tekst */
                   if (!use_net) draw_text(X_NET+60, Y_NET, no_inscription); 
                   else draw_text(X_NET+60, Y_NET, yes_inscription);

                  // SDL_UpdateRect(screen, X_NET+60, Y_NET,
                  //   yes_inscription->w, yes_inscription->h);
                                                           
                   draw_text(X_NET, Y_NET, yellow_net_inscription);
                 //  SDL_UpdateRect(screen, X_NET, Y_NET,
                 //    yellow_net_inscription->w, yellow_net_inscription->h);                               
                }                      
                else {              

                   draw_text(X_NET, Y_NET, white_net_inscription);
                   //SDL_UpdateRect(screen, X_NET, Y_NET, 
                   //  white_net_inscription->w, white_net_inscription->h);
//                  printf ("nie wcisnieto \n");
                } 

                /* Kursor na powrot do menu */
                if (!event.button.button && event.button.x >= X_RETURN &&
                   event.button.y >= Y_RETURN && 
                   event.button.x <= X_RETURN + yellow_return_inscription->w &&
                   event.button.y <= Y_RETURN + yellow_return_inscription->h) {

                   draw_text(X_RETURN, Y_RETURN, yellow_return_inscription);
                  // SDL_UpdateRect(screen, X_RETURN, Y_RETURN, 
                  //   yellow_return_inscription->w, yellow_return_inscription->h); 
 
                }
 
                /* gdy wcisnieto powrot do menu */
                else if (event.button.button && event.button.x >= X_RETURN &&
                   event.button.y >= Y_RETURN &&
                   event.button.x <= X_RETURN + yellow_return_inscription->w &&
                   event.button.y <= Y_RETURN + yellow_return_inscription->h) {
                        
                   done = 1; 
                   save_settings();                                       
                   draw_text(X_RETURN, Y_RETURN, yellow_return_inscription);
                  // SDL_UpdateRect(screen, X_RETURN, Y_RETURN,
                 //    yellow_return_inscription->w, yellow_return_inscription->h);                               
                }                      
                else {              
                   /* powrot do menu na bialo */
                   draw_text(X_RETURN, Y_RETURN, white_return_inscription);
                 //  SDL_UpdateRect(screen, X_RETURN, Y_RETURN, 
                 //    white_return_inscription->w, white_return_inscription->h);
                } 
 
            break;
         }
      }
//      //SDL_Flip(screen);
		dest = set_rect(0, 0, screen->w, screen->h);
		//SDL_FillRect(screen, &dest, SDL_MapRGB(screen->format, 255, 255, 255));

		source = set_rect(0, 0, screen->w, screen->h);

		tex_screen = SDL_CreateTextureFromSurface(renderer, screen);
		SDL_RenderClear ( renderer );
		SDL_RenderCopy(renderer, tex_screen,&source,&dest);
		SDL_RenderPresent(renderer);
		SDL_DestroyTexture(tex_screen);
   }   



   // czyscimy ekran przed powrotem 
   destrect = set_rect(0,0,screen->w,screen->h);
   SDL_FillRect(screen,&destrect,0); 
   //SDL_Flip(screen);

   
   
   SDL_FreeSurface(start_level_inscription);
   SDL_FreeSurface(white_net_inscription);
   SDL_FreeSurface(yellow_net_inscription);
   SDL_FreeSurface(white_minus_inscription);
   SDL_FreeSurface(yellow_minus_inscription);
   SDL_FreeSurface(white_plus_inscription);
   SDL_FreeSurface(yellow_plus_inscription);
   SDL_FreeSurface(yes_inscription);
   SDL_FreeSurface(no_inscription);
   SDL_FreeSurface(white_return_inscription);
   SDL_FreeSurface(yellow_return_inscription);
   
}

void wait_for_return (void) {
   
   int done;
   SDL_Surface * white_return_inscription;
   SDL_Surface * yellow_return_inscription; 
     
   white_return_inscription = (SDL_Surface *) prepare_text(255, 255, 255, "RETURN TO MENU");
   yellow_return_inscription = (SDL_Surface *) prepare_text(237, 0, 255, "RETURN TO MENU");
   
	draw_text(X_RETURN, Y_RETURN, white_return_inscription);
   
//   //SDL_Flip(screen);
  // SDL_UpdateRect(screen, X_RETURN, Y_RETURN,
	//	white_return_inscription->w, white_return_inscription->h);
	

   done = 0;
   while (!done)
   {
      SDL_Event event;

      /* Check for events */
      while (SDL_PollEvent (&event))
      {
         switch (event.type)   
         {
            case SDL_KEYDOWN:
//               printf("Nacini�o klawisz: %s\n",
//               SDL_GetKeyName(event.key.keysym.sym));
               
               if (event.key.keysym.sym==SDLK_ESCAPE)
                  done = 1;
               break;
            case SDL_QUIT:
                exit(0);                 
                break;   
            case SDL_MOUSEMOTION:  
               
            case SDL_MOUSEBUTTONDOWN:
//                printf("Nacini�o przycisk o numerze %d na "
//                "punkcie o wsp�rz�nych %d,%d\n", event.button.button, 
//                event.button.x, event.button.y);
 
                /* Kursor na powrot do menu */                
                if (!event.button.button && event.button.x >= X_RETURN &&
                   event.button.y >= Y_RETURN && 
                   event.button.x <= X_RETURN + yellow_return_inscription->w &&
                   event.button.y <= Y_RETURN + yellow_return_inscription->h) {

                   draw_text(X_RETURN, Y_RETURN, yellow_return_inscription);
                 //  SDL_UpdateRect(screen, X_RETURN, Y_RETURN, 
                  //   yellow_return_inscription->w, yellow_return_inscription->h); 
 
                }
 
                /* gdy wcisnieto powrot do menu */
                else if (event.button.button && event.button.x >= X_RETURN &&
                   event.button.y >= Y_RETURN &&
                   event.button.x <= X_RETURN + yellow_return_inscription->w &&
                   event.button.y <= Y_RETURN + yellow_return_inscription->h) {

                   done = 1;                                         
                   draw_text(X_RETURN, Y_RETURN, yellow_return_inscription);
               //    SDL_UpdateRect(screen, X_RETURN, Y_RETURN,
               //      yellow_return_inscription->w, yellow_return_inscription->h);                               
                }                      
                else {              
                   /* powrot do manu na bialo */
                   draw_text(X_RETURN, Y_RETURN, white_return_inscription);
                //   SDL_UpdateRect(screen, X_RETURN, Y_RETURN, 
                //     white_return_inscription->w, white_return_inscription->h);
                } 
 
            break;
         }
      }
      
      
		dest = set_rect(0, 0, screen->w, screen->h);
		//SDL_FillRect(screen, &dest, SDL_MapRGB(screen->format, 255, 255, 255));

		source = set_rect(0, 0, screen->w, screen->h);

		tex_screen = SDL_CreateTextureFromSurface(renderer, screen);
		SDL_RenderClear ( renderer );
		SDL_RenderCopy(renderer, tex_screen,&source,&dest);
		SDL_RenderPresent(renderer);
		SDL_DestroyTexture(tex_screen);
      
   }   

   SDL_FreeSurface(white_return_inscription);
   SDL_FreeSurface(yellow_return_inscription);
}


void about (void) {

   SDL_Surface * about;
   SDL_Rect srcrect, destrect;
   
   about=IMG_ReadXPMFromArray(about_xpm);
   if(!about) {
      printf("IMG_ReadXPMFromArray: %s\n", IMG_GetError());
      exit(1);
   }
   
   /* czysci ekran */
   destrect = set_rect(0,0,screen->w,screen->h);
   SDL_FillRect(screen,&destrect,0);
   
   /* umieszcza inskrypcje na ekranie */
   destrect = set_rect(X_CENTER(about->w),50,about->w,about->h);
   srcrect = set_rect(0, 0, about->w, about->h);
   SDL_BlitSurface(about,&srcrect, screen,&destrect);
//   SDL_UpdateRect(screen, X_CENTER(about->w), 50, about->w, about->h);
   
   //SDL_Flip(screen);
   
   wait_for_return();
   
   SDL_FreeSurface(about);
   
   /* czyscimy ekran przed powrotem */
   destrect = set_rect(0,0,screen->w,screen->h);
   SDL_FillRect(screen,&destrect,0); 
   //SDL_Flip(screen);
   
}
   



void hiscores(void) {

   SDL_Surface * place_inscription[5];
   SDL_Rect srcrect, destrect;
   int done, i, y_place;
   char buffor[50];


   destrect = set_rect(0,0,screen->w,screen->h);
   SDL_FillRect(screen,&destrect,0); 
   
   /* tworzenie obrazkow z wynikami */
   for (i=0; i<5; ++i) {
      sprintf(buffor, "%d %s %d", i+1, tab_hiscores[i].name, tab_hiscores[i].score);
      place_inscription[i]= (SDL_Surface *) prepare_text(255, 255, 255, buffor);
   }   
   
   
   /* wypisuje ranking */
   y_place = 50;
   for (i=0; i<5; ++i) {
      draw_text(X_CENTER(place_inscription[i]->w), y_place, place_inscription[i]);
      y_place += 50;
   }
   //SDL_Flip(screen);
   
   wait_for_return();
   
   /* usuwanie obrazkow*/
   for (i=0; i<5; ++i) 
      SDL_FreeSurface(place_inscription[i]);

   
   // czyscimy ekran przed powrotem 
   destrect = set_rect(0,0,screen->w,screen->h);
   SDL_FillRect(screen,&destrect,0); 
   //SDL_Flip(screen);      
   

}


int menu() {
   
   int done;
   SDL_Rect srcrect, destrect;
   SDL_Surface * white_start_inscription;
   SDL_Surface * yellow_start_inscription; 
   SDL_Surface * white_hiscores_inscription;
   SDL_Surface * yellow_hiscores_inscription;
   SDL_Surface * white_about_inscription;
   SDL_Surface * yellow_about_inscription;
   SDL_Surface * white_options_inscription;
   SDL_Surface * yellow_options_inscription;


	white_start_inscription = (SDL_Surface *) prepare_text(255, 255, 255, "START");
   white_hiscores_inscription = (SDL_Surface *) prepare_text(255, 255, 255, "HiSCORES");
   white_about_inscription = (SDL_Surface *) prepare_text(255, 255, 255, "ABOUT");
   white_options_inscription = (SDL_Surface *) prepare_text(255, 255, 255, "OPTIONS");
   yellow_start_inscription = (SDL_Surface *) prepare_text(237, 0, 255, "START");
   yellow_hiscores_inscription = (SDL_Surface *) prepare_text(237, 0, 255, "HiSCORES");  
   yellow_about_inscription = (SDL_Surface *) prepare_text(237, 0, 255, "ABOUT");
   yellow_options_inscription = (SDL_Surface *) prepare_text(237, 0, 255, "OPTIONS");

	/* czysci ekran */
   destrect = set_rect(0,0,screen->w,screen->h);
   SDL_FillRect(screen,&destrect,0);

   /* rysuje banner */
   destrect = set_rect(X_CENTER(banner->w),50,banner->w,banner->h);
   srcrect = set_rect(0, 0, banner->w, banner->h);
   SDL_BlitSurface(banner,&srcrect, screen,&destrect);
   // SDL_UpdateRect(screen, X_CENTER(banner->w), 50, banner->w, banner->h);


   draw_text(X_START, Y_START, white_start_inscription);
   draw_text(X_HISCORES, Y_HISCORES, white_hiscores_inscription);
   draw_text(X_OPTIONS, Y_OPTIONS, white_options_inscription);
   draw_text(X_ABOUT, Y_ABOUT, white_about_inscription);

   //SDL_Flip(screen);
   
   done = 0;
   while (!done)
   {
      SDL_Event event;

      /* Check for events */
      while (SDL_PollEvent (&event))
      {
         switch (event.type)
         {
            case SDL_KEYDOWN: 
//               printf("Nacini�o klawisz: %s\n", 
//               SDL_GetKeyName(event.key.keysym.sym));
               
               if (event.key.keysym.sym==SDLK_ESCAPE)
                  done = QUIT_GAME;
               break;
            case SDL_QUIT:
                done = QUIT_GAME;
               break; 
            case SDL_MOUSEMOTION:
            case SDL_MOUSEBUTTONDOWN:
                /* kursor na starcie */
                if (!event.button.button && event.button.x >= X_START &&
                   event.button.y >= Y_START &&
                   event.button.x <= X_START + yellow_start_inscription->w &&
                   event.button.y <= Y_START + yellow_start_inscription->h) {

                   draw_text(X_START, Y_START, yellow_start_inscription);
                //   SDL_UpdateRect(screen, X_START, Y_START, 
               //      yellow_start_inscription->w, yellow_start_inscription->h);
                }
                /* gdy wcisnieto start */
                else if (event.button.button && event.button.x >= X_START &&
                   event.button.y >= Y_START &&
                   event.button.x <= X_START + yellow_start_inscription->w &&
                   event.button.y <= Y_START + yellow_start_inscription->h) {
 
                   done = START_GAME;                                    

                   draw_text(X_START, Y_START, yellow_start_inscription);
               //    SDL_UpdateRect(screen, X_START, Y_START, 
              //       yellow_start_inscription->w, yellow_start_inscription->h);                               
                }                      
                else {              
                     /* kursor poza napisem start */
                   draw_text(X_START, Y_START, white_start_inscription);
                 //  SDL_UpdateRect(screen, X_START, Y_START, 
                 //    white_start_inscription->w, white_start_inscription->h);
                }
                /* kursor na hiscores */
                if (!event.button.button && event.button.x >= X_HISCORES &&
                   event.button.y >= Y_HISCORES &&
                   event.button.x <= X_HISCORES + yellow_hiscores_inscription->w &&
                   event.button.y <= Y_HISCORES + yellow_hiscores_inscription->h) {

                   draw_text(X_HISCORES, Y_HISCORES, yellow_hiscores_inscription);
               //    SDL_UpdateRect(screen, X_HISCORES, Y_HISCORES, 
                //     yellow_hiscores_inscription->w, yellow_hiscores_inscription->h);
                }
                /* gdy wcisnieto hiscores */
                else if (event.button.button && event.button.x >= X_HISCORES &&
                   event.button.y >= Y_HISCORES &&
                   event.button.x <= X_HISCORES + yellow_hiscores_inscription->w &&
                   event.button.y <= Y_HISCORES + yellow_hiscores_inscription->h) {

                   done = HISCORES;

                   draw_text(X_HISCORES, Y_HISCORES, yellow_hiscores_inscription);
               //    SDL_UpdateRect(screen, X_HISCORES, Y_HISCORES, 
              //       yellow_hiscores_inscription->w, yellow_hiscores_inscription->h);
                }                              
                else {
                  /* kursor poza napisem hiscore */
                  draw_text(X_HISCORES, Y_HISCORES, white_hiscores_inscription);
               //   SDL_UpdateRect(screen, X_HISCORES, Y_HISCORES, 
               //      white_hiscores_inscription->w, white_hiscores_inscription->h);
                }                
                /* kursor na options */
                if (!event.button.button && event.button.x >= X_OPTIONS &&
                   event.button.y >= Y_OPTIONS &&
                   event.button.x <= X_OPTIONS + yellow_options_inscription->w &&
                   event.button.y <= Y_OPTIONS + yellow_options_inscription->h) {

                   draw_text(X_OPTIONS, Y_OPTIONS, yellow_options_inscription);
              //     SDL_UpdateRect(screen, X_OPTIONS, Y_OPTIONS, 
              //       yellow_options_inscription->w, yellow_options_inscription->h);
                }
                /* gdy wcisnieto options */
                else if (event.button.button && event.button.x >= X_OPTIONS &&
                   event.button.y >= Y_OPTIONS &&
                   event.button.x <= X_OPTIONS + yellow_options_inscription->w &&
                   event.button.y <= Y_OPTIONS + yellow_options_inscription->h) {

                   done = OPTIONS;

                   draw_text(X_OPTIONS, Y_OPTIONS, yellow_options_inscription);
              //     SDL_UpdateRect(screen, X_OPTIONS, Y_OPTIONS, 
               //      yellow_options_inscription->w, yellow_options_inscription->h);
                }                              
                else {
                  /* kursor poza napisem options */
                  draw_text(X_OPTIONS, Y_OPTIONS, white_options_inscription);
             //     SDL_UpdateRect(screen, X_OPTIONS, Y_OPTIONS, 
               //      white_options_inscription->w, white_options_inscription->h);
                }                
           
           
                /* kursor na about */
                if (!event.button.button && event.button.x >= X_ABOUT &&
                   event.button.y >= Y_ABOUT &&
                   event.button.x <= X_ABOUT + yellow_about_inscription->w &&
                   event.button.y <= Y_ABOUT + yellow_about_inscription->h) {

                   draw_text(X_ABOUT, Y_ABOUT, yellow_about_inscription);
              //     SDL_UpdateRect(screen, X_ABOUT, Y_ABOUT, 
              //       yellow_about_inscription->w, yellow_about_inscription->h);
                }
                /* gdy wcisnieto about */
                else if (event.button.button && event.button.x >= X_ABOUT &&
                   event.button.y >= Y_ABOUT &&
                   event.button.x <= X_ABOUT + yellow_about_inscription->w &&
                   event.button.y <= Y_ABOUT + yellow_about_inscription->h) {

                   done = ABOUT;

                   draw_text(X_ABOUT, Y_ABOUT, yellow_about_inscription);
               //    SDL_UpdateRect(screen, X_ABOUT, Y_ABOUT, 
               //      yellow_about_inscription->w, yellow_about_inscription->h);
                }                              
                else {
                  /* kursor poza napisem about */
                  draw_text(X_ABOUT, Y_ABOUT, white_about_inscription);
               //   SDL_UpdateRect(screen, X_ABOUT, Y_ABOUT, 
               //      white_about_inscription->w, white_about_inscription->h);
                }                
      
                break; 
            default:
               break;
                              
         }             
      }

        dest = set_rect(0, 0, screen->w, screen->h);
		source = set_rect(0, 0, screen->w, screen->h);

		tex_screen = SDL_CreateTextureFromSurface(renderer, screen);
		SDL_RenderClear ( renderer );
		SDL_RenderCopy(renderer, tex_screen,&source,&dest);
		SDL_RenderPresent(renderer);
		SDL_DestroyTexture(tex_screen);
      
   }
   SDL_FreeSurface(white_start_inscription);
   SDL_FreeSurface(yellow_start_inscription); 
   SDL_FreeSurface(white_hiscores_inscription);
   SDL_FreeSurface(yellow_hiscores_inscription);
   SDL_FreeSurface(white_about_inscription);
   SDL_FreeSurface(yellow_about_inscription);
   SDL_FreeSurface(white_options_inscription);
   SDL_FreeSurface(yellow_options_inscription);
   
   return done;
}