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