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