Mercurial > MadButterfly
annotate examples/tank/tank_main.c @ 130:3a4d6179e6a9
change mb_c_source.m4 and mb_c_header.m4 to specify parent for SVG object
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Tue, 16 Sep 2008 21:23:34 +0800 |
parents | ba581d8a4b9b |
children | 6a8588df68af |
rev | line source |
---|---|
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; | |
129
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
43 |
120 | 44 mb_progm_t *tank1_progm; |
129
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
45 |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
46 observer_t *kb_observer; |
115 | 47 }; |
48 | |
49 #define CHANGE_POS(g, x, y) do { \ | |
50 (g)->root_coord->matrix[0] = 1.0; \ | |
51 (g)->root_coord->matrix[2] = x; \ | |
52 (g)->root_coord->matrix[4] = 1.0; \ | |
53 (g)->root_coord->matrix[5] = y; \ | |
54 rdman_coord_changed(rdman, (g)->root_coord); \ | |
55 } while(0) | |
56 | |
129
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
57 static void free_progm_handler(event_t *event, void *arg) { |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
58 tank_rt_t *tank_rt = (tank_rt_t *)arg; |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
59 |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
60 mb_progm_free(tank_rt->tank1_progm); |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
61 tank_rt->tank1_progm = NULL; |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
62 } |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
63 |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
64 static void keyboard_handler(event_t *event, void *arg) { |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
65 X_kb_event_t *xkey = (X_kb_event_t *)event; |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
66 tank_rt_t *tank_rt = (tank_rt_t *)arg; |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
67 redraw_man_t *rdman; |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
68 mb_tman_t *tman; |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
69 mb_word_t *word; |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
70 ob_factory_t *factory; |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
71 subject_t *comp_sub; |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
72 mb_timeval_t start_tm, playing, now; |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
73 |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
74 if(tank_rt->tank1_progm != NULL) |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
75 return; |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
76 |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
77 rdman = X_MB_rdman(tank_rt->mb_rt); |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
78 tman = X_MB_tman(tank_rt->mb_rt); |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
79 |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
80 tank_rt->tank1_progm = mb_progm_new(2, rdman); |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
81 comp_sub = mb_progm_get_complete(tank_rt->tank1_progm); |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
82 factory = rdman_get_ob_factory(rdman); |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
83 subject_add_observer(factory, comp_sub, |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
84 free_progm_handler, |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
85 tank_rt); |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
86 |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
87 MB_TIMEVAL_SET(&start_tm, 0, 0); |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
88 MB_TIMEVAL_SET(&playing, 0, 500000); |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
89 word = mb_progm_next_word(tank_rt->tank1_progm, |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
90 &start_tm, &playing); |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
91 |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
92 switch(xkey->sym) { |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
93 case 0xff51: /* left */ |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
94 mb_shift_new(-50, 0, tank_rt->tank1->root_coord, word); |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
95 break; |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
96 |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
97 case 0xff52: /* up */ |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
98 mb_shift_new(0, -50, tank_rt->tank1->root_coord, word); |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
99 break; |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
100 |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
101 case 0xff53: /* right */ |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
102 mb_shift_new(50, 0, tank_rt->tank1->root_coord, word); |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
103 break; |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
104 |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
105 case 0xff54: /* down */ |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
106 mb_shift_new(0, 50, tank_rt->tank1->root_coord, word); |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
107 break; |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
108 |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
109 case 0x20: /* space */ |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
110 case 0xff0d: /* enter */ |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
111 break; |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
112 } |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
113 get_now(&now); |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
114 mb_progm_start(tank_rt->tank1_progm, tman, &now); |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
115 } |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
116 |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
117 static void init_keyboard(tank_rt_t *tank_rt) { |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
118 X_MB_runtime_t *mb_rt; |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
119 subject_t *kbevents; |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
120 redraw_man_t *rdman; |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
121 ob_factory_t *factory; |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
122 |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
123 mb_rt = tank_rt->mb_rt; |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
124 kbevents = X_MB_kbevents(mb_rt); |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
125 |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
126 rdman = X_MB_rdman(mb_rt); |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
127 factory = rdman_get_ob_factory(rdman); |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
128 |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
129 tank_rt->kb_observer = |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
130 subject_add_observer(factory, kbevents, keyboard_handler, tank_rt); |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
131 } |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
132 |
115 | 133 void |
134 initial_tank(tank_rt_t *tank_rt, X_MB_runtime_t *mb_rt) { | |
135 redraw_man_t *rdman; | |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
136 mb_tman_t *tman; |
115 | 137 mud_t *mud; |
138 brick_t *brick; | |
139 rock_t *rock; | |
140 bush_t *bush; | |
120 | 141 mb_word_t *word; |
142 mb_timeval_t start, playing; | |
143 mb_timeval_t mbtv; | |
129
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
144 subject_t *comp_sub; |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
145 ob_factory_t *factory; |
115 | 146 int i, j; |
147 | |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
148 rdman = X_MB_rdman(mb_rt); |
115 | 149 |
150 tank_rt->mb_rt = mb_rt; | |
151 for(i = 0; i < 12; i++) { | |
152 for(j = 0; j < 16; j++) { | |
153 switch(map[i][j]) { | |
154 case MUD: | |
130
3a4d6179e6a9
change mb_c_source.m4 and mb_c_header.m4 to specify parent for SVG object
Thinker K.F. Li <thinker@branda.to>
parents:
129
diff
changeset
|
155 mud = mud_new(rdman, rdman->root_coord); |
115 | 156 CHANGE_POS(mud, j * 50, i * 50); |
157 tank_rt->map[i][j] = (void *)mud; | |
158 break; | |
159 case BRI: | |
130
3a4d6179e6a9
change mb_c_source.m4 and mb_c_header.m4 to specify parent for SVG object
Thinker K.F. Li <thinker@branda.to>
parents:
129
diff
changeset
|
160 brick = brick_new(rdman, rdman->root_coord); |
115 | 161 CHANGE_POS(brick, j * 50, i * 50); |
162 tank_rt->map[i][j] = (void *)brick; | |
163 break; | |
164 case ROC: | |
130
3a4d6179e6a9
change mb_c_source.m4 and mb_c_header.m4 to specify parent for SVG object
Thinker K.F. Li <thinker@branda.to>
parents:
129
diff
changeset
|
165 rock = rock_new(rdman, rdman->root_coord); |
115 | 166 CHANGE_POS(rock, j * 50, i * 50); |
167 tank_rt->map[i][j] = (void *)rock; | |
168 break; | |
169 case BSH: | |
130
3a4d6179e6a9
change mb_c_source.m4 and mb_c_header.m4 to specify parent for SVG object
Thinker K.F. Li <thinker@branda.to>
parents:
129
diff
changeset
|
170 bush = bush_new(rdman, rdman->root_coord); |
115 | 171 CHANGE_POS(bush, j * 50, i * 50); |
172 tank_rt->map[i][j] = (void *)bush; | |
173 break; | |
174 } | |
175 } | |
176 } | |
177 | |
130
3a4d6179e6a9
change mb_c_source.m4 and mb_c_header.m4 to specify parent for SVG object
Thinker K.F. Li <thinker@branda.to>
parents:
129
diff
changeset
|
178 tank_rt->tank1 = tank1_new(rdman, rdman->root_coord); |
117 | 179 CHANGE_POS(tank_rt->tank1, 5 * 50, 11 * 50); |
130
3a4d6179e6a9
change mb_c_source.m4 and mb_c_header.m4 to specify parent for SVG object
Thinker K.F. Li <thinker@branda.to>
parents:
129
diff
changeset
|
180 tank_rt->tank2 = tank2_new(rdman, rdman->root_coord); |
117 | 181 CHANGE_POS(tank_rt->tank2, 10 * 50, 11 * 50); |
182 for(i = 0; i < 3; i++) { | |
130
3a4d6179e6a9
change mb_c_source.m4 and mb_c_header.m4 to specify parent for SVG object
Thinker K.F. Li <thinker@branda.to>
parents:
129
diff
changeset
|
183 tank_rt->tank_enemies[i] = tank_en_new(rdman, rdman->root_coord); |
117 | 184 CHANGE_POS(tank_rt->tank_enemies[i], (2 + i * 3) * 50, 0); |
185 } | |
186 tank_rt->n_enemy = i; | |
120 | 187 |
188 tank_rt->tank1_progm = mb_progm_new(4, rdman); | |
189 | |
190 MB_TIMEVAL_SET(&start, 1, 0); | |
191 MB_TIMEVAL_SET(&playing, 3, 0); | |
192 word = mb_progm_next_word(tank_rt->tank1_progm, &start, &playing); | |
193 | |
194 mb_shift_new(0, -150, tank_rt->tank1->root_coord, word); | |
195 mb_shift_new(0, -150, tank_rt->tank2->root_coord, word); | |
196 | |
197 MB_TIMEVAL_SET(&start, 5, 0); | |
198 MB_TIMEVAL_SET(&playing, 3, 0); | |
199 word = mb_progm_next_word(tank_rt->tank1_progm, &start, &playing); | |
200 | |
201 mb_shift_new(0, 150, tank_rt->tank1->root_coord, word); | |
202 mb_shift_new(0, 150, tank_rt->tank2->root_coord, word); | |
203 | |
129
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
204 /* Free program after program completed. */ |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
205 comp_sub = mb_progm_get_complete(tank_rt->tank1_progm); |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
206 factory = rdman_get_ob_factory(rdman); |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
207 subject_add_observer(factory, comp_sub, free_progm_handler, tank_rt); |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
208 |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
209 tman = X_MB_tman(mb_rt); |
120 | 210 get_now(&mbtv); |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
211 mb_progm_start(tank_rt->tank1_progm, tman, &mbtv); |
129
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
212 |
ba581d8a4b9b
Now, tank1 can be controlled by user with keyboard
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
213 init_keyboard(tank_rt); |
115 | 214 } |
215 | |
216 int | |
217 main(int argc, char *const argv[]) { | |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
218 X_MB_runtime_t *rt; |
115 | 219 tank_rt_t tank_rt; |
220 | |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
221 rt = X_MB_new(":0.0", 800, 600); |
115 | 222 |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
223 initial_tank(&tank_rt, rt); |
115 | 224 |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
225 X_MB_handle_connection(rt); |
115 | 226 |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
227 X_MB_free(rt); |
115 | 228 } |