Mercurial > hg > Members > kono > Cerium
annotate Renderer/Test/boss1_action.cc @ 558:b05bae017029
boss1_action
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 22 Oct 2009 18:38:07 +0900 |
parents | ec72b601b71f |
children | a5fda4e51498 |
rev | line source |
---|---|
557
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
1 #include "SceneGraphRoot.h" |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
2 #include "MainLoop.h" |
507 | 3 #include "boss1_action.h" |
558 | 4 #include "xml_file/boss1.xml.h" |
507 | 5 |
6 /* | |
7 static void | |
8 null_move(SceneGraphPtr node, int screen_w, int screen_h) | |
9 { | |
10 } | |
11 */ | |
12 | |
13 static void | |
14 null_collision(SceneGraphPtr node, int screen_w, int screen_h, | |
15 SceneGraphPtr tree) | |
16 { | |
17 } | |
18 | |
19 | |
20 static void | |
21 boss1_move_right(SceneGraphPtr node, int screen_w, int screen_h) { | |
22 node->xyz[0] += node->stack_xyz[0]; | |
23 if(node->xyz[0] > (screen_w - boss_radius_x)) { | |
24 node->set_move_collision(boss1_move_left, null_collision); | |
25 } | |
26 } | |
27 | |
28 //ボスが左に移動する動作 | |
29 static void | |
30 boss1_move_left(SceneGraphPtr node, int screen_w, int screen_h) { | |
31 node->xyz[0] -= node->stack_xyz[0]; | |
32 if(node->xyz[0] < boss_radius_x) { | |
33 node->set_move_collision(boss1_move_right, null_collision); | |
34 } | |
35 } | |
36 | |
37 //ボスが戦闘位置へ戻る時の動作 | |
38 /* | |
39 static void | |
40 boss1_move_return(SceneGraphPtr node, int screen_w, int screen_h) | |
41 { | |
42 node->xyz[1] -= node->stack_xyz[1]; | |
43 node->xyz[2] -= node->stack_xyz[2]; | |
44 | |
45 if((node->xyz[2] = 0)) { | |
46 node->stack_xyz[0] = 1.0; | |
47 node->set_move_collision(boss1_move_left, null_collision); | |
48 } | |
49 } | |
50 */ | |
51 | |
52 //ボス登場時の動き | |
53 /* | |
54 static void | |
55 boss1_first_move(SceneGraphPtr node, int screen_w, int screen_h) | |
56 { | |
57 node->xyz[1] += node->stack_xyz[1]; | |
58 if(node->xyz[1] > screen_h) { | |
59 float time = first_boss1_depth / node->stack_xyz[2]; | |
60 node->stack_xyz[1] = (screen_h - boss_radius_y) / time; | |
61 node->stack_xyz[2] = return_boss1_depth_speed; | |
62 node->set_move_collision(boss1_move_return, null_collision); | |
63 } | |
64 } | |
65 */ | |
66 | |
67 static void | |
68 player_move(SceneGraphPtr node, int screen_w, int screen_h) | |
69 { | |
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 void | |
128 player_collision(SceneGraphPtr node, int screen_w, int screen_h, | |
129 SceneGraphPtr tree) | |
130 { | |
131 //自機とボスのx,y座標での距離と2点間の距離 | |
132 static float x_distant, y_distant, distance; | |
133 //ボスの四角形の四隅の座標 | |
134 // static float boss_low_x, boss_low_y, boss_high_x, boss_high_y; | |
135 | |
136 SceneGraphIteratorPtr it = sgroot->getIterator(tree); | |
137 | |
138 | |
139 for (; it->hasNext(BOSS1);) { | |
140 it->next(BOSS1); | |
141 SceneGraphPtr enemy = it->get(); | |
142 | |
143 //各変数の初期化 | |
144 x_distant = node->xyz[0] - enemy->xyz[0]; | |
145 y_distant = node->xyz[1] - enemy->xyz[1]; | |
146 | |
147 //hypotfで2点間の距離を求める | |
148 distance = hypotf(x_distant, y_distant); | |
149 | |
150 /*四角形と円のcollision | |
151 if( (fabs( node->xyz[1] - ( boss_low_y ))) | |
152 */ | |
153 | |
154 //円同士のcollision | |
155 if(distance < (player_radius + boss_radius_y)) { | |
156 printf("!!!CAUTION!!!\n"); | |
157 } | |
158 } | |
159 } | |
160 | |
161 static void | |
162 shot_move(SceneGraphPtr node, int screen_w, int screen_h) | |
163 { | |
164 node->xyz[1] -= shot_speed; | |
165 | |
166 // 描画領域から抜けたら削除 | |
167 if (node->xyz[1] < 0) { | |
168 node->remove(); | |
169 } | |
170 } | |
171 | |
172 static void | |
173 shot_collision(SceneGraphPtr node, int screen_2, int screen_h, | |
174 SceneGraphPtr tree) | |
175 { | |
176 //自機とボスのx,y座標での距離と2点間の距離 | |
177 static float x_distant, y_distant, distance; | |
178 //ボスの四角形の四隅の座標 | |
179 // static float boss_low_x, boss_low_y, boss_high_x, boss_high_y; | |
180 | |
181 SceneGraphIteratorPtr it = sgroot->getIterator(tree); | |
182 | |
183 | |
184 for (; it->hasNext(BOSS1);) { | |
185 it->next(BOSS1); | |
186 SceneGraphPtr enemy = it->get(); | |
187 | |
188 x_distant = node->xyz[0] - enemy->xyz[0]; | |
189 y_distant = node->xyz[1] - enemy->xyz[1]; | |
190 | |
191 //hypotfで2点間の距離を求める | |
192 distance = hypotf(x_distant, y_distant); | |
193 | |
194 //円同士のcollision | |
195 if(distance < boss_radius_y) { | |
196 SceneGraphPtr blast = sgroot->createSceneGraph(BLAST1); | |
197 | |
198 blast->set_move_collision(blast_move, null_collision); | |
199 blast->xyz[0] = node->xyz[0]; | |
200 blast->xyz[1] = node->xyz[1]; | |
201 node->addBrother(blast); | |
202 node->remove(); | |
203 } | |
204 } | |
205 } | |
206 | |
557
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
207 extern Application * |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
208 application() { |
558 | 209 return new boss1_action(); |
557
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
210 } |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
211 |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
212 const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n"; |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
213 |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
214 |
507 | 215 static void |
216 blast_move(SceneGraphPtr node, int screen_w, int screen_h) | |
217 { | |
218 if(node->sgid > BLAST8) { | |
219 SceneGraphPtr blast = sgroot->createSceneGraph(node->sgid - 1); | |
220 blast->set_move_collision(blast_move, null_collision); | |
221 blast->xyz[0] = node->xyz[0]; | |
222 blast->xyz[1] = node->xyz[1]; | |
223 node->addBrother(blast); | |
224 } | |
225 | |
226 if (node->sgid == BLAST8) { | |
227 node->flag_drawable = 1; | |
228 } | |
229 | |
230 if((node->frame > 1)) { | |
231 node->remove(); | |
232 } | |
233 node->frame += 1; | |
234 } | |
235 | |
557
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
236 MainLoopPtr |
558 | 237 boss1_action::init(Viewer *sgroot, int screen_w, int screen_h) |
507 | 238 { |
239 | |
558 | 240 sgroot->createFromXMLfile("xml_file/boss1.xml"); |
241 sgroot->createFromXMLfile("xml_file/player1.xml"); | |
242 sgroot->createFromXMLfile("xml_file/p_shot.xml"); | |
243 sgroot->createFromXMLfile("xml_file/blast.xml"); | |
507 | 244 |
245 //rootとなるSceneGraphを生成 | |
557
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
246 SceneGraphPtr root = sgroot->createSceneGraph(); |
507 | 247 |
248 //自機の初期化 | |
557
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
249 SceneGraphPtr player = sgroot->createSceneGraph(PLAYER); |
507 | 250 player->xyz[0] = screen_w/2; |
251 player->xyz[1] = screen_h - player_radius; | |
252 root->addChild(player); | |
253 | |
254 //ボスの初期化 | |
557
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
255 SceneGraphPtr boss1 = sgroot->createSceneGraph(BOSS1); |
507 | 256 boss1->xyz[0] = screen_w/2; |
257 boss1->xyz[1] = boss_radius_y; | |
258 // boss1->xyz[2] = first_boss1_depth; | |
259 boss1->stack_xyz[0] = first_boss1_speed; | |
260 root->addChild(boss1); | |
261 | |
262 //ボスの左右パーツを追加 | |
557
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
263 SceneGraphPtr left_parts = sgroot->createSceneGraph(BOSS1_L); |
507 | 264 boss1->addChild(left_parts); |
557
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
265 SceneGraphPtr right_parts = sgroot->createSceneGraph(BOSS1_R); |
507 | 266 boss1->addChild(right_parts); |
267 | |
268 //各機体の動きと当たり判定をセット | |
269 player->set_move_collision(player_move, player_collision); | |
270 boss1->set_move_collision(boss1_move_left, null_collision); | |
271 | |
272 //仕上げ | |
273 sgroot->setSceneData(root); | |
557
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
274 return sgroot; |
507 | 275 } |
557
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
276 |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
277 extern int init(TaskManager *manager, int argc, char *argv[]); |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
278 extern void task_initialize(); |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
279 static void TMend(TaskManager *manager); |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
280 |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
281 int |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
282 TMmain(TaskManager *manager, int argc, char *argv[]) |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
283 { |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
284 task_initialize(); |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
285 manager->set_TMend(TMend); |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
286 return init(manager, argc, argv); |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
287 |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
288 } |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
289 |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
290 void |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
291 TMend(TaskManager *manager) |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
292 { |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
293 printf("test_nogl end\n"); |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
294 } |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
295 |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
296 |