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
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 117
diff changeset
1 #include <sys/time.h>
115
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
2 #include <mb/mb.h>
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 #include "svgs.h"
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5 enum { MUD, ROC, BRI, BSH };
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7 static char map[12][16] = {
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8 { MUD, MUD, MUD, MUD, MUD, MUD, MUD, MUD,
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
9 MUD, MUD, MUD, MUD, MUD, MUD, MUD, MUD},
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10 { MUD, ROC, ROC, ROC, MUD, BSH, BSH, ROC,
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11 BSH, ROC, MUD, BSH, BSH, ROC, ROC, MUD},
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
12 { MUD, MUD, BRI, MUD, MUD, MUD, MUD, MUD,
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
13 MUD, MUD, MUD, BRI, MUD, MUD, BSH, MUD},
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
14 { BRI, MUD, MUD, MUD, MUD, MUD, BRI, MUD,
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15 BRI, MUD, MUD, MUD, MUD, MUD, MUD, MUD},
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16 { MUD, MUD, BRI, MUD, BRI, BSH, BRI, BRI,
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17 BRI, BRI, BSH, ROC, ROC, MUD, BRI, MUD},
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18 { MUD, BRI, BRI, MUD, BRI, MUD, BRI, MUD,
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 ROC, MUD, MUD, MUD, MUD, MUD, MUD, MUD},
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20 { MUD, MUD, MUD, MUD, MUD, MUD, MUD, MUD,
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21 MUD, MUD, MUD, BRI, BRI, BRI, BRI, MUD},
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 { MUD, BRI, MUD, BRI, BRI, MUD, BRI, BRI,
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 BSH, BRI, MUD, MUD, MUD, MUD, MUD, MUD},
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24 { MUD, BRI, MUD, MUD, MUD, MUD, MUD, MUD,
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25 MUD, MUD, MUD, BRI, BRI, MUD, BRI, BRI},
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26 { MUD, BRI, MUD, BRI, BRI, MUD, BRI, BRI,
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 BRI, BRI, MUD, BRI, MUD, MUD, MUD, MUD},
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 { MUD, BSH, MUD, BRI, MUD, MUD, BRI, MUD,
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 MUD, BRI, MUD, MUD, MUD, BRI, BRI, MUD},
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30 { MUD, MUD, MUD, MUD, MUD, MUD, BRI, MUD,
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31 MUD, BRI, MUD, BRI, MUD, MUD, MUD, MUD}
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
32 };
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
33
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 typedef struct _tank_rt tank_rt_t;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36 struct _tank_rt {
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 tank1_t *tank1;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38 tank2_t *tank2;
117
Thinker K.F. Li <thinker@branda.to>
parents: 115
diff changeset
39 int n_enemy;
Thinker K.F. Li <thinker@branda.to>
parents: 115
diff changeset
40 tank_en_t *tank_enemies[10];
115
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 void *map[12][16];
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
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
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 117
diff changeset
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
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47 };
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
49 #define CHANGE_POS(g, x, y) do { \
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50 (g)->root_coord->matrix[0] = 1.0; \
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51 (g)->root_coord->matrix[2] = x; \
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
52 (g)->root_coord->matrix[4] = 1.0; \
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
53 (g)->root_coord->matrix[5] = y; \
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54 rdman_coord_changed(rdman, (g)->root_coord); \
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
55 } while(0)
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
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
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
133 void
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
134 initial_tank(tank_rt_t *tank_rt, X_MB_runtime_t *mb_rt) {
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
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
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
137 mud_t *mud;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
138 brick_t *brick;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
139 rock_t *rock;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
140 bush_t *bush;
120
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 117
diff changeset
141 mb_word_t *word;
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 117
diff changeset
142 mb_timeval_t start, playing;
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 117
diff changeset
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
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
146 int i, j;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
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
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
149
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
150 tank_rt->mb_rt = mb_rt;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
151 for(i = 0; i < 12; i++) {
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
152 for(j = 0; j < 16; j++) {
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
153 switch(map[i][j]) {
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
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
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
156 CHANGE_POS(mud, j * 50, i * 50);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
157 tank_rt->map[i][j] = (void *)mud;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
158 break;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
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
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
161 CHANGE_POS(brick, j * 50, i * 50);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
162 tank_rt->map[i][j] = (void *)brick;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
163 break;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
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
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
166 CHANGE_POS(rock, j * 50, i * 50);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
167 tank_rt->map[i][j] = (void *)rock;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
168 break;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
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
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
171 CHANGE_POS(bush, j * 50, i * 50);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
172 tank_rt->map[i][j] = (void *)bush;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
173 break;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
174 }
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
175 }
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
176 }
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
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
Thinker K.F. Li <thinker@branda.to>
parents: 115
diff changeset
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
Thinker K.F. Li <thinker@branda.to>
parents: 115
diff changeset
181 CHANGE_POS(tank_rt->tank2, 10 * 50, 11 * 50);
Thinker K.F. Li <thinker@branda.to>
parents: 115
diff changeset
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
Thinker K.F. Li <thinker@branda.to>
parents: 115
diff changeset
184 CHANGE_POS(tank_rt->tank_enemies[i], (2 + i * 3) * 50, 0);
Thinker K.F. Li <thinker@branda.to>
parents: 115
diff changeset
185 }
Thinker K.F. Li <thinker@branda.to>
parents: 115
diff changeset
186 tank_rt->n_enemy = i;
120
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 117
diff changeset
187
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 117
diff changeset
188 tank_rt->tank1_progm = mb_progm_new(4, rdman);
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 117
diff changeset
189
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 117
diff changeset
190 MB_TIMEVAL_SET(&start, 1, 0);
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 117
diff changeset
191 MB_TIMEVAL_SET(&playing, 3, 0);
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 117
diff changeset
192 word = mb_progm_next_word(tank_rt->tank1_progm, &start, &playing);
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 117
diff changeset
193
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 117
diff changeset
194 mb_shift_new(0, -150, tank_rt->tank1->root_coord, word);
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 117
diff changeset
195 mb_shift_new(0, -150, tank_rt->tank2->root_coord, word);
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 117
diff changeset
196
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 117
diff changeset
197 MB_TIMEVAL_SET(&start, 5, 0);
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 117
diff changeset
198 MB_TIMEVAL_SET(&playing, 3, 0);
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 117
diff changeset
199 word = mb_progm_next_word(tank_rt->tank1_progm, &start, &playing);
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 117
diff changeset
200
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 117
diff changeset
201 mb_shift_new(0, 150, tank_rt->tank1->root_coord, word);
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 117
diff changeset
202 mb_shift_new(0, 150, tank_rt->tank2->root_coord, word);
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 117
diff changeset
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
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 117
diff changeset
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
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
214 }
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
215
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
216 int
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
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
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
219 tank_rt_t tank_rt;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
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
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
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
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
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
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
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
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
228 }