diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/game.c | 813 | ||||
-rw-r--r-- | src/main.c | 652 | ||||
-rw-r--r-- | src/menu.c | 879 | ||||
-rw-r--r-- | src/trix.h | 156 |
4 files changed, 2500 insertions, 0 deletions
diff --git a/src/game.c b/src/game.c new file mode 100644 index 0000000..175f03f --- /dev/null +++ b/src/game.c @@ -0,0 +1,813 @@ +/*
+ * Trix - klikanie po klockach
+ * Przemysław R. Pietraszczyk
+ *
+ * paźdżiernik 2006 r.
+ *
+ * licencja: Public Domain
+ */
+
+#include "trix.h"
+
+#define X_SCORE_INSCRIPTION 10
+#define X_LEVEL_INSCRIPTION 200
+#define X_HISCORE_INSCRIPTION 340
+#define Y_ALL_INSCRIPTION 0
+
+#define X_HIGH_SLAT 1
+#define Y_HIGH_SLAT 40
+#define X_SIZE_HIGH_SLAT (screen->w)
+#define Y_SIZE_HIGH_SLAT FIELD_SIZE
+
+#define X_ACTION 1
+#define Y_ACTION 60
+#define X_SIZE_ACTION (screen->w)
+#define Y_SIZE_ACTION (screen->h)
+
+/*
+// 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 const catalogue[N_PIC][40];
+// z trix.h end
+
+*/
+
+
+
+static SDL_Surface * var_level_inscription;
+static SDL_Surface * var_hiscore_inscription;
+
+/* tablica struktur przechowuje pozycje kasowanych elementow */
+static struct ghost gh[598];
+static int gh_index;
+
+SDL_Surface * prepare_text(int r, int b, int g, char *buffer);
+void load_background(int n);
+void print_inscription(char * buffor, int desx, int desy);
+void draw_text (int x, int y, SDL_Surface * image);
+
+void get_name_of_player(void);
+
+
+
+/* sprawdza czy klocki nie osiagnely masymalnej wysokosci */
+int behind_high(void) {
+
+ int i;
+
+ /* jesli znajdzie na szczycie jakis klocek o stalym statusie
+ zwraca prawde */
+ for (i=0; i<23; ++i) {
+ if (field[i][1].type && field[i][1].status == STAND)
+ return 1;
+ }
+
+ return 0;
+}
+
+/* zeruje strukture elementow */
+void zero_field(void) {
+
+ int i, j;
+
+ for (j=0; j<26;++j) {
+ for (i=0; i<23;++i) {
+ field[i][j].type = NULL;
+ field[i][j].status=0;
+ }
+ }
+
+}
+
+
+void set_background(void) {
+
+ SDL_Rect srcrect, destrect;
+
+ destrect = set_rect(0, 0, bg->w, bg->h);
+ srcrect = set_rect(0,0, bg->w, bg->h);
+ SDL_BlitSurface(bg,&srcrect,screen,&destrect);
+}
+
+void set_net(void) {
+
+ SDL_Rect srcrect, destrect;
+
+ destrect = set_rect(0, 0, net->w, net->h);
+ srcrect = set_rect(0,0, net->w, net->h);
+ SDL_BlitSurface(net,&srcrect,screen,&destrect);
+}
+
+
+/* sprawdza czy na planszy sa jakies klocki */
+int shortage_blocks(void) {
+
+ int i, j;
+
+ for (j=1; j<26; j++) {
+ for (i=0; i<23; i++) {
+ if (field[i][j].type) {
+ if (field[i][j].type == wall) continue;
+ else goto end;
+ }
+ }
+ }
+
+end:
+ /* gdy brak klockow */
+ if (j==26 && i==23) {
+ printf ("brak klockow\n");
+ return 1;
+ }
+
+ /* gdy sa klocki */
+ return 0;
+
+
+}
+
+
+/* elementy zaczynaja opadac z gornej belki */
+void drop_from_high_slat(void) {
+
+ int i;
+
+ for (i=22; i>=0; --i) {
+ field[i][0].status = DROP;
+ }
+}
+
+void set_element(int f, int x, int y) {
+
+ switch(f) {
+// od 0 do 49 pustka
+ case 50 ... 64:
+ field[x][y].type = bomb;
+ break;
+ case 65 ... 73:
+ field[x][y].type = block[0];
+ break;
+ case 74 ... 80:
+ field[x][y].type = block[1];
+ break;
+ case 81 ... 85:
+ field[x][y].type = block[2];
+ break;
+ case 86 ... 90:
+ field[x][y].type = block[3];
+ break;
+ case 91 ... 99:
+ field[x][y].type = block[4];
+ break;
+ case 100 ... 106:
+ field[x][y].type = block[5];
+ break;
+ case 107 ... 111:
+ field[x][y].type = block[6];
+ break;
+ case 112 ... 116:
+ field[x][y].type = block[7];
+ break;
+ default:
+ field[x][y].type = NULL;
+ break;
+ }
+}
+
+/* wypelnia studnie elementami */
+void fill_board(struct data_levels * dl) {
+
+ int x, y, f;
+
+ for (y=24; y>2; --y) {
+ for (x=0; x<23; ++x) {
+label:
+ f=rand()%dl->max;
+ if (f<40) goto label;
+ set_element(f, x, y);
+
+ field[x][y].status = DROP;
+ }
+ }
+
+}
+
+
+/* gorna listwa */
+void high_slat(struct data_levels * dl, SDL_bool only_bomb) {
+
+ int i, f;
+
+ /* przesuwamy klocki w prawo */
+ for (i=22; i>0; --i)
+ field[i][0] = field[i-1][0];
+
+ /* losujemy element dla pozycji 0,0 */
+ if (!only_bomb) f=rand()%dl->max;
+ else f=55;
+
+ set_element(f, 0, 0);
+
+ field[0][0].status = 0;
+
+}
+
+/* funkcja sprawdza status elementu i jesli
+ element opada to obniza element na planszy */
+void drop_elements(void) {
+
+ int j, i;
+
+
+ for (j=25; j>=0; --j) {
+ for (i=0; i<23; ++i) {
+ if (field[i][j].status == DROP) {
+
+ /* jesli analizowana pozycja jest pusta */
+ if (!field[i][j+1].type) {
+ field[i][j+1] = field[i][j];
+
+
+ // wyzerowanie poprzedniej pozycji
+ field[i][j].status = 0;
+ field[i][j].type = NULL;
+
+ /* osiadlo na dnie */
+ if (j==24) {
+ field[i][j+1].status = STAND;
+ }
+ }
+ /* wprzeciwnym wypadku stawiamy element na
+ elemencie */
+ else {
+ field[i][j].status = STAND;
+ }
+
+
+
+
+ }
+ }
+ }
+
+}
+
+/* kasuje elementy po skasowaniu klockow badz wybuchu bomb */
+void delete_elements(void) {
+
+ int x, y;
+
+ /* to musi byc przynajmniej para wiec mozna
+ tak sprawdzac */
+ if (gh_index) {
+
+ /* index jest o jeden wiekszy trzeba go zmnniejszyc */
+ gh_index--;
+
+ printf ("gh_index: %d\n", gh_index);
+
+ do {
+ /* kasowanie elementow po zniknieciu lub wybuchu */
+ field[gh[gh_index].x][gh[gh_index].y].type = NULL;
+ field[gh[gh_index].x][gh[gh_index].y].status = 0;
+
+ printf ("kasowanie x: %d y: %d\n", gh[gh_index].x, gh[gh_index].y);
+
+ x = gh[gh_index].x;
+ y = gh[gh_index].y - 1; // dotyczy elementu znajdujacego sie nad kasowanym elementem
+
+// gh[gh_index].x = 0;
+// gh[gh_index].y = 0;
+
+ /* zmiana statusu elementom znajdujacym sie wyzej
+ o ile nie znikaja */
+ while (y>1 && field[x][y].status == STAND) {
+ field[x][y].status = DROP;
+ --y;
+ }
+
+ }while(gh_index--);
+ gh_index = 0;
+ }
+}
+
+
+
+
+/* wyszukuje klocki o tym samym kolorze i zmienia je w dymek*/
+void search_block(SDL_Surface * color, int x, int y) {
+
+// printf ("s... type: %p color: %p x: %d y: %d\n", field[x][y].type, color, x, y);
+
+ if (field[x][y].type == color && field[x][y].status == STAND) {
+
+ printf ("Fade : %p color %p x: %d y: %d\n", field[x][y].type, color, x, y);
+
+ field[x][y].status = FADE;
+ field[x][y].type = smoke;
+ score++;
+ bonus++;
+
+ /* zapamietuje pozycje ktora trzeba bedzie pozniej skasowac */
+// printf ("gh_index = %d\n", gh_index);
+ gh[gh_index].x = x;
+ gh[gh_index].y = y;
+ gh_index++;
+
+ /* nastepne klocki do sprawdzenia */
+ if (y<25) search_block(color, x, y+1);
+ if (y>1) search_block(color,x, y-1);
+ if (x>0) search_block(color, x-1, y);
+ if (x<22) search_block(color,x+1, y);
+
+
+ }
+
+}
+
+/* szuka pary do skasowania */
+void pre_delete_block(int x, int y) {
+
+
+// printf ("\npre_delete: %p x: %d y: %d \n\n", field[x][y].type, x, y);
+
+ /* szuka przynajmniej pary */
+ if (field[x][y].type == field[x][y+1].type ||
+ field[x][y].type == field[x][y-1].type ||
+ field[x][y].type == field[x+1][y].type ||
+ field[x][y].type == field[x-1][y].type && field[x][y].status == STAND) {
+
+
+ if (y<25) search_block(field[x][y].type, x, y+1);
+ if (y>1) search_block(field[x][y].type, x, y-1);
+ if (x>0) search_block(field[x][y].type, x-1, y);
+ if (x<22) search_block(field[x][y].type, x+1, y);
+
+// raczej niepotrzebne juz
+// field[x][y].status = FADE;
+// field[x][y].type = smoke;
+
+ }
+
+
+}
+/* eksplozja elementow znajdujacych sie wokol bomb */
+void power_strike (int x, int y){
+
+ if (field[x][y].type != bomb && field[x][y].status == STAND) {
+
+ field[x][y].status = FADE;
+ field[x][y].type = explode;
+
+ /* zapamietuje pozycje ktora trzeba bedzie pozniej skasowac */
+ gh[gh_index].x = x;
+ gh[gh_index].y = y;
+ gh_index++;
+ }
+
+}
+
+/* szuka bomb i dokonuje eksplozji */
+void search_bomb(int x, int y) {
+
+ if (field[x][y].type == bomb && field[x][y].status == STAND) {
+
+ printf ("Fade : %p bomb %p x: %d y: %d\n", field[x][y].type, bomb, x, y);
+
+ field[x][y].status = FADE;
+ field[x][y].type = explode;
+
+ /* zapamietuje pozycje ktora trzeba bedzie pozniej skasowac */
+ gh[gh_index].x = x;
+ gh[gh_index].y = y;
+ gh_index++;
+
+ /* nastepne klocki do sprawdzenia */
+ if (y<25) search_bomb(x, y+1);
+ if (y>1) search_bomb(x, y-1);
+ if (x>0) search_bomb(x-1, y);
+ if (x<22) search_bomb(x+1, y);
+ if (x>0 && y>1) search_bomb(x-1, y-1);
+ if (x<22 && y>1) search_bomb(x+1, y-1);
+ if (x>0 && y<25) search_bomb(x-1, y+1);
+ if (x<22 && y<25) search_bomb(x+1, y+1);
+
+ /* sila razenia */
+ if (y<25) power_strike(x, y+1);
+ if (y>1) power_strike(x, y-1);
+ if (x>0) power_strike(x-1, y);
+ if (x<22) power_strike(x+1, y);
+ if (x>0 && y>1) power_strike(x-1, y-1);
+ if (x<22 && y>1) power_strike(x+1, y-1);
+ if (x>0 && y<25) power_strike(x-1, y+1);
+ if (x<22 && y<25) power_strike(x+1, y+1);
+
+
+ }
+
+}
+
+/* szuka pary bomb */
+void pre_delete_bomb(int x, int y) {
+
+ /* szuka przynajmniej pary */
+ if (field[x][y].type == field[x][y+1].type ||
+ field[x][y].type == field[x][y-1].type ||
+ field[x][y].type == field[x+1][y].type ||
+ field[x][y].type == field[x-1][y].type && field[x][y].status == STAND) {
+
+
+ if (y<25) search_bomb(x, y+1);
+ if (y>1) search_bomb(x, y-1);
+ if (x>0) search_bomb(x-1, y);
+ if (x<22) search_bomb(x+1, y);
+
+ }
+}
+
+/* sprawdza czy mozna dosunac elemnty do prawej strony */
+//void check_before_field(void) {
+ void on_the_right(void) {
+
+ int i,j,k,l;
+
+ for (i=21; i>=0; --i) {
+
+ /* jesli pole przed elementem jest puste */
+ if (!field[i+1][25].type && field[i][25].status == STAND) {
+
+ /* sprawdza jak wysoko siegaja kolocki */
+ k=0;
+// while(field[i][25-k].type && field[i][25-k].status == STAND)k++;
+ while(field[i][25-k].type)k++;
+ ++k;
+
+// printf (" K: %d\n", k);
+
+ /* sprawdza czy nie wystaja jakies klocki na przedpolu */
+ for (l=0; l<k; l++) {
+ /* jesli jest jakis klocek to wyskakuje z petli */
+ if (field[i+1][25-l].type) break;
+ }
+// printf (" L: %d\n", l);
+
+ /* gdy brak elementow na przedpolu mozna przesowac */
+ if (k == l) {
+ j=25;
+ /* przesowa kolejno elementy ustawione pionowo oprocz
+ eksplozji i zanikniec */
+ while (field[i][j].type && field[i][j].status != FADE) {
+
+ field[i+1][j] = field[i][j];
+
+ field[i][j].status = 0;
+ field[i][j].type = NULL;
+ --j;
+ }
+ }
+
+ }
+ }
+
+}
+
+
+void start_game(void) {
+
+ int done;
+ char buffor[100];
+ int i, j, x, y;
+ int move=1; // zmienna odpowiedzialna za przesowanie elem. gornel listwy
+ int over =-1; // zmienna odpowiedzialna za pojawienie sie napisu game over
+ int virtual_level, level;
+ int vis, drop_slat, pic;
+ SDL_Rect srcrect, destrect;
+ SDL_bool only_bomb = SDL_FALSE;
+
+ /*
+ struct data_levels data_level[10] = {
+ {85, 200, 0},
+ {90, 200, 0},
+ {99, 150, 0},
+ {99, 150, 0},
+ {106, 150, 0},
+ {111, 100, 0},
+ {111, 150, 1},
+ {111, 100, 1},
+ {116, 150, 1},
+ {116, 100, 1}};
+*/
+ struct data_levels data_level[10] = {
+ {85, 200, 0},
+ {90, 200, 0},
+ {99, 150, 0},
+ {99, 150, 0},
+ {106, 200, 0},
+ {106, 150, 0},
+ {85, 200, 1},
+ {90, 200, 1},
+ {99, 150, 1},
+ {111, 100, 1}};
+
+ virtual_level = level = start_level;
+ score = 0;
+ srand(time(NULL));
+
+ destrect = set_rect(0,0,screen->w,screen->h);
+ SDL_FillRect(screen,&destrect,0);
+ //SDL_Flip(screen);
+
+
+ sprintf (buffor, "%d", tab_hiscores[0].score);
+ var_hiscore_inscription = (SDL_Surface *) prepare_text(255, 255, 255, buffor);
+
+new_level:
+ bonus = 0;
+
+ sprintf(buffor, "%d", virtual_level);
+ var_level_inscription = (SDL_Surface *) prepare_text(255, 255, 255, buffor);
+
+ pic = rand()%N_PIC;
+ load_background(pic);
+
+
+ drop_slat = data_level[level-1].drop;
+ vis = 15;
+
+ /* ustawia murek */
+ if (data_level[level-1].wall) {
+ field[10][25].type = wall;
+ field[10][25].status = WALL;
+ }
+
+
+ /* wypelnia studnie elementami */
+ fill_board(&data_level[level-1]);
+
+ done = 0;
+ while (!done)
+ {
+
+
+
+
+ set_background();
+
+ if (use_net) set_net();
+
+ /* sprawdza czy na planszy sa jakies klocki */
+ if (shortage_blocks()) {
+ virtual_level++;
+ if (level < 10) level++;
+
+ SDL_FreeSurface(var_level_inscription);
+
+ score += bonus *3;
+ goto new_level;
+ }
+
+ delete_elements();
+
+
+ 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));
+
+ switch (event.key.keysym.sym) {
+ case SDLK_ESCAPE:
+ done = 1;
+ break;
+ case SDLK_b:
+ if (only_bomb) only_bomb=SDL_FALSE;
+ else only_bomb=SDL_TRUE;
+ break;
+ }
+ break;
+ case SDL_QUIT:
+ exit(0);
+ break;
+ case SDL_MOUSEMOTION:
+// if (event.motion.state & SDL_BUTTON(1))
+// printf("Ruch z pierwszym przyciskeim myszy\n");
+
+// if (event.motion.state & SDL_BUTTON(2))
+// printf("Ruch z drugim przyciskiem myszy\n");
+
+// if (event.motion.state & SDL_BUTTON(3))
+// printf("Ruch z trzecim przyciskiem myszy\n");
+
+// printf("Przesuni�o myszk�o %d,%d\n",
+// event.motion.xrel, event.motion.yrel);
+ 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);
+
+
+ if (event.button.button &&
+ event.button.x >= X_HIGH_SLAT +1 &&
+ event.button.y >= Y_HIGH_SLAT &&
+ event.button.x <= X_SIZE_HIGH_SLAT &&
+ event.button.y <= (Y_SIZE_HIGH_SLAT + Y_HIGH_SLAT)) {
+
+ printf ("opadanie\n");
+ drop_from_high_slat();
+ move = 0;
+ drop_slat = data_level[level-1].drop;
+ }
+ else if (event.button.button &&
+ event.button.x >= X_ACTION &&
+ event.button.y >= Y_ACTION &&
+ event.button.x <= X_SIZE_ACTION &&
+ event.button.y <= Y_SIZE_ACTION) {
+
+ x=event.button.x/FIELD_SIZE;
+ y=event.button.y/FIELD_SIZE-2;
+
+ if (field[x][y].type == bomb)
+ pre_delete_bomb(x, y);
+ else if (field[x][y].type)
+ pre_delete_block(x, y);
+
+ }
+
+
+ }
+ }
+
+
+ drop_slat--;
+ /* gdy zero program sam zrzuca klocki z gornej listwy */
+ if (!drop_slat) {
+ drop_from_high_slat();
+ move = 0;
+ drop_slat = data_level[level-1].drop;
+ }
+
+
+ /* przesowa klocki na gornej listwie zapobiegajac przy okazji
+ opadaniu pod katem */
+ if (!only_bomb){
+ if (move) high_slat(&data_level[level-1], SDL_FALSE);
+ else move = 1;
+ }
+ else {
+ if (move) high_slat(&data_level[level-1], SDL_TRUE);
+ else move = 1;
+ }
+
+ /* przesowa elemnty do prawej strony */
+ on_the_right();
+
+ /* opuszcza elementy */
+ drop_elements();
+
+
+// for (j=0; j<26; ++j) {
+// for (i=0; i<23; ++i) {
+
+// if (field[i][j].type)
+// printf ("j: %d i: %d type: %p\n", j, i, field[i][j].type);
+// }
+// }
+// printf("\n\n");
+
+
+
+ /* umieszczanie elementow na planszy */
+ srcrect = set_rect(0,0,FIELD_SIZE,FIELD_SIZE);
+ for (j=0; j<26; ++j) {
+ for (i=0; i<23; ++i) {
+
+// if (field[i][j].type)
+// printf ("j: %d i: %d type: %p\n", j, i, field[i][j].type);
+
+ destrect = set_rect(FIELD_SIZE * i,FIELD_SIZE * j+ 40, FIELD_SIZE, FIELD_SIZE);
+ SDL_BlitSurface(field[i][j].type,&srcrect, screen,&destrect);
+ }
+ }
+
+// for (j=0; j<20; ++j) {
+// for (i=0; i<23; ++i) {
+// if (field[i][j].status == DROP) putchar('|');
+// else if (field[i][j].status == STAND) putchar ('=');
+// else if (field[i][j].status == 0) putchar(' ');
+// }
+// putchar('\n');
+// }
+
+ /* przy rozpoczeciu poziomu wyswietla numer poziomu */
+ if (vis) {
+ sprintf (buffor, " LEVEL %d", virtual_level);
+ print_inscription(buffor, 190, 200);
+ vis -= 1;
+ }
+
+ /* sprawdza czy nie ma przepelnienia */
+ if (behind_high() && over == -1)
+ over = 15;
+ /* wyswietla napis game over */
+ if (!over)
+ done = 1;
+ else if (over > 0) {
+ strcpy(buffor, "GAME OVER");
+ print_inscription(buffor, 160, 200);
+ // SDL_UpdateRect(screen, 160, 200, 136, 32);
+ over -= 1;
+ }
+
+ sprintf (buffor, "%d", score);
+ print_inscription(buffor, 20, Y_ALL_INSCRIPTION);
+ draw_text(X_LEVEL_INSCRIPTION, Y_ALL_INSCRIPTION, var_level_inscription);
+ draw_text(X_HISCORE_INSCRIPTION, Y_ALL_INSCRIPTION, var_hiscore_inscription);
+
+ // printf ("wysokosc : %d \n", var_hiscore_inscription->h);
+
+ // 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);
+
+
+
+
+
+ SDL_Delay(300);
+ }
+
+
+ /* sprawdza czy jest mozliwosc wpisu */
+ if (score > tab_hiscores[4].score) {
+ get_name_of_player();
+ }
+
+ zero_field();
+
+ /* czysci ekran przed powrotem do menu */
+ destrect = set_rect(0,0,screen->w,screen->h);
+ SDL_FillRect(screen,&destrect,0);
+ // SDL_Flip(screen);
+
+ 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);
+
+ /* zwalnia pamiec po nieaktualnych obrazkach z liczbami */
+ SDL_FreeSurface(var_level_inscription);
+ SDL_FreeSurface(var_hiscore_inscription);
+
+}
+
+
diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..861c2fb --- /dev/null +++ b/src/main.c @@ -0,0 +1,652 @@ +/*
+ * Trix - klikanie po klockach
+ * Przemysław R. Pietraszczyk
+ *
+ * paźdżiernik 2006 r.
+ *
+ * licencja: Public Domain
+ */
+#include <sys/stat.h> // mkdir
+#include "trix.h"
+
+
+
+SDL_Window *window = NULL;
+
+
+void options (void);
+void about (void);
+void hiscores(void);
+int menu();
+
+void start_game(void);
+
+SDL_Rect set_rect(int x, int y, int w, int h)
+{
+ SDL_Rect rect;
+ rect.x = x;
+ rect.y = y;
+ rect.w = w;
+ rect.h = h;
+ return rect;
+}
+
+Uint32 getpixel(SDL_Surface *surface, int x, int y)
+{
+ int bpp = surface->format->BytesPerPixel;
+ /* Here p is the address to the pixel we want to retrieve */
+ Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
+
+ switch(bpp) {
+ case 1:
+ return *p;
+ case 2:
+ return *(Uint16 *)p;
+ case 3:
+ if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
+ return p[0] << 16 | p[1] << 8 | p[2];
+ else
+ return p[0] | p[1] << 8 | p[2] << 16;
+ case 4:
+ return *(Uint32 *)p;
+ default:
+ return 0;
+ }
+}
+
+void putpixel(SDL_Surface *surface, int x, int y, Uint8 R, Uint8 G, Uint8 B)
+{
+ Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x *
+ surface->format->BytesPerPixel;
+ if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
+ {
+ p[0] = R;
+ p[1] = G;
+ p[2] = B;
+ }
+ else
+ {
+ p[0] = B;
+ p[1] = G;
+ p[2] = R;
+ }
+}
+
+void create_net (void) {
+
+ SDL_Rect destrect;
+ int i, j;
+
+ net = SDL_CreateRGBSurface(SDL_SWSURFACE,screen->w,screen->h,16,0,0,0,0);
+
+ destrect = set_rect(0, 0, net->w, net->h);
+ SDL_FillRect(net,&destrect, SDL_MapRGB(net->format,255,255,255));
+
+ SDL_SetColorKey(net,SDL_TRUE,getpixel(net,0,0));
+
+ /* tworzy kolumny */
+ for (i=20; i<460; i+=20)
+ for (j=40; j<560; j += 3)
+ putpixel(net, i, j, 175, 175, 175);
+
+ /* tworzy wiersze */
+ for (j=40; j<560; j+=20)
+ for (i=0; i<460; i += 3)
+ putpixel(net, i, j, 175, 175, 175);
+
+
+}
+
+/* drukuje informacje */
+void print_inscription(char * buffor, int desx, int desy) {
+
+ SDL_Rect srcrect, destrect;
+ SDL_Color bgcolor;
+ SDL_Color fgcolor;
+ SDL_Surface * image;
+
+ fgcolor.r = 255;
+ fgcolor.b = 255;
+ fgcolor.g = 255;
+ bgcolor.r = 0;
+ bgcolor.g = 0;
+ bgcolor.b = 0;
+
+ //image = TTF_RenderUTF8_Shaded(font,buffor,fgcolor, bgcolor);
+ image = TTF_RenderText_Solid(font, buffor, fgcolor);
+
+ SDL_SetColorKey(image,SDL_TRUE,getpixel(image,0,0));
+
+ destrect = set_rect(desx, desy, image->w, image->h);
+ srcrect = set_rect(0,0,image->w, image->h);
+ SDL_BlitSurface(image,&srcrect,screen,&destrect);
+ SDL_FreeSurface(image);
+
+}
+
+
+void draw_text (int x, int y, SDL_Surface * image) {
+
+ SDL_Rect srcrect, destrect;
+
+ //SDL_SetColorKey(image,SDL_TRUE,getpixel(image,0,0));
+
+ destrect = set_rect(x, y, image->w, image->h);
+ srcrect = set_rect(0,0,image->w, image->h);
+ SDL_BlitSurface(image,&srcrect,screen,&destrect);
+// SDL_UpdateRect(screen, x, y, image->w, image->h);
+}
+
+SDL_Surface * prepare_text(int r, int b, int g, char *buffer) {
+
+// SDL_Rect srcrect, destrect;
+ SDL_Surface* image;
+ SDL_Color bgcolor;
+ SDL_Color fgcolor;
+
+ fgcolor.r = r;
+ fgcolor.b = b;
+ fgcolor.g = g;
+ bgcolor.r = 0;
+ bgcolor.g = 0;
+ bgcolor.b = 0;
+
+ return TTF_RenderText_Solid(font, buffer, fgcolor);
+ //return TTF_RenderUTF8_Shaded(font,buffer,fgcolor, bgcolor);
+}
+
+void load_banner() {
+
+ banner=IMG_ReadXPMFromArray(banner_xpm);
+ printf("banner: %p\n", banner);
+
+ if(!banner) {
+ printf("IMG_ReadXPMFromArray: %s\n", IMG_GetError());
+ exit(1);
+ }
+}
+
+
+/* odczytuje plik z wynikami i umieszcza dane w strukturze */
+void load_hiscores_from_file(void) {
+
+ FILE *fp;
+ int j;
+
+ if((fp = fopen(hifile,"r")) == NULL) {
+ printf("\nCannot read from file %s\n", hifile);
+ //exit (1);
+ }
+ else {
+ for (j = 0; j < 5; ++j)
+ fscanf(fp,"%s %d", &tab_hiscores[j].name, &tab_hiscores[j].score);
+ fclose(fp);
+ }
+}
+
+void save_hiscores_to_file (void) {
+
+ FILE *fp;
+ int j;
+
+ if((fp = fopen(hifile,"w")) == NULL) {
+ printf("\nCannot write to file %s\n", hifile);
+ exit (1);
+ }
+ for (j = 0; j < 5; ++j)
+ fprintf(fp,"%s %d\n", tab_hiscores[j].name, tab_hiscores[j].score);
+ fclose(fp);
+}
+
+void create_hifile(void) {
+
+ FILE *fp;
+ int j;
+ struct tab hi[] = {{"gecko", 50},
+ {"gecko", 40},
+ {"gecko", 30},
+ {"gecko", 20},
+ {"gecko", 10}};
+
+ if((fp = fopen(hifile,"w")) == NULL) {
+ printf("\nCannot write to file %s\n", hifile);
+ //exit (1);
+ }
+ else {
+ for (j = 0; j < 5; ++j)
+ fprintf(fp,"%s %d\n", hi[j].name, hi[j].score);
+ fclose(fp);
+ }
+}
+
+void load_catalogue(void) {
+
+ FILE *fp;
+ int j;
+
+ if((fp = fopen(CATALOGUE,"r")) == NULL) {
+ printf("\nCannot read from file %s\n", CATALOGUE);
+ exit (1);
+ }
+ for (j = 0; j < N_PIC; ++j)
+ fscanf(fp,"%s", &catalogue[j]);
+ fclose(fp);
+
+}
+
+
+void load_background(int n) {
+
+ char buffor[256];
+
+ sprintf(buffor, "%s%s", BG_DIR, catalogue[n]);
+
+ SDL_FreeSurface(bg);
+
+ if ((bg = IMG_Load(buffor)) == NULL) {
+ fprintf(stdout,"Cannot load icon bitmap: %s\n", IMG_GetError ());
+ exit(1);
+ }
+}
+
+
+void load_settings(void) {
+
+ FILE *fp;
+ char line[256];
+ char * p;
+
+
+#if LINUX
+ char *path;
+ char * HOME = "HOME";
+ path=(char *)malloc(strlen(getenv(HOME))+strlen(SETTINGS)+1);
+
+ strcpy(path, getenv(HOME));
+ strcat(path, SETTINGS);
+
+ if ((fp = fopen(path,"r"))==NULL) {
+ printf ("Nie mozna otworzyc pliku: settings\n");
+
+ start_level = 1;
+ net = 0;
+ }
+#elif WINDOWS
+ if ((fp = fopen(SETTINGS,"r"))==NULL) {
+ printf ("Nie mozna otworzyc pliku: settings\n");
+
+ start_level = 1;
+ net = 0;
+ }
+#endif
+ if (fp) {
+ while((fgets(line, 256 , fp)) != NULL) {
+ if (!strncmp(line, "start", 5)) {
+ p = strrchr(line, ' ');
+ printf (" start: %d\n", atoi(p));
+ start_level = atoi(p);
+ }
+ else if (!strncmp(line, "net", 3)) {
+ p = strrchr(line, ' ');
+ printf (" net: %d\n", atoi(p));
+ use_net = atoi(p);
+ }
+ }
+ fclose(fp);
+ }
+#if LINUX
+ free(path);
+#endif
+}
+
+void save_settings(void) {
+
+ FILE *fp;
+#if LINUX
+ char *path;
+ char * HOME = "HOME";
+ path=(char *)malloc(strlen(getenv(HOME))+strlen(SETTINGS)+1);
+
+ strcpy(path, getenv(HOME));
+ strcat(path, SETTINGS);
+ printf("save settings: 1\n");
+ if ((fp = fopen(path,"w"))==NULL) {
+ printf ("Nie mozna zapisac pliku: settings\n");
+
+ start_level = 1;
+ net = 0;
+ }
+ printf("save settings: 2n");
+
+ free(path);
+#elif WINDOWS
+ if ((fp = fopen(SETTINGS,"w"))==NULL) {
+ printf ("Nie mozna zapisac pliku: settings\n");
+
+ start_level = 1;
+ net = 0;
+ }
+#endif
+
+/*
+ if((fp = fopen(SETTINGS,"w")) == NULL) {
+ printf("\nNie moge zapisac pliku: settings\n");
+// exit (1);
+ }
+*/
+ if (fp) {
+ fprintf(fp, "start %d\n", start_level);
+ fprintf(fp, "net %d\n", use_net);
+ fclose(fp);
+ }
+
+}
+
+/*
+
+void load_settings(void) {
+
+ FILE *fp;
+ char line[256];
+ char * p;
+
+ if ((fp = fopen(SETTINGS,"r"))==NULL) {
+ printf ("Nie mozna otworzyc pliku: settings\n");
+
+ start_level = 1;
+ net = 0;
+ }
+ if (fp) {
+ while((fgets(line, 256 , fp)) != NULL) {
+ if (!strncmp(line, "start", 5)) {
+ p = strrchr(line, ' ');
+ printf (" start: %d\n", atoi(p));
+ start_level = atoi(p);
+ }
+ else if (!strncmp(line, "net", 3)) {
+ p = strrchr(line, ' ');
+ printf (" net: %d\n", atoi(p));
+ use_net = atoi(p);
+ }
+ }
+ fclose(fp);
+ }
+}
+
+void save_settings(void) {
+
+ FILE *fp;
+
+ if((fp = fopen(SETTINGS,"w")) == NULL) {
+ printf("\nNie moge zapisac pliku: settings\n");
+// exit (1);
+ }
+ else {
+ fprintf(fp, "start %d\n", start_level);
+ fprintf(fp, "net %d\n", use_net);
+ fclose(fp);
+ }
+
+}
+
+*/
+
+
+void load_bitmaps(void) {
+
+ int i;
+ SDL_Rect srcrect, destrect;
+ SDL_Color bgcolor;
+ SDL_Color fgcolor;
+ SDL_Surface* icons;
+
+ fgcolor.r = 255;
+ fgcolor.g = 255;
+ fgcolor.b = 255;
+ bgcolor.r = 0;
+ bgcolor.g = 0;
+ bgcolor.b = 0;
+
+
+
+ destrect = set_rect(0,0,FIELD_SIZE,FIELD_SIZE);
+
+ if((icons = SDL_LoadBMP(ICONS)) == NULL) {
+ fprintf(stdout,"Cannot load icon bitmap: %s\n", SDL_GetError ());
+ exit(1);
+ }
+
+ /* przestrzen dla klockow */
+ for (i=0; i < 8;++i) {
+ block[i] = SDL_CreateRGBSurface(SDL_SWSURFACE,FIELD_SIZE,FIELD_SIZE,16,0,0,0,0);
+ srcrect = set_rect(i*20,0,FIELD_SIZE,FIELD_SIZE);
+ SDL_BlitSurface(icons,&srcrect, block[i],&destrect);
+ }
+
+
+ /* przestrzen dla bomby */
+ bomb = SDL_CreateRGBSurface(SDL_SWSURFACE,FIELD_SIZE,FIELD_SIZE,16,0,0,0,0);
+ srcrect = set_rect(160,0,FIELD_SIZE,FIELD_SIZE);
+ SDL_BlitSurface(icons,&srcrect, bomb,&destrect);
+ /* ustawiamy kolor przezroczystosci */
+ SDL_SetColorKey(bomb,SDL_TRUE,getpixel(bomb,0,0));
+
+ /* przestrzen dla eksplozji */
+ explode = SDL_CreateRGBSurface(SDL_SWSURFACE,FIELD_SIZE,FIELD_SIZE,16,0,0,0,0);
+ srcrect = set_rect(180,0,FIELD_SIZE,FIELD_SIZE);
+ SDL_BlitSurface(icons, &srcrect, explode, &destrect);
+ /* ustawiamy kolor przezroczystosci */
+ SDL_SetColorKey(explode,SDL_TRUE,getpixel(explode,0,0));
+
+
+ wall = SDL_CreateRGBSurface(SDL_SWSURFACE,FIELD_SIZE,FIELD_SIZE,16,0,0,0,0);
+ srcrect = set_rect(200,0,FIELD_SIZE,FIELD_SIZE);
+ SDL_BlitSurface(icons, &srcrect, wall, &destrect);
+
+ /* przestrzen dla dymku */
+ smoke = SDL_CreateRGBSurface(SDL_SWSURFACE,FIELD_SIZE,FIELD_SIZE,16,0,0,0,0);
+ srcrect = set_rect(220,0,FIELD_SIZE,FIELD_SIZE);
+ SDL_BlitSurface(icons, &srcrect, smoke, &destrect);
+ /* ustawiamy kolor przezroczystosci */
+ SDL_SetColorKey(smoke,SDL_TRUE,getpixel(smoke,0,0));
+
+ SDL_FreeSurface(icons);
+}
+
+int atrap() {
+ return START_GAME;
+}
+
+
+ int main (int argc, char ** argv)
+{
+ int done = 0;
+
+
+ if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0)
+ {
+ printf ("Nie mozna zainicjowac SDL: %s\n", SDL_GetError ());
+ exit (1);
+ }
+ atexit (SDL_Quit);
+
+ window = SDL_CreateWindow( "Trix", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 460, 560, SDL_WINDOW_SHOWN );
+
+ //screen = SDL_SetVideoMode (460, 560, 16, SDL_SWSURFACE | SDL_DOUBLEBUF);
+ if (window == NULL)
+ {
+ printf ("Nie mozna ustawic trybu 460x560x16: %s\n", SDL_GetError ());
+ exit (2);
+ }
+ else {
+ renderer = SDL_CreateRenderer(window, -1,0);
+ SDL_SetRenderDrawColor ( renderer ,65, 190, 215 , 255 );
+ SDL_RenderClear ( renderer );
+ //Get window surface
+ screen= SDL_GetWindowSurface( window );
+ }
+
+ /* inicjalizacja fontow */
+ if(TTF_Init()==-1) {
+ printf("TTF_Init: %s\n", TTF_GetError());
+ exit(2);
+ }
+ atexit (TTF_Quit);
+ if((font = TTF_OpenFont(NAMEFONT,FONTSIZE)) == NULL) {
+ printf("TTF_OpenFont: %s\n", TTF_GetError());
+ exit(1);
+ }
+
+#if LINUX
+ char * FILE_HISCORES_FILE = "/.trix/hiscores";
+ char * HOME = "HOME";
+ char *path;
+ int c;
+
+ path=(char *)malloc(strlen(getenv(HOME))+strlen("/.trix")+1);
+ strcpy(path, getenv(HOME));
+ strcat(path, "/.trix");
+
+
+
+ /* jesli brak katalogu to zwraca -1 */
+ if ((c = chdir(path))) {
+
+ perror("chdir");
+ if (mkdir(path, 0777)) {
+ perror("mkdir");
+ }
+
+ }
+ printf ("\n\nc: %d\n\n", c);
+ free(path);
+
+ hifile=(char *)malloc(strlen(getenv(HOME))+strlen(FILE_HISCORES_FILE)+1);
+
+ strcpy(hifile, getenv(HOME));
+ strcat(hifile, FILE_HISCORES_FILE);
+
+ if (access(hifile, F_OK)==0){
+ printf("PLIK istnieje %s",hifile);
+ //free(hifile);
+
+ }
+ else {
+ printf("PLIK nie istnieje %s",hifile);
+ create_hifile();
+ //free(hifile);
+ }
+
+
+ SDL_Surface * icon = SDL_LoadBMP("/usr/share/trix/img/trix-icon.bmp");
+ SDL_SetWindowIcon(window, icon);
+ //load_hiscores_from_file();
+
+#elif WINDOWS
+ char * FILE_HISCORES = "\\trix.txt";
+ //char * FILE_HISCORES = "/trix.txt";
+
+ //char * PATH_TRIX = "/.trix";
+ char * HOME = "HOMEPATH";
+ //char *path;
+ int c;
+
+ hifile=(char *)malloc(strlen(getenv(HOME))+strlen(FILE_HISCORES)+1);
+
+ strcpy(hifile, getenv(HOME));
+ strcat(hifile, FILE_HISCORES);
+
+ if (access(hifile, F_OK)==0){
+ printf("PLIK istnieje %s\n", hifile);
+ //free(file);
+ char bufor[48];
+
+ FILE * fp = fopen(hifile, "r");
+ for (int j = 0; j < 5; ++j)
+ fscanf(fp,"%s %d", &tab_hiscores[j].name, &tab_hiscores[j].score);
+ fclose(fp);
+
+
+
+ }
+ else{
+ printf("PLIK nie istnieje %s\n",hifile);
+
+ create_hifile();
+/*
+ FILE * fp;
+ struct tab hi[] = {{"gecko", 50},
+ {"gecko", 40},
+ {"gecko", 30},
+ {"gecko", 20},
+ {"gecko", 10}};
+
+ if((fp = fopen(hifile,"w")) == NULL) {
+ printf("\nCannot write to file %s\n", hifile);
+ exit (1);
+ }
+ for (int j = 0; j < 5; ++j){
+ fprintf(fp,"%s %d\n", hi[j].name, hi[j].score);
+ strcpy(tab_hiscores[j].name , hi[j].name);
+ tab_hiscores[j].score = hi[j].score;
+ }
+ fclose(fp);
+
+ /
+ printf ("Zapisałem: %s\n", hifile);
+ */
+ }
+#endif
+
+ load_hiscores_from_file();
+ printf("\nAAAA\n");
+ start_level = 1;
+ load_settings();
+ printf("BBBB\n");
+
+ load_bitmaps();
+ printf("CCCC\n");
+
+ load_banner();
+ printf("DDDD\n");
+
+ printf ("B\n");
+
+ load_catalogue();
+ printf("EEEEEE\n");
+
+ create_net();
+ printf("FFFFF\n");
+
+ while(!done) {
+ switch (menu()) {
+ //switch (atrap()) {
+ case START_GAME:
+ start_game();
+ printf ("start game\n");
+ break;
+ case HISCORES:
+ hiscores();
+ printf ("hiscores\n");
+ break;
+ case OPTIONS:
+ options();
+ printf ("options\n");
+ break;
+ case ABOUT:
+ about();
+ printf ("about\n");
+ break;
+ case QUIT_GAME:
+ done = 1;
+ break;
+ }
+ }
+
+
+ SDL_DestroyTexture(tex_screen);
+ SDL_DestroyRenderer(renderer);
+ SDL_DestroyWindow(window);
+ //free(hifile);
+
+}
diff --git a/src/menu.c b/src/menu.c new file mode 100644 index 0000000..31e204b --- /dev/null +++ b/src/menu.c @@ -0,0 +1,879 @@ +#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;
+}
diff --git a/src/trix.h b/src/trix.h new file mode 100644 index 0000000..4fa512a --- /dev/null +++ b/src/trix.h @@ -0,0 +1,156 @@ +/*
+ * Trix - klikanie po klockach
+ * Przemysław R. Pietraszczyk
+ *
+ * paźdżiernik 2006 r.
+ *
+ * licencja: Public Domain
+ */
+
+#ifndef TRIX_H
+#define TRIX_H
+
+#include <errno.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <limits.h>
+#include <string.h>
+#include <time.h>
+#include <SDL2/SDL.h>
+#include <SDL2/SDL_ttf.h>
+#include <SDL2/SDL_image.h>
+
+#if WINDOWS
+#include <windows.h>
+#endif
+
+
+#if WINDOWS
+//#include "img\\banner.xpm"
+#include "..img/banner.xpm"
+#include "..img/about.xpm"
+#elif LINUX
+#include "../img/banner.xpm"
+#include "../img/about.xpm"
+#endif
+
+
+#define FONTSIZE 25
+
+#define FIELD_SIZE 20
+
+
+
+#if WINDOWS
+#define CATALOGUE "img\\bg\\catalogue.txt"
+#define BG_DIR "img\\bg\\"
+#define ICONS "img\\icons.bmp"
+#define HISCORES_FILE "hiscores"
+#define NAMEFONT "ZapfHumanist.ttf"
+//#define SETTINGS "trix.ini"
+#define SETTINGS "settings"
+#elif LINUX
+#define CATALOGUE "/usr/share/trix/img/bg/catalogue.txt"
+#define BG_DIR "/usr/share/trix/img/bg/"
+#define ICONS "/usr/share/trix/img/icons.bmp"
+#define NAMEFONT "/usr/share/trix/ZapfHumanist.ttf"
+#define SETTINGS "/.trix/trixrc"
+
+//#define CATALOGUE "img/bg/catalogue.txt"
+//#define BG_DIR "img/bg/"
+//#define ICONS "img/icons.bmp"
+//#define NAMEFONT "./ZapfHumanist.ttf"
+//#define SETTINGS "/.trix/trixrc"
+
+#endif
+
+#define N_PIC 6 // ilosc zdjec tla
+
+#define START_GAME 1
+#define HISCORES 2
+#define QUIT_GAME 3
+#define ABOUT 4
+#define OPTIONS 5
+// #define GAME_OVER 6
+
+
+#define Y_START 200 // 100
+#define Y_HISCORES 250 // 150
+#define Y_OPTIONS 300
+#define Y_ABOUT 350
+
+#define X_CENTER(w) (230-w/2)
+
+
+
+extern SDL_Surface * block[8];
+extern SDL_Surface * explode;
+extern SDL_Surface * bomb;
+extern SDL_Surface * wall;
+extern SDL_Surface * smoke;
+
+extern SDL_Surface * net;
+extern SDL_Surface * banner;
+extern SDL_Surface * bg;
+extern SDL_Surface * screen;
+extern TTF_Font* font;
+
+extern SDL_Renderer * renderer;
+extern SDL_Texture * tex_screen;
+
+extern SDL_Rect source, dest;
+
+
+extern int use_net; // zmienna wyswietlania siatki
+extern int start_level; // start gry od poziomu ...
+extern int score;
+extern int bonus; // nalicza premie
+
+extern char * hifile; // path do hiscore
+
+struct tab {
+ char name[20];
+ int score;
+};
+
+extern struct tab tab_hiscores[5];
+/*
+struct FIELD{
+ SDL_Surface * type;
+ int status; // 0:brak statusu 2:stoi -1:opada 1:znika lub wybucha
+} field[23][26];
+*/
+struct FIELD{
+ SDL_Surface * type;
+ int status; // 0:brak statusu 2:stoi -1:opada 1:znika lub wybucha
+};
+
+extern struct FIELD field[23][26];
+
+#define DROP -1 // opada
+#define FADE 1 // element zanika
+#define STAND 2 // stoi
+#define WALL 3 // murek
+
+
+/* struktura przechowuje pozycje kasowanych elementow */
+struct ghost {
+ int x, y;
+};
+
+/* struktura przechowujaca dane o danym poziomie */
+struct data_levels {
+ int max; // zakres liczb losowych
+ int drop; // flaga zrzutu
+ int wall; // 1: ustawiony murek na dnie studni 0; brak murka
+};
+
+extern char catalogue[N_PIC][40]; // tla
+
+SDL_Rect set_rect(int x, int y, int w, int h);
+Uint32 getpixel(SDL_Surface *surface, int x, int y);
+
+#endif
|