Mercurial > hg > Members > e085722 > Cerium
comparison Renderer/Test_/ieshoot.cc @ 4:b5b462ac9b3b
Cerium Blender ball_bound
author | Daiki KINJYO <e085722@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 29 Nov 2010 16:42:42 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3:3f6fe22ac669 | 4:b5b462ac9b3b |
---|---|
1 #include "SceneGraphRoot.h" | |
2 #include "ieshoot.h" | |
3 | |
4 static const float jiki_speed = 6.0f; | |
5 static const float jiki_radius = 32.0f; | |
6 | |
7 static const float tama_speed = 10.0f; | |
8 static const float tama_radius = 16.0f; | |
9 | |
10 static const float boss_radius_x = 64.0f; | |
11 static const float boss_radius_y = 128.0f; | |
12 | |
13 static const float iebosstama_speed = 15.0f; | |
14 | |
15 static void | |
16 ieboss_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, | |
17 SceneGraphPtr tree); | |
18 static void | |
19 ieboss_collision_invincibil(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, SceneGraphPtr tree); | |
20 static void ieboss_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h); | |
21 | |
22 static void iebosstama_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h); | |
23 | |
24 | |
25 static void | |
26 iejiki_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, | |
27 SceneGraphPtr tree) | |
28 { | |
29 } | |
30 | |
31 static void | |
32 ietama_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, | |
33 SceneGraphPtr tree) | |
34 { | |
35 } | |
36 | |
37 static void | |
38 ieboss_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, | |
39 SceneGraphPtr tree) | |
40 { | |
41 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; | |
42 SceneGraphIteratorPtr it = sgroot->getIterator(tree); | |
43 static int damage = 0; | |
44 int ietama = sgroot->getSgid("IETAMA"); | |
45 for (; it->hasNext(ietama);) { | |
46 it->next(ietama); | |
47 SceneGraphPtr tama = it->get(); | |
48 | |
49 if (node->xyz[0] - boss_radius_x < tama->xyz[0] + tama_radius | |
50 && node->xyz[0] + boss_radius_x > tama->xyz[0] - tama_radius | |
51 && node->xyz[1] + boss_radius_y > tama->xyz[1] - tama_radius) { | |
52 tama->remove(); | |
53 | |
54 node->set_move_collision(ieboss_move, ieboss_collision_invincibil); | |
55 | |
56 SceneGraphPtr iebosstama = sgroot->createSceneGraph("Earth"); | |
57 iebosstama->set_move_collision(iebosstama_move, ietama_collision); | |
58 iebosstama->xyz[0] = node->xyz[0]; | |
59 iebosstama->xyz[1] = node->xyz[1] + boss_radius_y; | |
60 //iebosstama->xyz[2] = 50.0f; | |
61 node->addBrother(iebosstama); | |
62 | |
63 damage++; | |
64 } | |
65 } | |
66 | |
67 if (damage > 10) { | |
68 node->remove(); | |
69 } | |
70 } | |
71 | |
72 static void | |
73 ieboss_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) | |
74 { | |
75 /** | |
76 * TODO | |
77 * Boss が複数居た場合、これじゃ駄目 | |
78 */ | |
79 static float x_speed = 5.0f; | |
80 static float z_speed = 5.0f; | |
81 | |
82 node->xyz[0] += x_speed; | |
83 | |
84 if (node->xyz[0] - boss_radius_x < 0) { | |
85 x_speed = -x_speed; | |
86 node->xyz[0] = boss_radius_x; | |
87 } else if (node->xyz[0] + boss_radius_x > screen_w) { | |
88 x_speed = -x_speed; | |
89 node->xyz[0] = screen_w - boss_radius_x; | |
90 } | |
91 | |
92 //node->xyz[2] += z_speed; | |
93 if (node->xyz[2] >= 100.0f) { | |
94 node->xyz[2] = 99.99f; | |
95 z_speed = -z_speed; | |
96 } else if (node->xyz[2] <= -100.0f) { | |
97 node->xyz[2] = -99.99f; | |
98 z_speed = -z_speed; | |
99 } | |
100 } | |
101 | |
102 static void | |
103 ieboss_collision_invincibil(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, | |
104 SceneGraphPtr tree) | |
105 { | |
106 static int frame = 0; | |
107 | |
108 frame++; | |
109 | |
110 node->flag_drawable ^= 1; | |
111 | |
112 if (frame > 60) { | |
113 frame = 0; | |
114 node->flag_drawable = 1; | |
115 node->set_move_collision(ieboss_move, ieboss_collision); | |
116 } | |
117 } | |
118 | |
119 static void | |
120 iebosstama_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) | |
121 { | |
122 node->xyz[1] += iebosstama_speed; | |
123 | |
124 // 描画領域から抜けたら削除 | |
125 if (node->xyz[1] > screen_h) { | |
126 node->remove(); | |
127 } | |
128 } | |
129 | |
130 static void | |
131 ietama_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) | |
132 { | |
133 node->xyz[1] -= tama_speed; | |
134 | |
135 // 描画領域から抜けたら削除 | |
136 if (node->xyz[1] < 0) { | |
137 node->remove(); | |
138 } | |
139 } | |
140 | |
141 static void | |
142 iejiki_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) | |
143 { | |
144 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; | |
145 Pad *pad = sgroot->getController(); | |
146 | |
147 if (pad->left.isPush() | |
148 || pad->left.isHold()) { | |
149 node->xyz[0] -= jiki_speed; | |
150 | |
151 if (node->xyz[0] - jiki_radius< 0) { | |
152 node->xyz[0] = jiki_radius; | |
153 } | |
154 } | |
155 | |
156 if (pad->right.isPush() | |
157 || pad->right.isHold()) { | |
158 node->xyz[0] += jiki_speed; | |
159 | |
160 if (node->xyz[0] + jiki_radius > screen_w) { | |
161 node->xyz[0] = screen_w - jiki_radius; | |
162 } | |
163 } | |
164 | |
165 if (pad->up.isPush() | |
166 || pad->up.isHold()) { | |
167 node->xyz[1] -= jiki_speed; | |
168 | |
169 if (node->xyz[1] - jiki_radius < 0) { | |
170 node->xyz[1] = jiki_radius; | |
171 } | |
172 } | |
173 | |
174 if (pad->down.isPush() | |
175 || pad->down.isHold()) { | |
176 node->xyz[1] += jiki_speed; | |
177 | |
178 if (node->xyz[1] + jiki_radius > screen_h) { | |
179 node->xyz[1] = screen_h - jiki_radius; | |
180 } | |
181 } | |
182 | |
183 if (pad->circle.isPush()) { | |
184 SceneGraphPtr ietama = sgroot->createSceneGraph("IETAMA"); | |
185 ietama->set_move_collision(ietama_move, ietama_collision); | |
186 ietama->xyz[0] = node->xyz[0]; | |
187 ietama->xyz[1] = node->xyz[1]; | |
188 node->addBrother(ietama); | |
189 } | |
190 } | |
191 | |
192 | |
193 MainLoopPtr | |
194 ieshoot::init(Viewer *sgroot, int w, int h) | |
195 { | |
196 SceneGraphPtr iejiki; | |
197 SceneGraphPtr enemy; | |
198 SceneGraphPtr back; | |
199 | |
200 sgroot->createFromXMLfile( "xml_file/ietama.xml"); | |
201 sgroot->createFromXMLfile( "xml_file/ieboss.xml"); | |
202 sgroot->createFromXMLfile( "xml_file/iejiki.xml"); | |
203 sgroot->createFromXMLfile( "xml_file/universe.xml"); | |
204 | |
205 back = sgroot->createSceneGraph(); | |
206 | |
207 iejiki = sgroot->createSceneGraph("IEJIKI"); | |
208 iejiki->set_move_collision(iejiki_move, iejiki_collision); | |
209 iejiki->xyz[2] = 20; | |
210 back->addChild(iejiki); | |
211 | |
212 enemy = sgroot->createSceneGraph("IEBOSS"); | |
213 enemy->set_move_collision(ieboss_move, ieboss_collision); | |
214 enemy->xyz[1] = boss_radius_y; | |
215 back->addChild(enemy); | |
216 | |
217 sgroot->setSceneData(back); | |
218 return sgroot; | |
219 } | |
220 | |
221 extern Application * | |
222 application() { | |
223 return new ieshoot(); | |
224 } | |
225 | |
226 const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n"; | |
227 | |
228 extern int init(TaskManager *manager, int argc, char *argv[]); | |
229 extern void task_initialize(); | |
230 static void TMend(TaskManager *manager); | |
231 | |
232 int | |
233 TMmain(TaskManager *manager, int argc, char *argv[]) | |
234 { | |
235 task_initialize(); | |
236 manager->set_TMend(TMend); | |
237 return init(manager, argc, argv); | |
238 | |
239 } | |
240 | |
241 void | |
242 TMend(TaskManager *manager) | |
243 { | |
244 printf("test_nogl end\n"); | |
245 } | |
246 |