annotate trix/src/main.c @ 16:8fa14e28f099

flappyufo-spec fix
author Przemyslaw <prymula76@outlook.com>
date Sat, 24 Feb 2024 17:25:30 +0100
parents 2787f5e749ae
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
prymula <prymula76@outlook.com>
parents:
diff changeset
1 /*
prymula <prymula76@outlook.com>
parents:
diff changeset
2 * Trix - klikanie po klockach
prymula <prymula76@outlook.com>
parents:
diff changeset
3 * Przemysław R. Pietraszczyk
prymula <prymula76@outlook.com>
parents:
diff changeset
4 *
prymula <prymula76@outlook.com>
parents:
diff changeset
5 * paźdżiernik 2006 r.
prymula <prymula76@outlook.com>
parents:
diff changeset
6 *
prymula <prymula76@outlook.com>
parents:
diff changeset
7 * licencja: Public Domain
prymula <prymula76@outlook.com>
parents:
diff changeset
8 */
prymula <prymula76@outlook.com>
parents:
diff changeset
9 #include <sys/stat.h> // mkdir
prymula <prymula76@outlook.com>
parents:
diff changeset
10 #include "trix.h"
prymula <prymula76@outlook.com>
parents:
diff changeset
11
prymula <prymula76@outlook.com>
parents:
diff changeset
12
prymula <prymula76@outlook.com>
parents:
diff changeset
13
prymula <prymula76@outlook.com>
parents:
diff changeset
14 SDL_Window *window = NULL;
prymula <prymula76@outlook.com>
parents:
diff changeset
15
prymula <prymula76@outlook.com>
parents:
diff changeset
16
prymula <prymula76@outlook.com>
parents:
diff changeset
17 void options (void);
prymula <prymula76@outlook.com>
parents:
diff changeset
18 void about (void);
prymula <prymula76@outlook.com>
parents:
diff changeset
19 void hiscores(void);
prymula <prymula76@outlook.com>
parents:
diff changeset
20 int menu();
prymula <prymula76@outlook.com>
parents:
diff changeset
21
prymula <prymula76@outlook.com>
parents:
diff changeset
22 void start_game(void);
prymula <prymula76@outlook.com>
parents:
diff changeset
23
prymula <prymula76@outlook.com>
parents:
diff changeset
24 SDL_Rect set_rect(int x, int y, int w, int h)
prymula <prymula76@outlook.com>
parents:
diff changeset
25 {
prymula <prymula76@outlook.com>
parents:
diff changeset
26 SDL_Rect rect;
prymula <prymula76@outlook.com>
parents:
diff changeset
27 rect.x = x;
prymula <prymula76@outlook.com>
parents:
diff changeset
28 rect.y = y;
prymula <prymula76@outlook.com>
parents:
diff changeset
29 rect.w = w;
prymula <prymula76@outlook.com>
parents:
diff changeset
30 rect.h = h;
prymula <prymula76@outlook.com>
parents:
diff changeset
31 return rect;
prymula <prymula76@outlook.com>
parents:
diff changeset
32 }
prymula <prymula76@outlook.com>
parents:
diff changeset
33
prymula <prymula76@outlook.com>
parents:
diff changeset
34 Uint32 getpixel(SDL_Surface *surface, int x, int y)
prymula <prymula76@outlook.com>
parents:
diff changeset
35 {
prymula <prymula76@outlook.com>
parents:
diff changeset
36 int bpp = surface->format->BytesPerPixel;
prymula <prymula76@outlook.com>
parents:
diff changeset
37 /* Here p is the address to the pixel we want to retrieve */
prymula <prymula76@outlook.com>
parents:
diff changeset
38 Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
prymula <prymula76@outlook.com>
parents:
diff changeset
39
prymula <prymula76@outlook.com>
parents:
diff changeset
40 switch(bpp) {
prymula <prymula76@outlook.com>
parents:
diff changeset
41 case 1:
prymula <prymula76@outlook.com>
parents:
diff changeset
42 return *p;
prymula <prymula76@outlook.com>
parents:
diff changeset
43 case 2:
prymula <prymula76@outlook.com>
parents:
diff changeset
44 return *(Uint16 *)p;
prymula <prymula76@outlook.com>
parents:
diff changeset
45 case 3:
prymula <prymula76@outlook.com>
parents:
diff changeset
46 if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
prymula <prymula76@outlook.com>
parents:
diff changeset
47 return p[0] << 16 | p[1] << 8 | p[2];
prymula <prymula76@outlook.com>
parents:
diff changeset
48 else
prymula <prymula76@outlook.com>
parents:
diff changeset
49 return p[0] | p[1] << 8 | p[2] << 16;
prymula <prymula76@outlook.com>
parents:
diff changeset
50 case 4:
prymula <prymula76@outlook.com>
parents:
diff changeset
51 return *(Uint32 *)p;
prymula <prymula76@outlook.com>
parents:
diff changeset
52 default:
prymula <prymula76@outlook.com>
parents:
diff changeset
53 return 0;
prymula <prymula76@outlook.com>
parents:
diff changeset
54 }
prymula <prymula76@outlook.com>
parents:
diff changeset
55 }
prymula <prymula76@outlook.com>
parents:
diff changeset
56
prymula <prymula76@outlook.com>
parents:
diff changeset
57 void putpixel(SDL_Surface *surface, int x, int y, Uint8 R, Uint8 G, Uint8 B)
prymula <prymula76@outlook.com>
parents:
diff changeset
58 {
prymula <prymula76@outlook.com>
parents:
diff changeset
59 Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x *
prymula <prymula76@outlook.com>
parents:
diff changeset
60 surface->format->BytesPerPixel;
prymula <prymula76@outlook.com>
parents:
diff changeset
61 if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
prymula <prymula76@outlook.com>
parents:
diff changeset
62 {
prymula <prymula76@outlook.com>
parents:
diff changeset
63 p[0] = R;
prymula <prymula76@outlook.com>
parents:
diff changeset
64 p[1] = G;
prymula <prymula76@outlook.com>
parents:
diff changeset
65 p[2] = B;
prymula <prymula76@outlook.com>
parents:
diff changeset
66 }
prymula <prymula76@outlook.com>
parents:
diff changeset
67 else
prymula <prymula76@outlook.com>
parents:
diff changeset
68 {
prymula <prymula76@outlook.com>
parents:
diff changeset
69 p[0] = B;
prymula <prymula76@outlook.com>
parents:
diff changeset
70 p[1] = G;
prymula <prymula76@outlook.com>
parents:
diff changeset
71 p[2] = R;
prymula <prymula76@outlook.com>
parents:
diff changeset
72 }
prymula <prymula76@outlook.com>
parents:
diff changeset
73 }
prymula <prymula76@outlook.com>
parents:
diff changeset
74
prymula <prymula76@outlook.com>
parents:
diff changeset
75 void create_net (void) {
prymula <prymula76@outlook.com>
parents:
diff changeset
76
prymula <prymula76@outlook.com>
parents:
diff changeset
77 SDL_Rect destrect;
prymula <prymula76@outlook.com>
parents:
diff changeset
78 int i, j;
prymula <prymula76@outlook.com>
parents:
diff changeset
79
prymula <prymula76@outlook.com>
parents:
diff changeset
80 net = SDL_CreateRGBSurface(SDL_SWSURFACE,screen->w,screen->h,16,0,0,0,0);
prymula <prymula76@outlook.com>
parents:
diff changeset
81
prymula <prymula76@outlook.com>
parents:
diff changeset
82 destrect = set_rect(0, 0, net->w, net->h);
prymula <prymula76@outlook.com>
parents:
diff changeset
83 SDL_FillRect(net,&destrect, SDL_MapRGB(net->format,255,255,255));
prymula <prymula76@outlook.com>
parents:
diff changeset
84
prymula <prymula76@outlook.com>
parents:
diff changeset
85 SDL_SetColorKey(net,SDL_TRUE,getpixel(net,0,0));
prymula <prymula76@outlook.com>
parents:
diff changeset
86
prymula <prymula76@outlook.com>
parents:
diff changeset
87 /* tworzy kolumny */
prymula <prymula76@outlook.com>
parents:
diff changeset
88 for (i=20; i<460; i+=20)
prymula <prymula76@outlook.com>
parents:
diff changeset
89 for (j=40; j<560; j += 3)
prymula <prymula76@outlook.com>
parents:
diff changeset
90 putpixel(net, i, j, 175, 175, 175);
prymula <prymula76@outlook.com>
parents:
diff changeset
91
prymula <prymula76@outlook.com>
parents:
diff changeset
92 /* tworzy wiersze */
prymula <prymula76@outlook.com>
parents:
diff changeset
93 for (j=40; j<560; j+=20)
prymula <prymula76@outlook.com>
parents:
diff changeset
94 for (i=0; i<460; i += 3)
prymula <prymula76@outlook.com>
parents:
diff changeset
95 putpixel(net, i, j, 175, 175, 175);
prymula <prymula76@outlook.com>
parents:
diff changeset
96
prymula <prymula76@outlook.com>
parents:
diff changeset
97
prymula <prymula76@outlook.com>
parents:
diff changeset
98 }
prymula <prymula76@outlook.com>
parents:
diff changeset
99
prymula <prymula76@outlook.com>
parents:
diff changeset
100 /* drukuje informacje */
prymula <prymula76@outlook.com>
parents:
diff changeset
101 void print_inscription(char * buffor, int desx, int desy) {
prymula <prymula76@outlook.com>
parents:
diff changeset
102
prymula <prymula76@outlook.com>
parents:
diff changeset
103 SDL_Rect srcrect, destrect;
prymula <prymula76@outlook.com>
parents:
diff changeset
104 SDL_Color bgcolor;
prymula <prymula76@outlook.com>
parents:
diff changeset
105 SDL_Color fgcolor;
prymula <prymula76@outlook.com>
parents:
diff changeset
106 SDL_Surface * image;
prymula <prymula76@outlook.com>
parents:
diff changeset
107
prymula <prymula76@outlook.com>
parents:
diff changeset
108 fgcolor.r = 255;
prymula <prymula76@outlook.com>
parents:
diff changeset
109 fgcolor.b = 255;
prymula <prymula76@outlook.com>
parents:
diff changeset
110 fgcolor.g = 255;
prymula <prymula76@outlook.com>
parents:
diff changeset
111 bgcolor.r = 0;
prymula <prymula76@outlook.com>
parents:
diff changeset
112 bgcolor.g = 0;
prymula <prymula76@outlook.com>
parents:
diff changeset
113 bgcolor.b = 0;
prymula <prymula76@outlook.com>
parents:
diff changeset
114
prymula <prymula76@outlook.com>
parents:
diff changeset
115 //image = TTF_RenderUTF8_Shaded(font,buffor,fgcolor, bgcolor);
prymula <prymula76@outlook.com>
parents:
diff changeset
116 image = TTF_RenderText_Solid(font, buffor, fgcolor);
prymula <prymula76@outlook.com>
parents:
diff changeset
117
prymula <prymula76@outlook.com>
parents:
diff changeset
118 SDL_SetColorKey(image,SDL_TRUE,getpixel(image,0,0));
prymula <prymula76@outlook.com>
parents:
diff changeset
119
prymula <prymula76@outlook.com>
parents:
diff changeset
120 destrect = set_rect(desx, desy, image->w, image->h);
prymula <prymula76@outlook.com>
parents:
diff changeset
121 srcrect = set_rect(0,0,image->w, image->h);
prymula <prymula76@outlook.com>
parents:
diff changeset
122 SDL_BlitSurface(image,&srcrect,screen,&destrect);
prymula <prymula76@outlook.com>
parents:
diff changeset
123 SDL_FreeSurface(image);
prymula <prymula76@outlook.com>
parents:
diff changeset
124
prymula <prymula76@outlook.com>
parents:
diff changeset
125 }
prymula <prymula76@outlook.com>
parents:
diff changeset
126
prymula <prymula76@outlook.com>
parents:
diff changeset
127
prymula <prymula76@outlook.com>
parents:
diff changeset
128 void draw_text (int x, int y, SDL_Surface * image) {
prymula <prymula76@outlook.com>
parents:
diff changeset
129
prymula <prymula76@outlook.com>
parents:
diff changeset
130 SDL_Rect srcrect, destrect;
prymula <prymula76@outlook.com>
parents:
diff changeset
131
prymula <prymula76@outlook.com>
parents:
diff changeset
132 //SDL_SetColorKey(image,SDL_TRUE,getpixel(image,0,0));
prymula <prymula76@outlook.com>
parents:
diff changeset
133
prymula <prymula76@outlook.com>
parents:
diff changeset
134 destrect = set_rect(x, y, image->w, image->h);
prymula <prymula76@outlook.com>
parents:
diff changeset
135 srcrect = set_rect(0,0,image->w, image->h);
prymula <prymula76@outlook.com>
parents:
diff changeset
136 SDL_BlitSurface(image,&srcrect,screen,&destrect);
prymula <prymula76@outlook.com>
parents:
diff changeset
137 // SDL_UpdateRect(screen, x, y, image->w, image->h);
prymula <prymula76@outlook.com>
parents:
diff changeset
138 }
prymula <prymula76@outlook.com>
parents:
diff changeset
139
prymula <prymula76@outlook.com>
parents:
diff changeset
140 SDL_Surface * prepare_text(int r, int b, int g, char *buffer) {
prymula <prymula76@outlook.com>
parents:
diff changeset
141
prymula <prymula76@outlook.com>
parents:
diff changeset
142 // SDL_Rect srcrect, destrect;
prymula <prymula76@outlook.com>
parents:
diff changeset
143 SDL_Surface* image;
prymula <prymula76@outlook.com>
parents:
diff changeset
144 SDL_Color bgcolor;
prymula <prymula76@outlook.com>
parents:
diff changeset
145 SDL_Color fgcolor;
prymula <prymula76@outlook.com>
parents:
diff changeset
146
prymula <prymula76@outlook.com>
parents:
diff changeset
147 fgcolor.r = r;
prymula <prymula76@outlook.com>
parents:
diff changeset
148 fgcolor.b = b;
prymula <prymula76@outlook.com>
parents:
diff changeset
149 fgcolor.g = g;
prymula <prymula76@outlook.com>
parents:
diff changeset
150 bgcolor.r = 0;
prymula <prymula76@outlook.com>
parents:
diff changeset
151 bgcolor.g = 0;
prymula <prymula76@outlook.com>
parents:
diff changeset
152 bgcolor.b = 0;
prymula <prymula76@outlook.com>
parents:
diff changeset
153
prymula <prymula76@outlook.com>
parents:
diff changeset
154 return TTF_RenderText_Solid(font, buffer, fgcolor);
prymula <prymula76@outlook.com>
parents:
diff changeset
155 //return TTF_RenderUTF8_Shaded(font,buffer,fgcolor, bgcolor);
prymula <prymula76@outlook.com>
parents:
diff changeset
156 }
prymula <prymula76@outlook.com>
parents:
diff changeset
157
prymula <prymula76@outlook.com>
parents:
diff changeset
158 void load_banner() {
prymula <prymula76@outlook.com>
parents:
diff changeset
159
prymula <prymula76@outlook.com>
parents:
diff changeset
160 banner=IMG_ReadXPMFromArray(banner_xpm);
prymula <prymula76@outlook.com>
parents:
diff changeset
161 printf("banner: %p\n", banner);
prymula <prymula76@outlook.com>
parents:
diff changeset
162
prymula <prymula76@outlook.com>
parents:
diff changeset
163 if(!banner) {
prymula <prymula76@outlook.com>
parents:
diff changeset
164 printf("IMG_ReadXPMFromArray: %s\n", IMG_GetError());
prymula <prymula76@outlook.com>
parents:
diff changeset
165 exit(1);
prymula <prymula76@outlook.com>
parents:
diff changeset
166 }
prymula <prymula76@outlook.com>
parents:
diff changeset
167 }
prymula <prymula76@outlook.com>
parents:
diff changeset
168
prymula <prymula76@outlook.com>
parents:
diff changeset
169
prymula <prymula76@outlook.com>
parents:
diff changeset
170 /* odczytuje plik z wynikami i umieszcza dane w strukturze */
prymula <prymula76@outlook.com>
parents:
diff changeset
171 void load_hiscores_from_file(void) {
prymula <prymula76@outlook.com>
parents:
diff changeset
172
prymula <prymula76@outlook.com>
parents:
diff changeset
173 FILE *fp;
prymula <prymula76@outlook.com>
parents:
diff changeset
174 int j;
prymula <prymula76@outlook.com>
parents:
diff changeset
175
prymula <prymula76@outlook.com>
parents:
diff changeset
176 if((fp = fopen(hifile,"r")) == NULL) {
prymula <prymula76@outlook.com>
parents:
diff changeset
177 printf("\nCannot read from file %s\n", hifile);
prymula <prymula76@outlook.com>
parents:
diff changeset
178 //exit (1);
prymula <prymula76@outlook.com>
parents:
diff changeset
179 }
prymula <prymula76@outlook.com>
parents:
diff changeset
180 else {
prymula <prymula76@outlook.com>
parents:
diff changeset
181 for (j = 0; j < 5; ++j)
prymula <prymula76@outlook.com>
parents:
diff changeset
182 fscanf(fp,"%s %d", &tab_hiscores[j].name, &tab_hiscores[j].score);
prymula <prymula76@outlook.com>
parents:
diff changeset
183 fclose(fp);
prymula <prymula76@outlook.com>
parents:
diff changeset
184 }
prymula <prymula76@outlook.com>
parents:
diff changeset
185 }
prymula <prymula76@outlook.com>
parents:
diff changeset
186
prymula <prymula76@outlook.com>
parents:
diff changeset
187 void save_hiscores_to_file (void) {
prymula <prymula76@outlook.com>
parents:
diff changeset
188
prymula <prymula76@outlook.com>
parents:
diff changeset
189 FILE *fp;
prymula <prymula76@outlook.com>
parents:
diff changeset
190 int j;
prymula <prymula76@outlook.com>
parents:
diff changeset
191
prymula <prymula76@outlook.com>
parents:
diff changeset
192 if((fp = fopen(hifile,"w")) == NULL) {
prymula <prymula76@outlook.com>
parents:
diff changeset
193 printf("\nCannot write to file %s\n", hifile);
prymula <prymula76@outlook.com>
parents:
diff changeset
194 exit (1);
prymula <prymula76@outlook.com>
parents:
diff changeset
195 }
prymula <prymula76@outlook.com>
parents:
diff changeset
196 for (j = 0; j < 5; ++j)
prymula <prymula76@outlook.com>
parents:
diff changeset
197 fprintf(fp,"%s %d\n", tab_hiscores[j].name, tab_hiscores[j].score);
prymula <prymula76@outlook.com>
parents:
diff changeset
198 fclose(fp);
prymula <prymula76@outlook.com>
parents:
diff changeset
199 }
prymula <prymula76@outlook.com>
parents:
diff changeset
200
prymula <prymula76@outlook.com>
parents:
diff changeset
201 void create_hifile(void) {
prymula <prymula76@outlook.com>
parents:
diff changeset
202
prymula <prymula76@outlook.com>
parents:
diff changeset
203 FILE *fp;
prymula <prymula76@outlook.com>
parents:
diff changeset
204 int j;
prymula <prymula76@outlook.com>
parents:
diff changeset
205 struct tab hi[] = {{"gecko", 50},
prymula <prymula76@outlook.com>
parents:
diff changeset
206 {"gecko", 40},
prymula <prymula76@outlook.com>
parents:
diff changeset
207 {"gecko", 30},
prymula <prymula76@outlook.com>
parents:
diff changeset
208 {"gecko", 20},
prymula <prymula76@outlook.com>
parents:
diff changeset
209 {"gecko", 10}};
prymula <prymula76@outlook.com>
parents:
diff changeset
210
prymula <prymula76@outlook.com>
parents:
diff changeset
211 if((fp = fopen(hifile,"w")) == NULL) {
prymula <prymula76@outlook.com>
parents:
diff changeset
212 printf("\nCannot write to file %s\n", hifile);
prymula <prymula76@outlook.com>
parents:
diff changeset
213 //exit (1);
prymula <prymula76@outlook.com>
parents:
diff changeset
214 }
prymula <prymula76@outlook.com>
parents:
diff changeset
215 else {
prymula <prymula76@outlook.com>
parents:
diff changeset
216 for (j = 0; j < 5; ++j)
prymula <prymula76@outlook.com>
parents:
diff changeset
217 fprintf(fp,"%s %d\n", hi[j].name, hi[j].score);
prymula <prymula76@outlook.com>
parents:
diff changeset
218 fclose(fp);
prymula <prymula76@outlook.com>
parents:
diff changeset
219 }
prymula <prymula76@outlook.com>
parents:
diff changeset
220 }
prymula <prymula76@outlook.com>
parents:
diff changeset
221
prymula <prymula76@outlook.com>
parents:
diff changeset
222 void load_catalogue(void) {
prymula <prymula76@outlook.com>
parents:
diff changeset
223
prymula <prymula76@outlook.com>
parents:
diff changeset
224 FILE *fp;
prymula <prymula76@outlook.com>
parents:
diff changeset
225 int j;
prymula <prymula76@outlook.com>
parents:
diff changeset
226
prymula <prymula76@outlook.com>
parents:
diff changeset
227 if((fp = fopen(CATALOGUE,"r")) == NULL) {
prymula <prymula76@outlook.com>
parents:
diff changeset
228 printf("\nCannot read from file %s\n", CATALOGUE);
prymula <prymula76@outlook.com>
parents:
diff changeset
229 exit (1);
prymula <prymula76@outlook.com>
parents:
diff changeset
230 }
prymula <prymula76@outlook.com>
parents:
diff changeset
231 for (j = 0; j < N_PIC; ++j)
prymula <prymula76@outlook.com>
parents:
diff changeset
232 fscanf(fp,"%s", &catalogue[j]);
prymula <prymula76@outlook.com>
parents:
diff changeset
233 fclose(fp);
prymula <prymula76@outlook.com>
parents:
diff changeset
234
prymula <prymula76@outlook.com>
parents:
diff changeset
235 }
prymula <prymula76@outlook.com>
parents:
diff changeset
236
prymula <prymula76@outlook.com>
parents:
diff changeset
237
prymula <prymula76@outlook.com>
parents:
diff changeset
238 void load_background(int n) {
prymula <prymula76@outlook.com>
parents:
diff changeset
239
prymula <prymula76@outlook.com>
parents:
diff changeset
240 char buffor[256];
prymula <prymula76@outlook.com>
parents:
diff changeset
241
prymula <prymula76@outlook.com>
parents:
diff changeset
242 sprintf(buffor, "%s%s", BG_DIR, catalogue[n]);
prymula <prymula76@outlook.com>
parents:
diff changeset
243
prymula <prymula76@outlook.com>
parents:
diff changeset
244 SDL_FreeSurface(bg);
prymula <prymula76@outlook.com>
parents:
diff changeset
245
prymula <prymula76@outlook.com>
parents:
diff changeset
246 if ((bg = IMG_Load(buffor)) == NULL) {
prymula <prymula76@outlook.com>
parents:
diff changeset
247 fprintf(stdout,"Cannot load icon bitmap: %s\n", IMG_GetError ());
prymula <prymula76@outlook.com>
parents:
diff changeset
248 exit(1);
prymula <prymula76@outlook.com>
parents:
diff changeset
249 }
prymula <prymula76@outlook.com>
parents:
diff changeset
250 }
prymula <prymula76@outlook.com>
parents:
diff changeset
251
prymula <prymula76@outlook.com>
parents:
diff changeset
252
prymula <prymula76@outlook.com>
parents:
diff changeset
253 void load_settings(void) {
prymula <prymula76@outlook.com>
parents:
diff changeset
254
prymula <prymula76@outlook.com>
parents:
diff changeset
255 FILE *fp;
prymula <prymula76@outlook.com>
parents:
diff changeset
256 char line[256];
prymula <prymula76@outlook.com>
parents:
diff changeset
257 char * p;
prymula <prymula76@outlook.com>
parents:
diff changeset
258
prymula <prymula76@outlook.com>
parents:
diff changeset
259
prymula <prymula76@outlook.com>
parents:
diff changeset
260 #if LINUX
prymula <prymula76@outlook.com>
parents:
diff changeset
261 char *path;
prymula <prymula76@outlook.com>
parents:
diff changeset
262 char * HOME = "HOME";
prymula <prymula76@outlook.com>
parents:
diff changeset
263 path=(char *)malloc(strlen(getenv(HOME))+strlen(SETTINGS)+1);
prymula <prymula76@outlook.com>
parents:
diff changeset
264
prymula <prymula76@outlook.com>
parents:
diff changeset
265 strcpy(path, getenv(HOME));
prymula <prymula76@outlook.com>
parents:
diff changeset
266 strcat(path, SETTINGS);
prymula <prymula76@outlook.com>
parents:
diff changeset
267
prymula <prymula76@outlook.com>
parents:
diff changeset
268 if ((fp = fopen(path,"r"))==NULL) {
prymula <prymula76@outlook.com>
parents:
diff changeset
269 printf ("Nie mozna otworzyc pliku: settings\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
270
prymula <prymula76@outlook.com>
parents:
diff changeset
271 start_level = 1;
prymula <prymula76@outlook.com>
parents:
diff changeset
272 net = 0;
prymula <prymula76@outlook.com>
parents:
diff changeset
273 }
prymula <prymula76@outlook.com>
parents:
diff changeset
274 #elif WINDOWS
prymula <prymula76@outlook.com>
parents:
diff changeset
275 if ((fp = fopen(SETTINGS,"r"))==NULL) {
prymula <prymula76@outlook.com>
parents:
diff changeset
276 printf ("Nie mozna otworzyc pliku: settings\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
277
prymula <prymula76@outlook.com>
parents:
diff changeset
278 start_level = 1;
prymula <prymula76@outlook.com>
parents:
diff changeset
279 net = 0;
prymula <prymula76@outlook.com>
parents:
diff changeset
280 }
prymula <prymula76@outlook.com>
parents:
diff changeset
281 #endif
prymula <prymula76@outlook.com>
parents:
diff changeset
282 if (fp) {
prymula <prymula76@outlook.com>
parents:
diff changeset
283 while((fgets(line, 256 , fp)) != NULL) {
prymula <prymula76@outlook.com>
parents:
diff changeset
284 if (!strncmp(line, "start", 5)) {
prymula <prymula76@outlook.com>
parents:
diff changeset
285 p = strrchr(line, ' ');
prymula <prymula76@outlook.com>
parents:
diff changeset
286 printf (" start: %d\n", atoi(p));
prymula <prymula76@outlook.com>
parents:
diff changeset
287 start_level = atoi(p);
prymula <prymula76@outlook.com>
parents:
diff changeset
288 }
prymula <prymula76@outlook.com>
parents:
diff changeset
289 else if (!strncmp(line, "net", 3)) {
prymula <prymula76@outlook.com>
parents:
diff changeset
290 p = strrchr(line, ' ');
prymula <prymula76@outlook.com>
parents:
diff changeset
291 printf (" net: %d\n", atoi(p));
prymula <prymula76@outlook.com>
parents:
diff changeset
292 use_net = atoi(p);
prymula <prymula76@outlook.com>
parents:
diff changeset
293 }
prymula <prymula76@outlook.com>
parents:
diff changeset
294 }
prymula <prymula76@outlook.com>
parents:
diff changeset
295 fclose(fp);
prymula <prymula76@outlook.com>
parents:
diff changeset
296 }
prymula <prymula76@outlook.com>
parents:
diff changeset
297 #if LINUX
prymula <prymula76@outlook.com>
parents:
diff changeset
298 free(path);
prymula <prymula76@outlook.com>
parents:
diff changeset
299 #endif
prymula <prymula76@outlook.com>
parents:
diff changeset
300 }
prymula <prymula76@outlook.com>
parents:
diff changeset
301
prymula <prymula76@outlook.com>
parents:
diff changeset
302 void save_settings(void) {
prymula <prymula76@outlook.com>
parents:
diff changeset
303
prymula <prymula76@outlook.com>
parents:
diff changeset
304 FILE *fp;
prymula <prymula76@outlook.com>
parents:
diff changeset
305 #if LINUX
prymula <prymula76@outlook.com>
parents:
diff changeset
306 char *path;
prymula <prymula76@outlook.com>
parents:
diff changeset
307 char * HOME = "HOME";
prymula <prymula76@outlook.com>
parents:
diff changeset
308 path=(char *)malloc(strlen(getenv(HOME))+strlen(SETTINGS)+1);
prymula <prymula76@outlook.com>
parents:
diff changeset
309
prymula <prymula76@outlook.com>
parents:
diff changeset
310 strcpy(path, getenv(HOME));
prymula <prymula76@outlook.com>
parents:
diff changeset
311 strcat(path, SETTINGS);
prymula <prymula76@outlook.com>
parents:
diff changeset
312 printf("save settings: 1\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
313 if ((fp = fopen(path,"w"))==NULL) {
prymula <prymula76@outlook.com>
parents:
diff changeset
314 printf ("Nie mozna zapisac pliku: settings\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
315
prymula <prymula76@outlook.com>
parents:
diff changeset
316 start_level = 1;
prymula <prymula76@outlook.com>
parents:
diff changeset
317 net = 0;
prymula <prymula76@outlook.com>
parents:
diff changeset
318 }
prymula <prymula76@outlook.com>
parents:
diff changeset
319 printf("save settings: 2n");
prymula <prymula76@outlook.com>
parents:
diff changeset
320
prymula <prymula76@outlook.com>
parents:
diff changeset
321 free(path);
prymula <prymula76@outlook.com>
parents:
diff changeset
322 #elif WINDOWS
prymula <prymula76@outlook.com>
parents:
diff changeset
323 if ((fp = fopen(SETTINGS,"w"))==NULL) {
prymula <prymula76@outlook.com>
parents:
diff changeset
324 printf ("Nie mozna zapisac pliku: settings\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
325
prymula <prymula76@outlook.com>
parents:
diff changeset
326 start_level = 1;
prymula <prymula76@outlook.com>
parents:
diff changeset
327 net = 0;
prymula <prymula76@outlook.com>
parents:
diff changeset
328 }
prymula <prymula76@outlook.com>
parents:
diff changeset
329 #endif
prymula <prymula76@outlook.com>
parents:
diff changeset
330
prymula <prymula76@outlook.com>
parents:
diff changeset
331 /*
prymula <prymula76@outlook.com>
parents:
diff changeset
332 if((fp = fopen(SETTINGS,"w")) == NULL) {
prymula <prymula76@outlook.com>
parents:
diff changeset
333 printf("\nNie moge zapisac pliku: settings\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
334 // exit (1);
prymula <prymula76@outlook.com>
parents:
diff changeset
335 }
prymula <prymula76@outlook.com>
parents:
diff changeset
336 */
prymula <prymula76@outlook.com>
parents:
diff changeset
337 if (fp) {
prymula <prymula76@outlook.com>
parents:
diff changeset
338 fprintf(fp, "start %d\n", start_level);
prymula <prymula76@outlook.com>
parents:
diff changeset
339 fprintf(fp, "net %d\n", use_net);
prymula <prymula76@outlook.com>
parents:
diff changeset
340 fclose(fp);
prymula <prymula76@outlook.com>
parents:
diff changeset
341 }
prymula <prymula76@outlook.com>
parents:
diff changeset
342
prymula <prymula76@outlook.com>
parents:
diff changeset
343 }
prymula <prymula76@outlook.com>
parents:
diff changeset
344
prymula <prymula76@outlook.com>
parents:
diff changeset
345 /*
prymula <prymula76@outlook.com>
parents:
diff changeset
346
prymula <prymula76@outlook.com>
parents:
diff changeset
347 void load_settings(void) {
prymula <prymula76@outlook.com>
parents:
diff changeset
348
prymula <prymula76@outlook.com>
parents:
diff changeset
349 FILE *fp;
prymula <prymula76@outlook.com>
parents:
diff changeset
350 char line[256];
prymula <prymula76@outlook.com>
parents:
diff changeset
351 char * p;
prymula <prymula76@outlook.com>
parents:
diff changeset
352
prymula <prymula76@outlook.com>
parents:
diff changeset
353 if ((fp = fopen(SETTINGS,"r"))==NULL) {
prymula <prymula76@outlook.com>
parents:
diff changeset
354 printf ("Nie mozna otworzyc pliku: settings\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
355
prymula <prymula76@outlook.com>
parents:
diff changeset
356 start_level = 1;
prymula <prymula76@outlook.com>
parents:
diff changeset
357 net = 0;
prymula <prymula76@outlook.com>
parents:
diff changeset
358 }
prymula <prymula76@outlook.com>
parents:
diff changeset
359 if (fp) {
prymula <prymula76@outlook.com>
parents:
diff changeset
360 while((fgets(line, 256 , fp)) != NULL) {
prymula <prymula76@outlook.com>
parents:
diff changeset
361 if (!strncmp(line, "start", 5)) {
prymula <prymula76@outlook.com>
parents:
diff changeset
362 p = strrchr(line, ' ');
prymula <prymula76@outlook.com>
parents:
diff changeset
363 printf (" start: %d\n", atoi(p));
prymula <prymula76@outlook.com>
parents:
diff changeset
364 start_level = atoi(p);
prymula <prymula76@outlook.com>
parents:
diff changeset
365 }
prymula <prymula76@outlook.com>
parents:
diff changeset
366 else if (!strncmp(line, "net", 3)) {
prymula <prymula76@outlook.com>
parents:
diff changeset
367 p = strrchr(line, ' ');
prymula <prymula76@outlook.com>
parents:
diff changeset
368 printf (" net: %d\n", atoi(p));
prymula <prymula76@outlook.com>
parents:
diff changeset
369 use_net = atoi(p);
prymula <prymula76@outlook.com>
parents:
diff changeset
370 }
prymula <prymula76@outlook.com>
parents:
diff changeset
371 }
prymula <prymula76@outlook.com>
parents:
diff changeset
372 fclose(fp);
prymula <prymula76@outlook.com>
parents:
diff changeset
373 }
prymula <prymula76@outlook.com>
parents:
diff changeset
374 }
prymula <prymula76@outlook.com>
parents:
diff changeset
375
prymula <prymula76@outlook.com>
parents:
diff changeset
376 void save_settings(void) {
prymula <prymula76@outlook.com>
parents:
diff changeset
377
prymula <prymula76@outlook.com>
parents:
diff changeset
378 FILE *fp;
prymula <prymula76@outlook.com>
parents:
diff changeset
379
prymula <prymula76@outlook.com>
parents:
diff changeset
380 if((fp = fopen(SETTINGS,"w")) == NULL) {
prymula <prymula76@outlook.com>
parents:
diff changeset
381 printf("\nNie moge zapisac pliku: settings\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
382 // exit (1);
prymula <prymula76@outlook.com>
parents:
diff changeset
383 }
prymula <prymula76@outlook.com>
parents:
diff changeset
384 else {
prymula <prymula76@outlook.com>
parents:
diff changeset
385 fprintf(fp, "start %d\n", start_level);
prymula <prymula76@outlook.com>
parents:
diff changeset
386 fprintf(fp, "net %d\n", use_net);
prymula <prymula76@outlook.com>
parents:
diff changeset
387 fclose(fp);
prymula <prymula76@outlook.com>
parents:
diff changeset
388 }
prymula <prymula76@outlook.com>
parents:
diff changeset
389
prymula <prymula76@outlook.com>
parents:
diff changeset
390 }
prymula <prymula76@outlook.com>
parents:
diff changeset
391
prymula <prymula76@outlook.com>
parents:
diff changeset
392 */
prymula <prymula76@outlook.com>
parents:
diff changeset
393
prymula <prymula76@outlook.com>
parents:
diff changeset
394
prymula <prymula76@outlook.com>
parents:
diff changeset
395 void load_bitmaps(void) {
prymula <prymula76@outlook.com>
parents:
diff changeset
396
prymula <prymula76@outlook.com>
parents:
diff changeset
397 int i;
prymula <prymula76@outlook.com>
parents:
diff changeset
398 SDL_Rect srcrect, destrect;
prymula <prymula76@outlook.com>
parents:
diff changeset
399 SDL_Color bgcolor;
prymula <prymula76@outlook.com>
parents:
diff changeset
400 SDL_Color fgcolor;
prymula <prymula76@outlook.com>
parents:
diff changeset
401 SDL_Surface* icons;
prymula <prymula76@outlook.com>
parents:
diff changeset
402
prymula <prymula76@outlook.com>
parents:
diff changeset
403 fgcolor.r = 255;
prymula <prymula76@outlook.com>
parents:
diff changeset
404 fgcolor.g = 255;
prymula <prymula76@outlook.com>
parents:
diff changeset
405 fgcolor.b = 255;
prymula <prymula76@outlook.com>
parents:
diff changeset
406 bgcolor.r = 0;
prymula <prymula76@outlook.com>
parents:
diff changeset
407 bgcolor.g = 0;
prymula <prymula76@outlook.com>
parents:
diff changeset
408 bgcolor.b = 0;
prymula <prymula76@outlook.com>
parents:
diff changeset
409
prymula <prymula76@outlook.com>
parents:
diff changeset
410
prymula <prymula76@outlook.com>
parents:
diff changeset
411
prymula <prymula76@outlook.com>
parents:
diff changeset
412 destrect = set_rect(0,0,FIELD_SIZE,FIELD_SIZE);
prymula <prymula76@outlook.com>
parents:
diff changeset
413
prymula <prymula76@outlook.com>
parents:
diff changeset
414 if((icons = SDL_LoadBMP(ICONS)) == NULL) {
prymula <prymula76@outlook.com>
parents:
diff changeset
415 fprintf(stdout,"Cannot load icon bitmap: %s\n", SDL_GetError ());
prymula <prymula76@outlook.com>
parents:
diff changeset
416 exit(1);
prymula <prymula76@outlook.com>
parents:
diff changeset
417 }
prymula <prymula76@outlook.com>
parents:
diff changeset
418
prymula <prymula76@outlook.com>
parents:
diff changeset
419 /* przestrzen dla klockow */
prymula <prymula76@outlook.com>
parents:
diff changeset
420 for (i=0; i < 8;++i) {
prymula <prymula76@outlook.com>
parents:
diff changeset
421 block[i] = SDL_CreateRGBSurface(SDL_SWSURFACE,FIELD_SIZE,FIELD_SIZE,16,0,0,0,0);
prymula <prymula76@outlook.com>
parents:
diff changeset
422 srcrect = set_rect(i*20,0,FIELD_SIZE,FIELD_SIZE);
prymula <prymula76@outlook.com>
parents:
diff changeset
423 SDL_BlitSurface(icons,&srcrect, block[i],&destrect);
prymula <prymula76@outlook.com>
parents:
diff changeset
424 }
prymula <prymula76@outlook.com>
parents:
diff changeset
425
prymula <prymula76@outlook.com>
parents:
diff changeset
426
prymula <prymula76@outlook.com>
parents:
diff changeset
427 /* przestrzen dla bomby */
prymula <prymula76@outlook.com>
parents:
diff changeset
428 bomb = SDL_CreateRGBSurface(SDL_SWSURFACE,FIELD_SIZE,FIELD_SIZE,16,0,0,0,0);
prymula <prymula76@outlook.com>
parents:
diff changeset
429 srcrect = set_rect(160,0,FIELD_SIZE,FIELD_SIZE);
prymula <prymula76@outlook.com>
parents:
diff changeset
430 SDL_BlitSurface(icons,&srcrect, bomb,&destrect);
prymula <prymula76@outlook.com>
parents:
diff changeset
431 /* ustawiamy kolor przezroczystosci */
prymula <prymula76@outlook.com>
parents:
diff changeset
432 SDL_SetColorKey(bomb,SDL_TRUE,getpixel(bomb,0,0));
prymula <prymula76@outlook.com>
parents:
diff changeset
433
prymula <prymula76@outlook.com>
parents:
diff changeset
434 /* przestrzen dla eksplozji */
prymula <prymula76@outlook.com>
parents:
diff changeset
435 explode = SDL_CreateRGBSurface(SDL_SWSURFACE,FIELD_SIZE,FIELD_SIZE,16,0,0,0,0);
prymula <prymula76@outlook.com>
parents:
diff changeset
436 srcrect = set_rect(180,0,FIELD_SIZE,FIELD_SIZE);
prymula <prymula76@outlook.com>
parents:
diff changeset
437 SDL_BlitSurface(icons, &srcrect, explode, &destrect);
prymula <prymula76@outlook.com>
parents:
diff changeset
438 /* ustawiamy kolor przezroczystosci */
prymula <prymula76@outlook.com>
parents:
diff changeset
439 SDL_SetColorKey(explode,SDL_TRUE,getpixel(explode,0,0));
prymula <prymula76@outlook.com>
parents:
diff changeset
440
prymula <prymula76@outlook.com>
parents:
diff changeset
441
prymula <prymula76@outlook.com>
parents:
diff changeset
442 wall = SDL_CreateRGBSurface(SDL_SWSURFACE,FIELD_SIZE,FIELD_SIZE,16,0,0,0,0);
prymula <prymula76@outlook.com>
parents:
diff changeset
443 srcrect = set_rect(200,0,FIELD_SIZE,FIELD_SIZE);
prymula <prymula76@outlook.com>
parents:
diff changeset
444 SDL_BlitSurface(icons, &srcrect, wall, &destrect);
prymula <prymula76@outlook.com>
parents:
diff changeset
445
prymula <prymula76@outlook.com>
parents:
diff changeset
446 /* przestrzen dla dymku */
prymula <prymula76@outlook.com>
parents:
diff changeset
447 smoke = SDL_CreateRGBSurface(SDL_SWSURFACE,FIELD_SIZE,FIELD_SIZE,16,0,0,0,0);
prymula <prymula76@outlook.com>
parents:
diff changeset
448 srcrect = set_rect(220,0,FIELD_SIZE,FIELD_SIZE);
prymula <prymula76@outlook.com>
parents:
diff changeset
449 SDL_BlitSurface(icons, &srcrect, smoke, &destrect);
prymula <prymula76@outlook.com>
parents:
diff changeset
450 /* ustawiamy kolor przezroczystosci */
prymula <prymula76@outlook.com>
parents:
diff changeset
451 SDL_SetColorKey(smoke,SDL_TRUE,getpixel(smoke,0,0));
prymula <prymula76@outlook.com>
parents:
diff changeset
452
prymula <prymula76@outlook.com>
parents:
diff changeset
453 SDL_FreeSurface(icons);
prymula <prymula76@outlook.com>
parents:
diff changeset
454 }
prymula <prymula76@outlook.com>
parents:
diff changeset
455
prymula <prymula76@outlook.com>
parents:
diff changeset
456 int atrap() {
prymula <prymula76@outlook.com>
parents:
diff changeset
457 return START_GAME;
prymula <prymula76@outlook.com>
parents:
diff changeset
458 }
prymula <prymula76@outlook.com>
parents:
diff changeset
459
prymula <prymula76@outlook.com>
parents:
diff changeset
460
prymula <prymula76@outlook.com>
parents:
diff changeset
461 int main (int argc, char ** argv)
prymula <prymula76@outlook.com>
parents:
diff changeset
462 {
prymula <prymula76@outlook.com>
parents:
diff changeset
463 int done = 0;
prymula <prymula76@outlook.com>
parents:
diff changeset
464
prymula <prymula76@outlook.com>
parents:
diff changeset
465
prymula <prymula76@outlook.com>
parents:
diff changeset
466 if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0)
prymula <prymula76@outlook.com>
parents:
diff changeset
467 {
prymula <prymula76@outlook.com>
parents:
diff changeset
468 printf ("Nie mozna zainicjowac SDL: %s\n", SDL_GetError ());
prymula <prymula76@outlook.com>
parents:
diff changeset
469 exit (1);
prymula <prymula76@outlook.com>
parents:
diff changeset
470 }
prymula <prymula76@outlook.com>
parents:
diff changeset
471 atexit (SDL_Quit);
prymula <prymula76@outlook.com>
parents:
diff changeset
472
prymula <prymula76@outlook.com>
parents:
diff changeset
473 window = SDL_CreateWindow( "Trix", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 460, 560, SDL_WINDOW_SHOWN );
prymula <prymula76@outlook.com>
parents:
diff changeset
474
prymula <prymula76@outlook.com>
parents:
diff changeset
475 //screen = SDL_SetVideoMode (460, 560, 16, SDL_SWSURFACE | SDL_DOUBLEBUF);
prymula <prymula76@outlook.com>
parents:
diff changeset
476 if (window == NULL)
prymula <prymula76@outlook.com>
parents:
diff changeset
477 {
prymula <prymula76@outlook.com>
parents:
diff changeset
478 printf ("Nie mozna ustawic trybu 460x560x16: %s\n", SDL_GetError ());
prymula <prymula76@outlook.com>
parents:
diff changeset
479 exit (2);
prymula <prymula76@outlook.com>
parents:
diff changeset
480 }
prymula <prymula76@outlook.com>
parents:
diff changeset
481 else {
prymula <prymula76@outlook.com>
parents:
diff changeset
482 renderer = SDL_CreateRenderer(window, -1,0);
prymula <prymula76@outlook.com>
parents:
diff changeset
483 SDL_SetRenderDrawColor ( renderer ,65, 190, 215 , 255 );
prymula <prymula76@outlook.com>
parents:
diff changeset
484 SDL_RenderClear ( renderer );
prymula <prymula76@outlook.com>
parents:
diff changeset
485 //Get window surface
prymula <prymula76@outlook.com>
parents:
diff changeset
486 screen= SDL_GetWindowSurface( window );
prymula <prymula76@outlook.com>
parents:
diff changeset
487 }
prymula <prymula76@outlook.com>
parents:
diff changeset
488
prymula <prymula76@outlook.com>
parents:
diff changeset
489 /* inicjalizacja fontow */
prymula <prymula76@outlook.com>
parents:
diff changeset
490 if(TTF_Init()==-1) {
prymula <prymula76@outlook.com>
parents:
diff changeset
491 printf("TTF_Init: %s\n", TTF_GetError());
prymula <prymula76@outlook.com>
parents:
diff changeset
492 exit(2);
prymula <prymula76@outlook.com>
parents:
diff changeset
493 }
prymula <prymula76@outlook.com>
parents:
diff changeset
494 atexit (TTF_Quit);
prymula <prymula76@outlook.com>
parents:
diff changeset
495 if((font = TTF_OpenFont(NAMEFONT,FONTSIZE)) == NULL) {
prymula <prymula76@outlook.com>
parents:
diff changeset
496 printf("TTF_OpenFont: %s\n", TTF_GetError());
prymula <prymula76@outlook.com>
parents:
diff changeset
497 exit(1);
prymula <prymula76@outlook.com>
parents:
diff changeset
498 }
prymula <prymula76@outlook.com>
parents:
diff changeset
499
prymula <prymula76@outlook.com>
parents:
diff changeset
500 #if LINUX
prymula <prymula76@outlook.com>
parents:
diff changeset
501 char * FILE_HISCORES_FILE = "/.trix/hiscores";
prymula <prymula76@outlook.com>
parents:
diff changeset
502 char * HOME = "HOME";
prymula <prymula76@outlook.com>
parents:
diff changeset
503 char *path;
prymula <prymula76@outlook.com>
parents:
diff changeset
504 int c;
prymula <prymula76@outlook.com>
parents:
diff changeset
505
prymula <prymula76@outlook.com>
parents:
diff changeset
506 path=(char *)malloc(strlen(getenv(HOME))+strlen("/.trix")+1);
prymula <prymula76@outlook.com>
parents:
diff changeset
507 strcpy(path, getenv(HOME));
prymula <prymula76@outlook.com>
parents:
diff changeset
508 strcat(path, "/.trix");
prymula <prymula76@outlook.com>
parents:
diff changeset
509
prymula <prymula76@outlook.com>
parents:
diff changeset
510
prymula <prymula76@outlook.com>
parents:
diff changeset
511
prymula <prymula76@outlook.com>
parents:
diff changeset
512 /* jesli brak katalogu to zwraca -1 */
prymula <prymula76@outlook.com>
parents:
diff changeset
513 if ((c = chdir(path))) {
prymula <prymula76@outlook.com>
parents:
diff changeset
514
prymula <prymula76@outlook.com>
parents:
diff changeset
515 perror("chdir");
prymula <prymula76@outlook.com>
parents:
diff changeset
516 if (mkdir(path, 0777)) {
prymula <prymula76@outlook.com>
parents:
diff changeset
517 perror("mkdir");
prymula <prymula76@outlook.com>
parents:
diff changeset
518 }
prymula <prymula76@outlook.com>
parents:
diff changeset
519
prymula <prymula76@outlook.com>
parents:
diff changeset
520 }
prymula <prymula76@outlook.com>
parents:
diff changeset
521 printf ("\n\nc: %d\n\n", c);
prymula <prymula76@outlook.com>
parents:
diff changeset
522 free(path);
prymula <prymula76@outlook.com>
parents:
diff changeset
523
prymula <prymula76@outlook.com>
parents:
diff changeset
524 hifile=(char *)malloc(strlen(getenv(HOME))+strlen(FILE_HISCORES_FILE)+1);
prymula <prymula76@outlook.com>
parents:
diff changeset
525
prymula <prymula76@outlook.com>
parents:
diff changeset
526 strcpy(hifile, getenv(HOME));
prymula <prymula76@outlook.com>
parents:
diff changeset
527 strcat(hifile, FILE_HISCORES_FILE);
prymula <prymula76@outlook.com>
parents:
diff changeset
528
prymula <prymula76@outlook.com>
parents:
diff changeset
529 if (access(hifile, F_OK)==0){
prymula <prymula76@outlook.com>
parents:
diff changeset
530 printf("PLIK istnieje %s",hifile);
prymula <prymula76@outlook.com>
parents:
diff changeset
531 //free(hifile);
prymula <prymula76@outlook.com>
parents:
diff changeset
532
prymula <prymula76@outlook.com>
parents:
diff changeset
533 }
prymula <prymula76@outlook.com>
parents:
diff changeset
534 else {
prymula <prymula76@outlook.com>
parents:
diff changeset
535 printf("PLIK nie istnieje %s",hifile);
prymula <prymula76@outlook.com>
parents:
diff changeset
536 create_hifile();
prymula <prymula76@outlook.com>
parents:
diff changeset
537 //free(hifile);
prymula <prymula76@outlook.com>
parents:
diff changeset
538 }
prymula <prymula76@outlook.com>
parents:
diff changeset
539
prymula <prymula76@outlook.com>
parents:
diff changeset
540
prymula <prymula76@outlook.com>
parents:
diff changeset
541 SDL_Surface * icon = SDL_LoadBMP("/usr/share/trix/img/trix-icon.bmp");
prymula <prymula76@outlook.com>
parents:
diff changeset
542 SDL_SetWindowIcon(window, icon);
prymula <prymula76@outlook.com>
parents:
diff changeset
543 //load_hiscores_from_file();
prymula <prymula76@outlook.com>
parents:
diff changeset
544
prymula <prymula76@outlook.com>
parents:
diff changeset
545 #elif WINDOWS
prymula <prymula76@outlook.com>
parents:
diff changeset
546 char * FILE_HISCORES = "\\trix.txt";
prymula <prymula76@outlook.com>
parents:
diff changeset
547 //char * FILE_HISCORES = "/trix.txt";
prymula <prymula76@outlook.com>
parents:
diff changeset
548
prymula <prymula76@outlook.com>
parents:
diff changeset
549 //char * PATH_TRIX = "/.trix";
prymula <prymula76@outlook.com>
parents:
diff changeset
550 char * HOME = "HOMEPATH";
prymula <prymula76@outlook.com>
parents:
diff changeset
551 //char *path;
prymula <prymula76@outlook.com>
parents:
diff changeset
552 int c;
prymula <prymula76@outlook.com>
parents:
diff changeset
553
prymula <prymula76@outlook.com>
parents:
diff changeset
554 hifile=(char *)malloc(strlen(getenv(HOME))+strlen(FILE_HISCORES)+1);
prymula <prymula76@outlook.com>
parents:
diff changeset
555
prymula <prymula76@outlook.com>
parents:
diff changeset
556 strcpy(hifile, getenv(HOME));
prymula <prymula76@outlook.com>
parents:
diff changeset
557 strcat(hifile, FILE_HISCORES);
prymula <prymula76@outlook.com>
parents:
diff changeset
558
prymula <prymula76@outlook.com>
parents:
diff changeset
559 if (access(hifile, F_OK)==0){
prymula <prymula76@outlook.com>
parents:
diff changeset
560 printf("PLIK istnieje %s\n", hifile);
prymula <prymula76@outlook.com>
parents:
diff changeset
561 //free(file);
prymula <prymula76@outlook.com>
parents:
diff changeset
562 char bufor[48];
prymula <prymula76@outlook.com>
parents:
diff changeset
563
prymula <prymula76@outlook.com>
parents:
diff changeset
564 FILE * fp = fopen(hifile, "r");
prymula <prymula76@outlook.com>
parents:
diff changeset
565 for (int j = 0; j < 5; ++j)
prymula <prymula76@outlook.com>
parents:
diff changeset
566 fscanf(fp,"%s %d", &tab_hiscores[j].name, &tab_hiscores[j].score);
prymula <prymula76@outlook.com>
parents:
diff changeset
567 fclose(fp);
prymula <prymula76@outlook.com>
parents:
diff changeset
568
prymula <prymula76@outlook.com>
parents:
diff changeset
569
prymula <prymula76@outlook.com>
parents:
diff changeset
570
prymula <prymula76@outlook.com>
parents:
diff changeset
571 }
prymula <prymula76@outlook.com>
parents:
diff changeset
572 else{
prymula <prymula76@outlook.com>
parents:
diff changeset
573 printf("PLIK nie istnieje %s\n",hifile);
prymula <prymula76@outlook.com>
parents:
diff changeset
574
prymula <prymula76@outlook.com>
parents:
diff changeset
575 create_hifile();
prymula <prymula76@outlook.com>
parents:
diff changeset
576 /*
prymula <prymula76@outlook.com>
parents:
diff changeset
577 FILE * fp;
prymula <prymula76@outlook.com>
parents:
diff changeset
578 struct tab hi[] = {{"gecko", 50},
prymula <prymula76@outlook.com>
parents:
diff changeset
579 {"gecko", 40},
prymula <prymula76@outlook.com>
parents:
diff changeset
580 {"gecko", 30},
prymula <prymula76@outlook.com>
parents:
diff changeset
581 {"gecko", 20},
prymula <prymula76@outlook.com>
parents:
diff changeset
582 {"gecko", 10}};
prymula <prymula76@outlook.com>
parents:
diff changeset
583
prymula <prymula76@outlook.com>
parents:
diff changeset
584 if((fp = fopen(hifile,"w")) == NULL) {
prymula <prymula76@outlook.com>
parents:
diff changeset
585 printf("\nCannot write to file %s\n", hifile);
prymula <prymula76@outlook.com>
parents:
diff changeset
586 exit (1);
prymula <prymula76@outlook.com>
parents:
diff changeset
587 }
prymula <prymula76@outlook.com>
parents:
diff changeset
588 for (int j = 0; j < 5; ++j){
prymula <prymula76@outlook.com>
parents:
diff changeset
589 fprintf(fp,"%s %d\n", hi[j].name, hi[j].score);
prymula <prymula76@outlook.com>
parents:
diff changeset
590 strcpy(tab_hiscores[j].name , hi[j].name);
prymula <prymula76@outlook.com>
parents:
diff changeset
591 tab_hiscores[j].score = hi[j].score;
prymula <prymula76@outlook.com>
parents:
diff changeset
592 }
prymula <prymula76@outlook.com>
parents:
diff changeset
593 fclose(fp);
prymula <prymula76@outlook.com>
parents:
diff changeset
594
prymula <prymula76@outlook.com>
parents:
diff changeset
595 /
prymula <prymula76@outlook.com>
parents:
diff changeset
596 printf ("Zapisałem: %s\n", hifile);
prymula <prymula76@outlook.com>
parents:
diff changeset
597 */
prymula <prymula76@outlook.com>
parents:
diff changeset
598 }
prymula <prymula76@outlook.com>
parents:
diff changeset
599 #endif
prymula <prymula76@outlook.com>
parents:
diff changeset
600
prymula <prymula76@outlook.com>
parents:
diff changeset
601 load_hiscores_from_file();
prymula <prymula76@outlook.com>
parents:
diff changeset
602 printf("\nAAAA\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
603 start_level = 1;
prymula <prymula76@outlook.com>
parents:
diff changeset
604 load_settings();
prymula <prymula76@outlook.com>
parents:
diff changeset
605 printf("BBBB\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
606
prymula <prymula76@outlook.com>
parents:
diff changeset
607 load_bitmaps();
prymula <prymula76@outlook.com>
parents:
diff changeset
608 printf("CCCC\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
609
prymula <prymula76@outlook.com>
parents:
diff changeset
610 load_banner();
prymula <prymula76@outlook.com>
parents:
diff changeset
611 printf("DDDD\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
612
prymula <prymula76@outlook.com>
parents:
diff changeset
613 printf ("B\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
614
prymula <prymula76@outlook.com>
parents:
diff changeset
615 load_catalogue();
prymula <prymula76@outlook.com>
parents:
diff changeset
616 printf("EEEEEE\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
617
prymula <prymula76@outlook.com>
parents:
diff changeset
618 create_net();
prymula <prymula76@outlook.com>
parents:
diff changeset
619 printf("FFFFF\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
620
prymula <prymula76@outlook.com>
parents:
diff changeset
621 while(!done) {
prymula <prymula76@outlook.com>
parents:
diff changeset
622 switch (menu()) {
prymula <prymula76@outlook.com>
parents:
diff changeset
623 //switch (atrap()) {
prymula <prymula76@outlook.com>
parents:
diff changeset
624 case START_GAME:
prymula <prymula76@outlook.com>
parents:
diff changeset
625 start_game();
prymula <prymula76@outlook.com>
parents:
diff changeset
626 printf ("start game\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
627 break;
prymula <prymula76@outlook.com>
parents:
diff changeset
628 case HISCORES:
prymula <prymula76@outlook.com>
parents:
diff changeset
629 hiscores();
prymula <prymula76@outlook.com>
parents:
diff changeset
630 printf ("hiscores\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
631 break;
prymula <prymula76@outlook.com>
parents:
diff changeset
632 case OPTIONS:
prymula <prymula76@outlook.com>
parents:
diff changeset
633 options();
prymula <prymula76@outlook.com>
parents:
diff changeset
634 printf ("options\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
635 break;
prymula <prymula76@outlook.com>
parents:
diff changeset
636 case ABOUT:
prymula <prymula76@outlook.com>
parents:
diff changeset
637 about();
prymula <prymula76@outlook.com>
parents:
diff changeset
638 printf ("about\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
639 break;
prymula <prymula76@outlook.com>
parents:
diff changeset
640 case QUIT_GAME:
prymula <prymula76@outlook.com>
parents:
diff changeset
641 done = 1;
prymula <prymula76@outlook.com>
parents:
diff changeset
642 break;
prymula <prymula76@outlook.com>
parents:
diff changeset
643 }
prymula <prymula76@outlook.com>
parents:
diff changeset
644 }
prymula <prymula76@outlook.com>
parents:
diff changeset
645
prymula <prymula76@outlook.com>
parents:
diff changeset
646
prymula <prymula76@outlook.com>
parents:
diff changeset
647 SDL_DestroyTexture(tex_screen);
prymula <prymula76@outlook.com>
parents:
diff changeset
648 SDL_DestroyRenderer(renderer);
prymula <prymula76@outlook.com>
parents:
diff changeset
649 SDL_DestroyWindow(window);
prymula <prymula76@outlook.com>
parents:
diff changeset
650 //free(hifile);
prymula <prymula76@outlook.com>
parents:
diff changeset
651
prymula <prymula76@outlook.com>
parents:
diff changeset
652 }