annotate examples/tank/tank_main.c @ 115:3895d2224e67

Tank
author Thinker K.F. Li <thinker@branda.to>
date Sun, 14 Sep 2008 02:17:57 +0800
parents
children e4e47d2cdbcd
rev   line source
115
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 #include <mb/mb.h>
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
2 #include "svgs.h"
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 enum { MUD, ROC, BRI, BSH };
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6 static char map[12][16] = {
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7 { MUD, MUD, MUD, MUD, MUD, MUD, MUD, MUD,
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, ROC, ROC, ROC, MUD, BSH, BSH, ROC,
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10 BSH, ROC, MUD, BSH, BSH, ROC, ROC, MUD},
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11 { MUD, MUD, BRI, MUD, MUD, MUD, MUD, MUD,
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
12 MUD, MUD, MUD, BRI, MUD, MUD, BSH, MUD},
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
13 { BRI, MUD, MUD, MUD, MUD, MUD, BRI, MUD,
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
14 BRI, MUD, MUD, MUD, MUD, MUD, MUD, MUD},
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15 { MUD, MUD, BRI, MUD, BRI, BSH, BRI, BRI,
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16 BRI, BRI, BSH, ROC, ROC, MUD, BRI, MUD},
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17 { MUD, BRI, BRI, MUD, BRI, MUD, BRI, MUD,
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18 ROC, MUD, MUD, MUD, MUD, MUD, MUD, MUD},
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 { MUD, MUD, MUD, MUD, MUD, MUD, MUD, MUD,
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20 MUD, MUD, MUD, BRI, BRI, BRI, BRI, MUD},
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21 { MUD, BRI, MUD, BRI, BRI, MUD, BRI, BRI,
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 BSH, BRI, MUD, MUD, MUD, MUD, MUD, MUD},
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 { MUD, BRI, MUD, MUD, MUD, MUD, MUD, MUD,
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24 MUD, MUD, MUD, BRI, BRI, MUD, BRI, BRI},
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25 { MUD, BRI, MUD, BRI, BRI, MUD, BRI, BRI,
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26 BRI, BRI, MUD, BRI, MUD, MUD, MUD, MUD},
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 { MUD, BSH, MUD, BRI, MUD, MUD, BRI, MUD,
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 MUD, BRI, MUD, MUD, MUD, BRI, BRI, MUD},
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 { MUD, MUD, MUD, MUD, MUD, MUD, BRI, MUD,
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30 MUD, BRI, MUD, BRI, MUD, MUD, MUD, MUD}
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31 };
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
32
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
33 typedef struct _tank_rt tank_rt_t;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35 struct _tank_rt {
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36 tank1_t *tank1;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 tank2_t *tank2;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38 tank_en_t *tank_en;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39 void *map[12][16];
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
40 X_MB_runtime_t *mb_rt;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 };
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43 #define CHANGE_POS(g, x, y) do { \
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 (g)->root_coord->matrix[0] = 1.0; \
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45 (g)->root_coord->matrix[2] = x; \
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 (g)->root_coord->matrix[4] = 1.0; \
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47 (g)->root_coord->matrix[5] = y; \
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48 rdman_coord_changed(rdman, (g)->root_coord); \
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
49 } while(0)
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51 void
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
52 initial_tank(tank_rt_t *tank_rt, X_MB_runtime_t *mb_rt) {
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
53 redraw_man_t *rdman;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54 mud_t *mud;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
55 brick_t *brick;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
56 rock_t *rock;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
57 bush_t *bush;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
58 int i, j;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
60 rdman = mb_rt->rdman;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
61
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
62 tank_rt->mb_rt = mb_rt;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
63 for(i = 0; i < 12; i++) {
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
64 for(j = 0; j < 16; j++) {
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
65 switch(map[i][j]) {
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
66 case MUD:
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
67 mud = mud_new(rdman);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
68 CHANGE_POS(mud, j * 50, i * 50);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
69 tank_rt->map[i][j] = (void *)mud;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
70 break;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
71 case BRI:
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
72 brick = brick_new(rdman);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
73 CHANGE_POS(brick, j * 50, i * 50);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
74 tank_rt->map[i][j] = (void *)brick;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
75 break;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
76 case ROC:
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
77 rock = rock_new(rdman);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
78 CHANGE_POS(rock, j * 50, i * 50);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
79 tank_rt->map[i][j] = (void *)rock;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
80 break;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
81 case BSH:
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
82 bush = bush_new(rdman);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
83 CHANGE_POS(bush, j * 50, i * 50);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
84 tank_rt->map[i][j] = (void *)bush;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
85 break;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
86 }
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
87 }
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
88 }
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
89
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
90 tank_rt->tank1 = tank1_new(rdman);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
91 tank_rt->tank2 = tank2_new(rdman);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
92 CHANGE_POS(tank_rt->tank2, 50, 0);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
93 tank_rt->tank_en = tank_en_new(rdman);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
94 CHANGE_POS(tank_rt->tank_en, 100, 0);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
95 }
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
96
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
97 int
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
98 main(int argc, char *const argv[]) {
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
99 X_MB_runtime_t rt;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
100 tank_rt_t tank_rt;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
101
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
102 X_MB_init(":0.0", 800, 600, &rt);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
103
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
104 initial_tank(&tank_rt, &rt);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
105
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
106 X_MB_handle_connection(&rt);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
107
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
108 X_MB_destroy(&rt);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
109 }