Rev 5296 | Rev 5331 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5281 | ZblCoder | 1 | #include "smalllibc/kosSyst.h" |
2 | #include "smalllibc/kosFile.h" |
||
5283 | ZblCoder | 3 | #include "smalllibc/sprintf.h" |
5281 | ZblCoder | 4 | #include "smalllibc/func.h" |
5276 | ZblCoder | 5 | #include "render.h" |
6 | #include "image.h" |
||
7 | |||
8 | #define MODE_MENU 0 |
||
9 | #define MODE_LEVELS 1 |
||
10 | #define MODE_GAME 2 |
||
5297 | ZblCoder | 11 | #define MODE_PAUSE 4 |
5276 | ZblCoder | 12 | |
13 | #define GAME_NONE 0 |
||
14 | #define GAME_VICTORY 1 |
||
15 | #define GAME_DEFEAT 2 |
||
16 | |||
17 | #define MOUSE_LEFT 0 |
||
18 | |||
5287 | ZblCoder | 19 | #define FIELD_NONE 0 |
20 | #define FIELD_WATER 1 |
||
21 | #define FIELD_GROUND 2 |
||
22 | #define FIELD_BRICK 3 |
||
23 | #define FIELD_WALL 4 |
||
24 | #define FIELD_BOX 5 |
||
25 | #define FIELD_MISSLE_0 6 |
||
26 | #define FIELD_MISSLE_1 7 |
||
27 | #define FIELD_MISSLE_2 8 |
||
28 | #define FIELD_MISSLE_3 9 |
||
29 | #define FIELD_HERO 10 |
||
30 | #define FIELD_FINISH 11 |
||
31 | #define FIELD_GUN_0 12 |
||
32 | #define FIELD_GUN_1 13 |
||
33 | #define FIELD_GUN_2 14 |
||
34 | #define FIELD_GUN_3 15 |
||
35 | #define FIELD_BOX_MISSLE_0 16 |
||
36 | #define FIELD_BOX_MISSLE_1 17 |
||
37 | #define FIELD_BOX_MISSLE_2 18 |
||
38 | #define FIELD_BOX_MISSLE_3 19 |
||
5296 | ZblCoder | 39 | #define FIELD_WALL_X 20 |
40 | #define FIELD_WALL_H 21 |
||
41 | #define FIELD_WALL_V 22 |
||
42 | #define FIELD_BOX_WATER 23 |
||
43 | #define FIELD_BRICK_DES 24 |
||
44 | #define FIELD_CRATER 25 |
||
5287 | ZblCoder | 45 | |
5276 | ZblCoder | 46 | char* header = "Laser Tank"; |
47 | |||
48 | struct Level |
||
49 | { |
||
5287 | ZblCoder | 50 | Byte fileds[16][16]; |
5276 | ZblCoder | 51 | }; |
52 | |||
5287 | ZblCoder | 53 | void pause(int time) |
54 | { |
||
55 | kos_Pause(time); |
||
56 | Byte keyCode; |
||
57 | for (int i = 0; i < 10; ++i) |
||
58 | kos_GetKey(keyCode); |
||
59 | } |
||
60 | |||
5276 | ZblCoder | 61 | Level *levels; |
62 | int levelCount = 0; |
||
63 | int levelIndex = 0; |
||
5296 | ZblCoder | 64 | int levelPage = 0; |
5276 | ZblCoder | 65 | |
66 | RGBA img_tank[576]; |
||
67 | RGB img_water[576]; |
||
5287 | ZblCoder | 68 | RGB img_brick[11][576]; |
5276 | ZblCoder | 69 | RGB img_waterbox[576]; |
70 | RGB img_ground[576]; |
||
5296 | ZblCoder | 71 | RGB img_crater[576]; |
5276 | ZblCoder | 72 | RGB img_wall[576]; |
5296 | ZblCoder | 73 | RGB img_wall_x[576]; |
74 | RGB img_wall_h[576]; |
||
75 | RGB img_wall_v[576]; |
||
5276 | ZblCoder | 76 | RGB img_finish[576]; |
77 | RGBA img_box[576]; |
||
78 | RGBA img_laser[576]; |
||
5287 | ZblCoder | 79 | RGB img_mirror[4][576]; |
5296 | ZblCoder | 80 | RGBA img_mini_mirror[2304]; |
5276 | ZblCoder | 81 | RGBA img_laser1[576]; |
82 | RGBA img_laser2[576]; |
||
83 | RGB img_brick1[576]; |
||
84 | RGB img_menu[147456]; |
||
85 | RGBA img_explosion[8064]; |
||
5287 | ZblCoder | 86 | RGBA img_gun[576]; |
5296 | ZblCoder | 87 | RGB img_gamebg[9216]; |
5297 | ZblCoder | 88 | RGBA img_black[576]; |
5276 | ZblCoder | 89 | |
5296 | ZblCoder | 90 | RGBA img_number_box[2550]; |
91 | RGBA img_numbers[3500]; |
||
92 | RGBA img_button1[3249]; |
||
93 | RGBA img_button_arrow[375]; |
||
5276 | ZblCoder | 94 | |
5296 | ZblCoder | 95 | RGB img_levels[147456]; |
96 | |||
5297 | ZblCoder | 97 | RGB img_buttons[3][13053]; |
98 | |||
99 | |||
100 | |||
5276 | ZblCoder | 101 | Player player; |
102 | |||
103 | CKosRender* renderPlayer; |
||
104 | CKosImage* objPlayer; |
||
5297 | ZblCoder | 105 | CKosImage* objPlayer1; |
5276 | ZblCoder | 106 | |
5296 | ZblCoder | 107 | CKosRender* renderBox; |
108 | |||
5276 | ZblCoder | 109 | CKosImage* objLaser; |
110 | CKosImage* objLaser1; |
||
111 | CKosImage* objLaser2; |
||
5296 | ZblCoder | 112 | CKosImage* objMiniMirror; |
5276 | ZblCoder | 113 | CKosImage* objBox; |
5287 | ZblCoder | 114 | CKosImage* objGun; |
5296 | ZblCoder | 115 | CKosImage* objExplosion; |
5276 | ZblCoder | 116 | |
5297 | ZblCoder | 117 | CKosImage* objblack; |
118 | |||
5296 | ZblCoder | 119 | CKosRender* renderLevels; |
120 | CKosImage* objnumber_box; |
||
121 | CKosImage* objnumbers; |
||
5276 | ZblCoder | 122 | |
5296 | ZblCoder | 123 | CKosImage* objbutton1; |
124 | CKosImage* objbutton_arrow; |
||
125 | |||
5276 | ZblCoder | 126 | int gameMode = MODE_MENU; |
127 | int gameStatus = GAME_NONE; |
||
128 | |||
129 | void draw_window(); |
||
130 | void openLevel(int index); |
||
5287 | ZblCoder | 131 | void Laser(Point pos, Point vec, RGB color); |
5276 | ZblCoder | 132 | |
133 | bool CollRecrVsPoint(Point point, Rect rect) |
||
134 | { |
||
135 | return (point.X > rect.X && point.Y > rect.Y && point.X < rect.X + rect.Width && point.Y < rect.Y + rect.Height); |
||
136 | } |
||
137 | |||
138 | struct Button |
||
139 | { |
||
140 | Rect rect; |
||
141 | char* caption; |
||
142 | Button() {} |
||
143 | Button(char* caption, Rect rect) |
||
144 | { |
||
145 | this->caption = caption; |
||
146 | this->rect = rect; |
||
147 | } |
||
148 | }; |
||
149 | |||
150 | Button ToGame("Game", Rect(150, 258, 224, 50)); |
||
151 | Button ToExit("Exit", Rect(150, 321, 224, 50)); |
||
152 | |||
153 | struct LvlItem |
||
154 | { |
||
5287 | ZblCoder | 155 | Byte s; |
156 | Byte d; |
||
5276 | ZblCoder | 157 | Byte l; |
158 | }; |
||
159 | |||
160 | LvlItem level[16][16]; |
||
161 | |||
162 | char GetField(Point position, bool din) |
||
163 | { |
||
5287 | ZblCoder | 164 | if (din && level[position.Y][position.X].d != FIELD_NONE) |
5276 | ZblCoder | 165 | return level[position.Y][position.X].d; |
166 | return level[position.Y][position.X].s; |
||
167 | } |
||
168 | |||
5297 | ZblCoder | 169 | void SetMode(int mode) |
170 | { |
||
171 | gameMode = mode; |
||
172 | draw_window(); |
||
173 | } |
||
174 | |||
5276 | ZblCoder | 175 | RGB* GetImg(Point position, bool din) |
176 | { |
||
177 | switch (GetField(position, din)) |
||
178 | { |
||
5287 | ZblCoder | 179 | case FIELD_WALL: |
5276 | ZblCoder | 180 | return (RGB*)img_wall; |
5296 | ZblCoder | 181 | case FIELD_WALL_X: |
182 | return (RGB*)img_wall_x; |
||
183 | case FIELD_WALL_H: |
||
184 | return (RGB*)img_wall_h; |
||
185 | case FIELD_WALL_V: |
||
186 | return (RGB*)img_wall_v; |
||
5287 | ZblCoder | 187 | case FIELD_MISSLE_0: |
188 | return (RGB*)img_mirror[0]; |
||
189 | case FIELD_MISSLE_1: |
||
190 | return (RGB*)img_mirror[1]; |
||
191 | case FIELD_MISSLE_2: |
||
192 | return (RGB*)img_mirror[2]; |
||
193 | case FIELD_MISSLE_3: |
||
194 | return (RGB*)img_mirror[3]; |
||
5296 | ZblCoder | 195 | case FIELD_BOX_MISSLE_0: |
196 | renderBox->RenderImg(GetImg(position, false), Point(0, 0), 24, 24); |
||
197 | objMiniMirror->Draw(Point(0, 0), 0, 0); |
||
198 | return renderBox->buffer; |
||
199 | case FIELD_BOX_MISSLE_1: |
||
200 | renderBox->RenderImg(GetImg(position, false), Point(0, 0), 24, 24); |
||
201 | objMiniMirror->Draw(Point(0, 0), 0, 1); |
||
202 | return renderBox->buffer; |
||
203 | case FIELD_BOX_MISSLE_2: |
||
204 | renderBox->RenderImg(GetImg(position, false), Point(0, 0), 24, 24); |
||
205 | objMiniMirror->Draw(Point(0, 0), 0, 2); |
||
206 | return renderBox->buffer; |
||
207 | case FIELD_BOX_MISSLE_3: |
||
208 | renderBox->RenderImg(GetImg(position, false), Point(0, 0), 24, 24); |
||
209 | objMiniMirror->Draw(Point(0, 0), 0, 3); |
||
210 | return renderBox->buffer; |
||
5287 | ZblCoder | 211 | case FIELD_GUN_0: |
212 | renderBox->RenderImg(GetImg(position, false), Point(0, 0), 24, 24); |
||
213 | objGun->Draw(Point(0, 0), 0); |
||
214 | return renderBox->buffer; |
||
215 | case FIELD_GUN_1: |
||
216 | renderBox->RenderImg(GetImg(position, false), Point(0, 0), 24, 24); |
||
217 | objGun->Draw(Point(0, 0), 90); |
||
218 | return renderBox->buffer; |
||
219 | case FIELD_GUN_2: |
||
220 | renderBox->RenderImg(GetImg(position, false), Point(0, 0), 24, 24); |
||
221 | objGun->Draw(Point(0, 0), 180); |
||
222 | return renderBox->buffer; |
||
223 | case FIELD_GUN_3: |
||
224 | renderBox->RenderImg(GetImg(position, false), Point(0, 0), 24, 24); |
||
225 | objGun->Draw(Point(0, 0), 270); |
||
226 | return renderBox->buffer; |
||
227 | case FIELD_GROUND: |
||
5276 | ZblCoder | 228 | return (RGB*)img_ground; |
5296 | ZblCoder | 229 | case FIELD_CRATER: |
230 | return (RGB*)img_crater; |
||
5287 | ZblCoder | 231 | case FIELD_BOX: |
232 | renderBox->RenderImg(GetImg(position, false), Point(0, 0), 24, 24); |
||
5276 | ZblCoder | 233 | objBox->Draw(Point(0, 0), 0); |
234 | return renderBox->buffer; |
||
5287 | ZblCoder | 235 | case FIELD_FINISH: |
5276 | ZblCoder | 236 | return (RGB*)img_finish; |
5287 | ZblCoder | 237 | case FIELD_BRICK: |
238 | return (RGB*)img_brick[level[position.Y][position.X].l]; |
||
239 | case FIELD_WATER: |
||
5276 | ZblCoder | 240 | return (RGB*)img_water; |
5287 | ZblCoder | 241 | case FIELD_BOX_WATER: |
5276 | ZblCoder | 242 | return (RGB*)img_waterbox; |
5287 | ZblCoder | 243 | case FIELD_BRICK_DES: |
5276 | ZblCoder | 244 | return (RGB*)img_brick1; |
245 | } |
||
246 | return NULL; |
||
247 | } |
||
248 | |||
5287 | ZblCoder | 249 | Byte CollField(Point position) |
250 | { |
||
251 | if (position.X < 0 || position.Y < 0 || position.X > 15 || position.Y > 15) |
||
252 | return 0; |
||
253 | |||
254 | switch (GetField(position, true)) |
||
255 | { |
||
256 | case FIELD_NONE: |
||
257 | case FIELD_WATER: |
||
258 | case FIELD_GROUND: |
||
5296 | ZblCoder | 259 | case FIELD_CRATER: |
5287 | ZblCoder | 260 | case FIELD_BOX_WATER: |
261 | case FIELD_BRICK_DES: |
||
262 | case FIELD_FINISH: |
||
263 | return 1; |
||
264 | case FIELD_GUN_0: |
||
265 | return FIELD_GUN_0; |
||
266 | case FIELD_GUN_1: |
||
267 | return FIELD_GUN_1; |
||
268 | case FIELD_GUN_2: |
||
269 | return FIELD_GUN_2; |
||
270 | case FIELD_GUN_3: |
||
271 | return FIELD_GUN_3; |
||
272 | } |
||
273 | return 0; |
||
274 | } |
||
275 | |||
276 | bool ExistGun1(Point position, Point vec, int gun) |
||
277 | { |
||
278 | Point pos = position; |
||
279 | |||
280 | Byte result = 1; |
||
281 | while (result == 1) |
||
282 | { |
||
283 | pos = pos + vec; |
||
284 | result = CollField(pos); |
||
285 | } |
||
286 | if (result == gun) |
||
287 | { |
||
288 | Laser(pos, vec * -1, (RGB)0x00CCFF); |
||
289 | return true; |
||
290 | } |
||
291 | return false; |
||
292 | } |
||
293 | |||
294 | void ExistGun(Point position) |
||
295 | { |
||
296 | if (ExistGun1(position, Point(1, 0), FIELD_GUN_2)) |
||
297 | return; |
||
298 | if (ExistGun1(position, Point(0, 1), FIELD_GUN_3)) |
||
299 | return; |
||
300 | if (ExistGun1(position, Point(-1, 0), FIELD_GUN_0)) |
||
301 | return; |
||
302 | ExistGun1(position, Point(0, -1), FIELD_GUN_1); |
||
303 | } |
||
304 | |||
5276 | ZblCoder | 305 | void DrawElevent(Point position, bool din) |
306 | { |
||
307 | kos_PutImage(GetImg(position, din), 24, 24, 24 * position.X, 24 * position.Y); |
||
308 | } |
||
309 | |||
5296 | ZblCoder | 310 | void MoveElement(Point a, Point b, int element) |
5276 | ZblCoder | 311 | { |
5287 | ZblCoder | 312 | level[a.Y][a.X].d = FIELD_NONE; |
5296 | ZblCoder | 313 | DrawElevent(a, false); |
5287 | ZblCoder | 314 | if (level[b.Y][b.X].s == FIELD_WATER) |
5276 | ZblCoder | 315 | { |
5296 | ZblCoder | 316 | if (element == FIELD_BOX) |
5287 | ZblCoder | 317 | level[b.Y][b.X].s = FIELD_BOX_WATER; |
5276 | ZblCoder | 318 | } |
319 | else |
||
5296 | ZblCoder | 320 | level[b.Y][b.X].d = element; |
321 | DrawElevent(b, true); |
||
5276 | ZblCoder | 322 | } |
323 | |||
5287 | ZblCoder | 324 | void animation(Point vector, float angle, int obj) |
5276 | ZblCoder | 325 | { |
326 | for (int i = 2; i < 23; ++i) |
||
327 | { |
||
328 | kos_WindowRedrawStatus(1); |
||
5296 | ZblCoder | 329 | |
5276 | ZblCoder | 330 | DrawElevent(player.position, false); |
331 | DrawElevent(player.position + vector, false); |
||
332 | |||
5296 | ZblCoder | 333 | renderPlayer->RenderImg(GetImg(player.position, false), vector * -i, 24, 24); |
334 | renderPlayer->RenderImg(GetImg(player.position + vector, false), vector * -i + vector * 24, 24, 24); |
||
335 | |||
5276 | ZblCoder | 336 | objPlayer->Draw(Point(0, 0), angle); |
337 | renderPlayer->Draw(player.position * 24 + vector * i); |
||
5287 | ZblCoder | 338 | if (level[player.position.Y + vector.Y][player.position.X + vector.X].d == obj) |
5276 | ZblCoder | 339 | { |
5296 | ZblCoder | 340 | //renderBox->RenderImg(GetImg(player.position + vector, true), Point(0, 0), 24, 24); |
341 | renderBox->RenderImg(GetImg(player.position + vector, false), vector * -i, 24, 24); |
||
342 | renderBox->RenderImg(GetImg(player.position + vector * 2, false), vector * -i + vector * 24, 24, 24); |
||
5287 | ZblCoder | 343 | switch (obj) |
344 | { |
||
345 | case FIELD_GUN_0: |
||
5296 | ZblCoder | 346 | objGun->Draw(Point(0, 0), 0); |
5287 | ZblCoder | 347 | break; |
348 | case FIELD_GUN_1: |
||
5296 | ZblCoder | 349 | objGun->Draw(Point(0, 0), 90); |
5287 | ZblCoder | 350 | break; |
351 | case FIELD_GUN_2: |
||
5296 | ZblCoder | 352 | objGun->Draw(Point(0, 0), 180); |
5287 | ZblCoder | 353 | break; |
354 | case FIELD_GUN_3: |
||
5296 | ZblCoder | 355 | objGun->Draw(Point(0, 0), 270); |
5287 | ZblCoder | 356 | break; |
5296 | ZblCoder | 357 | case FIELD_BOX_MISSLE_0: |
358 | objMiniMirror->Draw(Point(0, 0), 0, 0); |
||
359 | break; |
||
360 | case FIELD_BOX_MISSLE_1: |
||
361 | objMiniMirror->Draw(Point(0, 0), 0, 1); |
||
362 | break; |
||
363 | case FIELD_BOX_MISSLE_2: |
||
364 | objMiniMirror->Draw(Point(0, 0), 0, 2); |
||
365 | break; |
||
366 | case FIELD_BOX_MISSLE_3: |
||
367 | objMiniMirror->Draw(Point(0, 0), 0, 3); |
||
368 | break; |
||
5287 | ZblCoder | 369 | case FIELD_BOX: |
370 | objBox->Draw(Point(0, 0), 0); |
||
371 | } |
||
5276 | ZblCoder | 372 | renderBox->Draw((player.position + vector) * 24 + vector * i); |
373 | } |
||
374 | kos_WindowRedrawStatus(2); |
||
5287 | ZblCoder | 375 | pause(1); |
5276 | ZblCoder | 376 | } |
377 | |||
5287 | ZblCoder | 378 | if (level[player.position.Y + vector.Y][player.position.X + vector.X].d == obj) |
5296 | ZblCoder | 379 | MoveElement(player.position + vector, player.position + vector * 2, GetField(player.position + vector, true)); |
5276 | ZblCoder | 380 | |
381 | DrawElevent(player.position, true); |
||
382 | DrawElevent(player.position + vector, true); |
||
383 | player.position = player.position + vector; |
||
384 | //kos_PutImage(GetImg(player.position + vector), 24, 24, 24 * player.position.X, 24 * player.position.Y); |
||
385 | renderPlayer->RenderImg(GetImg(player.position, false), Point(0, 0), 24, 24); |
||
386 | objPlayer->Draw(Point(0, 0), angle); |
||
387 | renderPlayer->Draw(player.position * 24); |
||
5287 | ZblCoder | 388 | ExistGun(player.position); |
5276 | ZblCoder | 389 | } |
390 | |||
5287 | ZblCoder | 391 | void DrawLaser(Point position, int frame, RGB color) |
5276 | ZblCoder | 392 | { |
5296 | ZblCoder | 393 | renderBox->RenderImg(GetImg(position, false), Point(0, 0), 24, 24); |
394 | Byte code = GetField(position, true); |
||
395 | if (code == FIELD_BOX_MISSLE_0 || code == FIELD_BOX_MISSLE_1 || code == FIELD_BOX_MISSLE_2 || code == FIELD_BOX_MISSLE_3) |
||
396 | objMiniMirror->Draw(Point(0, 0), 0, code - FIELD_BOX_MISSLE_0); |
||
5276 | ZblCoder | 397 | switch (frame) |
398 | { |
||
399 | case 1: |
||
5287 | ZblCoder | 400 | objLaser->Draw(Point(0, 0), 0, color); |
401 | break; |
||
5276 | ZblCoder | 402 | case 2: |
5287 | ZblCoder | 403 | objLaser->Draw(Point(0, 0), 90, color); |
5276 | ZblCoder | 404 | break; |
405 | case 3: |
||
5287 | ZblCoder | 406 | objLaser2->Draw(Point(0, 0), 0, color); |
5276 | ZblCoder | 407 | break; |
408 | default: |
||
5296 | ZblCoder | 409 | objLaser1->Draw(Point(0, 0), (float)frame, color); |
5276 | ZblCoder | 410 | } |
5296 | ZblCoder | 411 | renderBox->Draw(position * 24); |
5276 | ZblCoder | 412 | level[position.Y][position.X].l = 1; |
413 | } |
||
414 | |||
5296 | ZblCoder | 415 | bool LaserMoveElement(Point position, Point vector, int code, RGB color) |
416 | { |
||
417 | if (position + vector != player.position) |
||
418 | { |
||
419 | switch (GetField(position + vector, true)) |
||
420 | { |
||
421 | case FIELD_GROUND: |
||
422 | case FIELD_CRATER: |
||
423 | case FIELD_WATER: |
||
424 | case FIELD_BRICK_DES: |
||
425 | case FIELD_BOX_WATER: |
||
426 | for (int i = 2; i < 23; ++i) |
||
427 | { |
||
428 | renderBox->RenderImg(GetImg(position, false), Point(0, 0), 24, 24); |
||
429 | if (vector.X != 0) |
||
430 | objLaser->Draw((vector.X > 0) ? Point(i - 24, 0) : Point(24 - i, 0), 0, color); |
||
431 | else |
||
432 | objLaser->Draw((vector.Y > 0) ? Point(0, i - 24) : Point(0, 24 - i), 90, color); |
||
433 | renderBox->Draw(position * 24); |
||
434 | |||
435 | DrawElevent(position + vector, false); |
||
436 | |||
437 | renderBox->RenderImg(GetImg(position, false), vector * -i, 24, 24); |
||
438 | renderBox->RenderImg(GetImg(position + vector, false), vector * -i + vector * 24, 24, 24); |
||
439 | |||
440 | switch (code) |
||
441 | { |
||
442 | case FIELD_GUN_0: |
||
443 | objGun->Draw(Point(0, 0), 0); |
||
444 | break; |
||
445 | case FIELD_GUN_1: |
||
446 | objGun->Draw(Point(0, 0), 90); |
||
447 | break; |
||
448 | case FIELD_GUN_2: |
||
449 | objGun->Draw(Point(0, 0), 180); |
||
450 | break; |
||
451 | case FIELD_GUN_3: |
||
452 | objGun->Draw(Point(0, 0), 270); |
||
453 | break; |
||
454 | case FIELD_BOX_MISSLE_0: |
||
455 | objMiniMirror->Draw(Point(0, 0), 0, 0); |
||
456 | break; |
||
457 | case FIELD_BOX_MISSLE_1: |
||
458 | objMiniMirror->Draw(Point(0, 0), 0, 1); |
||
459 | break; |
||
460 | case FIELD_BOX_MISSLE_2: |
||
461 | objMiniMirror->Draw(Point(0, 0), 0, 2); |
||
462 | break; |
||
463 | case FIELD_BOX_MISSLE_3: |
||
464 | objMiniMirror->Draw(Point(0, 0), 0, 3); |
||
465 | break; |
||
466 | case FIELD_BOX: |
||
467 | objBox->Draw(Point(0, 0), 0); |
||
468 | } |
||
469 | renderBox->Draw((position)* 24 + vector * i); |
||
470 | kos_Pause(1); |
||
471 | } |
||
472 | MoveElement(position, position + vector, code); |
||
473 | return true; |
||
474 | } |
||
475 | } |
||
476 | return false; |
||
477 | } |
||
478 | |||
5287 | ZblCoder | 479 | void Laser(Point pos, Point vec, RGB color) |
5276 | ZblCoder | 480 | { |
5287 | ZblCoder | 481 | Point vector = vec; |
482 | Point position = pos + vector; |
||
5276 | ZblCoder | 483 | bool en = true; |
5287 | ZblCoder | 484 | Byte code; |
485 | bool LaserGun = false; |
||
486 | |||
5276 | ZblCoder | 487 | while (en) |
488 | { |
||
5287 | ZblCoder | 489 | code = GetField(position, true); |
490 | switch (code) |
||
5276 | ZblCoder | 491 | { |
5287 | ZblCoder | 492 | case FIELD_BOX: |
493 | case FIELD_GUN_0: |
||
494 | case FIELD_GUN_1: |
||
495 | case FIELD_GUN_2: |
||
496 | case FIELD_GUN_3: |
||
497 | if (code == FIELD_GUN_0 && vector == Point(-1, 0) || code == FIELD_GUN_1 && vector == Point(0, -1) |
||
498 | || code == FIELD_GUN_2 && vector == Point(1, 0) || code == FIELD_GUN_3 && vector == Point(0, 1)) |
||
499 | { |
||
500 | for (int i = 2; i < 23; ++i) |
||
501 | kos_Pause(1); |
||
502 | for (int y = 0; y < 16; y++) |
||
503 | for (int x = 0; x < 16; x++) |
||
504 | if (level[y][x].l == 1) |
||
505 | { |
||
506 | DrawElevent(Point(x, y), true); |
||
507 | level[y][x].l = 0; |
||
508 | } |
||
509 | for (int i = 0; i < 14; ++i) |
||
510 | { |
||
5296 | ZblCoder | 511 | renderBox->RenderImg(GetImg(position, false), Point(0, 0), 24, 24); |
5287 | ZblCoder | 512 | objExplosion->Draw(Point(0, 0), 0, i); |
5296 | ZblCoder | 513 | renderBox->Draw((position)* 24); |
5287 | ZblCoder | 514 | pause(2); |
515 | } |
||
516 | level[position.Y][position.X].d = FIELD_NONE; |
||
5296 | ZblCoder | 517 | if (level[position.Y][position.X].s == FIELD_GROUND) |
518 | level[position.Y][position.X].s = FIELD_CRATER; |
||
5287 | ZblCoder | 519 | draw_window(); |
520 | return; |
||
521 | } |
||
522 | else |
||
5296 | ZblCoder | 523 | { |
524 | if (!LaserMoveElement(position, vector, code, color)) |
||
5276 | ZblCoder | 525 | { |
526 | for (int i = 2; i < 23; ++i) |
||
5296 | ZblCoder | 527 | pause(1); |
528 | } |
||
529 | else |
||
5287 | ZblCoder | 530 | LaserGun = true; |
531 | } |
||
5276 | ZblCoder | 532 | en = false; |
533 | break; |
||
5287 | ZblCoder | 534 | case FIELD_BRICK: |
535 | for (int i = 0; i < 6; ++i) |
||
5276 | ZblCoder | 536 | { |
5287 | ZblCoder | 537 | level[position.Y][position.X].l += 1; |
538 | if (level[position.Y][position.X].l == 11) |
||
5276 | ZblCoder | 539 | { |
5287 | ZblCoder | 540 | level[position.Y][position.X].s = FIELD_BRICK_DES; |
541 | level[position.Y][position.X].l = 0; |
||
542 | LaserGun = true; |
||
5276 | ZblCoder | 543 | } |
5287 | ZblCoder | 544 | DrawElevent(position, false); |
545 | pause(5); |
||
5276 | ZblCoder | 546 | } |
547 | en = false; |
||
548 | break; |
||
5296 | ZblCoder | 549 | case FIELD_WALL_X: |
550 | break; |
||
551 | case FIELD_WALL_H: |
||
552 | if (vector.X == 0) |
||
553 | { |
||
554 | for (int i = 2; i < 23; ++i) |
||
555 | pause(1); |
||
556 | en = false; |
||
557 | } |
||
558 | break; |
||
559 | case FIELD_WALL_V: |
||
560 | if (vector.Y == 0) |
||
561 | { |
||
562 | for (int i = 2; i < 23; ++i) |
||
563 | pause(1); |
||
564 | en = false; |
||
565 | } |
||
566 | break; |
||
5287 | ZblCoder | 567 | case FIELD_GROUND: |
5296 | ZblCoder | 568 | case FIELD_CRATER: |
5287 | ZblCoder | 569 | case FIELD_WATER: |
570 | case FIELD_FINISH: |
||
571 | case FIELD_BRICK_DES: |
||
572 | case FIELD_BOX_WATER: |
||
5276 | ZblCoder | 573 | if (player.position == position) |
574 | { |
||
575 | for (int i = 2; i < 23; ++i) |
||
576 | kos_Pause(1); |
||
577 | for (int y = 0; y < 16; y++) |
||
578 | for (int x = 0; x < 16; x++) |
||
579 | if (level[y][x].l == 1) |
||
580 | { |
||
581 | DrawElevent(Point(x, y), true); |
||
582 | level[y][x].l = 0; |
||
583 | } |
||
584 | for (int i = 0; i < 14; ++i) |
||
585 | { |
||
5296 | ZblCoder | 586 | renderBox->RenderImg(GetImg(position, false), Point(0, 0), 24, 24); |
5276 | ZblCoder | 587 | objExplosion->Draw(Point(0, 0), 0, i); |
5296 | ZblCoder | 588 | renderBox->Draw((position)* 24); |
5287 | ZblCoder | 589 | pause(2); |
5276 | ZblCoder | 590 | } |
5296 | ZblCoder | 591 | level[player.position.Y][player.position.X].s = FIELD_CRATER; |
5276 | ZblCoder | 592 | gameStatus = GAME_DEFEAT; |
5297 | ZblCoder | 593 | SetMode(MODE_PAUSE); |
5276 | ZblCoder | 594 | return; |
595 | } |
||
596 | else |
||
597 | { |
||
598 | if (level[position.Y][position.X].l == 1) |
||
5287 | ZblCoder | 599 | DrawLaser(position, 3, color); |
5276 | ZblCoder | 600 | else |
5287 | ZblCoder | 601 | DrawLaser(position, (vector.X != 0) ? 1 : 2, color); |
5276 | ZblCoder | 602 | } |
603 | break; |
||
5296 | ZblCoder | 604 | case FIELD_BOX_MISSLE_0: |
605 | rtlDebugOutString("FIELD_BOX_MISSLE_0"); |
||
5276 | ZblCoder | 606 | if (vector == Point(-1, 0) || vector == Point(0, -1)) |
607 | { |
||
608 | vector = (vector.Y == -1) ? Point(1, 0) : Point(0, 1); |
||
5287 | ZblCoder | 609 | DrawLaser(position, 0, color); |
5276 | ZblCoder | 610 | } |
611 | else |
||
612 | { |
||
5296 | ZblCoder | 613 | if (!LaserMoveElement(position, vector, code, color)) |
614 | { |
||
615 | for (int i = 2; i < 23; ++i) |
||
616 | pause(1); |
||
617 | } |
||
618 | else |
||
619 | LaserGun = true; |
||
5276 | ZblCoder | 620 | en = false; |
621 | } |
||
622 | break; |
||
5296 | ZblCoder | 623 | case FIELD_BOX_MISSLE_1: |
624 | rtlDebugOutString("FIELD_BOX_MISSLE_1"); |
||
5276 | ZblCoder | 625 | if (vector == Point(0, -1) || vector == Point(1, 0)) |
626 | { |
||
627 | vector = (vector.Y == -1) ? Point(-1, 0) : Point(0, 1); |
||
5287 | ZblCoder | 628 | DrawLaser(position, 90, color); |
5276 | ZblCoder | 629 | } |
630 | else |
||
631 | { |
||
5296 | ZblCoder | 632 | if (!LaserMoveElement(position, vector, code, color)) |
633 | { |
||
634 | for (int i = 2; i < 23; ++i) |
||
635 | pause(1); |
||
636 | } |
||
637 | else |
||
638 | LaserGun = true; |
||
5276 | ZblCoder | 639 | en = false; |
640 | } |
||
641 | break; |
||
5296 | ZblCoder | 642 | case FIELD_BOX_MISSLE_2: |
643 | rtlDebugOutString("FIELD_BOX_MISSLE_2"); |
||
644 | if (vector == Point(1, 0) || vector == Point(0, 1)) |
||
645 | { |
||
646 | vector = (vector.Y == 1) ? Point(-1, 0) : Point(0, -1); |
||
647 | DrawLaser(position, 180, color); |
||
648 | } |
||
649 | else |
||
650 | { |
||
651 | if (!LaserMoveElement(position, vector, code, color)) |
||
652 | { |
||
653 | for (int i = 2; i < 23; ++i) |
||
654 | pause(1); |
||
655 | } |
||
656 | else |
||
657 | LaserGun = true; |
||
658 | en = false; |
||
659 | } |
||
660 | break; |
||
661 | case FIELD_BOX_MISSLE_3: |
||
662 | rtlDebugOutString("FIELD_BOX_MISSLE_3"); |
||
5276 | ZblCoder | 663 | if (vector == Point(-1, 0) || vector == Point(0, 1)) |
664 | { |
||
665 | vector = (vector.Y == 1) ? Point(1, 0) : Point(0, -1); |
||
5287 | ZblCoder | 666 | DrawLaser(position, 270, color); |
5276 | ZblCoder | 667 | } |
668 | else |
||
669 | { |
||
5296 | ZblCoder | 670 | if (!LaserMoveElement(position, vector, code, color)) |
671 | { |
||
672 | for (int i = 2; i < 23; ++i) |
||
673 | pause(1); |
||
674 | } |
||
675 | else |
||
676 | LaserGun = true; |
||
677 | en = false; |
||
678 | } |
||
679 | break; |
||
680 | case FIELD_MISSLE_0: |
||
681 | if (vector == Point(-1, 0) || vector == Point(0, -1)) |
||
682 | { |
||
683 | vector = (vector.Y == -1) ? Point(1, 0) : Point(0, 1); |
||
684 | DrawLaser(position, 0, color); |
||
685 | } |
||
686 | else |
||
687 | { |
||
5276 | ZblCoder | 688 | for (int i = 2; i < 23; ++i) |
5287 | ZblCoder | 689 | pause(1); |
5276 | ZblCoder | 690 | en = false; |
691 | } |
||
692 | break; |
||
5296 | ZblCoder | 693 | case FIELD_MISSLE_1: |
694 | if (vector == Point(0, -1) || vector == Point(1, 0)) |
||
695 | { |
||
696 | vector = (vector.Y == -1) ? Point(-1, 0) : Point(0, 1); |
||
697 | DrawLaser(position, 90, color); |
||
698 | } |
||
699 | else |
||
700 | { |
||
701 | for (int i = 2; i < 23; ++i) |
||
702 | pause(1); |
||
703 | en = false; |
||
704 | } |
||
705 | break; |
||
5287 | ZblCoder | 706 | case FIELD_MISSLE_2: |
5276 | ZblCoder | 707 | if (vector == Point(1, 0) || vector == Point(0, 1)) |
708 | { |
||
709 | vector = (vector.Y == 1) ? Point(-1, 0) : Point(0, -1); |
||
5287 | ZblCoder | 710 | DrawLaser(position, 180, color); |
5276 | ZblCoder | 711 | } |
712 | else |
||
713 | { |
||
714 | for (int i = 2; i < 23; ++i) |
||
5287 | ZblCoder | 715 | pause(1); |
5276 | ZblCoder | 716 | en = false; |
717 | } |
||
718 | break; |
||
5296 | ZblCoder | 719 | case FIELD_MISSLE_3: |
720 | if (vector == Point(-1, 0) || vector == Point(0, 1)) |
||
721 | { |
||
722 | vector = (vector.Y == 1) ? Point(1, 0) : Point(0, -1); |
||
723 | DrawLaser(position, 270, color); |
||
724 | } |
||
725 | else |
||
726 | { |
||
727 | for (int i = 2; i < 23; ++i) |
||
728 | pause(1); |
||
729 | en = false; |
||
730 | } |
||
731 | break; |
||
5276 | ZblCoder | 732 | default: |
733 | for (int i = 2; i < 23; ++i) |
||
5287 | ZblCoder | 734 | pause(1); |
5276 | ZblCoder | 735 | en = false; |
736 | } |
||
737 | position = position + vector; |
||
738 | } |
||
739 | |||
740 | for (int y = 0; y < 16; y++) |
||
741 | for (int x = 0; x < 16; x++) |
||
742 | if (level[y][x].l == 1) |
||
743 | { |
||
744 | DrawElevent(Point(x, y), true); |
||
745 | level[y][x].l = 0; |
||
746 | } |
||
747 | |||
5287 | ZblCoder | 748 | if (LaserGun) |
749 | ExistGun(player.position); |
||
5276 | ZblCoder | 750 | } |
751 | |||
752 | void player_move(Point vector, float angle) |
||
753 | { |
||
754 | if (player.vector == vector) |
||
755 | { |
||
5287 | ZblCoder | 756 | Byte code = GetField(player.position + vector, true); |
757 | switch (code) |
||
5276 | ZblCoder | 758 | { |
5296 | ZblCoder | 759 | case FIELD_BOX_MISSLE_0: |
760 | case FIELD_BOX_MISSLE_1: |
||
761 | case FIELD_BOX_MISSLE_2: |
||
762 | case FIELD_BOX_MISSLE_3: |
||
763 | switch (GetField(player.position + vector * 2, true)) |
||
764 | { |
||
765 | case FIELD_GROUND: |
||
766 | case FIELD_CRATER: |
||
767 | case FIELD_WATER: |
||
768 | case FIELD_BOX_WATER: |
||
769 | case FIELD_BRICK_DES: |
||
770 | if (code == FIELD_BOX_MISSLE_0 && (vector == Point(1, 0) || vector == Point(0, 1)) |
||
771 | || code == FIELD_BOX_MISSLE_1 && (vector == Point(-1, 0) || vector == Point(0, 1)) |
||
772 | || code == FIELD_BOX_MISSLE_2 && (vector == Point(-1, 0) || vector == Point(0, -1)) |
||
773 | || code == FIELD_BOX_MISSLE_3 && (vector == Point(1, 0) || vector == Point(0, -1)) |
||
774 | ) |
||
775 | animation(vector, angle, code); |
||
776 | return; |
||
777 | } |
||
778 | break; |
||
5287 | ZblCoder | 779 | case FIELD_GUN_0: |
780 | case FIELD_GUN_1: |
||
781 | case FIELD_GUN_2: |
||
782 | case FIELD_GUN_3: |
||
5296 | ZblCoder | 783 | case FIELD_BOX: |
5276 | ZblCoder | 784 | switch (GetField(player.position + vector * 2, true)) |
785 | { |
||
5287 | ZblCoder | 786 | case FIELD_GROUND: |
5296 | ZblCoder | 787 | case FIELD_CRATER: |
5287 | ZblCoder | 788 | case FIELD_WATER: |
789 | case FIELD_BOX_WATER: |
||
790 | case FIELD_BRICK_DES: |
||
791 | animation(vector, angle, code); |
||
5276 | ZblCoder | 792 | return; |
793 | } |
||
794 | break; |
||
5287 | ZblCoder | 795 | case FIELD_FINISH: |
5276 | ZblCoder | 796 | gameStatus = GAME_VICTORY; |
5297 | ZblCoder | 797 | SetMode(MODE_PAUSE); |
5276 | ZblCoder | 798 | draw_window(); |
799 | break; |
||
5287 | ZblCoder | 800 | case FIELD_NONE: |
801 | case FIELD_BRICK: |
||
802 | case FIELD_WALL: |
||
5296 | ZblCoder | 803 | case FIELD_WALL_H: |
804 | case FIELD_WALL_V: |
||
805 | case FIELD_WALL_X: |
||
5287 | ZblCoder | 806 | case FIELD_WATER: |
807 | case FIELD_MISSLE_0: |
||
808 | case FIELD_MISSLE_1: |
||
809 | case FIELD_MISSLE_2: |
||
810 | case FIELD_MISSLE_3: |
||
5276 | ZblCoder | 811 | break; |
812 | default: |
||
5287 | ZblCoder | 813 | animation(vector, angle, -1); |
5276 | ZblCoder | 814 | } |
815 | } |
||
816 | else |
||
817 | { |
||
818 | int cnt; |
||
819 | float addAngle; |
||
820 | if (player.vector == vector * -1) |
||
821 | { |
||
822 | cnt = 48; |
||
823 | addAngle = 3.5f; |
||
824 | } |
||
825 | else |
||
826 | { |
||
827 | cnt = 24; |
||
828 | if (player.angle == 270 && angle == 0 || player.angle == 0 && angle == 270) |
||
829 | addAngle = (player.angle == 0) ? -3.5f : 3.5f; |
||
830 | else |
||
831 | addAngle = (angle < player.angle) ? -3.5f : 3.5f; |
||
832 | } |
||
833 | |||
834 | for (int i = 1; i < cnt - 1; ++i) |
||
835 | { |
||
836 | player.angle += addAngle; |
||
837 | renderPlayer->RenderImg(GetImg(player.position, false), Point(0, 0), 24, 24); |
||
838 | objPlayer->Draw(Point(0, 0), player.angle); |
||
839 | renderPlayer->Draw(player.position * 24); |
||
5287 | ZblCoder | 840 | pause(1); |
5276 | ZblCoder | 841 | } |
842 | |||
843 | player.vector = vector; |
||
844 | player.angle = angle; |
||
845 | |||
846 | renderPlayer->RenderImg(GetImg(player.position, false), Point(0, 0), 24, 24); |
||
847 | objPlayer->Draw(Point(0, 0), player.angle); |
||
848 | renderPlayer->Draw(player.position * 24); |
||
849 | } |
||
850 | } |
||
851 | |||
852 | void key_press(int key) |
||
853 | { |
||
854 | //rtlDebugOutString(ftoa(key)); |
||
855 | |||
856 | switch (gameMode) |
||
857 | { |
||
858 | case MODE_MENU: |
||
5296 | ZblCoder | 859 | if (key = 27) |
860 | kos_ExitApp(); |
||
5276 | ZblCoder | 861 | break; |
862 | case MODE_LEVELS: |
||
5296 | ZblCoder | 863 | if (key = 27) |
864 | SetMode(MODE_MENU); |
||
5276 | ZblCoder | 865 | break; |
866 | case MODE_GAME: |
||
867 | switch (key) |
||
868 | { |
||
869 | case 119: // Up |
||
870 | case 178: // W |
||
871 | if (gameStatus == GAME_NONE) |
||
872 | player_move(Point(0, -1), 270); |
||
873 | break; |
||
874 | case 177: // Down |
||
875 | case 115: // S |
||
876 | if (gameStatus == GAME_NONE) |
||
877 | player_move(Point(0, 1), 90); |
||
878 | break; |
||
879 | case 176: // Left |
||
880 | case 97: // A |
||
881 | if (gameStatus == GAME_NONE) |
||
882 | player_move(Point(-1, 0), 180); |
||
883 | break; |
||
884 | case 179: // Right |
||
885 | case 100: // D |
||
886 | if (gameStatus == GAME_NONE) |
||
887 | player_move(Point(1, 0), 0); |
||
888 | break; |
||
889 | case 32: // Space |
||
890 | if (gameStatus == GAME_NONE) |
||
5287 | ZblCoder | 891 | Laser(player.position, player.vector, (RGB)0x00FF00); |
5276 | ZblCoder | 892 | break; |
893 | case 13: |
||
5296 | ZblCoder | 894 | rtlDebugOutString(ftoa(rtlRand())); |
895 | |||
5287 | ZblCoder | 896 | // openLevel(levelIndex + 1); |
5276 | ZblCoder | 897 | if (gameStatus == GAME_VICTORY) |
898 | openLevel(levelIndex + 1); |
||
899 | else |
||
900 | if (gameStatus == GAME_DEFEAT) |
||
901 | openLevel(levelIndex); |
||
5296 | ZblCoder | 902 | |
5276 | ZblCoder | 903 | break; |
5296 | ZblCoder | 904 | case 27: |
5297 | ZblCoder | 905 | SetMode(MODE_PAUSE); |
5276 | ZblCoder | 906 | } |
907 | break; |
||
908 | } |
||
909 | } |
||
910 | |||
911 | void MousePress(int button, Point position) |
||
912 | { |
||
913 | //rtlDebugOutString("Mouse"); |
||
914 | //rtlDebugOutString(ftoa(position.X)); |
||
915 | //rtlDebugOutString(ftoa(position.Y)); |
||
5296 | ZblCoder | 916 | Point level_pos = Point(0, 0); |
5276 | ZblCoder | 917 | switch (gameMode) |
918 | { |
||
919 | case MODE_MENU: |
||
920 | if (CollRecrVsPoint(position, ToGame.rect)) |
||
5296 | ZblCoder | 921 | SetMode(MODE_LEVELS); |
5276 | ZblCoder | 922 | if (CollRecrVsPoint(position, ToExit.rect)) |
923 | kos_ExitApp(); |
||
924 | break; |
||
925 | case MODE_LEVELS: |
||
5296 | ZblCoder | 926 | if (CollRecrVsPoint(position, ToExit.rect)) |
927 | SetMode(MODE_MENU); |
||
928 | else |
||
929 | if (levelPage > 0 && CollRecrVsPoint(position, Rect(9, 318, 57, 57))) |
||
930 | { |
||
931 | levelPage--; |
||
932 | draw_window(); |
||
933 | } |
||
934 | else |
||
935 | if (levelPage < (int)(levelCount / 30) && CollRecrVsPoint(position, Rect(70, 318, 57, 57))) |
||
936 | { |
||
937 | levelPage++; |
||
938 | draw_window(); |
||
939 | } |
||
940 | else |
||
941 | { |
||
942 | for (int i = levelPage * 30; i < min(levelCount, (levelPage + 1) * 30); i++) |
||
943 | { |
||
5276 | ZblCoder | 944 | |
5296 | ZblCoder | 945 | if (i % 6 == 0 && i != levelPage * 30) |
946 | { |
||
947 | level_pos.X = 0; |
||
948 | level_pos.Y++; |
||
949 | } |
||
950 | if (CollRecrVsPoint(position, Rect(11 + level_pos.X * 62, 11 + 61 * level_pos.Y, 51, 50))) |
||
951 | { |
||
952 | openLevel(i); |
||
953 | //rtlDebugOutString(ftoa(i)); |
||
954 | SetMode(MODE_GAME); |
||
955 | return; |
||
956 | } |
||
957 | level_pos.X++; |
||
958 | } |
||
959 | } |
||
5276 | ZblCoder | 960 | break; |
5297 | ZblCoder | 961 | case MODE_PAUSE: |
962 | if (CollRecrVsPoint(position, Rect(77, 318, 229, 57))) |
||
963 | SetMode(MODE_LEVELS); |
||
964 | else |
||
965 | if (CollRecrVsPoint(position, Rect(77, 255, 229, 57))) |
||
966 | { |
||
967 | openLevel(levelIndex); |
||
968 | SetMode(MODE_GAME); |
||
969 | } |
||
970 | else |
||
971 | if (gameStatus != GAME_DEFEAT && CollRecrVsPoint(position, Rect(77, 192, 229, 57))) |
||
972 | { |
||
973 | if (gameStatus == GAME_VICTORY) |
||
974 | openLevel(levelIndex + 1); |
||
975 | SetMode(MODE_GAME); |
||
976 | } |
||
5276 | ZblCoder | 977 | case MODE_GAME: |
978 | |||
979 | break; |
||
980 | } |
||
981 | } |
||
982 | |||
5296 | ZblCoder | 983 | void draw_level_number(Point position, int number, RGB color) // 0x252317 |
984 | { |
||
985 | if (number > 99) |
||
986 | { |
||
987 | objnumbers->Draw(position + Point(4, 12), 0, (int)(number / 100), color); |
||
988 | objnumbers->Draw(position + Point(18, 12), 0, (int)((number % 100) / 10), color); |
||
989 | objnumbers->Draw(position + Point(32, 12), 0, (int)(number % 10), color); |
||
990 | } |
||
991 | else |
||
992 | if (number > 9) |
||
993 | { |
||
994 | objnumbers->Draw(position + Point(11, 12), 0, (int)((number % 100) / 10), color); |
||
995 | objnumbers->Draw(position + Point(25, 12), 0, (int)(number % 10), color); |
||
996 | } |
||
997 | else |
||
998 | if (number < 10) |
||
999 | objnumbers->Draw(position + Point(18, 12), 0, number, color); |
||
1000 | } |
||
1001 | |||
5276 | ZblCoder | 1002 | void draw_window(void) |
1003 | { |
||
1004 | kos_WindowRedrawStatus(1); |
||
1005 | kos_DefineAndDrawWindow(10, 40, 384 + 9, 384 + 25, 0x33, 0x444444, 0, 0, (Dword)header); |
||
5296 | ZblCoder | 1006 | Point level_pos = Point(0, 0); |
5276 | ZblCoder | 1007 | switch (gameMode) |
1008 | { |
||
1009 | case MODE_MENU: |
||
1010 | kos_PutImage((RGB*)img_menu, 384, 384, 0, 0); |
||
1011 | |||
1012 | // kos_PutImage((RGB*)img_button, 150, 50, ToGame.rect.X, ToGame.rect.Y); |
||
1013 | |||
1014 | |||
1015 | break; |
||
1016 | case MODE_LEVELS: |
||
5296 | ZblCoder | 1017 | renderLevels->RenderImg(img_levels, Point(0, 0), 384, 384); |
1018 | for (int i = levelPage * 30; i < min(levelCount, (levelPage + 1) * 30); i++) |
||
1019 | { |
||
1020 | if (i % 6 == 0 && i != levelPage * 30) |
||
1021 | { |
||
1022 | level_pos.X = 0; |
||
1023 | level_pos.Y++; |
||
1024 | } |
||
1025 | objnumber_box->Draw(Point(11 + level_pos.X * 62, 11 + 61 * level_pos.Y), 0); |
||
1026 | draw_level_number(Point(11 + level_pos.X * 62, 11 + 61 * level_pos.Y), i + 1, (RGB)0x252317); |
||
5276 | ZblCoder | 1027 | |
5296 | ZblCoder | 1028 | level_pos.X++; |
1029 | } |
||
1030 | |||
1031 | if (levelPage > 0) |
||
1032 | { |
||
1033 | objbutton1->Draw(Point(9, 318), 0); |
||
1034 | objbutton_arrow->Draw(Point(24, 338), 0); |
||
1035 | } |
||
1036 | |||
1037 | if (levelPage < (int)(levelCount / 30)) |
||
1038 | { |
||
1039 | objbutton1->Draw(Point(70, 318), 0); |
||
1040 | objbutton_arrow->Draw(Point(89, 339), 180); |
||
1041 | } |
||
1042 | |||
1043 | renderLevels->Draw(Point(0, 0)); |
||
5297 | ZblCoder | 1044 | //kos_PutImage((RGB*)img_ground, 24, 24, 100, 100); |
1045 | break; |
||
1046 | case MODE_PAUSE: |
||
1047 | for (int y = 0; y < 4; y++) |
||
1048 | for (int x = 0; x < 4; x++) |
||
1049 | renderLevels->RenderImg((RGB*)img_gamebg, Point(96 * x, 96 * y), 96, 96); |
||
5296 | ZblCoder | 1050 | |
5297 | ZblCoder | 1051 | for (int y = 0; y < 16; y++) |
1052 | for (int x = 0; x < 16; x++) |
||
1053 | if (level[y][x].s != FIELD_NONE) |
||
1054 | renderLevels->RenderImg(GetImg(Point(x, y), true), Point(24 * x, 24 * y), 24, 24); |
||
1055 | |||
1056 | switch (gameStatus) |
||
1057 | { |
||
1058 | case GAME_NONE: |
||
1059 | objPlayer1->Draw(player.position * 24, player.angle); |
||
1060 | break; |
||
1061 | case GAME_VICTORY: |
||
1062 | kos_WriteTextToWindow(30, 10, 0x80, 0xFFFFFF, "VICTORY", 0); |
||
1063 | break; |
||
1064 | case GAME_DEFEAT: |
||
1065 | kos_WriteTextToWindow(30, 10, 0x80, 0xFFFFFF, "DEFEAT", 0); |
||
1066 | break; |
||
1067 | } |
||
1068 | |||
1069 | for (int y = 0; y < 16; y++) |
||
1070 | for (int x = 0; x < 16; x++) |
||
1071 | objblack->Draw(Point(24 * x, 24 * y), 0); |
||
1072 | |||
1073 | if (gameStatus != GAME_DEFEAT) |
||
1074 | renderLevels->RenderImg((RGB*)img_buttons[1], Point(77, 192), 229, 57); |
||
1075 | renderLevels->RenderImg((RGB*)img_buttons[2], Point(77, 255), 229, 57); |
||
1076 | renderLevels->RenderImg((RGB*)img_buttons[0], Point(77, 318), 229, 57); |
||
1077 | |||
1078 | renderLevels->Draw(Point(0, 0)); |
||
5276 | ZblCoder | 1079 | break; |
1080 | case MODE_GAME: |
||
5296 | ZblCoder | 1081 | for (int y = 0; y < 4; y++) |
1082 | for (int x = 0; x < 4; x++) |
||
1083 | kos_PutImage((RGB*)img_gamebg, 96, 96, 96 * x, 96 * y); |
||
1084 | |||
5276 | ZblCoder | 1085 | for (int y = 0; y < 16; y++) |
1086 | for (int x = 0; x < 16; x++) |
||
5287 | ZblCoder | 1087 | if (level[y][x].s != FIELD_NONE) |
5297 | ZblCoder | 1088 | kos_PutImage(GetImg(Point(x, y), true), 24, 24, 24 * x, 24 * y); |
5276 | ZblCoder | 1089 | |
5297 | ZblCoder | 1090 | if(gameStatus != GAME_DEFEAT) |
5276 | ZblCoder | 1091 | { |
1092 | renderPlayer->RenderImg(GetImg(player.position, false), Point(0, 0), 24, 24); |
||
1093 | objPlayer->Draw(Point(0, 0), player.angle); |
||
1094 | renderPlayer->Draw(player.position * 24); |
||
1095 | } |
||
1096 | break; |
||
1097 | } |
||
1098 | kos_WindowRedrawStatus(2); |
||
1099 | } |
||
1100 | |||
1101 | void LevelsLoad() |
||
1102 | { |
||
1103 | char *cPtr; |
||
1104 | cPtr = strrchr(kosExePath, '/'); |
||
1105 | |||
1106 | if (cPtr == NULL) |
||
1107 | { |
||
1108 | rtlDebugOutString("Invalid path to executable."); |
||
1109 | return; |
||
1110 | } |
||
1111 | cPtr[1] = 0; |
||
5296 | ZblCoder | 1112 | strcpy(cPtr + 1, "data.lvl"); |
5276 | ZblCoder | 1113 | |
1114 | CKosFile *file = new CKosFile(kosExePath); |
||
1115 | |||
1116 | Byte block[256]; |
||
1117 | while (file->Read(block, 256) == 256) |
||
1118 | { |
||
1119 | levelCount++; |
||
1120 | } |
||
1121 | //levelCount++; |
||
1122 | rtlDebugOutString(ftoa(levelCount)); |
||
1123 | |||
1124 | levels = new Level[levelCount]; |
||
1125 | |||
1126 | file->Seek(0, SEEK_SET); |
||
1127 | for (int i = 0; i < levelCount; ++i) |
||
1128 | { |
||
1129 | file->Read(block, 256); |
||
1130 | int k = 0; |
||
1131 | |||
1132 | for (int y = 0; y < 16; y++) |
||
1133 | for (int x = 0; x < 16; x++) |
||
1134 | { |
||
5287 | ZblCoder | 1135 | levels[i].fileds[y][x] = block[k]; |
5276 | ZblCoder | 1136 | k++; |
1137 | } |
||
1138 | } |
||
1139 | } |
||
1140 | |||
1141 | void openLevel(int index) |
||
1142 | { |
||
1143 | levelIndex = index; |
||
1144 | for (int y = 0; y < 16; y++) |
||
1145 | for (int x = 0; x < 16; x++) |
||
1146 | { |
||
1147 | level[y][x].s = levels[index].fileds[y][x]; |
||
5287 | ZblCoder | 1148 | level[y][x].d = FIELD_NONE; |
5276 | ZblCoder | 1149 | level[y][x].l = 0; |
1150 | switch (levels[index].fileds[y][x]) |
||
1151 | { |
||
5287 | ZblCoder | 1152 | case FIELD_BOX: |
1153 | case FIELD_GUN_0: |
||
1154 | case FIELD_GUN_1: |
||
1155 | case FIELD_GUN_2: |
||
1156 | case FIELD_GUN_3: |
||
5296 | ZblCoder | 1157 | case FIELD_BOX_MISSLE_0: |
1158 | case FIELD_BOX_MISSLE_1: |
||
1159 | case FIELD_BOX_MISSLE_2: |
||
1160 | case FIELD_BOX_MISSLE_3: |
||
5287 | ZblCoder | 1161 | level[y][x].s = FIELD_GROUND; |
1162 | level[y][x].d = levels[index].fileds[y][x]; |
||
5276 | ZblCoder | 1163 | break; |
5287 | ZblCoder | 1164 | case FIELD_HERO: |
5276 | ZblCoder | 1165 | player = Player(Point(x, y)); |
5287 | ZblCoder | 1166 | level[y][x].s = FIELD_GROUND; |
5276 | ZblCoder | 1167 | break; |
5287 | ZblCoder | 1168 | case FIELD_BRICK: |
1169 | level[y][x].l = 0; |
||
5276 | ZblCoder | 1170 | break; |
1171 | } |
||
1172 | } |
||
1173 | gameStatus = GAME_NONE; |
||
1174 | draw_window(); |
||
1175 | } |
||
1176 | |||
1177 | void kos_Main() |
||
1178 | { |
||
1179 | rtlDebugOutString(" "); |
||
1180 | rtlDebugOutString("kos_Main"); |
||
1181 | char *cPtr; |
||
1182 | cPtr = strrchr(kosExePath, '/'); |
||
1183 | // проверка ;) |
||
1184 | if (cPtr == NULL) |
||
1185 | { |
||
1186 | rtlDebugOutString("Invalid path to executable."); |
||
1187 | return; |
||
1188 | } |
||
1189 | cPtr[1] = 0; |
||
5296 | ZblCoder | 1190 | strcpy(cPtr + 1, "data01.pak"); |
5276 | ZblCoder | 1191 | |
1192 | CKosFile *file = new CKosFile(kosExePath); |
||
1193 | |||
1194 | file->LoadTex((Byte*)img_box, 4, 24, 24); |
||
5287 | ZblCoder | 1195 | for (int i = 0; i < 11; ++i) |
1196 | file->LoadTex((Byte*)img_brick[i], 3, 24, 24); |
||
1197 | file->LoadTex((Byte*)img_brick1, 3, 24, 24); |
||
5276 | ZblCoder | 1198 | file->LoadTex((Byte*)img_finish, 3, 24, 24); |
1199 | file->LoadTex((Byte*)img_ground, 3, 24, 24); |
||
1200 | file->LoadTex((Byte*)img_laser, 4, 24, 24); |
||
1201 | file->LoadTex((Byte*)img_laser1, 4, 24, 24); |
||
1202 | file->LoadTex((Byte*)img_laser2, 4, 24, 24); |
||
1203 | |||
5287 | ZblCoder | 1204 | for (int i = 0; i < 4; ++i) |
1205 | file->LoadTex((Byte*)img_mirror[i], 3, 24, 24); |
||
5276 | ZblCoder | 1206 | |
5296 | ZblCoder | 1207 | //for (int i = 0; i < 4; ++i) |
1208 | file->LoadTex((Byte*)img_mini_mirror, 4, 24, 96); |
||
5276 | ZblCoder | 1209 | |
1210 | file->LoadTex((Byte*)img_tank, 4, 24, 24); |
||
1211 | file->LoadTex((Byte*)img_wall, 3, 24, 24); |
||
1212 | file->LoadTex((Byte*)img_water, 3, 24, 24); |
||
1213 | file->LoadTex((Byte*)img_waterbox, 3, 24, 24); |
||
1214 | file->LoadTex((Byte*)img_menu, 3, 384, 384); |
||
1215 | file->LoadTex((Byte*)img_explosion, 4, 24, 336); |
||
5287 | ZblCoder | 1216 | file->LoadTex((Byte*)img_gun, 4, 24, 24); |
5296 | ZblCoder | 1217 | file->LoadTex((Byte*)img_gamebg, 3, 96, 96); |
5276 | ZblCoder | 1218 | |
1219 | delete file; |
||
1220 | |||
5296 | ZblCoder | 1221 | strcpy(cPtr + 1, "data02.pak"); |
1222 | |||
1223 | file = new CKosFile(kosExePath); |
||
1224 | |||
1225 | file->LoadTex((Byte*)img_levels, 3, 384, 384); |
||
1226 | file->LoadTex((Byte*)img_number_box, 4, 51, 50); |
||
1227 | file->LoadTex((Byte*)img_numbers, 4, 14, 250); |
||
1228 | |||
1229 | file->LoadTex((Byte*)img_button1, 4, 57, 57); |
||
1230 | file->LoadTex((Byte*)img_button_arrow, 4, 25, 15); |
||
1231 | |||
1232 | file->LoadTex((Byte*)img_wall_h, 3, 24, 24); |
||
1233 | file->LoadTex((Byte*)img_wall_v, 3, 24, 24); |
||
1234 | file->LoadTex((Byte*)img_wall_x, 3, 24, 24); |
||
1235 | |||
1236 | file->LoadTex((Byte*)img_crater, 3, 24, 24); |
||
5297 | ZblCoder | 1237 | |
1238 | file->LoadTex((Byte*)img_black, 4, 24, 24); |
||
1239 | |||
1240 | for (int i = 0; i < 3; ++i) |
||
1241 | file->LoadTex((Byte*)img_buttons[i], 3, 229, 57); |
||
1242 | |||
5296 | ZblCoder | 1243 | delete file; |
1244 | |||
5276 | ZblCoder | 1245 | renderPlayer = new CKosRender(24, 24); |
1246 | objPlayer = new CKosImage(renderPlayer, (RGBA*)img_tank, 24, 24); |
||
1247 | |||
5296 | ZblCoder | 1248 | renderBox = new CKosRender(24, 24); |
1249 | objLaser = new CKosImage(renderBox, (RGBA*)img_laser, 24, 24); |
||
5276 | ZblCoder | 1250 | objLaser->SetMode(DRAW_ALPHA_ADD); |
5296 | ZblCoder | 1251 | objLaser1 = new CKosImage(renderBox, (RGBA*)img_laser1, 24, 24); |
5276 | ZblCoder | 1252 | objLaser1->SetMode(DRAW_ALPHA_ADD); |
5296 | ZblCoder | 1253 | objLaser2 = new CKosImage(renderBox, (RGBA*)img_laser2, 24, 24); |
5276 | ZblCoder | 1254 | objLaser2->SetMode(DRAW_ALPHA_ADD); |
1255 | |||
5296 | ZblCoder | 1256 | //for (int i = 0; i < 4; ++i) |
1257 | objMiniMirror = new CKosImage(renderBox, (RGBA*)img_mini_mirror, 24, 24); |
||
1258 | objMiniMirror->SetFrameSize(24, 24); |
||
5276 | ZblCoder | 1259 | |
1260 | objBox = new CKosImage(renderBox, (RGBA*)img_box, 24, 24); |
||
5287 | ZblCoder | 1261 | objGun = new CKosImage(renderBox, (RGBA*)img_gun, 24, 24); |
5276 | ZblCoder | 1262 | |
5296 | ZblCoder | 1263 | objExplosion = new CKosImage(renderBox, (RGBA*)img_explosion, 24, 24); |
5276 | ZblCoder | 1264 | objExplosion->SetFrameSize(24, 24); |
1265 | |||
5296 | ZblCoder | 1266 | renderLevels = new CKosRender(384, 384); |
5297 | ZblCoder | 1267 | |
1268 | objPlayer1 = new CKosImage(renderLevels, (RGBA*)img_tank, 24, 24); |
||
5296 | ZblCoder | 1269 | objnumber_box = new CKosImage(renderLevels, (RGBA*)img_number_box, 51, 50); |
1270 | objnumbers = new CKosImage(renderLevels, (RGBA*)img_numbers, 14, 25); |
||
1271 | objnumbers->SetFrameSize(14, 25); |
||
1272 | |||
1273 | objbutton1 = new CKosImage(renderLevels, (RGBA*)img_button1, 57, 57); |
||
1274 | objbutton_arrow = new CKosImage(renderLevels, (RGBA*)img_button_arrow, 25, 15); |
||
5297 | ZblCoder | 1275 | |
1276 | objblack = new CKosImage(renderLevels, (RGBA*)img_black, 24, 24); |
||
5296 | ZblCoder | 1277 | |
5276 | ZblCoder | 1278 | LevelsLoad(); |
1279 | |||
1280 | openLevel(0); |
||
1281 | |||
1282 | kos_SetMaskForEvents(0x27); |
||
1283 | for (;;) |
||
1284 | { |
||
1285 | switch (kos_WaitForEvent()) |
||
1286 | { |
||
1287 | case 1: |
||
1288 | draw_window(); |
||
1289 | break; |
||
1290 | case 2: |
||
1291 | Byte keyCode; |
||
1292 | kos_GetKey(keyCode); |
||
1293 | key_press(keyCode); |
||
1294 | break; |
||
1295 | case 3: |
||
1296 | kos_ExitApp(); |
||
1297 | break; |
||
1298 | case 6: |
||
1299 | Dword buttons; |
||
1300 | int mX, mY; |
||
1301 | kos_GetMouseState(buttons, mX, mY); |
||
1302 | if (buttons & 1) |
||
1303 | MousePress(MOUSE_LEFT, Point(mX, mY)); |
||
1304 | break; |
||
1305 | } |
||
1306 | } |
||
1307 | }>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |