annotate arkanoid/arkanoid.c @ 17:e9c503d896a6

flappyufo-0.230919-1_add_pkgbuild
author Przemyslaw <prymula76@outlook.com>
date Sat, 24 Feb 2024 17:47:35 +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 arkanoid - moja implementacja klasyka
prymula <prymula76@outlook.com>
parents:
diff changeset
3 wymaga: SDL2, SDL_TTF2
prymula <prymula76@outlook.com>
parents:
diff changeset
4 09-01-2021
prymula <prymula76@outlook.com>
parents:
diff changeset
5 licencja: Public Domain
prymula <prymula76@outlook.com>
parents:
diff changeset
6 edytor: VS Code
prymula <prymula76@outlook.com>
parents:
diff changeset
7 utworzono na platformie: Windows 10 - MinGW32
prymula <prymula76@outlook.com>
parents:
diff changeset
8 */
prymula <prymula76@outlook.com>
parents:
diff changeset
9
prymula <prymula76@outlook.com>
parents:
diff changeset
10 #include "arkanoid.h"
prymula <prymula76@outlook.com>
parents:
diff changeset
11 #include "levels.h"
prymula <prymula76@outlook.com>
parents:
diff changeset
12
prymula <prymula76@outlook.com>
parents:
diff changeset
13 Kafel kafle[8][8];
prymula <prymula76@outlook.com>
parents:
diff changeset
14 SDL_Surface * gumka_kafla;
prymula <prymula76@outlook.com>
parents:
diff changeset
15 SDL_Window *gWindow=NULL;
prymula <prymula76@outlook.com>
parents:
diff changeset
16 SDL_Renderer * renderer=NULL;
prymula <prymula76@outlook.com>
parents:
diff changeset
17 SDL_Texture * tex_screen=NULL;
prymula <prymula76@outlook.com>
parents:
diff changeset
18
prymula <prymula76@outlook.com>
parents:
diff changeset
19 int liczba_kafli=0;
prymula <prymula76@outlook.com>
parents:
diff changeset
20 int wynik, najlepszy, poziom, zycia;
prymula <prymula76@outlook.com>
parents:
diff changeset
21
prymula <prymula76@outlook.com>
parents:
diff changeset
22 void rysuj_obrazek (int x, int y, SDL_Surface * obrazek, int przezroczystosc);
prymula <prymula76@outlook.com>
parents:
diff changeset
23 SDL_Surface * utworz_powierzchnie(int sz, int w, int r, int g, int b);
prymula <prymula76@outlook.com>
parents:
diff changeset
24
prymula <prymula76@outlook.com>
parents:
diff changeset
25 SDL_Rect set_rect(int x, int y, int w, int h)
prymula <prymula76@outlook.com>
parents:
diff changeset
26 {
prymula <prymula76@outlook.com>
parents:
diff changeset
27 SDL_Rect rect;
prymula <prymula76@outlook.com>
parents:
diff changeset
28 rect.x = x;
prymula <prymula76@outlook.com>
parents:
diff changeset
29 rect.y = y;
prymula <prymula76@outlook.com>
parents:
diff changeset
30 rect.w = w;
prymula <prymula76@outlook.com>
parents:
diff changeset
31 rect.h = h;
prymula <prymula76@outlook.com>
parents:
diff changeset
32 return rect;
prymula <prymula76@outlook.com>
parents:
diff changeset
33 }
prymula <prymula76@outlook.com>
parents:
diff changeset
34
prymula <prymula76@outlook.com>
parents:
diff changeset
35 Uint32 getpixel(SDL_Surface *surface, int x, int y)
prymula <prymula76@outlook.com>
parents:
diff changeset
36 {
prymula <prymula76@outlook.com>
parents:
diff changeset
37 int bpp = surface->format->BytesPerPixel;
prymula <prymula76@outlook.com>
parents:
diff changeset
38 /* Here p is the address to the pixel we want to retrieve */
prymula <prymula76@outlook.com>
parents:
diff changeset
39 Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
prymula <prymula76@outlook.com>
parents:
diff changeset
40
prymula <prymula76@outlook.com>
parents:
diff changeset
41 switch(bpp) {
prymula <prymula76@outlook.com>
parents:
diff changeset
42 case 1:
prymula <prymula76@outlook.com>
parents:
diff changeset
43 return *p;
prymula <prymula76@outlook.com>
parents:
diff changeset
44 case 2:
prymula <prymula76@outlook.com>
parents:
diff changeset
45 return *(Uint16 *)p;
prymula <prymula76@outlook.com>
parents:
diff changeset
46 case 3:
prymula <prymula76@outlook.com>
parents:
diff changeset
47 if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
prymula <prymula76@outlook.com>
parents:
diff changeset
48 return p[0] << 16 | p[1] << 8 | p[2];
prymula <prymula76@outlook.com>
parents:
diff changeset
49 else
prymula <prymula76@outlook.com>
parents:
diff changeset
50 return p[0] | p[1] << 8 | p[2] << 16;
prymula <prymula76@outlook.com>
parents:
diff changeset
51 case 4:
prymula <prymula76@outlook.com>
parents:
diff changeset
52 return *(Uint32 *)p;
prymula <prymula76@outlook.com>
parents:
diff changeset
53 default:
prymula <prymula76@outlook.com>
parents:
diff changeset
54 return 0;
prymula <prymula76@outlook.com>
parents:
diff changeset
55 }
prymula <prymula76@outlook.com>
parents:
diff changeset
56 }
prymula <prymula76@outlook.com>
parents:
diff changeset
57
prymula <prymula76@outlook.com>
parents:
diff changeset
58
prymula <prymula76@outlook.com>
parents:
diff changeset
59
prymula <prymula76@outlook.com>
parents:
diff changeset
60 void putpixel(SDL_Surface *surface, int x, int y, Uint8 R, Uint8 G, Uint8 B)
prymula <prymula76@outlook.com>
parents:
diff changeset
61 {
prymula <prymula76@outlook.com>
parents:
diff changeset
62 Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x *
prymula <prymula76@outlook.com>
parents:
diff changeset
63 surface->format->BytesPerPixel;
prymula <prymula76@outlook.com>
parents:
diff changeset
64 if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
prymula <prymula76@outlook.com>
parents:
diff changeset
65 {
prymula <prymula76@outlook.com>
parents:
diff changeset
66 p[0] = R;
prymula <prymula76@outlook.com>
parents:
diff changeset
67 p[1] = G;
prymula <prymula76@outlook.com>
parents:
diff changeset
68 p[2] = B;
prymula <prymula76@outlook.com>
parents:
diff changeset
69 }
prymula <prymula76@outlook.com>
parents:
diff changeset
70 else
prymula <prymula76@outlook.com>
parents:
diff changeset
71 {
prymula <prymula76@outlook.com>
parents:
diff changeset
72 p[0] = B;
prymula <prymula76@outlook.com>
parents:
diff changeset
73 p[1] = G;
prymula <prymula76@outlook.com>
parents:
diff changeset
74 p[2] = R;
prymula <prymula76@outlook.com>
parents:
diff changeset
75 }
prymula <prymula76@outlook.com>
parents:
diff changeset
76 }
prymula <prymula76@outlook.com>
parents:
diff changeset
77
prymula <prymula76@outlook.com>
parents:
diff changeset
78 SDL_Surface * preparuj_tekst(int r, int b, int g, char *bufor) {
prymula <prymula76@outlook.com>
parents:
diff changeset
79
prymula <prymula76@outlook.com>
parents:
diff changeset
80 SDL_Color fgcolor;
prymula <prymula76@outlook.com>
parents:
diff changeset
81
prymula <prymula76@outlook.com>
parents:
diff changeset
82 fgcolor.r = r;
prymula <prymula76@outlook.com>
parents:
diff changeset
83 fgcolor.b = b;
prymula <prymula76@outlook.com>
parents:
diff changeset
84 fgcolor.g = g;
prymula <prymula76@outlook.com>
parents:
diff changeset
85
prymula <prymula76@outlook.com>
parents:
diff changeset
86 return TTF_RenderText_Solid(font_panel, bufor, fgcolor);
prymula <prymula76@outlook.com>
parents:
diff changeset
87 }
prymula <prymula76@outlook.com>
parents:
diff changeset
88
prymula <prymula76@outlook.com>
parents:
diff changeset
89
prymula <prymula76@outlook.com>
parents:
diff changeset
90 void print_text(int r, int g, int b, char *c, int x, int y, int z) {
prymula <prymula76@outlook.com>
parents:
diff changeset
91
prymula <prymula76@outlook.com>
parents:
diff changeset
92 SDL_Surface * obraz_info;
prymula <prymula76@outlook.com>
parents:
diff changeset
93 SDL_Surface * gum_info;
prymula <prymula76@outlook.com>
parents:
diff changeset
94 SDL_Rect zrodlo, cel;
prymula <prymula76@outlook.com>
parents:
diff changeset
95
prymula <prymula76@outlook.com>
parents:
diff changeset
96 obraz_info = (SDL_Surface *) preparuj_tekst(r, g, b, c);
prymula <prymula76@outlook.com>
parents:
diff changeset
97
prymula <prymula76@outlook.com>
parents:
diff changeset
98 // chce wymazac napis
prymula <prymula76@outlook.com>
parents:
diff changeset
99 //cel = set_rect(obraz_info->clip_rect.x, obraz_info->clip_rect.y,
prymula <prymula76@outlook.com>
parents:
diff changeset
100 // obraz_info->w, obraz_info->h);
prymula <prymula76@outlook.com>
parents:
diff changeset
101 cel = set_rect(x, y,
prymula <prymula76@outlook.com>
parents:
diff changeset
102 obraz_info->w, obraz_info->h);
prymula <prymula76@outlook.com>
parents:
diff changeset
103 zrodlo = set_rect(0, 0, obraz_info->w, obraz_info->h);
prymula <prymula76@outlook.com>
parents:
diff changeset
104 gum_info=utworz_powierzchnie(obraz_info->w, obraz_info->h, 65, 190, 215);
prymula <prymula76@outlook.com>
parents:
diff changeset
105
prymula <prymula76@outlook.com>
parents:
diff changeset
106 SDL_BlitSurface(gum_info, &zrodlo, obraz, &cel);
prymula <prymula76@outlook.com>
parents:
diff changeset
107 SDL_FreeSurface(gum_info);
prymula <prymula76@outlook.com>
parents:
diff changeset
108
prymula <prymula76@outlook.com>
parents:
diff changeset
109 rysuj_obrazek(x, y, obraz_info, 1);
prymula <prymula76@outlook.com>
parents:
diff changeset
110 SDL_FreeSurface(obraz_info);
prymula <prymula76@outlook.com>
parents:
diff changeset
111 }
prymula <prymula76@outlook.com>
parents:
diff changeset
112
prymula <prymula76@outlook.com>
parents:
diff changeset
113
prymula <prymula76@outlook.com>
parents:
diff changeset
114 SDL_Surface * ustaw_kolor (Kolor kol) {
prymula <prymula76@outlook.com>
parents:
diff changeset
115
prymula <prymula76@outlook.com>
parents:
diff changeset
116 SDL_Surface * kafel;
prymula <prymula76@outlook.com>
parents:
diff changeset
117 SDL_Rect cel;
prymula <prymula76@outlook.com>
parents:
diff changeset
118
prymula <prymula76@outlook.com>
parents:
diff changeset
119 kafel = SDL_CreateRGBSurface(SDL_SWSURFACE, XKAFLA, YKAFLA,16,0,0,0,0);
prymula <prymula76@outlook.com>
parents:
diff changeset
120 cel = set_rect(0, 0, XKAFLA, YKAFLA);
prymula <prymula76@outlook.com>
parents:
diff changeset
121 SDL_FillRect(kafel, &cel, SDL_MapRGB(kafel->format, kol.r, kol.g, kol.b));
prymula <prymula76@outlook.com>
parents:
diff changeset
122
prymula <prymula76@outlook.com>
parents:
diff changeset
123 return kafel;
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 void ustaw_kolor_tla(void) {
prymula <prymula76@outlook.com>
parents:
diff changeset
128
prymula <prymula76@outlook.com>
parents:
diff changeset
129 SDL_Rect przez;
prymula <prymula76@outlook.com>
parents:
diff changeset
130 //obraz->clip_rect.x=0;
prymula <prymula76@outlook.com>
parents:
diff changeset
131 //obraz->clip_rect.y=0;
prymula <prymula76@outlook.com>
parents:
diff changeset
132 //obraz->clip_rect.w=640;
prymula <prymula76@outlook.com>
parents:
diff changeset
133 //obraz->clip_rect.h=480;
prymula <prymula76@outlook.com>
parents:
diff changeset
134 asm("nop");
prymula <prymula76@outlook.com>
parents:
diff changeset
135 przez = set_rect(0, 0, obraz->w, obraz->h);
prymula <prymula76@outlook.com>
parents:
diff changeset
136 //przez = set_rect(0, 0, 640, 480);
prymula <prymula76@outlook.com>
parents:
diff changeset
137
prymula <prymula76@outlook.com>
parents:
diff changeset
138 SDL_FillRect(obraz, &przez, SDL_MapRGB(obraz->format,65,190,215));
prymula <prymula76@outlook.com>
parents:
diff changeset
139 //SDL_Flip(obraz);
prymula <prymula76@outlook.com>
parents:
diff changeset
140 SDL_RenderPresent ( renderer );
prymula <prymula76@outlook.com>
parents:
diff changeset
141 }
prymula <prymula76@outlook.com>
parents:
diff changeset
142
prymula <prymula76@outlook.com>
parents:
diff changeset
143 void erase (RuchomyObiekt *p){
prymula <prymula76@outlook.com>
parents:
diff changeset
144
prymula <prymula76@outlook.com>
parents:
diff changeset
145 SDL_Rect zrodlo, cel;
prymula <prymula76@outlook.com>
parents:
diff changeset
146
prymula <prymula76@outlook.com>
parents:
diff changeset
147 cel = set_rect(p->px, p->py, p->gumka->w, p->gumka->h);
prymula <prymula76@outlook.com>
parents:
diff changeset
148 zrodlo = set_rect(0, 0, p->gumka->w, p->gumka->h);
prymula <prymula76@outlook.com>
parents:
diff changeset
149 SDL_BlitSurface(p->gumka,&zrodlo,obraz,&cel);
prymula <prymula76@outlook.com>
parents:
diff changeset
150 }
prymula <prymula76@outlook.com>
parents:
diff changeset
151
prymula <prymula76@outlook.com>
parents:
diff changeset
152
prymula <prymula76@outlook.com>
parents:
diff changeset
153 void przerysuj(RuchomyObiekt *p) {
prymula <prymula76@outlook.com>
parents:
diff changeset
154 SDL_Rect zrodlo, cel;
prymula <prymula76@outlook.com>
parents:
diff changeset
155 // wymazuje stara pozycje
prymula <prymula76@outlook.com>
parents:
diff changeset
156 cel = set_rect(p->px, p->py, p->gumka->w, p->gumka->h);
prymula <prymula76@outlook.com>
parents:
diff changeset
157 zrodlo = set_rect(0, 0, p->gumka->w, p->gumka->h);
prymula <prymula76@outlook.com>
parents:
diff changeset
158 SDL_BlitSurface(p->gumka,&zrodlo,obraz,&cel);
prymula <prymula76@outlook.com>
parents:
diff changeset
159 // rysuje na nowej pozycji
prymula <prymula76@outlook.com>
parents:
diff changeset
160 cel = set_rect(p->ax, p->ay, p->obraz->w, p->obraz->h);
prymula <prymula76@outlook.com>
parents:
diff changeset
161 zrodlo = set_rect(0, 0, p->obraz->w, p->obraz->h);
prymula <prymula76@outlook.com>
parents:
diff changeset
162 SDL_BlitSurface(p->obraz,&zrodlo,obraz,&cel);
prymula <prymula76@outlook.com>
parents:
diff changeset
163
prymula <prymula76@outlook.com>
parents:
diff changeset
164 }
prymula <prymula76@outlook.com>
parents:
diff changeset
165
prymula <prymula76@outlook.com>
parents:
diff changeset
166 void rysuj_obrazek (int x, int y, SDL_Surface * obrazek, int przezroczystosc) {
prymula <prymula76@outlook.com>
parents:
diff changeset
167
prymula <prymula76@outlook.com>
parents:
diff changeset
168 SDL_Rect srcrect, destrect;
prymula <prymula76@outlook.com>
parents:
diff changeset
169
prymula <prymula76@outlook.com>
parents:
diff changeset
170 if (przezroczystosc) SDL_SetColorKey(obrazek,SDL_TRUE,getpixel(obrazek,0,0));
prymula <prymula76@outlook.com>
parents:
diff changeset
171
prymula <prymula76@outlook.com>
parents:
diff changeset
172 destrect = set_rect(x, y, obrazek->w, obrazek->h);
prymula <prymula76@outlook.com>
parents:
diff changeset
173 srcrect = set_rect(0,0,obrazek->w, obrazek->h);
prymula <prymula76@outlook.com>
parents:
diff changeset
174 SDL_BlitSurface(obrazek,&srcrect,obraz,&destrect);
prymula <prymula76@outlook.com>
parents:
diff changeset
175 }
prymula <prymula76@outlook.com>
parents:
diff changeset
176
prymula <prymula76@outlook.com>
parents:
diff changeset
177
prymula <prymula76@outlook.com>
parents:
diff changeset
178 SDL_Surface * utworz_powierzchnie(int sz, int w, int r, int g, int b) {
prymula <prymula76@outlook.com>
parents:
diff changeset
179
prymula <prymula76@outlook.com>
parents:
diff changeset
180 SDL_Surface * powierzchnia;
prymula <prymula76@outlook.com>
parents:
diff changeset
181 SDL_Rect cel;
prymula <prymula76@outlook.com>
parents:
diff changeset
182
prymula <prymula76@outlook.com>
parents:
diff changeset
183 powierzchnia = SDL_CreateRGBSurface(SDL_SWSURFACE, sz, w,16,0,0,0,0);
prymula <prymula76@outlook.com>
parents:
diff changeset
184 cel = set_rect(0, 0, sz, w);
prymula <prymula76@outlook.com>
parents:
diff changeset
185 SDL_FillRect(powierzchnia, &cel, SDL_MapRGB(powierzchnia->format, r, g, b));
prymula <prymula76@outlook.com>
parents:
diff changeset
186
prymula <prymula76@outlook.com>
parents:
diff changeset
187 return powierzchnia;
prymula <prymula76@outlook.com>
parents:
diff changeset
188 }
prymula <prymula76@outlook.com>
parents:
diff changeset
189
prymula <prymula76@outlook.com>
parents:
diff changeset
190 Uint32 ruch_pilki(Uint32 interval, void *param)
prymula <prymula76@outlook.com>
parents:
diff changeset
191 {
prymula <prymula76@outlook.com>
parents:
diff changeset
192 SDL_Rect zrodlo, cel;
prymula <prymula76@outlook.com>
parents:
diff changeset
193 Teczka * t = (Teczka *) param;
prymula <prymula76@outlook.com>
parents:
diff changeset
194 int i, j;
prymula <prymula76@outlook.com>
parents:
diff changeset
195
prymula <prymula76@outlook.com>
parents:
diff changeset
196 przerysuj(t->pilka);
prymula <prymula76@outlook.com>
parents:
diff changeset
197
prymula <prymula76@outlook.com>
parents:
diff changeset
198 if (t->pilka->ax <= 5) t->pilka->kx=5;
prymula <prymula76@outlook.com>
parents:
diff changeset
199 if (t->pilka->ax >= 605) t->pilka->kx=-5;
prymula <prymula76@outlook.com>
parents:
diff changeset
200 if (t->pilka->ay <=30) t->pilka->ky=5;
prymula <prymula76@outlook.com>
parents:
diff changeset
201
prymula <prymula76@outlook.com>
parents:
diff changeset
202 /* odpicie przez paletke */
prymula <prymula76@outlook.com>
parents:
diff changeset
203 if (t->pilka->ax+XPILKI >= t->paletka->ax && (t->pilka->ax) <= (t->paletka->ax+XPALETKI) &&
prymula <prymula76@outlook.com>
parents:
diff changeset
204 t->pilka->ay >= 420) {
prymula <prymula76@outlook.com>
parents:
diff changeset
205
prymula <prymula76@outlook.com>
parents:
diff changeset
206 /* odbicie lewym brzegiem */
prymula <prymula76@outlook.com>
parents:
diff changeset
207 if (t->pilka->ax >= t->paletka->ax && t->pilka->ax <= t->paletka->ax+30) {
prymula <prymula76@outlook.com>
parents:
diff changeset
208 t->pilka->kx=-5;
prymula <prymula76@outlook.com>
parents:
diff changeset
209 printf ("kx = -5\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
210
prymula <prymula76@outlook.com>
parents:
diff changeset
211 }
prymula <prymula76@outlook.com>
parents:
diff changeset
212 /* odbicie lewym srodkiem */
prymula <prymula76@outlook.com>
parents:
diff changeset
213 else if (t->pilka->ax >= t->paletka->ax+30 && t->pilka->ax <= t->paletka->ax+60) {
prymula <prymula76@outlook.com>
parents:
diff changeset
214 t->pilka->kx=-2;
prymula <prymula76@outlook.com>
parents:
diff changeset
215 printf ("kx = -2\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
216 }
prymula <prymula76@outlook.com>
parents:
diff changeset
217 /* odbicie prawym srodkiem */
prymula <prymula76@outlook.com>
parents:
diff changeset
218 else if (t->pilka->ax >= t->paletka->ax+60 && t->pilka->ax <= t->paletka->ax+90) {
prymula <prymula76@outlook.com>
parents:
diff changeset
219 t->pilka->kx=2;
prymula <prymula76@outlook.com>
parents:
diff changeset
220 printf ("kx = 2\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
221 }
prymula <prymula76@outlook.com>
parents:
diff changeset
222 /* odbicie prawym brzegiem */
prymula <prymula76@outlook.com>
parents:
diff changeset
223 else if (t->pilka->ax >= t->paletka->ax+90 && t->pilka->ax <= t->paletka->ax+120) {
prymula <prymula76@outlook.com>
parents:
diff changeset
224 // t->pilka->kx=-5;
prymula <prymula76@outlook.com>
parents:
diff changeset
225 t->pilka->kx=5;
prymula <prymula76@outlook.com>
parents:
diff changeset
226 printf ("kx = 5\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
227
prymula <prymula76@outlook.com>
parents:
diff changeset
228 }
prymula <prymula76@outlook.com>
parents:
diff changeset
229
prymula <prymula76@outlook.com>
parents:
diff changeset
230 /* odbijamy od paletki */
prymula <prymula76@outlook.com>
parents:
diff changeset
231 t->pilka->ky=-5;
prymula <prymula76@outlook.com>
parents:
diff changeset
232 }
prymula <prymula76@outlook.com>
parents:
diff changeset
233
prymula <prymula76@outlook.com>
parents:
diff changeset
234 int flaga_zmiany=0; // zapobiega przebijaniu sie pilki przez kafle
prymula <prymula76@outlook.com>
parents:
diff changeset
235 /* reakcje pilki z kaflami */
prymula <prymula76@outlook.com>
parents:
diff changeset
236 for (i=0; i<8; i++) {
prymula <prymula76@outlook.com>
parents:
diff changeset
237
prymula <prymula76@outlook.com>
parents:
diff changeset
238 for (j=0; j<8; j++) {
prymula <prymula76@outlook.com>
parents:
diff changeset
239 if (kafle[i][j].obraz != NULL) {
prymula <prymula76@outlook.com>
parents:
diff changeset
240
prymula <prymula76@outlook.com>
parents:
diff changeset
241 if (t->pilka->ay+YPILKI >= kafle[i][j].y &&
prymula <prymula76@outlook.com>
parents:
diff changeset
242 t->pilka->ay <= kafle[i][j].y+YKAFLA &&
prymula <prymula76@outlook.com>
parents:
diff changeset
243 t->pilka->ax >= kafle[i][j].x-XPILKI &&
prymula <prymula76@outlook.com>
parents:
diff changeset
244 t->pilka->ax <= kafle[i][j].x+XKAFLA) {
prymula <prymula76@outlook.com>
parents:
diff changeset
245 #define XTOL 1
prymula <prymula76@outlook.com>
parents:
diff changeset
246 // #define YTOL 3
prymula <prymula76@outlook.com>
parents:
diff changeset
247 printf ("twardosc: %d\n", kafle[i][j].twardosc);
prymula <prymula76@outlook.com>
parents:
diff changeset
248 if (kafle[i][j].twardosc !=2) {
prymula <prymula76@outlook.com>
parents:
diff changeset
249 rysuj_obrazek(kafle[i][j].x, kafle[i][j].y, gumka_kafla, 0);
prymula <prymula76@outlook.com>
parents:
diff changeset
250 kafle[i][j].obraz=NULL;
prymula <prymula76@outlook.com>
parents:
diff changeset
251 // w ktora strone znikajacy kafel odbije pilke
prymula <prymula76@outlook.com>
parents:
diff changeset
252
prymula <prymula76@outlook.com>
parents:
diff changeset
253 // lewy przeg kafla
prymula <prymula76@outlook.com>
parents:
diff changeset
254
prymula <prymula76@outlook.com>
parents:
diff changeset
255 printf ("ax: %d kafel %d \n", t->pilka->ax, kafle[i][j].x+XKAFLA);
prymula <prymula76@outlook.com>
parents:
diff changeset
256
prymula <prymula76@outlook.com>
parents:
diff changeset
257 if (t->pilka->ay+YPILKI >= kafle[i][j].y &&
prymula <prymula76@outlook.com>
parents:
diff changeset
258 t->pilka->ay <= kafle[i][j].y+YKAFLA &&
prymula <prymula76@outlook.com>
parents:
diff changeset
259 t->pilka->ax >= kafle[i][j].x-XPILKI &&
prymula <prymula76@outlook.com>
parents:
diff changeset
260 t->pilka->ax <= kafle[i][j].x-XPILKI+XTOL) {
prymula <prymula76@outlook.com>
parents:
diff changeset
261
prymula <prymula76@outlook.com>
parents:
diff changeset
262 if (!flaga_zmiany) {
prymula <prymula76@outlook.com>
parents:
diff changeset
263 t->pilka->kx = -5;
prymula <prymula76@outlook.com>
parents:
diff changeset
264 flaga_zmiany=1;
prymula <prymula76@outlook.com>
parents:
diff changeset
265 }
prymula <prymula76@outlook.com>
parents:
diff changeset
266
prymula <prymula76@outlook.com>
parents:
diff changeset
267 printf ("lewy bok\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
268 liczba_kafli--;
prymula <prymula76@outlook.com>
parents:
diff changeset
269 wynik+=PUNKTY;
prymula <prymula76@outlook.com>
parents:
diff changeset
270 //
prymula <prymula76@outlook.com>
parents:
diff changeset
271 }
prymula <prymula76@outlook.com>
parents:
diff changeset
272 // prawy przeg kafla
prymula <prymula76@outlook.com>
parents:
diff changeset
273 else if (t->pilka->ay+YPILKI >= kafle[i][j].y &&
prymula <prymula76@outlook.com>
parents:
diff changeset
274 t->pilka->ay <= kafle[i][j].y+YKAFLA &&
prymula <prymula76@outlook.com>
parents:
diff changeset
275 t->pilka->ax <= kafle[i][j].x+XKAFLA &&
prymula <prymula76@outlook.com>
parents:
diff changeset
276 t->pilka->ax >= kafle[i][j].x+XKAFLA-XTOL) {
prymula <prymula76@outlook.com>
parents:
diff changeset
277
prymula <prymula76@outlook.com>
parents:
diff changeset
278 if (!flaga_zmiany) {
prymula <prymula76@outlook.com>
parents:
diff changeset
279 t->pilka->kx = 5;
prymula <prymula76@outlook.com>
parents:
diff changeset
280 flaga_zmiany=1;
prymula <prymula76@outlook.com>
parents:
diff changeset
281 }
prymula <prymula76@outlook.com>
parents:
diff changeset
282 printf ("prawy bok\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
283 liczba_kafli--;
prymula <prymula76@outlook.com>
parents:
diff changeset
284 wynik+=PUNKTY;
prymula <prymula76@outlook.com>
parents:
diff changeset
285 //
prymula <prymula76@outlook.com>
parents:
diff changeset
286 }
prymula <prymula76@outlook.com>
parents:
diff changeset
287 else if (t->pilka->ky == 5) {
prymula <prymula76@outlook.com>
parents:
diff changeset
288 if (!flaga_zmiany) {
prymula <prymula76@outlook.com>
parents:
diff changeset
289 t->pilka->ky =-5;
prymula <prymula76@outlook.com>
parents:
diff changeset
290 flaga_zmiany=1;
prymula <prymula76@outlook.com>
parents:
diff changeset
291 }
prymula <prymula76@outlook.com>
parents:
diff changeset
292 printf ("zmina kirunku: do gory (%d)\n", t->pilka->ay);
prymula <prymula76@outlook.com>
parents:
diff changeset
293 liczba_kafli--;
prymula <prymula76@outlook.com>
parents:
diff changeset
294 wynik+=PUNKTY;
prymula <prymula76@outlook.com>
parents:
diff changeset
295 }
prymula <prymula76@outlook.com>
parents:
diff changeset
296 else if (t->pilka->ky == -5) {
prymula <prymula76@outlook.com>
parents:
diff changeset
297 if (!flaga_zmiany) {
prymula <prymula76@outlook.com>
parents:
diff changeset
298 t->pilka->ky =5;
prymula <prymula76@outlook.com>
parents:
diff changeset
299 flaga_zmiany=1;
prymula <prymula76@outlook.com>
parents:
diff changeset
300 }
prymula <prymula76@outlook.com>
parents:
diff changeset
301 printf ("zmina kirunku: na dól %d \n", t->pilka->ay );
prymula <prymula76@outlook.com>
parents:
diff changeset
302 liczba_kafli--;
prymula <prymula76@outlook.com>
parents:
diff changeset
303 wynik+=PUNKTY;
prymula <prymula76@outlook.com>
parents:
diff changeset
304 }
prymula <prymula76@outlook.com>
parents:
diff changeset
305
prymula <prymula76@outlook.com>
parents:
diff changeset
306
prymula <prymula76@outlook.com>
parents:
diff changeset
307 printf ("\n\nliczba kafli: %d\n", liczba_kafli);
prymula <prymula76@outlook.com>
parents:
diff changeset
308 }
prymula <prymula76@outlook.com>
parents:
diff changeset
309 /* jesli twardosc 2 */
prymula <prymula76@outlook.com>
parents:
diff changeset
310 else {
prymula <prymula76@outlook.com>
parents:
diff changeset
311 if (t->pilka->ay+YPILKI >= kafle[i][j].y &&
prymula <prymula76@outlook.com>
parents:
diff changeset
312 t->pilka->ay <= kafle[i][j].y+YKAFLA &&
prymula <prymula76@outlook.com>
parents:
diff changeset
313 t->pilka->ax >= kafle[i][j].x-XPILKI &&
prymula <prymula76@outlook.com>
parents:
diff changeset
314 t->pilka->ax <= kafle[i][j].x-XPILKI+XTOL) {
prymula <prymula76@outlook.com>
parents:
diff changeset
315
prymula <prymula76@outlook.com>
parents:
diff changeset
316 if (!flaga_zmiany) {
prymula <prymula76@outlook.com>
parents:
diff changeset
317 t->pilka->kx = -5;
prymula <prymula76@outlook.com>
parents:
diff changeset
318 flaga_zmiany=1;
prymula <prymula76@outlook.com>
parents:
diff changeset
319 }
prymula <prymula76@outlook.com>
parents:
diff changeset
320 printf ("lewy bok\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
321 // liczba_kafli--;
prymula <prymula76@outlook.com>
parents:
diff changeset
322 kafle[i][j].twardosc=1;
prymula <prymula76@outlook.com>
parents:
diff changeset
323 //
prymula <prymula76@outlook.com>
parents:
diff changeset
324 }
prymula <prymula76@outlook.com>
parents:
diff changeset
325 // prawy przeg kafla
prymula <prymula76@outlook.com>
parents:
diff changeset
326 else if (t->pilka->ay+YPILKI >= kafle[i][j].y &&
prymula <prymula76@outlook.com>
parents:
diff changeset
327 t->pilka->ay <= kafle[i][j].y+YKAFLA &&
prymula <prymula76@outlook.com>
parents:
diff changeset
328 t->pilka->ax <= kafle[i][j].x+XKAFLA &&
prymula <prymula76@outlook.com>
parents:
diff changeset
329 t->pilka->ax >= kafle[i][j].x+XKAFLA-XTOL) {
prymula <prymula76@outlook.com>
parents:
diff changeset
330
prymula <prymula76@outlook.com>
parents:
diff changeset
331 if (!flaga_zmiany) {
prymula <prymula76@outlook.com>
parents:
diff changeset
332 t->pilka->kx = 5;
prymula <prymula76@outlook.com>
parents:
diff changeset
333 flaga_zmiany=1;
prymula <prymula76@outlook.com>
parents:
diff changeset
334 }
prymula <prymula76@outlook.com>
parents:
diff changeset
335
prymula <prymula76@outlook.com>
parents:
diff changeset
336 printf ("prawy bok\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
337 // liczba_kafli--;
prymula <prymula76@outlook.com>
parents:
diff changeset
338 kafle[i][j].twardosc=1;
prymula <prymula76@outlook.com>
parents:
diff changeset
339 //
prymula <prymula76@outlook.com>
parents:
diff changeset
340 }
prymula <prymula76@outlook.com>
parents:
diff changeset
341
prymula <prymula76@outlook.com>
parents:
diff changeset
342 else if (t->pilka->ky == 5) {
prymula <prymula76@outlook.com>
parents:
diff changeset
343 if (!flaga_zmiany) {
prymula <prymula76@outlook.com>
parents:
diff changeset
344 t->pilka->ky =-5;
prymula <prymula76@outlook.com>
parents:
diff changeset
345 flaga_zmiany=1;
prymula <prymula76@outlook.com>
parents:
diff changeset
346 }
prymula <prymula76@outlook.com>
parents:
diff changeset
347 printf ("zmina kirunku: do gory (%d)\n", t->pilka->ay);
prymula <prymula76@outlook.com>
parents:
diff changeset
348 liczba_kafli--;
prymula <prymula76@outlook.com>
parents:
diff changeset
349 }
prymula <prymula76@outlook.com>
parents:
diff changeset
350 else if (t->pilka->ky == -5) {
prymula <prymula76@outlook.com>
parents:
diff changeset
351 if (!flaga_zmiany) {
prymula <prymula76@outlook.com>
parents:
diff changeset
352 t->pilka->ky =5;
prymula <prymula76@outlook.com>
parents:
diff changeset
353 flaga_zmiany=1;
prymula <prymula76@outlook.com>
parents:
diff changeset
354 }
prymula <prymula76@outlook.com>
parents:
diff changeset
355 printf ("zmina kirunku: na dól %d \n", t->pilka->ay );
prymula <prymula76@outlook.com>
parents:
diff changeset
356 liczba_kafli--;
prymula <prymula76@outlook.com>
parents:
diff changeset
357 }
prymula <prymula76@outlook.com>
parents:
diff changeset
358 printf("opuszczam Twardosc 2\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
359 }
prymula <prymula76@outlook.com>
parents:
diff changeset
360
prymula <prymula76@outlook.com>
parents:
diff changeset
361 }
prymula <prymula76@outlook.com>
parents:
diff changeset
362 }
prymula <prymula76@outlook.com>
parents:
diff changeset
363 }
prymula <prymula76@outlook.com>
parents:
diff changeset
364 }
prymula <prymula76@outlook.com>
parents:
diff changeset
365
prymula <prymula76@outlook.com>
parents:
diff changeset
366
prymula <prymula76@outlook.com>
parents:
diff changeset
367
prymula <prymula76@outlook.com>
parents:
diff changeset
368 t->pilka->px=t->pilka->ax;
prymula <prymula76@outlook.com>
parents:
diff changeset
369 t->pilka->py=t->pilka->ay;
prymula <prymula76@outlook.com>
parents:
diff changeset
370 t->pilka->ax+=t->pilka->kx;
prymula <prymula76@outlook.com>
parents:
diff changeset
371 t->pilka->ay+=t->pilka->ky;
prymula <prymula76@outlook.com>
parents:
diff changeset
372
prymula <prymula76@outlook.com>
parents:
diff changeset
373 //return interval;
prymula <prymula76@outlook.com>
parents:
diff changeset
374 }
prymula <prymula76@outlook.com>
parents:
diff changeset
375
prymula <prymula76@outlook.com>
parents:
diff changeset
376
prymula <prymula76@outlook.com>
parents:
diff changeset
377
prymula <prymula76@outlook.com>
parents:
diff changeset
378 /* poziom liczymy od zera */
prymula <prymula76@outlook.com>
parents:
diff changeset
379 void zaladuj_poziom(SDL_Surface ** kolor_kafla, int poziom) {
prymula <prymula76@outlook.com>
parents:
diff changeset
380
prymula <prymula76@outlook.com>
parents:
diff changeset
381 int i, j, l, x, y;
prymula <prymula76@outlook.com>
parents:
diff changeset
382
prymula <prymula76@outlook.com>
parents:
diff changeset
383 printf ("bede rysowac poziom: %d\n", poziom);
prymula <prymula76@outlook.com>
parents:
diff changeset
384 /* dane odczytwane beda dla poziomu 'level' */
prymula <prymula76@outlook.com>
parents:
diff changeset
385 l = poziom*8;
prymula <prymula76@outlook.com>
parents:
diff changeset
386 liczba_kafli=0;
prymula <prymula76@outlook.com>
parents:
diff changeset
387 x=0;
prymula <prymula76@outlook.com>
parents:
diff changeset
388 y=30;
prymula <prymula76@outlook.com>
parents:
diff changeset
389 // wiersze
prymula <prymula76@outlook.com>
parents:
diff changeset
390 for (i=0; i < 8; ++i) {
prymula <prymula76@outlook.com>
parents:
diff changeset
391 // kolumny
prymula <prymula76@outlook.com>
parents:
diff changeset
392 for (j = 0; j < 8; ++j) {
prymula <prymula76@outlook.com>
parents:
diff changeset
393
prymula <prymula76@outlook.com>
parents:
diff changeset
394 printf ("levels -%d-", levels[i+l][j]);
prymula <prymula76@outlook.com>
parents:
diff changeset
395 /* jesli pole rozne od zera to jakis kafel */
prymula <prymula76@outlook.com>
parents:
diff changeset
396 if (levels[i+l][j] != 48) {
prymula <prymula76@outlook.com>
parents:
diff changeset
397 kafle[i][j].obraz= kolor_kafla[levels[i+l][j]-48];
prymula <prymula76@outlook.com>
parents:
diff changeset
398
prymula <prymula76@outlook.com>
parents:
diff changeset
399 if (levels[i+l][j] != 52) kafle[i][j].twardosc=1;
prymula <prymula76@outlook.com>
parents:
diff changeset
400 else kafle[i][j].twardosc=2;
prymula <prymula76@outlook.com>
parents:
diff changeset
401
prymula <prymula76@outlook.com>
parents:
diff changeset
402 kafle[i][j].x = x;
prymula <prymula76@outlook.com>
parents:
diff changeset
403 kafle[i][j].y = y;
prymula <prymula76@outlook.com>
parents:
diff changeset
404 liczba_kafli++;
prymula <prymula76@outlook.com>
parents:
diff changeset
405 }
prymula <prymula76@outlook.com>
parents:
diff changeset
406 else {
prymula <prymula76@outlook.com>
parents:
diff changeset
407 kafle[i][j].obraz= NULL;
prymula <prymula76@outlook.com>
parents:
diff changeset
408 }
prymula <prymula76@outlook.com>
parents:
diff changeset
409 x+=XKAFLA;
prymula <prymula76@outlook.com>
parents:
diff changeset
410 }
prymula <prymula76@outlook.com>
parents:
diff changeset
411 x=0;
prymula <prymula76@outlook.com>
parents:
diff changeset
412 y+=YKAFLA;
prymula <prymula76@outlook.com>
parents:
diff changeset
413
prymula <prymula76@outlook.com>
parents:
diff changeset
414 putchar('\n');
prymula <prymula76@outlook.com>
parents:
diff changeset
415 // if (i == 19) putchar('\n');
prymula <prymula76@outlook.com>
parents:
diff changeset
416 }
prymula <prymula76@outlook.com>
parents:
diff changeset
417
prymula <prymula76@outlook.com>
parents:
diff changeset
418 }
prymula <prymula76@outlook.com>
parents:
diff changeset
419
prymula <prymula76@outlook.com>
parents:
diff changeset
420 void wyswietl_kafle(void) {
prymula <prymula76@outlook.com>
parents:
diff changeset
421
prymula <prymula76@outlook.com>
parents:
diff changeset
422 int i, j;
prymula <prymula76@outlook.com>
parents:
diff changeset
423 SDL_Rect zrodlo, cel;
prymula <prymula76@outlook.com>
parents:
diff changeset
424
prymula <prymula76@outlook.com>
parents:
diff changeset
425 for (i=0; i < 8; ++i) {
prymula <prymula76@outlook.com>
parents:
diff changeset
426
prymula <prymula76@outlook.com>
parents:
diff changeset
427 for (j = 0; j < 8; ++j) {
prymula <prymula76@outlook.com>
parents:
diff changeset
428
prymula <prymula76@outlook.com>
parents:
diff changeset
429 if (kafle[i][j].obraz != NULL) {
prymula <prymula76@outlook.com>
parents:
diff changeset
430 printf ("rysuje\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
431 cel = set_rect(kafle[i][j].x, kafle[i][j].y, kafle[i][j].obraz->w, kafle[i][j].obraz->h);
prymula <prymula76@outlook.com>
parents:
diff changeset
432 zrodlo = set_rect(0, 0, kafle[i][j].obraz->w, kafle[i][j].obraz->h);
prymula <prymula76@outlook.com>
parents:
diff changeset
433 SDL_BlitSurface(kafle[i][j].obraz, &zrodlo, obraz, &cel);
prymula <prymula76@outlook.com>
parents:
diff changeset
434
prymula <prymula76@outlook.com>
parents:
diff changeset
435 }
prymula <prymula76@outlook.com>
parents:
diff changeset
436 //else printf ("Kafle nie maja przydzielonego obrazu\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
437 }
prymula <prymula76@outlook.com>
parents:
diff changeset
438 }
prymula <prymula76@outlook.com>
parents:
diff changeset
439 }
prymula <prymula76@outlook.com>
parents:
diff changeset
440
prymula <prymula76@outlook.com>
parents:
diff changeset
441 SDL_Surface * utworz_kafle(SDL_Surface ** tab) {
prymula <prymula76@outlook.com>
parents:
diff changeset
442 int i;
prymula <prymula76@outlook.com>
parents:
diff changeset
443 Kolor kolory[4] = {{62, 246, 26}, // zielony
prymula <prymula76@outlook.com>
parents:
diff changeset
444 {246, 26, 202}, // filoet
prymula <prymula76@outlook.com>
parents:
diff changeset
445 {26, 36, 246}, // indygo
prymula <prymula76@outlook.com>
parents:
diff changeset
446 {246, 26, 52}}; // czerwony
prymula <prymula76@outlook.com>
parents:
diff changeset
447 // {253, 157, 79} // pomaranczowy
prymula <prymula76@outlook.com>
parents:
diff changeset
448 for (i=0; i<8; i++) {
prymula <prymula76@outlook.com>
parents:
diff changeset
449 tab[i] = ustaw_kolor(kolory[i]);
prymula <prymula76@outlook.com>
parents:
diff changeset
450 }
prymula <prymula76@outlook.com>
parents:
diff changeset
451
prymula <prymula76@outlook.com>
parents:
diff changeset
452 }
prymula <prymula76@outlook.com>
parents:
diff changeset
453
prymula <prymula76@outlook.com>
parents:
diff changeset
454 SDL_bool end() {
prymula <prymula76@outlook.com>
parents:
diff changeset
455 SDL_Rect zrodlo, cel;
prymula <prymula76@outlook.com>
parents:
diff changeset
456 char txt1[30] = "G A M E O V E R";
prymula <prymula76@outlook.com>
parents:
diff changeset
457 char txt2[10] = "Wynik";
prymula <prymula76@outlook.com>
parents:
diff changeset
458 char txt3[24];
prymula <prymula76@outlook.com>
parents:
diff changeset
459 ustaw_kolor_tla();
prymula <prymula76@outlook.com>
parents:
diff changeset
460
prymula <prymula76@outlook.com>
parents:
diff changeset
461 print_text(0, 0, 0, txt1, 200, 200, 10);
prymula <prymula76@outlook.com>
parents:
diff changeset
462 print_text(234, 0, 0, txt2, 250, 250, 10);
prymula <prymula76@outlook.com>
parents:
diff changeset
463 sprintf (txt3, "%d", wynik);
prymula <prymula76@outlook.com>
parents:
diff changeset
464 print_text(33, 249, 11, txt3, 260, 300, 10);
prymula <prymula76@outlook.com>
parents:
diff changeset
465
prymula <prymula76@outlook.com>
parents:
diff changeset
466 cel = set_rect(0, 0, obraz->w, obraz->h);
prymula <prymula76@outlook.com>
parents:
diff changeset
467 zrodlo = set_rect(0, 0, obraz->w, obraz->h);
prymula <prymula76@outlook.com>
parents:
diff changeset
468 tex_screen = SDL_CreateTextureFromSurface(renderer, obraz);
prymula <prymula76@outlook.com>
parents:
diff changeset
469 SDL_RenderClear ( renderer );
prymula <prymula76@outlook.com>
parents:
diff changeset
470 SDL_RenderCopy(renderer, tex_screen,&zrodlo,&cel);
prymula <prymula76@outlook.com>
parents:
diff changeset
471 SDL_RenderPresent(renderer);
prymula <prymula76@outlook.com>
parents:
diff changeset
472 SDL_DestroyTexture(tex_screen);
prymula <prymula76@outlook.com>
parents:
diff changeset
473
prymula <prymula76@outlook.com>
parents:
diff changeset
474 sleep(5);
prymula <prymula76@outlook.com>
parents:
diff changeset
475 return SDL_TRUE;
prymula <prymula76@outlook.com>
parents:
diff changeset
476 }
prymula <prymula76@outlook.com>
parents:
diff changeset
477
prymula <prymula76@outlook.com>
parents:
diff changeset
478 SDL_bool file_exist(){
prymula <prymula76@outlook.com>
parents:
diff changeset
479 char *file;
prymula <prymula76@outlook.com>
parents:
diff changeset
480
prymula <prymula76@outlook.com>
parents:
diff changeset
481 #if WINDOWS
prymula <prymula76@outlook.com>
parents:
diff changeset
482 char * FILE_NAME = "\\arkanoid.txt";
prymula <prymula76@outlook.com>
parents:
diff changeset
483 char * HOME = "HOMEPATH";
prymula <prymula76@outlook.com>
parents:
diff changeset
484
prymula <prymula76@outlook.com>
parents:
diff changeset
485 #elif LINUX
prymula <prymula76@outlook.com>
parents:
diff changeset
486 char * FILE_NAME = "/.arkanoid.txt";
prymula <prymula76@outlook.com>
parents:
diff changeset
487 char * HOME = "HOME";
prymula <prymula76@outlook.com>
parents:
diff changeset
488 #endif
prymula <prymula76@outlook.com>
parents:
diff changeset
489
prymula <prymula76@outlook.com>
parents:
diff changeset
490
prymula <prymula76@outlook.com>
parents:
diff changeset
491 if (!getenv(HOME)) exit (1);
prymula <prymula76@outlook.com>
parents:
diff changeset
492
prymula <prymula76@outlook.com>
parents:
diff changeset
493 file=(char *)malloc(strlen(getenv(HOME))+strlen(FILE_NAME)+1);
prymula <prymula76@outlook.com>
parents:
diff changeset
494
prymula <prymula76@outlook.com>
parents:
diff changeset
495 strcpy(file, getenv(HOME));
prymula <prymula76@outlook.com>
parents:
diff changeset
496 strcat(file, FILE_NAME);
prymula <prymula76@outlook.com>
parents:
diff changeset
497 printf("1");
prymula <prymula76@outlook.com>
parents:
diff changeset
498
prymula <prymula76@outlook.com>
parents:
diff changeset
499 if (access(file, F_OK)==0){
prymula <prymula76@outlook.com>
parents:
diff changeset
500 printf("PLIK istnieje %s",file);
prymula <prymula76@outlook.com>
parents:
diff changeset
501 free(file);
prymula <prymula76@outlook.com>
parents:
diff changeset
502 return SDL_TRUE;
prymula <prymula76@outlook.com>
parents:
diff changeset
503 }
prymula <prymula76@outlook.com>
parents:
diff changeset
504 printf("PLIK nie istnieje %s",file);
prymula <prymula76@outlook.com>
parents:
diff changeset
505 free(file);
prymula <prymula76@outlook.com>
parents:
diff changeset
506 return SDL_FALSE;
prymula <prymula76@outlook.com>
parents:
diff changeset
507
prymula <prymula76@outlook.com>
parents:
diff changeset
508 }
prymula <prymula76@outlook.com>
parents:
diff changeset
509
prymula <prymula76@outlook.com>
parents:
diff changeset
510 void save_hiscore(){
prymula <prymula76@outlook.com>
parents:
diff changeset
511 char *file;
prymula <prymula76@outlook.com>
parents:
diff changeset
512
prymula <prymula76@outlook.com>
parents:
diff changeset
513 #if WINDOWS
prymula <prymula76@outlook.com>
parents:
diff changeset
514 char * FILE_NAME = "\\arkanoid.txt";
prymula <prymula76@outlook.com>
parents:
diff changeset
515 char * HOME = "HOMEPATH";
prymula <prymula76@outlook.com>
parents:
diff changeset
516
prymula <prymula76@outlook.com>
parents:
diff changeset
517 #elif LINUX
prymula <prymula76@outlook.com>
parents:
diff changeset
518 char * FILE_NAME = "/.arkanoid.txt";
prymula <prymula76@outlook.com>
parents:
diff changeset
519 char * HOME = "HOME";
prymula <prymula76@outlook.com>
parents:
diff changeset
520 #endif
prymula <prymula76@outlook.com>
parents:
diff changeset
521
prymula <prymula76@outlook.com>
parents:
diff changeset
522
prymula <prymula76@outlook.com>
parents:
diff changeset
523 char bufor[48];
prymula <prymula76@outlook.com>
parents:
diff changeset
524
prymula <prymula76@outlook.com>
parents:
diff changeset
525 if (!getenv(HOME)) exit (1);
prymula <prymula76@outlook.com>
parents:
diff changeset
526
prymula <prymula76@outlook.com>
parents:
diff changeset
527
prymula <prymula76@outlook.com>
parents:
diff changeset
528 //file=(char *)malloc(strlen(getenv(HOME)+strlen(FILE_NAME)+1));
prymula <prymula76@outlook.com>
parents:
diff changeset
529 file=(char *)malloc(strlen(getenv(HOME))+strlen(FILE_NAME)+1);
prymula <prymula76@outlook.com>
parents:
diff changeset
530
prymula <prymula76@outlook.com>
parents:
diff changeset
531 strcpy(file, getenv(HOME));
prymula <prymula76@outlook.com>
parents:
diff changeset
532 strcat(file, FILE_NAME);
prymula <prymula76@outlook.com>
parents:
diff changeset
533
prymula <prymula76@outlook.com>
parents:
diff changeset
534 sprintf(bufor,"%d",najlepszy);
prymula <prymula76@outlook.com>
parents:
diff changeset
535
prymula <prymula76@outlook.com>
parents:
diff changeset
536 FILE * f = fopen(file, "w");
prymula <prymula76@outlook.com>
parents:
diff changeset
537 fwrite(bufor, sizeof(char), strlen(bufor), f);
prymula <prymula76@outlook.com>
parents:
diff changeset
538 fclose(f);
prymula <prymula76@outlook.com>
parents:
diff changeset
539 printf ("Zapisałem: %s\n", file);
prymula <prymula76@outlook.com>
parents:
diff changeset
540 free(file);
prymula <prymula76@outlook.com>
parents:
diff changeset
541
prymula <prymula76@outlook.com>
parents:
diff changeset
542
prymula <prymula76@outlook.com>
parents:
diff changeset
543
prymula <prymula76@outlook.com>
parents:
diff changeset
544 }
prymula <prymula76@outlook.com>
parents:
diff changeset
545
prymula <prymula76@outlook.com>
parents:
diff changeset
546 void load_hiscore(){
prymula <prymula76@outlook.com>
parents:
diff changeset
547 char *file;
prymula <prymula76@outlook.com>
parents:
diff changeset
548
prymula <prymula76@outlook.com>
parents:
diff changeset
549 #if WINDOWS
prymula <prymula76@outlook.com>
parents:
diff changeset
550 char * FILE_NAME = "\\arkanoid.txt";
prymula <prymula76@outlook.com>
parents:
diff changeset
551 char * HOME = "HOMEPATH";
prymula <prymula76@outlook.com>
parents:
diff changeset
552
prymula <prymula76@outlook.com>
parents:
diff changeset
553 #elif LINUX
prymula <prymula76@outlook.com>
parents:
diff changeset
554 char * FILE_NAME = "/.arkanoid.txt";
prymula <prymula76@outlook.com>
parents:
diff changeset
555 char * HOME = "HOME";
prymula <prymula76@outlook.com>
parents:
diff changeset
556 #endif
prymula <prymula76@outlook.com>
parents:
diff changeset
557
prymula <prymula76@outlook.com>
parents:
diff changeset
558
prymula <prymula76@outlook.com>
parents:
diff changeset
559 char bufor[48];
prymula <prymula76@outlook.com>
parents:
diff changeset
560
prymula <prymula76@outlook.com>
parents:
diff changeset
561 if (!getenv(HOME)) exit (1);
prymula <prymula76@outlook.com>
parents:
diff changeset
562
prymula <prymula76@outlook.com>
parents:
diff changeset
563 //file=(char *)malloc(strlen(getenv(HOME)+strlen(FILE_NAME)+1));
prymula <prymula76@outlook.com>
parents:
diff changeset
564 file=(char *)malloc(strlen(getenv(HOME))+strlen(FILE_NAME)+1);
prymula <prymula76@outlook.com>
parents:
diff changeset
565
prymula <prymula76@outlook.com>
parents:
diff changeset
566 strcpy(file, getenv(HOME));
prymula <prymula76@outlook.com>
parents:
diff changeset
567 strcat(file, FILE_NAME);
prymula <prymula76@outlook.com>
parents:
diff changeset
568
prymula <prymula76@outlook.com>
parents:
diff changeset
569 FILE * f = fopen(file, "r");
prymula <prymula76@outlook.com>
parents:
diff changeset
570 fscanf(f, "%s", bufor);
prymula <prymula76@outlook.com>
parents:
diff changeset
571 fclose(f);
prymula <prymula76@outlook.com>
parents:
diff changeset
572 free(file);
prymula <prymula76@outlook.com>
parents:
diff changeset
573
prymula <prymula76@outlook.com>
parents:
diff changeset
574 najlepszy=atoi(bufor);
prymula <prymula76@outlook.com>
parents:
diff changeset
575
prymula <prymula76@outlook.com>
parents:
diff changeset
576 // najlepszy=0;
prymula <prymula76@outlook.com>
parents:
diff changeset
577 }
prymula <prymula76@outlook.com>
parents:
diff changeset
578
prymula <prymula76@outlook.com>
parents:
diff changeset
579
prymula <prymula76@outlook.com>
parents:
diff changeset
580
prymula <prymula76@outlook.com>
parents:
diff changeset
581
prymula <prymula76@outlook.com>
parents:
diff changeset
582 SDL_bool gra () {
prymula <prymula76@outlook.com>
parents:
diff changeset
583
prymula <prymula76@outlook.com>
parents:
diff changeset
584 int wykonano, rozpoczecie;
prymula <prymula76@outlook.com>
parents:
diff changeset
585 int px, py, kx, ky;
prymula <prymula76@outlook.com>
parents:
diff changeset
586 char bufor[50];
prymula <prymula76@outlook.com>
parents:
diff changeset
587 SDL_bool quit=SDL_TRUE;
prymula <prymula76@outlook.com>
parents:
diff changeset
588
prymula <prymula76@outlook.com>
parents:
diff changeset
589 SDL_Surface * tablica_kolorow_kafli[4];
prymula <prymula76@outlook.com>
parents:
diff changeset
590 SDL_TimerID uchwyt_pilki;
prymula <prymula76@outlook.com>
parents:
diff changeset
591 Uint32 predkosc_pilki=50, czas_zwloki=50;
prymula <prymula76@outlook.com>
parents:
diff changeset
592 RuchomyObiekt pilka, paletka;
prymula <prymula76@outlook.com>
parents:
diff changeset
593 Teczka teczka;
prymula <prymula76@outlook.com>
parents:
diff changeset
594 // Teczka2 teczka2;
prymula <prymula76@outlook.com>
parents:
diff changeset
595 // Kafel kafle[4][8];
prymula <prymula76@outlook.com>
parents:
diff changeset
596 int powolna_paletka=0, pauza=0;
prymula <prymula76@outlook.com>
parents:
diff changeset
597 SDL_Rect zrodlo, cel;
prymula <prymula76@outlook.com>
parents:
diff changeset
598 char level_bufor[24], score_bufor[24], lives_bufor[24], hi_bufor[24];
prymula <prymula76@outlook.com>
parents:
diff changeset
599
prymula <prymula76@outlook.com>
parents:
diff changeset
600 wynik=000;
prymula <prymula76@outlook.com>
parents:
diff changeset
601 pilka.ax=640/2-XPILKI/2;
prymula <prymula76@outlook.com>
parents:
diff changeset
602 pilka.ay=420;
prymula <prymula76@outlook.com>
parents:
diff changeset
603 pilka.px=pilka.ax;
prymula <prymula76@outlook.com>
parents:
diff changeset
604 pilka.py=pilka.ay;
prymula <prymula76@outlook.com>
parents:
diff changeset
605 pilka.kx=-5;
prymula <prymula76@outlook.com>
parents:
diff changeset
606 pilka.ky=-5;
prymula <prymula76@outlook.com>
parents:
diff changeset
607
prymula <prymula76@outlook.com>
parents:
diff changeset
608 zycia=2;
prymula <prymula76@outlook.com>
parents:
diff changeset
609 poziom=1;
prymula <prymula76@outlook.com>
parents:
diff changeset
610 //najlepszy=1000;
prymula <prymula76@outlook.com>
parents:
diff changeset
611
prymula <prymula76@outlook.com>
parents:
diff changeset
612 asm("nop");
prymula <prymula76@outlook.com>
parents:
diff changeset
613 ustaw_kolor_tla();
prymula <prymula76@outlook.com>
parents:
diff changeset
614
prymula <prymula76@outlook.com>
parents:
diff changeset
615 pilka.obraz=utworz_pilke();
prymula <prymula76@outlook.com>
parents:
diff changeset
616 //pilka.obraz = SDL_LoadBMP("ball.bmp");
prymula <prymula76@outlook.com>
parents:
diff changeset
617 //pilka.gumka=utworz_powierzchnie(XPILKI, YPILKI, 65, 190, 215);
prymula <prymula76@outlook.com>
parents:
diff changeset
618 #if WINDOWS
prymula <prymula76@outlook.com>
parents:
diff changeset
619 pilka.gumka = SDL_LoadBMP("icon/gumka_arkanoid.bmp");
prymula <prymula76@outlook.com>
parents:
diff changeset
620 #elif LINUX
prymula <prymula76@outlook.com>
parents:
diff changeset
621 pilka.gumka = SDL_LoadBMP("/usr/share/pixmaps/gumka_arkanoid.bmp");
prymula <prymula76@outlook.com>
parents:
diff changeset
622 #endif
prymula <prymula76@outlook.com>
parents:
diff changeset
623
prymula <prymula76@outlook.com>
parents:
diff changeset
624 SDL_SetColorKey(pilka.gumka,SDL_TRUE,getpixel(pilka.gumka,0,0));
prymula <prymula76@outlook.com>
parents:
diff changeset
625 rysuj_obrazek(pilka.ax, pilka.ay, pilka.obraz, 1); // colorskey powinno byc 1
prymula <prymula76@outlook.com>
parents:
diff changeset
626
prymula <prymula76@outlook.com>
parents:
diff changeset
627 paletka.ax=640/2-XPALETKI/2;
prymula <prymula76@outlook.com>
parents:
diff changeset
628 paletka.ay=450;
prymula <prymula76@outlook.com>
parents:
diff changeset
629 // paletka.px=paletka.ax;
prymula <prymula76@outlook.com>
parents:
diff changeset
630 paletka.py=paletka.ay;
prymula <prymula76@outlook.com>
parents:
diff changeset
631
prymula <prymula76@outlook.com>
parents:
diff changeset
632 paletka.obraz=utworz_powierzchnie(XPALETKI, YPALETKI, 0, 0, 0);
prymula <prymula76@outlook.com>
parents:
diff changeset
633 paletka.gumka=utworz_powierzchnie(XPALETKI, YPALETKI, 65, 190, 215);
prymula <prymula76@outlook.com>
parents:
diff changeset
634
prymula <prymula76@outlook.com>
parents:
diff changeset
635 rysuj_obrazek(paletka.ax, paletka.ay, paletka.obraz, 0);
prymula <prymula76@outlook.com>
parents:
diff changeset
636
prymula <prymula76@outlook.com>
parents:
diff changeset
637
prymula <prymula76@outlook.com>
parents:
diff changeset
638 teczka.pilka=&pilka;
prymula <prymula76@outlook.com>
parents:
diff changeset
639 teczka.paletka=&paletka;
prymula <prymula76@outlook.com>
parents:
diff changeset
640
prymula <prymula76@outlook.com>
parents:
diff changeset
641 utworz_kafle(tablica_kolorow_kafli);
prymula <prymula76@outlook.com>
parents:
diff changeset
642 zaladuj_poziom(tablica_kolorow_kafli, poziom-1);
prymula <prymula76@outlook.com>
parents:
diff changeset
643 wyswietl_kafle();
prymula <prymula76@outlook.com>
parents:
diff changeset
644 gumka_kafla=utworz_powierzchnie(XKAFLA, YKAFLA, 65, 190, 215);
prymula <prymula76@outlook.com>
parents:
diff changeset
645
prymula <prymula76@outlook.com>
parents:
diff changeset
646 rozpoczecie = wykonano = 0;
prymula <prymula76@outlook.com>
parents:
diff changeset
647
prymula <prymula76@outlook.com>
parents:
diff changeset
648 sprintf (level_bufor, "%d", poziom);
prymula <prymula76@outlook.com>
parents:
diff changeset
649 print_text(253, 255, 100, level_bufor, 250, 0, 2);
prymula <prymula76@outlook.com>
parents:
diff changeset
650 sprintf (lives_bufor, "%d", zycia);
prymula <prymula76@outlook.com>
parents:
diff changeset
651 print_text(33, 249, 11, lives_bufor, 400, 0, 2);
prymula <prymula76@outlook.com>
parents:
diff changeset
652 sprintf (hi_bufor, "%d", najlepszy);
prymula <prymula76@outlook.com>
parents:
diff changeset
653 print_text(249, 33, 11, hi_bufor, 550, 0, 3);
prymula <prymula76@outlook.com>
parents:
diff changeset
654
prymula <prymula76@outlook.com>
parents:
diff changeset
655 //SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
prymula <prymula76@outlook.com>
parents:
diff changeset
656
prymula <prymula76@outlook.com>
parents:
diff changeset
657 while(!wykonano) {
prymula <prymula76@outlook.com>
parents:
diff changeset
658
prymula <prymula76@outlook.com>
parents:
diff changeset
659 SDL_Event event;
prymula <prymula76@outlook.com>
parents:
diff changeset
660 // SDL_KeyboardEvent zd_klawiszy;
prymula <prymula76@outlook.com>
parents:
diff changeset
661
prymula <prymula76@outlook.com>
parents:
diff changeset
662
prymula <prymula76@outlook.com>
parents:
diff changeset
663 if (pilka.ax+pilka.obraz->w <= 0){
prymula <prymula76@outlook.com>
parents:
diff changeset
664 pilka.ax=640;
prymula <prymula76@outlook.com>
parents:
diff changeset
665 }
prymula <prymula76@outlook.com>
parents:
diff changeset
666
prymula <prymula76@outlook.com>
parents:
diff changeset
667 while (SDL_PollEvent (&event)) {
prymula <prymula76@outlook.com>
parents:
diff changeset
668
prymula <prymula76@outlook.com>
parents:
diff changeset
669 switch (event.type) {
prymula <prymula76@outlook.com>
parents:
diff changeset
670
prymula <prymula76@outlook.com>
parents:
diff changeset
671 case SDL_KEYDOWN:
prymula <prymula76@outlook.com>
parents:
diff changeset
672 printf("Naciśnięto klawisz: %s\n", SDL_GetKeyName(event.key.keysym.sym));
prymula <prymula76@outlook.com>
parents:
diff changeset
673
prymula <prymula76@outlook.com>
parents:
diff changeset
674 if (event.key.keysym.sym==SDLK_ESCAPE)
prymula <prymula76@outlook.com>
parents:
diff changeset
675 wykonano = 1;
prymula <prymula76@outlook.com>
parents:
diff changeset
676
prymula <prymula76@outlook.com>
parents:
diff changeset
677 if (event.key.keysym.sym==SDLK_SPACE && !rozpoczecie) {
prymula <prymula76@outlook.com>
parents:
diff changeset
678 // teczka.poprzedni_y=pilka.ay;
prymula <prymula76@outlook.com>
parents:
diff changeset
679 // uchwyt_pilki = SDL_AddTimer(predkosc_pilki, ruch_pilki, &teczka);
prymula <prymula76@outlook.com>
parents:
diff changeset
680 rozpoczecie = 1;
prymula <prymula76@outlook.com>
parents:
diff changeset
681 }
prymula <prymula76@outlook.com>
parents:
diff changeset
682
prymula <prymula76@outlook.com>
parents:
diff changeset
683 //printf("powolna_paleka: %d", powolna_paletka);
prymula <prymula76@outlook.com>
parents:
diff changeset
684 if (event.key.keysym.sym==SDLK_LEFT && paletka.ax>0) {
prymula <prymula76@outlook.com>
parents:
diff changeset
685 printf("PALETKA LEWA\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
686 if(powolna_paletka>=1) {
prymula <prymula76@outlook.com>
parents:
diff changeset
687 paletka.px=paletka.ax;
prymula <prymula76@outlook.com>
parents:
diff changeset
688 paletka.ax-=10;
prymula <prymula76@outlook.com>
parents:
diff changeset
689 przerysuj(&paletka);
prymula <prymula76@outlook.com>
parents:
diff changeset
690 if (!rozpoczecie) {
prymula <prymula76@outlook.com>
parents:
diff changeset
691 pilka.px=pilka.ax;
prymula <prymula76@outlook.com>
parents:
diff changeset
692 pilka.ax-=10;
prymula <prymula76@outlook.com>
parents:
diff changeset
693 przerysuj(&pilka);
prymula <prymula76@outlook.com>
parents:
diff changeset
694 }
prymula <prymula76@outlook.com>
parents:
diff changeset
695 powolna_paletka=0;
prymula <prymula76@outlook.com>
parents:
diff changeset
696 }
prymula <prymula76@outlook.com>
parents:
diff changeset
697 }
prymula <prymula76@outlook.com>
parents:
diff changeset
698 if (event.key.keysym.sym==SDLK_RIGHT && paletka.ax<(640-XPALETKI)) {
prymula <prymula76@outlook.com>
parents:
diff changeset
699 if(powolna_paletka>=1) {
prymula <prymula76@outlook.com>
parents:
diff changeset
700 paletka.px=paletka.ax;
prymula <prymula76@outlook.com>
parents:
diff changeset
701 paletka.ax+=10;
prymula <prymula76@outlook.com>
parents:
diff changeset
702 przerysuj(&paletka);
prymula <prymula76@outlook.com>
parents:
diff changeset
703 if (!rozpoczecie) {
prymula <prymula76@outlook.com>
parents:
diff changeset
704 pilka.px=pilka.ax;
prymula <prymula76@outlook.com>
parents:
diff changeset
705 pilka.ax+=10;
prymula <prymula76@outlook.com>
parents:
diff changeset
706 przerysuj(&pilka);
prymula <prymula76@outlook.com>
parents:
diff changeset
707 }
prymula <prymula76@outlook.com>
parents:
diff changeset
708 powolna_paletka=0;
prymula <prymula76@outlook.com>
parents:
diff changeset
709 }
prymula <prymula76@outlook.com>
parents:
diff changeset
710 }
prymula <prymula76@outlook.com>
parents:
diff changeset
711 if (event.key.keysym.sym==SDLK_r) {
prymula <prymula76@outlook.com>
parents:
diff changeset
712 wyswietl_kafle();
prymula <prymula76@outlook.com>
parents:
diff changeset
713 sprintf (score_bufor, "%d", wynik);
prymula <prymula76@outlook.com>
parents:
diff changeset
714 print_text(255, 255, 255, score_bufor, 10, 0, 3);
prymula <prymula76@outlook.com>
parents:
diff changeset
715 sprintf (level_bufor, "%d", poziom);
prymula <prymula76@outlook.com>
parents:
diff changeset
716 print_text(253, 255, 100, level_bufor, 250, 0, 2);
prymula <prymula76@outlook.com>
parents:
diff changeset
717 sprintf (lives_bufor, "%d", zycia);
prymula <prymula76@outlook.com>
parents:
diff changeset
718 print_text(33, 249, 11, lives_bufor, 400, 0, 2);
prymula <prymula76@outlook.com>
parents:
diff changeset
719 sprintf (hi_bufor, "%d", najlepszy);
prymula <prymula76@outlook.com>
parents:
diff changeset
720 print_text(249, 33, 11, hi_bufor, 550, 0, 3);
prymula <prymula76@outlook.com>
parents:
diff changeset
721 przerysuj(&paletka);
prymula <prymula76@outlook.com>
parents:
diff changeset
722 przerysuj(&pilka);
prymula <prymula76@outlook.com>
parents:
diff changeset
723 }
prymula <prymula76@outlook.com>
parents:
diff changeset
724
prymula <prymula76@outlook.com>
parents:
diff changeset
725 break;
prymula <prymula76@outlook.com>
parents:
diff changeset
726
prymula <prymula76@outlook.com>
parents:
diff changeset
727 case SDL_QUIT:
prymula <prymula76@outlook.com>
parents:
diff changeset
728 if (wynik>najlepszy){
prymula <prymula76@outlook.com>
parents:
diff changeset
729 najlepszy=wynik;
prymula <prymula76@outlook.com>
parents:
diff changeset
730 save_hiscore();
prymula <prymula76@outlook.com>
parents:
diff changeset
731 }
prymula <prymula76@outlook.com>
parents:
diff changeset
732 SDL_DestroyTexture(tex_screen);
prymula <prymula76@outlook.com>
parents:
diff changeset
733 SDL_DestroyRenderer(renderer);
prymula <prymula76@outlook.com>
parents:
diff changeset
734 SDL_DestroyWindow(gWindow);
prymula <prymula76@outlook.com>
parents:
diff changeset
735 exit(0);
prymula <prymula76@outlook.com>
parents:
diff changeset
736 break;
prymula <prymula76@outlook.com>
parents:
diff changeset
737
prymula <prymula76@outlook.com>
parents:
diff changeset
738 case SDL_MOUSEMOTION:
prymula <prymula76@outlook.com>
parents:
diff changeset
739 break;
prymula <prymula76@outlook.com>
parents:
diff changeset
740
prymula <prymula76@outlook.com>
parents:
diff changeset
741 case SDL_MOUSEBUTTONDOWN:
prymula <prymula76@outlook.com>
parents:
diff changeset
742 //if (!pauza) pauza=1;
prymula <prymula76@outlook.com>
parents:
diff changeset
743 //else pauza=0;
prymula <prymula76@outlook.com>
parents:
diff changeset
744 break;
prymula <prymula76@outlook.com>
parents:
diff changeset
745
prymula <prymula76@outlook.com>
parents:
diff changeset
746 case SDL_MOUSEBUTTONUP:
prymula <prymula76@outlook.com>
parents:
diff changeset
747 break;
prymula <prymula76@outlook.com>
parents:
diff changeset
748
prymula <prymula76@outlook.com>
parents:
diff changeset
749 default:
prymula <prymula76@outlook.com>
parents:
diff changeset
750 break;
prymula <prymula76@outlook.com>
parents:
diff changeset
751 }
prymula <prymula76@outlook.com>
parents:
diff changeset
752
prymula <prymula76@outlook.com>
parents:
diff changeset
753 }
prymula <prymula76@outlook.com>
parents:
diff changeset
754
prymula <prymula76@outlook.com>
parents:
diff changeset
755 if (pilka.ay+pilka.obraz->h>=480){
prymula <prymula76@outlook.com>
parents:
diff changeset
756 printf("Nowe rozdanie!\n\n\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
757 if(--zycia == -1){
prymula <prymula76@outlook.com>
parents:
diff changeset
758 wykonano=1;
prymula <prymula76@outlook.com>
parents:
diff changeset
759 quit=SDL_TRUE;
prymula <prymula76@outlook.com>
parents:
diff changeset
760 goto label;
prymula <prymula76@outlook.com>
parents:
diff changeset
761 }
prymula <prymula76@outlook.com>
parents:
diff changeset
762
prymula <prymula76@outlook.com>
parents:
diff changeset
763 //erase (&paletka);
prymula <prymula76@outlook.com>
parents:
diff changeset
764 //erase (&pilka);
prymula <prymula76@outlook.com>
parents:
diff changeset
765 // wymazujemy caly ekran, erase(&paletka) nie wymazuje dokladnie
prymula <prymula76@outlook.com>
parents:
diff changeset
766 ustaw_kolor_tla();
prymula <prymula76@outlook.com>
parents:
diff changeset
767 wyswietl_kafle();
prymula <prymula76@outlook.com>
parents:
diff changeset
768 //pisz_info(253, 255, 100, poziom, 250, 0, 2);
prymula <prymula76@outlook.com>
parents:
diff changeset
769 //pisz_info(33, 249, 11, zycia, 400, 0, 2);
prymula <prymula76@outlook.com>
parents:
diff changeset
770 //pisz_info(249, 33, 11, najlepszy, 550, 0, 3);
prymula <prymula76@outlook.com>
parents:
diff changeset
771 sprintf (level_bufor, "%d", poziom);
prymula <prymula76@outlook.com>
parents:
diff changeset
772 print_text(253, 255, 100, level_bufor, 250, 0, 2);
prymula <prymula76@outlook.com>
parents:
diff changeset
773 sprintf (lives_bufor, "%d", zycia);
prymula <prymula76@outlook.com>
parents:
diff changeset
774 print_text(33, 249, 11, lives_bufor, 400, 0, 2);
prymula <prymula76@outlook.com>
parents:
diff changeset
775 sprintf (hi_bufor, "%d", najlepszy);
prymula <prymula76@outlook.com>
parents:
diff changeset
776 print_text(249, 33, 11, hi_bufor, 550, 0, 3);
prymula <prymula76@outlook.com>
parents:
diff changeset
777 rozpoczecie=0;
prymula <prymula76@outlook.com>
parents:
diff changeset
778 pilka.ax=640/2-XPILKI/2;
prymula <prymula76@outlook.com>
parents:
diff changeset
779 pilka.ay=420;
prymula <prymula76@outlook.com>
parents:
diff changeset
780 pilka.px=pilka.ax;
prymula <prymula76@outlook.com>
parents:
diff changeset
781 pilka.py=pilka.ay;
prymula <prymula76@outlook.com>
parents:
diff changeset
782 pilka.kx=-5;
prymula <prymula76@outlook.com>
parents:
diff changeset
783 pilka.ky=-5;
prymula <prymula76@outlook.com>
parents:
diff changeset
784 paletka.ax=640/2-XPALETKI/2;
prymula <prymula76@outlook.com>
parents:
diff changeset
785 paletka.ay=450;
prymula <prymula76@outlook.com>
parents:
diff changeset
786 // paletka.px=paletka.ax;
prymula <prymula76@outlook.com>
parents:
diff changeset
787 paletka.py=paletka.ay;
prymula <prymula76@outlook.com>
parents:
diff changeset
788
prymula <prymula76@outlook.com>
parents:
diff changeset
789 if(powolna_paletka>=1) {
prymula <prymula76@outlook.com>
parents:
diff changeset
790 paletka.px=paletka.ax;
prymula <prymula76@outlook.com>
parents:
diff changeset
791 paletka.ax-=10;
prymula <prymula76@outlook.com>
parents:
diff changeset
792 przerysuj(&paletka);
prymula <prymula76@outlook.com>
parents:
diff changeset
793 if (!rozpoczecie) {
prymula <prymula76@outlook.com>
parents:
diff changeset
794 pilka.px=pilka.ax;
prymula <prymula76@outlook.com>
parents:
diff changeset
795 pilka.ax-=10;
prymula <prymula76@outlook.com>
parents:
diff changeset
796 przerysuj(&pilka);
prymula <prymula76@outlook.com>
parents:
diff changeset
797 }
prymula <prymula76@outlook.com>
parents:
diff changeset
798 powolna_paletka=0;
prymula <prymula76@outlook.com>
parents:
diff changeset
799 }
prymula <prymula76@outlook.com>
parents:
diff changeset
800 }
prymula <prymula76@outlook.com>
parents:
diff changeset
801 // zapobiega wywietleniu -1 zycia
prymula <prymula76@outlook.com>
parents:
diff changeset
802 label:
prymula <prymula76@outlook.com>
parents:
diff changeset
803
prymula <prymula76@outlook.com>
parents:
diff changeset
804 //pisz_info(255, 255, 255, wynik, 0, 0, 4);
prymula <prymula76@outlook.com>
parents:
diff changeset
805 sprintf (score_bufor, "%d", wynik);
prymula <prymula76@outlook.com>
parents:
diff changeset
806 print_text(255, 255, 255, score_bufor, 10, 0, 3);
prymula <prymula76@outlook.com>
parents:
diff changeset
807
prymula <prymula76@outlook.com>
parents:
diff changeset
808
prymula <prymula76@outlook.com>
parents:
diff changeset
809 if (rozpoczecie) {
prymula <prymula76@outlook.com>
parents:
diff changeset
810 if(!pauza) {
prymula <prymula76@outlook.com>
parents:
diff changeset
811
prymula <prymula76@outlook.com>
parents:
diff changeset
812 ruch_pilki(0, &teczka);
prymula <prymula76@outlook.com>
parents:
diff changeset
813 }
prymula <prymula76@outlook.com>
parents:
diff changeset
814 }
prymula <prymula76@outlook.com>
parents:
diff changeset
815 powolna_paletka+=1;
prymula <prymula76@outlook.com>
parents:
diff changeset
816
prymula <prymula76@outlook.com>
parents:
diff changeset
817
prymula <prymula76@outlook.com>
parents:
diff changeset
818 if (!liczba_kafli) {
prymula <prymula76@outlook.com>
parents:
diff changeset
819 printf ("poziom zaliczony\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
820 if (pilka.py>300 && poziom<8) {
prymula <prymula76@outlook.com>
parents:
diff changeset
821 poziom++;
prymula <prymula76@outlook.com>
parents:
diff changeset
822 printf ("rysuj nowy poziom liczba kafli przed: %d\n", liczba_kafli);
prymula <prymula76@outlook.com>
parents:
diff changeset
823 zaladuj_poziom(tablica_kolorow_kafli, poziom-1);
prymula <prymula76@outlook.com>
parents:
diff changeset
824 wyswietl_kafle();
prymula <prymula76@outlook.com>
parents:
diff changeset
825 sprintf (level_bufor, "%d", poziom);
prymula <prymula76@outlook.com>
parents:
diff changeset
826 print_text(253, 255, 100, level_bufor, 250, 0, 2);
prymula <prymula76@outlook.com>
parents:
diff changeset
827 printf("liczba kafli po: %d\n", liczba_kafli);
prymula <prymula76@outlook.com>
parents:
diff changeset
828 //pisz_info(253, 255, 100, poziom, 180, 0, 1);
prymula <prymula76@outlook.com>
parents:
diff changeset
829 }
prymula <prymula76@outlook.com>
parents:
diff changeset
830 else if (pilka.py>300 && poziom>=8){
prymula <prymula76@outlook.com>
parents:
diff changeset
831 poziom=1;
prymula <prymula76@outlook.com>
parents:
diff changeset
832 zaladuj_poziom(tablica_kolorow_kafli, poziom-1);
prymula <prymula76@outlook.com>
parents:
diff changeset
833 wyswietl_kafle();
prymula <prymula76@outlook.com>
parents:
diff changeset
834 sprintf (level_bufor, "%d", poziom);
prymula <prymula76@outlook.com>
parents:
diff changeset
835 print_text(253, 255, 100, level_bufor, 250, 0, 2);
prymula <prymula76@outlook.com>
parents:
diff changeset
836 printf("liczba kafli po: %d\n", liczba_kafli);
prymula <prymula76@outlook.com>
parents:
diff changeset
837 //wykonano=1;
prymula <prymula76@outlook.com>
parents:
diff changeset
838 }
prymula <prymula76@outlook.com>
parents:
diff changeset
839 // teczka2.czas=&zwloka;
prymula <prymula76@outlook.com>
parents:
diff changeset
840 // uchwyt_pilki = SDL_AddTimer(czas_zwloki, zwloka_dla_pilki, &teczka2);
prymula <prymula76@outlook.com>
parents:
diff changeset
841 }
prymula <prymula76@outlook.com>
parents:
diff changeset
842
prymula <prymula76@outlook.com>
parents:
diff changeset
843
prymula <prymula76@outlook.com>
parents:
diff changeset
844
prymula <prymula76@outlook.com>
parents:
diff changeset
845 cel = set_rect(0, 0, obraz->w, obraz->h);
prymula <prymula76@outlook.com>
parents:
diff changeset
846 zrodlo = set_rect(0, 0, obraz->w, obraz->h);
prymula <prymula76@outlook.com>
parents:
diff changeset
847 tex_screen = SDL_CreateTextureFromSurface(renderer, obraz);
prymula <prymula76@outlook.com>
parents:
diff changeset
848 SDL_RenderClear ( renderer );
prymula <prymula76@outlook.com>
parents:
diff changeset
849 SDL_RenderCopy(renderer, tex_screen,&zrodlo,&cel);
prymula <prymula76@outlook.com>
parents:
diff changeset
850 SDL_RenderPresent(renderer);
prymula <prymula76@outlook.com>
parents:
diff changeset
851 SDL_DestroyTexture(tex_screen);
prymula <prymula76@outlook.com>
parents:
diff changeset
852
prymula <prymula76@outlook.com>
parents:
diff changeset
853 SDL_Delay(40);
prymula <prymula76@outlook.com>
parents:
diff changeset
854 //SDL_Delay(500);
prymula <prymula76@outlook.com>
parents:
diff changeset
855 }
prymula <prymula76@outlook.com>
parents:
diff changeset
856 if (wynik>najlepszy){
prymula <prymula76@outlook.com>
parents:
diff changeset
857 najlepszy=wynik;
prymula <prymula76@outlook.com>
parents:
diff changeset
858 save_hiscore();
prymula <prymula76@outlook.com>
parents:
diff changeset
859 }
prymula <prymula76@outlook.com>
parents:
diff changeset
860 // SDL_RemoveTimer(uchwyt_pilki);
prymula <prymula76@outlook.com>
parents:
diff changeset
861 /* przywrocenie orginalnych ustawien */
prymula <prymula76@outlook.com>
parents:
diff changeset
862 //SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
prymula <prymula76@outlook.com>
parents:
diff changeset
863 return quit;
prymula <prymula76@outlook.com>
parents:
diff changeset
864 }
prymula <prymula76@outlook.com>
parents:
diff changeset
865
prymula <prymula76@outlook.com>
parents:
diff changeset
866
prymula <prymula76@outlook.com>
parents:
diff changeset
867
prymula <prymula76@outlook.com>
parents:
diff changeset
868 int main (int argc, char ** argv) {
prymula <prymula76@outlook.com>
parents:
diff changeset
869
prymula <prymula76@outlook.com>
parents:
diff changeset
870
prymula <prymula76@outlook.com>
parents:
diff changeset
871
prymula <prymula76@outlook.com>
parents:
diff changeset
872 if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0)
prymula <prymula76@outlook.com>
parents:
diff changeset
873 {
prymula <prymula76@outlook.com>
parents:
diff changeset
874 printf ("Nie mozna zainicjowac SDL: %s\n", SDL_GetError ());
prymula <prymula76@outlook.com>
parents:
diff changeset
875 exit (1);
prymula <prymula76@outlook.com>
parents:
diff changeset
876 }
prymula <prymula76@outlook.com>
parents:
diff changeset
877 atexit (SDL_Quit);
prymula <prymula76@outlook.com>
parents:
diff changeset
878
prymula <prymula76@outlook.com>
parents:
diff changeset
879 gWindow = SDL_CreateWindow( "Arkanoid", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN );
prymula <prymula76@outlook.com>
parents:
diff changeset
880 if( gWindow == NULL )
prymula <prymula76@outlook.com>
parents:
diff changeset
881 {
prymula <prymula76@outlook.com>
parents:
diff changeset
882 printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
prymula <prymula76@outlook.com>
parents:
diff changeset
883 exit(1);
prymula <prymula76@outlook.com>
parents:
diff changeset
884 }
prymula <prymula76@outlook.com>
parents:
diff changeset
885 else
prymula <prymula76@outlook.com>
parents:
diff changeset
886 {
prymula <prymula76@outlook.com>
parents:
diff changeset
887 renderer = SDL_CreateRenderer(gWindow, -1,0);
prymula <prymula76@outlook.com>
parents:
diff changeset
888 SDL_SetRenderDrawColor ( renderer ,65, 190, 215 , 255 );
prymula <prymula76@outlook.com>
parents:
diff changeset
889 SDL_RenderClear ( renderer );
prymula <prymula76@outlook.com>
parents:
diff changeset
890 //Get window surface
prymula <prymula76@outlook.com>
parents:
diff changeset
891 obraz = SDL_GetWindowSurface( gWindow );
prymula <prymula76@outlook.com>
parents:
diff changeset
892
prymula <prymula76@outlook.com>
parents:
diff changeset
893 }
prymula <prymula76@outlook.com>
parents:
diff changeset
894
prymula <prymula76@outlook.com>
parents:
diff changeset
895
prymula <prymula76@outlook.com>
parents:
diff changeset
896 /* inicjalizacja fontow */
prymula <prymula76@outlook.com>
parents:
diff changeset
897 if(TTF_Init()==-1) {
prymula <prymula76@outlook.com>
parents:
diff changeset
898 printf("TTF_Init: %s\n", TTF_GetError());
prymula <prymula76@outlook.com>
parents:
diff changeset
899 exit(2);
prymula <prymula76@outlook.com>
parents:
diff changeset
900 }
prymula <prymula76@outlook.com>
parents:
diff changeset
901 atexit (TTF_Quit);
prymula <prymula76@outlook.com>
parents:
diff changeset
902
prymula <prymula76@outlook.com>
parents:
diff changeset
903
prymula <prymula76@outlook.com>
parents:
diff changeset
904
prymula <prymula76@outlook.com>
parents:
diff changeset
905 #if WINDOWS
prymula <prymula76@outlook.com>
parents:
diff changeset
906 #define NAZWAFONTU "SpicyRice.ttf"
prymula <prymula76@outlook.com>
parents:
diff changeset
907 #elif LINUX
prymula <prymula76@outlook.com>
parents:
diff changeset
908 //#define NAZWAFONTU "/usr/share/fonts/SpicyRice.ttf"
prymula <prymula76@outlook.com>
parents:
diff changeset
909 #define NAZWAFONTU "/usr/share/arkanoid/SpicyRice.ttf"
prymula <prymula76@outlook.com>
parents:
diff changeset
910 #endif
prymula <prymula76@outlook.com>
parents:
diff changeset
911
prymula <prymula76@outlook.com>
parents:
diff changeset
912 if((font_panel = TTF_OpenFont(NAZWAFONTU, WIELKOSCFONTU)) == NULL) {
prymula <prymula76@outlook.com>
parents:
diff changeset
913 printf("TTF_OpenFont: %s\n", TTF_GetError());
prymula <prymula76@outlook.com>
parents:
diff changeset
914 exit(1);
prymula <prymula76@outlook.com>
parents:
diff changeset
915 }
prymula <prymula76@outlook.com>
parents:
diff changeset
916 if (file_exist()){
prymula <prymula76@outlook.com>
parents:
diff changeset
917 load_hiscore();
prymula <prymula76@outlook.com>
parents:
diff changeset
918 }
prymula <prymula76@outlook.com>
parents:
diff changeset
919 else {
prymula <prymula76@outlook.com>
parents:
diff changeset
920 najlepszy=0;
prymula <prymula76@outlook.com>
parents:
diff changeset
921 }
prymula <prymula76@outlook.com>
parents:
diff changeset
922 while(SDL_TRUE){
prymula <prymula76@outlook.com>
parents:
diff changeset
923 if (gra()==SDL_TRUE){
prymula <prymula76@outlook.com>
parents:
diff changeset
924 if (end()==SDL_TRUE){
prymula <prymula76@outlook.com>
parents:
diff changeset
925 printf ("\n\nkontynuje\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
926 continue;
prymula <prymula76@outlook.com>
parents:
diff changeset
927 }
prymula <prymula76@outlook.com>
parents:
diff changeset
928 else break;
prymula <prymula76@outlook.com>
parents:
diff changeset
929 }
prymula <prymula76@outlook.com>
parents:
diff changeset
930 }
prymula <prymula76@outlook.com>
parents:
diff changeset
931 printf ("\n\nwychodze\n");
prymula <prymula76@outlook.com>
parents:
diff changeset
932 SDL_DestroyTexture(tex_screen);
prymula <prymula76@outlook.com>
parents:
diff changeset
933 SDL_DestroyRenderer(renderer);
prymula <prymula76@outlook.com>
parents:
diff changeset
934 SDL_DestroyWindow(gWindow);
prymula <prymula76@outlook.com>
parents:
diff changeset
935 return 0;
prymula <prymula76@outlook.com>
parents:
diff changeset
936 }
prymula <prymula76@outlook.com>
parents:
diff changeset
937 // vi: sw=4: ts=4