120
|
1 #include <sys/time.h>
|
115
|
2 #include <mb/mb.h>
|
|
3 #include "svgs.h"
|
|
4
|
|
5 enum { MUD, ROC, BRI, BSH };
|
|
6
|
|
7 static char map[12][16] = {
|
|
8 { MUD, MUD, MUD, MUD, MUD, MUD, MUD, MUD,
|
|
9 MUD, MUD, MUD, MUD, MUD, MUD, MUD, MUD},
|
|
10 { MUD, ROC, ROC, ROC, MUD, BSH, BSH, ROC,
|
|
11 BSH, ROC, MUD, BSH, BSH, ROC, ROC, MUD},
|
|
12 { MUD, MUD, BRI, MUD, MUD, MUD, MUD, MUD,
|
|
13 MUD, MUD, MUD, BRI, MUD, MUD, BSH, MUD},
|
|
14 { BRI, MUD, MUD, MUD, MUD, MUD, BRI, MUD,
|
|
15 BRI, MUD, MUD, MUD, MUD, MUD, MUD, MUD},
|
|
16 { MUD, MUD, BRI, MUD, BRI, BSH, BRI, BRI,
|
|
17 BRI, BRI, BSH, ROC, ROC, MUD, BRI, MUD},
|
|
18 { MUD, BRI, BRI, MUD, BRI, MUD, BRI, MUD,
|
|
19 ROC, MUD, MUD, MUD, MUD, MUD, MUD, MUD},
|
|
20 { MUD, MUD, MUD, MUD, MUD, MUD, MUD, MUD,
|
|
21 MUD, MUD, MUD, BRI, BRI, BRI, BRI, MUD},
|
|
22 { MUD, BRI, MUD, BRI, BRI, MUD, BRI, BRI,
|
|
23 BSH, BRI, MUD, MUD, MUD, MUD, MUD, MUD},
|
|
24 { MUD, BRI, MUD, MUD, MUD, MUD, MUD, MUD,
|
|
25 MUD, MUD, MUD, BRI, BRI, MUD, BRI, BRI},
|
|
26 { MUD, BRI, MUD, BRI, BRI, MUD, BRI, BRI,
|
|
27 BRI, BRI, MUD, BRI, MUD, MUD, MUD, MUD},
|
|
28 { MUD, BSH, MUD, BRI, MUD, MUD, BRI, MUD,
|
|
29 MUD, BRI, MUD, MUD, MUD, BRI, BRI, MUD},
|
|
30 { MUD, MUD, MUD, MUD, MUD, MUD, BRI, MUD,
|
|
31 MUD, BRI, MUD, BRI, MUD, MUD, MUD, MUD}
|
|
32 };
|
|
33
|
|
34 typedef struct _tank_rt tank_rt_t;
|
|
35
|
|
36 struct _tank_rt {
|
|
37 tank1_t *tank1;
|
|
38 tank2_t *tank2;
|
117
|
39 int n_enemy;
|
|
40 tank_en_t *tank_enemies[10];
|
115
|
41 void *map[12][16];
|
|
42 X_MB_runtime_t *mb_rt;
|
120
|
43 mb_progm_t *tank1_progm;
|
115
|
44 };
|
|
45
|
|
46 #define CHANGE_POS(g, x, y) do { \
|
|
47 (g)->root_coord->matrix[0] = 1.0; \
|
|
48 (g)->root_coord->matrix[2] = x; \
|
|
49 (g)->root_coord->matrix[4] = 1.0; \
|
|
50 (g)->root_coord->matrix[5] = y; \
|
|
51 rdman_coord_changed(rdman, (g)->root_coord); \
|
|
52 } while(0)
|
|
53
|
|
54 void
|
|
55 initial_tank(tank_rt_t *tank_rt, X_MB_runtime_t *mb_rt) {
|
|
56 redraw_man_t *rdman;
|
|
57 mud_t *mud;
|
|
58 brick_t *brick;
|
|
59 rock_t *rock;
|
|
60 bush_t *bush;
|
120
|
61 mb_word_t *word;
|
|
62 mb_timeval_t start, playing;
|
|
63 mb_timeval_t mbtv;
|
115
|
64 int i, j;
|
|
65
|
|
66 rdman = mb_rt->rdman;
|
|
67
|
|
68 tank_rt->mb_rt = mb_rt;
|
|
69 for(i = 0; i < 12; i++) {
|
|
70 for(j = 0; j < 16; j++) {
|
|
71 switch(map[i][j]) {
|
|
72 case MUD:
|
|
73 mud = mud_new(rdman);
|
|
74 CHANGE_POS(mud, j * 50, i * 50);
|
|
75 tank_rt->map[i][j] = (void *)mud;
|
|
76 break;
|
|
77 case BRI:
|
|
78 brick = brick_new(rdman);
|
|
79 CHANGE_POS(brick, j * 50, i * 50);
|
|
80 tank_rt->map[i][j] = (void *)brick;
|
|
81 break;
|
|
82 case ROC:
|
|
83 rock = rock_new(rdman);
|
|
84 CHANGE_POS(rock, j * 50, i * 50);
|
|
85 tank_rt->map[i][j] = (void *)rock;
|
|
86 break;
|
|
87 case BSH:
|
|
88 bush = bush_new(rdman);
|
|
89 CHANGE_POS(bush, j * 50, i * 50);
|
|
90 tank_rt->map[i][j] = (void *)bush;
|
|
91 break;
|
|
92 }
|
|
93 }
|
|
94 }
|
|
95
|
|
96 tank_rt->tank1 = tank1_new(rdman);
|
117
|
97 CHANGE_POS(tank_rt->tank1, 5 * 50, 11 * 50);
|
115
|
98 tank_rt->tank2 = tank2_new(rdman);
|
117
|
99 CHANGE_POS(tank_rt->tank2, 10 * 50, 11 * 50);
|
|
100 for(i = 0; i < 3; i++) {
|
|
101 tank_rt->tank_enemies[i] = tank_en_new(rdman);
|
|
102 CHANGE_POS(tank_rt->tank_enemies[i], (2 + i * 3) * 50, 0);
|
|
103 }
|
|
104 tank_rt->n_enemy = i;
|
120
|
105
|
|
106 tank_rt->tank1_progm = mb_progm_new(4, rdman);
|
|
107
|
|
108 MB_TIMEVAL_SET(&start, 1, 0);
|
|
109 MB_TIMEVAL_SET(&playing, 3, 0);
|
|
110 word = mb_progm_next_word(tank_rt->tank1_progm, &start, &playing);
|
|
111
|
|
112 mb_shift_new(0, -150, tank_rt->tank1->root_coord, word);
|
|
113 mb_shift_new(0, -150, tank_rt->tank2->root_coord, word);
|
|
114
|
|
115 MB_TIMEVAL_SET(&start, 5, 0);
|
|
116 MB_TIMEVAL_SET(&playing, 3, 0);
|
|
117 word = mb_progm_next_word(tank_rt->tank1_progm, &start, &playing);
|
|
118
|
|
119 mb_shift_new(0, 150, tank_rt->tank1->root_coord, word);
|
|
120 mb_shift_new(0, 150, tank_rt->tank2->root_coord, word);
|
|
121
|
|
122 get_now(&mbtv);
|
|
123 mb_progm_start(tank_rt->tank1_progm, mb_rt->tman, &mbtv);
|
115
|
124 }
|
|
125
|
|
126 int
|
|
127 main(int argc, char *const argv[]) {
|
|
128 X_MB_runtime_t rt;
|
|
129 tank_rt_t tank_rt;
|
|
130
|
|
131 X_MB_init(":0.0", 800, 600, &rt);
|
|
132
|
|
133 initial_tank(&tank_rt, &rt);
|
|
134
|
|
135 X_MB_handle_connection(&rt);
|
|
136
|
|
137 X_MB_destroy(&rt);
|
|
138 }
|