00001 #include <math.h>
00002 #include <sys/time.h>
00003 #include <string.h>
00004 #include <mb.h>
00005 #include <mb_tools.h>
00006 #include "svgs.h"
00007
00008
00009
00010
00011
00012 enum { MUD, ROC, BRI, BSH };
00013
00014
00015 static char map[12][16] = {
00016 { MUD, MUD, MUD, MUD, MUD, MUD, MUD, MUD,
00017 MUD, MUD, MUD, MUD, MUD, MUD, MUD, MUD},
00018 { MUD, ROC, ROC, ROC, MUD, BSH, BSH, ROC,
00019 BSH, ROC, MUD, BSH, BSH, ROC, ROC, MUD},
00020 { MUD, MUD, BRI, MUD, MUD, MUD, MUD, MUD,
00021 MUD, MUD, MUD, BRI, MUD, MUD, BSH, MUD},
00022 { BRI, MUD, MUD, MUD, MUD, MUD, BRI, MUD,
00023 BRI, MUD, MUD, MUD, MUD, MUD, MUD, MUD},
00024 { MUD, MUD, BRI, MUD, BRI, BSH, BRI, BRI,
00025 BRI, BRI, BSH, ROC, ROC, MUD, BRI, MUD},
00026 { MUD, BRI, BRI, MUD, BRI, MUD, BRI, MUD,
00027 ROC, MUD, MUD, MUD, MUD, MUD, MUD, MUD},
00028 { MUD, MUD, MUD, MUD, MUD, MUD, MUD, MUD,
00029 MUD, MUD, MUD, BRI, BRI, BRI, BRI, MUD},
00030 { MUD, BRI, MUD, BRI, BRI, MUD, BRI, BRI,
00031 BSH, BRI, MUD, MUD, MUD, MUD, MUD, MUD},
00032 { MUD, BRI, MUD, MUD, MUD, MUD, MUD, MUD,
00033 MUD, MUD, MUD, BRI, BRI, MUD, BRI, BRI},
00034 { MUD, BRI, MUD, BRI, BRI, MUD, BRI, BRI,
00035 BRI, BRI, MUD, BRI, MUD, MUD, MUD, MUD},
00036 { MUD, BSH, MUD, BRI, MUD, MUD, BRI, MUD,
00037 MUD, BRI, MUD, MUD, MUD, BRI, BRI, MUD},
00038 { MUD, MUD, MUD, MUD, MUD, MUD, BRI, MUD,
00039 MUD, BRI, MUD, BRI, MUD, MUD, MUD, MUD}
00040 };
00041
00042 #define MAP_W 16
00043 #define MAP_H 12
00044
00045
00046
00047
00048
00049
00050
00051
00052 struct _tank_bullet {
00053 redraw_man_t *rdman;
00054 coord_t *coord_pos;
00055 coord_t *coord_rot;
00056 bullet_t *bullet_obj;
00057 int start_map_x, start_map_y;
00058 int direction;
00059 mb_progm_t *progm;
00060 mb_timeval_t start_time;
00061 observer_t *ob_redraw;
00062 mb_timer_t *hit_tmr;
00063 mb_tman_t *tman;
00064 };
00065 typedef struct _tank_bullet tank_bullet_t;
00066
00067
00068 enum { BU_UP = 0, BU_RIGHT, BU_DOWN, BU_LEFT };
00069
00070
00071
00072
00073
00074
00075
00076
00077 struct _tank {
00078 coord_t *coord_pos;
00079 coord_t *coord_rot;
00080 coord_t *coord_center;
00081 int map_x, map_y;
00082 int direction;
00083 mb_progm_t *progm;
00084 tank_bullet_t *bullet;
00085 struct _tank_rt *tank_rt;
00086
00087
00088 };
00089 typedef struct _tank tank_t;
00090 enum { TD_UP = 0, TD_RIGHT, TD_DOWN, TD_LEFT };
00091
00092
00093
00094 typedef struct _tank_rt tank_rt_t;
00095
00096
00097
00098 struct _tank_rt {
00099 tank_t *tank1;
00100 tank1_t *tank1_o;
00101 tank_t *tank2;
00102 tank2_t *tank2_o;
00103 int n_enemy;
00104 tank_t *tank_enemies[10];
00105 tank_en_t *tank_enemies_o[10];
00106 tank_t *tanks[12];
00107 int n_tanks;
00108 void *map[12][16];
00109 X_MB_runtime_t *mb_rt;
00110 observer_t *kb_observer;
00111 };
00112
00113
00114
00115
00116 static tank_t *tank_new(coord_t *coord_pos,
00117 coord_t *coord_rot,
00118 int map_x, int map_y,
00119 tank_rt_t *tank_rt) {
00120 tank_t *tank;
00121 redraw_man_t *rdman;
00122
00123 tank = O_ALLOC(tank_t);
00124 if(tank == NULL)
00125 return NULL;
00126
00127 rdman = X_MB_rdman(tank_rt->mb_rt);
00128
00129 tank->coord_pos = coord_pos;
00130 tank->coord_rot = coord_rot;
00131 tank->map_x = map_x;
00132 tank->map_y = map_y;
00133 tank->direction = TD_UP;
00134 tank->progm = NULL;
00135 tank->bullet = NULL;
00136 tank->tank_rt = tank_rt;
00137
00138 memset(coord_pos->matrix, 0, sizeof(co_aix[6]));
00139 coord_pos->matrix[0] = 1;
00140 coord_pos->matrix[2] = map_x * 50;
00141 coord_pos->matrix[4] = 1;
00142 coord_pos->matrix[5] = map_y * 50;
00143 rdman_coord_changed(rdman, coord_pos);
00144
00145 return tank;
00146 }
00147
00148 static void tank_free(tank_t *tank, X_MB_runtime_t *xmb_rt) {
00149 mb_tman_t *tman;
00150
00151 if(tank->progm) {
00152 tman = X_MB_tman(xmb_rt);
00153 mb_progm_abort(tank->progm);
00154 }
00155 free(tank);
00156 }
00157
00158
00159
00160
00161
00162 static void clean_tank_progm_handler(event_t *event, void *arg) {
00163 tank_t *tank = (tank_t *)arg;
00164
00165 mb_progm_free(tank->progm);
00166 tank->progm = NULL;
00167 }
00168
00169 #define PI 3.1415926
00170
00171 static void tank_move(tank_t *tank, int direction,
00172 tank_rt_t *tank_rt) {
00173 X_MB_runtime_t *xmb_rt = tank_rt->mb_rt;
00174 redraw_man_t *rdman;
00175 mb_tman_t *tman;
00176 ob_factory_t *factory;
00177
00178 mb_progm_t *progm;
00179 subject_t *comp_sub;
00180 mb_word_t *word;
00181 mb_timeval_t start, playing;
00182 mb_timeval_t now;
00183
00184 co_aix sh_x, sh_y;
00185
00186 float ang1, ang2;
00187 float rot_diff;
00188 int i;
00189 static co_aix shift_xy[][2] = {{0, -50}, {50, 0}, {0, 50}, {-50, 0}};
00190 static int map_shift[4][2] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}};
00191 static float angles[4] = {0, PI / 2, PI , PI * 3 / 2};
00192 static float rotations[7] = {PI / 2, PI , -PI / 2,
00193 0, PI / 2, PI , -PI / 2};
00194
00195 if(tank->progm != NULL)
00196 return;
00197
00198
00199
00200
00201 if(direction == tank->direction) {
00202 switch(direction) {
00203 case TD_UP:
00204 if(tank->map_y == 0)
00205 return;
00206 if(map[tank->map_y - 1][tank->map_x] != MUD)
00207 return;
00208 break;
00209 case TD_RIGHT:
00210 if(tank->map_x >= (MAP_W - 1))
00211 return;
00212 if(map[tank->map_y][tank->map_x + 1] != MUD)
00213 return;
00214 break;
00215 case TD_DOWN:
00216 if(tank->map_y >= (MAP_H - 1))
00217 return;
00218 if(map[tank->map_y + 1][tank->map_x] != MUD)
00219 return;
00220 break;
00221 case TD_LEFT:
00222 if(tank->map_x == 0)
00223 return;
00224 if(map[tank->map_y][tank->map_x - 1] != MUD)
00225 return;
00226 break;
00227 }
00228
00229 tank->map_x += map_shift[direction][0];
00230 tank->map_y += map_shift[direction][1];
00231 for(i = 0; i < tank_rt->n_tanks; i++) {
00232 if(tank != tank_rt->tanks[i] &&
00233 tank->map_x == tank_rt->tanks[i]->map_x &&
00234 tank->map_y == tank_rt->tanks[i]->map_y) {
00235 tank->map_x -= map_shift[direction][0];
00236 tank->map_y -= map_shift[direction][1];
00237 return;
00238 }
00239 }
00240 }
00241
00242 rdman = X_MB_rdman(xmb_rt);
00243 tman = X_MB_tman(xmb_rt);
00244 factory = X_MB_ob_factory(xmb_rt);
00245
00246 progm = mb_progm_new(1, rdman);
00247 tank->progm = progm;
00248
00249 MB_TIMEVAL_SET(&start, 0, 0);
00250 MB_TIMEVAL_SET(&playing, 0, 500000);
00251 word = mb_progm_next_word(progm, &start, &playing);
00252
00253 if(direction == tank->direction) {
00254
00255 sh_x = shift_xy[direction][0];
00256 sh_y = shift_xy[direction][1];
00257 mb_shift_new(sh_x, sh_y, tank->coord_pos, word);
00258 } else {
00259
00260 rot_diff = rotations[3 - tank->direction + direction];
00261 ang1 = angles[tank->direction];
00262 ang2 = ang1 + rot_diff;
00263 mb_rotate_new(ang1, ang2, tank->coord_rot, word);
00264 tank->direction = direction;
00265 }
00266
00267
00268 comp_sub = mb_progm_get_complete(progm);
00269 subject_add_observer(factory, comp_sub,
00270 clean_tank_progm_handler, tank);
00271
00272 get_now(&now);
00273 mb_progm_start(progm, tman, &now);
00274 }
00275
00276
00277
00278
00279
00280
00281
00282 static void make_bullet_elf_coords(redraw_man_t *rdman, coord_t **coord_pos,
00283 coord_t **coord_rot,
00284 coord_t **coord_center) {
00285 coord_t *coord_back;
00286
00287 *coord_pos = rdman_coord_new(rdman, rdman->root_coord);
00288
00289 coord_back = rdman_coord_new(rdman, *coord_pos);
00290 coord_back->matrix[2] = 25;
00291 coord_back->matrix[5] = 25;
00292 rdman_coord_changed(rdman, coord_back);
00293
00294 *coord_rot = rdman_coord_new(rdman, coord_back);
00295
00296 *coord_center = rdman_coord_new(rdman, *coord_rot);
00297 (*coord_center)->matrix[2] = -5;
00298 (*coord_center)->matrix[5] = +15;
00299 rdman_coord_changed(rdman, *coord_center);
00300 }
00301
00302 static tank_bullet_t *tank_bullet_new(redraw_man_t *rdman,
00303 int map_x, int map_y,
00304 int direction) {
00305 tank_bullet_t *bullet;
00306 coord_t *coord_center;
00307 co_aix *matrix;
00308 static float _sins[] = { 0, 1, 0, -1};
00309 static float _coss[] = { 1, 0, -1, 0};
00310 float _sin, _cos;
00311
00312 bullet = O_ALLOC(tank_bullet_t);
00313 bullet->rdman = rdman;
00314
00315 make_bullet_elf_coords(rdman, &bullet->coord_pos,
00316 &bullet->coord_rot,
00317 &coord_center);
00318 bullet->bullet_obj = bullet_new(rdman, coord_center);
00319
00320 bullet->start_map_x = map_x;
00321 bullet->start_map_y = map_y;
00322 bullet->direction = direction;
00323 bullet->progm = NULL;
00324
00325 matrix = bullet->coord_pos->matrix;
00326 matrix[2] = map_x * 50;
00327 matrix[5] = map_y * 50;
00328 rdman_coord_changed(rdman, bullet->coord_pos);
00329
00330 _sin = _sins[direction];
00331 _cos = _coss[direction];
00332 matrix = bullet->coord_rot->matrix;
00333 matrix[0] = _cos;
00334 matrix[1] = -_sin;
00335 matrix[3] = _sin;
00336 matrix[4] = _cos;
00337
00338 return bullet;
00339 }
00340
00341 static void tank_bullet_free(tank_bullet_t *bullet) {
00342 bullet_free(bullet->bullet_obj);
00343 rdman_coord_subtree_free(bullet->rdman, bullet->coord_pos);
00344 }
00345
00346 static void bullet_go_out_map(event_t *event, void *arg) {
00347 tank_t *tank = (tank_t *)arg;
00348 tank_bullet_t *bullet;
00349 redraw_man_t *rdman;
00350
00351 bullet = tank->bullet;
00352 rdman = bullet->rdman;
00353
00354 if(bullet->hit_tmr != NULL)
00355 mb_tman_remove(bullet->tman, bullet->hit_tmr);
00356
00357 coord_hide(bullet->coord_pos);
00358 rdman_coord_changed(rdman, bullet->coord_pos);
00359
00360 bullet = tank->bullet;
00361 mb_progm_free(bullet->progm);
00362 tank_bullet_free(tank->bullet);
00363 tank->bullet = NULL;
00364 }
00365
00366 static void bullet_bang(tank_bullet_t *bullet, int map_x, int map_y) {
00367 redraw_man_t *rdman;
00368 mb_tman_t *tman;
00369 mb_progm_t *progm;
00370 mb_word_t *word;
00371 mb_timeval_t start, playing;
00372 mb_timeval_t now;
00373 bang_t *bang;
00374 co_aix *matrix;
00375
00376 rdman = bullet->rdman;
00377 tman = bullet->tman;
00378
00379 bang = bang_new(rdman, rdman->root_coord);
00380 matrix = bang->root_coord->matrix;
00381 matrix[2] = map_x * 50;
00382 matrix[5] = map_y * 50;
00383 rdman_coord_changed(rdman, bang->root_coord);
00384
00385 progm = mb_progm_new(3, rdman);
00386
00387 MB_TIMEVAL_SET(&start, 1, 0);
00388 MB_TIMEVAL_SET(&playing, 0, 0);
00389 word = mb_progm_next_word(progm, &start, &playing);
00390 mb_visibility_new(VIS_HIDDEN, bang->root_coord, word);
00391
00392 MB_TIMEVAL_SET(&start, 1, 500000);
00393 word = mb_progm_next_word(progm, &start, &playing);
00394 mb_visibility_new(VIS_VISIBLE, bang->root_coord, word);
00395
00396
00397 get_now(&now);
00398 mb_progm_start(progm, tman, &now);
00399 }
00400
00401
00402 static void bullet_hit_chk(const mb_timeval_t *tmo,
00403 const mb_timeval_t *now,
00404 void *arg) {
00405 tank_t *tank = (tank_t *)arg;
00406 tank_rt_t *tank_rt = tank->tank_rt;
00407 tank_t *tank_hitted;
00408 tank_bullet_t *bullet;
00409 mb_timeval_t diff, next;
00410 mb_timeval_t unit_tm;
00411 float move_units_f;
00412 int move_units;
00413 int x, y;
00414 int dir;
00415 int i;
00416 static int move_adj[][2] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}};
00417
00418 bullet = tank->bullet;
00419 bullet->hit_tmr = NULL;
00420
00421
00422
00423 MB_TIMEVAL_CP(&diff, now);
00424 MB_TIMEVAL_DIFF(&diff, &bullet->start_time);
00425 MB_TIMEVAL_SET(&unit_tm, 0, 250000);
00426 move_units_f = MB_TIMEVAL_DIV(&diff, &unit_tm);
00427 move_units = floorl(move_units_f);
00428 dir = bullet->direction;
00429 x = bullet->start_map_x + move_adj[dir][0] * move_units;
00430 y = bullet->start_map_y + move_adj[dir][1] * move_units;
00431
00432 if(map[y][x] != MUD) {
00433 mb_progm_abort(bullet->progm);
00434 bullet_go_out_map(NULL, tank);
00435 bullet_bang(bullet, x, y);
00436 return;
00437 }
00438
00439
00440 for(i = 0; i < tank_rt->n_enemy; i++) {
00441 tank_hitted = tank_rt->tank_enemies[i];
00442 if(tank_hitted == tank)
00443 continue;
00444 if(tank_hitted->map_x == x &&
00445 tank_hitted->map_y == y) {
00446 mb_progm_abort(bullet->progm);
00447 bullet_go_out_map(NULL, tank);
00448 bullet_bang(bullet, x, y);
00449 return;
00450 }
00451 }
00452
00453 if(tank_rt->tank1 != tank) {
00454 tank_hitted = tank_rt->tank1;
00455 if(tank_hitted->map_x == x &&
00456 tank_hitted->map_y == y) {
00457 mb_progm_abort(bullet->progm);
00458 bullet_go_out_map(NULL, tank);
00459 bullet_bang(bullet, x, y);
00460 return;
00461 }
00462 }
00463
00464 if(tank_rt->tank2 != tank) {
00465 tank_hitted = tank_rt->tank2;
00466 if(tank_hitted->map_x == x &&
00467 tank_hitted->map_y == y) {
00468 mb_progm_abort(bullet->progm);
00469 bullet_go_out_map(NULL, tank);
00470 bullet_bang(bullet, x, y);
00471 return;
00472 }
00473 }
00474
00475 MB_TIMEVAL_SET(&next, 0, 100000);
00476 MB_TIMEVAL_ADD(&next, now);
00477 bullet->hit_tmr = mb_tman_timeout(bullet->tman, &next,
00478 bullet_hit_chk, arg);
00479 }
00480
00481
00482 static void tank_fire_bullet(tank_rt_t *tank_rt, tank_t *tank) {
00483 X_MB_runtime_t *xmb_rt;
00484 redraw_man_t *rdman;
00485 int map_x, map_y;
00486 int shift_x, shift_y;
00487 int shift_len;
00488 int dir;
00489 tank_bullet_t *bullet;
00490 mb_progm_t *progm;
00491 mb_word_t *word;
00492 mb_action_t *act;
00493 mb_timeval_t start, playing;
00494 mb_timeval_t now, next;
00495 ob_factory_t *factory;
00496 mb_tman_t *tman;
00497 subject_t *subject;
00498 static int map_xy_adj[][2] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}};
00499
00500 if(tank->bullet != NULL)
00501 return;
00502
00503 xmb_rt = tank_rt->mb_rt;
00504 rdman = X_MB_rdman(xmb_rt);
00505 tman = X_MB_tman(xmb_rt);
00506
00507 dir = tank->direction;
00508 map_x = tank->map_x + map_xy_adj[dir][0];
00509 map_y = tank->map_y + map_xy_adj[dir][1];
00510 switch(dir) {
00511 case TD_UP:
00512 shift_len = map_y + 1;
00513 shift_x = 0;
00514 shift_y = -shift_len * 50;
00515 break;
00516 case TD_RIGHT:
00517 shift_len = 16 - map_x;
00518 shift_x = shift_len * 50;
00519 shift_y = 0;
00520 break;
00521 case TD_DOWN:
00522 shift_len = 12 - map_y;
00523 shift_x = 0;
00524 shift_y = shift_len * 50;
00525 break;
00526 case TD_LEFT:
00527 shift_len = map_x + 1;
00528 shift_x = -shift_len * 50;
00529 shift_y = 0;
00530 break;
00531 }
00532
00533 if(shift_len <= 0)
00534 return;
00535
00536 tank->bullet = tank_bullet_new(rdman, map_x, map_y, dir);
00537 bullet = tank->bullet;
00538 bullet->tman = tman;
00539
00540 progm = mb_progm_new(2, rdman);
00541 MB_TIMEVAL_SET(&start, 0, 0);
00542 MB_TIMEVAL_SET(&playing, shift_len / 4, (shift_len % 4) * 250000);
00543 word = mb_progm_next_word(progm, &start, &playing);
00544 act = mb_shift_new(shift_x, shift_y, bullet->coord_pos, word);
00545 bullet->progm = progm;
00546
00547
00548 subject = mb_progm_get_complete(progm);
00549 factory = rdman_get_ob_factory(rdman);
00550 subject_add_observer(factory, subject, bullet_go_out_map, tank);
00551
00552 get_now(&now);
00553 MB_TIMEVAL_CP(&bullet->start_time, &now);
00554 mb_progm_start(progm, tman, &now);
00555
00556 MB_TIMEVAL_SET(&next, 0, 100000);
00557 MB_TIMEVAL_ADD(&next, &now);
00558 bullet->hit_tmr = mb_tman_timeout(tman, &next, bullet_hit_chk, tank);
00559 }
00560
00561
00562
00563
00564
00565
00566 #define CHANGE_POS(g, x, y) do { \
00567 (g)->root_coord->matrix[0] = 1.0; \
00568 (g)->root_coord->matrix[2] = x; \
00569 (g)->root_coord->matrix[4] = 1.0; \
00570 (g)->root_coord->matrix[5] = y; \
00571 rdman_coord_changed(rdman, (g)->root_coord); \
00572 } while(0)
00573
00574 static void keyboard_handler(event_t *event, void *arg) {
00575 X_kb_event_t *xkey = (X_kb_event_t *)event;
00576 tank_rt_t *tank_rt = (tank_rt_t *)arg;
00577 int direction;
00578
00579 if(xkey->event.type != EVT_KB_PRESS)
00580 return;
00581
00582 switch(xkey->sym) {
00583 case 0xff51:
00584 direction = TD_LEFT;
00585 tank_move(tank_rt->tank1, direction, tank_rt);
00586 break;
00587
00588 case 0xff52:
00589 direction = TD_UP;
00590 tank_move(tank_rt->tank1, direction, tank_rt);
00591 break;
00592
00593 case 0xff53:
00594 direction = TD_RIGHT;
00595 tank_move(tank_rt->tank1, direction, tank_rt);
00596 break;
00597
00598 case 0xff54:
00599 direction = TD_DOWN;
00600 tank_move(tank_rt->tank1, direction, tank_rt);
00601 break;
00602
00603 case 0x20:
00604 tank_fire_bullet(tank_rt, tank_rt->tank1);
00605 break;
00606 case 0xff0d:
00607 default:
00608 return;
00609 }
00610
00611 }
00612
00613 static void init_keyboard(tank_rt_t *tank_rt) {
00614 X_MB_runtime_t *mb_rt;
00615 subject_t *kbevents;
00616 redraw_man_t *rdman;
00617 ob_factory_t *factory;
00618
00619 mb_rt = tank_rt->mb_rt;
00620 kbevents = X_MB_kbevents(mb_rt);
00621
00622 rdman = X_MB_rdman(mb_rt);
00623 factory = rdman_get_ob_factory(rdman);
00624
00625 tank_rt->kb_observer =
00626 subject_add_observer(factory, kbevents, keyboard_handler, tank_rt);
00627 }
00628
00629
00630
00631
00632
00633
00634
00635 static void make_elf_coords(redraw_man_t *rdman, coord_t **coord_pos,
00636 coord_t **coord_rot, coord_t **coord_center) {
00637 coord_t *coord_back;
00638
00639 *coord_pos = rdman_coord_new(rdman, rdman->root_coord);
00640
00641 coord_back = rdman_coord_new(rdman, *coord_pos);
00642 coord_back->matrix[2] = 25;
00643 coord_back->matrix[5] = 25;
00644 rdman_coord_changed(rdman, coord_back);
00645
00646 *coord_rot = rdman_coord_new(rdman, coord_back);
00647
00648 *coord_center = rdman_coord_new(rdman, *coord_rot);
00649 (*coord_center)->matrix[2] = -25;
00650 (*coord_center)->matrix[5] = -25;
00651 rdman_coord_changed(rdman, *coord_center);
00652 }
00653
00654 void
00655 initial_tank(tank_rt_t *tank_rt, X_MB_runtime_t *mb_rt) {
00656 redraw_man_t *rdman;
00657
00658 mud_t *mud;
00659 brick_t *brick;
00660 rock_t *rock;
00661 bush_t *bush;
00662
00663 coord_t *coord_center, *coord_pos, *coord_rot;
00664 tank1_t *tank1_o;
00665 tank2_t *tank2_o;
00666 tank_en_t *tank_en_o;
00667 int i, j;
00668
00669 rdman = X_MB_rdman(mb_rt);
00670
00671 tank_rt->mb_rt = mb_rt;
00672 for(i = 0; i < 12; i++) {
00673 for(j = 0; j < 16; j++) {
00674 switch(map[i][j]) {
00675 case MUD:
00676 mud = mud_new(rdman, rdman->root_coord);
00677 CHANGE_POS(mud, j * 50, i * 50);
00678 tank_rt->map[i][j] = (void *)mud;
00679 break;
00680 case BRI:
00681 brick = brick_new(rdman, rdman->root_coord);
00682 CHANGE_POS(brick, j * 50, i * 50);
00683 tank_rt->map[i][j] = (void *)brick;
00684 break;
00685 case ROC:
00686 rock = rock_new(rdman, rdman->root_coord);
00687 CHANGE_POS(rock, j * 50, i * 50);
00688 tank_rt->map[i][j] = (void *)rock;
00689 break;
00690 case BSH:
00691 bush = bush_new(rdman, rdman->root_coord);
00692 CHANGE_POS(bush, j * 50, i * 50);
00693 tank_rt->map[i][j] = (void *)bush;
00694 break;
00695 }
00696 }
00697 }
00698
00699 make_elf_coords(rdman, &coord_pos, &coord_rot, &coord_center);
00700 tank1_o = tank1_new(rdman, coord_center);
00701 tank_rt->tank1 = tank_new(coord_pos, coord_rot, 5, 11, tank_rt);
00702 tank_rt->tank1_o = tank1_o;
00703
00704 make_elf_coords(rdman, &coord_pos, &coord_rot, &coord_center);
00705 tank2_o = tank2_new(rdman, coord_center);
00706 tank_rt->tank2 = tank_new(coord_pos, coord_rot, 10, 11, tank_rt);
00707 tank_rt->tank2_o = tank2_o;
00708
00709 for(i = 0; i < 3; i++) {
00710 make_elf_coords(rdman, &coord_pos, &coord_rot, &coord_center);
00711 tank_en_o = tank_en_new(rdman, coord_center);
00712 tank_rt->tank_enemies[i] = tank_new(coord_pos, coord_rot,
00713 i * 3 + 3, 0, tank_rt);
00714 tank_rt->tank_enemies_o[i] = tank_en_o;
00715 tank_rt->tanks[i] = tank_rt->tank_enemies[i];
00716 }
00717 tank_rt->n_enemy = i;
00718
00719 tank_rt->tanks[i++] =tank_rt->tank1;
00720 tank_rt->tanks[i++] =tank_rt->tank2;
00721 tank_rt->n_tanks = i;
00722
00723 init_keyboard(tank_rt);
00724 }
00725
00726 int
00727 main(int argc, char *const argv[]) {
00728 X_MB_runtime_t *rt;
00729 tank_rt_t tank_rt;
00730
00731 rt = X_MB_new(":0.0", 800, 600);
00732
00733 initial_tank(&tank_rt, rt);
00734
00735 X_MB_handle_connection(rt);
00736
00737 X_MB_free(rt);
00738 }
00739
00740