Mercurial > hg > Members > e085722 > Cerium
comparison Renderer/Test_/boss1_action.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 | 8f445f1bfe66 |
comparison
equal
deleted
inserted
replaced
3:3f6fe22ac669 | 4:b5b462ac9b3b |
---|---|
1 #include "SceneGraphRoot.h" | |
2 #include "MainLoop.h" | |
3 #include "boss1_action.h" | |
4 | |
5 /* | |
6 static void | |
7 null_move(SceneGraphPtr node, int screen_w, int screen_h) | |
8 { | |
9 } | |
10 */ | |
11 | |
12 static void | |
13 null_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, | |
14 SceneGraphPtr tree) | |
15 { | |
16 } | |
17 | |
18 | |
19 static void | |
20 boss1_move_right(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) { | |
21 node->xyz[0] += node->stack_xyz[0]; | |
22 if(node->xyz[0] > (screen_w - boss_radius_x)) { | |
23 node->set_move_collision(boss1_move_left, null_collision); | |
24 } | |
25 } | |
26 | |
27 //ボスが左に移動する動作 | |
28 static void | |
29 boss1_move_left(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) { | |
30 node->xyz[0] -= node->stack_xyz[0]; | |
31 if(node->xyz[0] < boss_radius_x) { | |
32 node->set_move_collision(boss1_move_right, null_collision); | |
33 } | |
34 } | |
35 | |
36 //ボスが戦闘位置へ戻る時の動作 | |
37 /* | |
38 static void | |
39 boss1_move_return(SceneGraphPtr node, int screen_w, int screen_h) | |
40 { | |
41 node->xyz[1] -= node->stack_xyz[1]; | |
42 node->xyz[2] -= node->stack_xyz[2]; | |
43 | |
44 if((node->xyz[2] = 0)) { | |
45 node->stack_xyz[0] = 1.0; | |
46 node->set_move_collision(boss1_move_left, null_collision); | |
47 } | |
48 } | |
49 */ | |
50 | |
51 //ボス登場時の動き | |
52 /* | |
53 static void | |
54 boss1_first_move(SceneGraphPtr node, int screen_w, int screen_h) | |
55 { | |
56 node->xyz[1] += node->stack_xyz[1]; | |
57 if(node->xyz[1] > screen_h) { | |
58 float time = first_boss1_depth / node->stack_xyz[2]; | |
59 node->stack_xyz[1] = (screen_h - boss_radius_y) / time; | |
60 node->stack_xyz[2] = return_boss1_depth_speed; | |
61 node->set_move_collision(boss1_move_return, null_collision); | |
62 } | |
63 } | |
64 */ | |
65 | |
66 static void | |
67 player_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) | |
68 { | |
69 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; | |
70 Pad *pad = sgroot->getController(); | |
71 | |
72 if (pad->left.isPush() | |
73 || pad->left.isHold()) { | |
74 #if 0 | |
75 SceneGraphPtr player_left; | |
76 player_left = sgroot->createSceneGraph(PLAYER_L); | |
77 player_left->set_move_collision(player_move_left, null_collision); | |
78 player_left->xyz[0] = node->xyz[0]; | |
79 player_left->xyz[1] = node->xyz[1]; | |
80 node->addChild(player_left); | |
81 node->flag_drawable = 1; | |
82 #endif | |
83 node->xyz[0] -= player_speed; | |
84 | |
85 if (node->xyz[0] - player_radius< 0) { | |
86 node->xyz[0] = player_radius; | |
87 } | |
88 } | |
89 | |
90 | |
91 if (pad->right.isPush() | |
92 || pad->right.isHold()) { | |
93 node->xyz[0] += player_speed; | |
94 | |
95 if (node->xyz[0] + player_radius > screen_w) { | |
96 node->xyz[0] = screen_w - player_radius; | |
97 } | |
98 } | |
99 | |
100 if (pad->up.isPush() | |
101 || pad->up.isHold()) { | |
102 node->xyz[1] -= player_speed; | |
103 | |
104 if (node->xyz[1] - player_radius < 0) { | |
105 node->xyz[1] = player_radius; | |
106 } | |
107 } | |
108 | |
109 if (pad->down.isPush() | |
110 || pad->down.isHold()) { | |
111 node->xyz[1] += player_speed; | |
112 | |
113 if (node->xyz[1] + player_radius > screen_h) { | |
114 node->xyz[1] = screen_h - player_radius; | |
115 } | |
116 } | |
117 | |
118 if (pad->circle.isPush()) { | |
119 SceneGraphPtr shot = sgroot->createSceneGraph("P_SHOT1"); | |
120 shot->set_move_collision(shot_move, shot_collision); | |
121 shot->xyz[0] = node->xyz[0]; | |
122 shot->xyz[1] = node->xyz[1] - player_radius; | |
123 node->addBrother(shot); | |
124 } | |
125 } | |
126 | |
127 static int boss1sgid; | |
128 | |
129 static void | |
130 player_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, | |
131 SceneGraphPtr tree) | |
132 { | |
133 | |
134 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; | |
135 //自機とボスのx,y座標での距離と2点間の距離 | |
136 static float x_distant, y_distant, distance; | |
137 //ボスの四角形の四隅の座標 | |
138 // static float boss_low_x, boss_low_y, boss_high_x, boss_high_y; | |
139 | |
140 SceneGraphIteratorPtr it = sgroot->getIterator(tree); | |
141 | |
142 | |
143 for (; it->hasNext(boss1sgid);) { | |
144 it->next(boss1sgid); | |
145 SceneGraphPtr enemy = it->get(); | |
146 | |
147 //各変数の初期化 | |
148 x_distant = node->xyz[0] - enemy->xyz[0]; | |
149 y_distant = node->xyz[1] - enemy->xyz[1]; | |
150 | |
151 //hypotfで2点間の距離を求める | |
152 distance = hypotf(x_distant, y_distant); | |
153 | |
154 /*四角形と円のcollision | |
155 if( (fabs( node->xyz[1] - ( boss_low_y ))) | |
156 */ | |
157 | |
158 //円同士のcollision | |
159 if(distance < (player_radius + boss_radius_y)) { | |
160 printf("!!!CAUTION!!!\n"); | |
161 } | |
162 } | |
163 } | |
164 | |
165 static void | |
166 shot_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) | |
167 { | |
168 node->xyz[1] -= shot_speed; | |
169 | |
170 // 描画領域から抜けたら削除 | |
171 if (node->xyz[1] < 0) { | |
172 node->remove(); | |
173 } | |
174 } | |
175 | |
176 static void | |
177 shot_collision(SceneGraphPtr node, void *sgroot_, int screen_2, int screen_h, | |
178 SceneGraphPtr tree) | |
179 { | |
180 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; | |
181 //自機とボスのx,y座標での距離と2点間の距離 | |
182 static float x_distant, y_distant, distance; | |
183 //ボスの四角形の四隅の座標 | |
184 // static float boss_low_x, boss_low_y, boss_high_x, boss_high_y; | |
185 | |
186 SceneGraphIteratorPtr it = sgroot->getIterator(tree); | |
187 | |
188 | |
189 for (; it->hasNext(boss1sgid);) { | |
190 it->next(boss1sgid); | |
191 SceneGraphPtr enemy = it->get(); | |
192 | |
193 x_distant = node->xyz[0] - enemy->xyz[0]; | |
194 y_distant = node->xyz[1] - enemy->xyz[1]; | |
195 | |
196 //hypotfで2点間の距離を求める | |
197 distance = hypotf(x_distant, y_distant); | |
198 | |
199 //円同士のcollision | |
200 if(distance < boss_radius_y) { | |
201 SceneGraphPtr blast = sgroot->createSceneGraph("BLAST1"); | |
202 | |
203 blast->set_move_collision(blast_move, null_collision); | |
204 blast->xyz[0] = node->xyz[0]; | |
205 blast->xyz[1] = node->xyz[1]; | |
206 node->addBrother(blast); | |
207 node->remove(); | |
208 } | |
209 } | |
210 } | |
211 | |
212 extern Application * | |
213 application() { | |
214 return new boss1_action(); | |
215 } | |
216 | |
217 const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n"; | |
218 | |
219 static int blast8; | |
220 | |
221 static void | |
222 blast_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) | |
223 { | |
224 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; | |
225 | |
226 if(node->sgid > blast8) { | |
227 SceneGraphPtr blast = sgroot->createSceneGraph(node->sgid - 1); | |
228 blast->set_move_collision(blast_move, null_collision); | |
229 blast->xyz[0] = node->xyz[0]; | |
230 blast->xyz[1] = node->xyz[1]; | |
231 node->addBrother(blast); | |
232 } | |
233 | |
234 if (node->sgid == blast8) { | |
235 node->flag_drawable = 1; | |
236 } | |
237 | |
238 if((node->frame > 1)) { | |
239 node->remove(); | |
240 } | |
241 node->frame += 1; | |
242 } | |
243 | |
244 MainLoopPtr | |
245 boss1_action::init(Viewer *sgroot, int screen_w, int screen_h) | |
246 { | |
247 | |
248 sgroot->createFromXMLfile("xml_file/boss1.xml"); | |
249 sgroot->createFromXMLfile("xml_file/player1.xml"); | |
250 sgroot->createFromXMLfile("xml_file/p_shot.xml"); | |
251 sgroot->createFromXMLfile("xml_file/blast.xml"); | |
252 | |
253 blast8 = sgroot->getSgid("BLAST8"); | |
254 | |
255 //rootとなるSceneGraphを生成 | |
256 SceneGraphPtr root = sgroot->createSceneGraph(); | |
257 | |
258 //自機の初期化 | |
259 SceneGraphPtr player = sgroot->createSceneGraph("PLAYER"); | |
260 player->xyz[0] = screen_w/2; | |
261 player->xyz[1] = screen_h - player_radius; | |
262 root->addChild(player); | |
263 | |
264 //ボスの初期化 | |
265 SceneGraphPtr boss1 = sgroot->createSceneGraph("BOSS1"); | |
266 boss1sgid = boss1->sgid; | |
267 | |
268 boss1->xyz[0] = screen_w/2; | |
269 boss1->xyz[1] = boss_radius_y; | |
270 // boss1->xyz[2] = first_boss1_depth; | |
271 boss1->stack_xyz[0] = first_boss1_speed; | |
272 root->addChild(boss1); | |
273 | |
274 //ボスの左右パーツを追加 | |
275 SceneGraphPtr left_parts = sgroot->createSceneGraph("BOSS1_L"); | |
276 boss1->addChild(left_parts); | |
277 SceneGraphPtr right_parts = sgroot->createSceneGraph("BOSS1_R"); | |
278 boss1->addChild(right_parts); | |
279 | |
280 //各機体の動きと当たり判定をセット | |
281 player->set_move_collision(player_move, player_collision); | |
282 boss1->set_move_collision(boss1_move_left, null_collision); | |
283 | |
284 //仕上げ | |
285 sgroot->setSceneData(root); | |
286 return sgroot; | |
287 } | |
288 | |
289 extern int init(TaskManager *manager, int argc, char *argv[]); | |
290 extern void task_initialize(); | |
291 static void TMend(TaskManager *manager); | |
292 | |
293 int | |
294 TMmain(TaskManager *manager, int argc, char *argv[]) | |
295 { | |
296 task_initialize(); | |
297 manager->set_TMend(TMend); | |
298 return init(manager, argc, argv); | |
299 | |
300 } | |
301 | |
302 void | |
303 TMend(TaskManager *manager) | |
304 { | |
305 printf("test_nogl end\n"); | |
306 } | |
307 | |
308 |