Mercurial > hg > Game > Cerium
annotate Renderer/Test/boss1_action.cc @ 557:764772be1e3c draft
fix examlples (on going)
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 22 Oct 2009 17:34:12 +0900 |
parents | 4c5264373c51 |
children | 00428ba0ba03 |
rev | line source |
---|---|
557
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
1 #include "SceneGraphRoot.h" |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
2 #include "MainLoop.h" |
539 | 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, int screen_w, int screen_h, | |
14 SceneGraphPtr tree) | |
15 { | |
16 } | |
17 | |
18 | |
19 static void | |
20 boss1_move_right(SceneGraphPtr node, 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, 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, int screen_w, int screen_h) | |
68 { | |
69 Pad *pad = sgroot->getController(); | |
70 | |
71 if (pad->left.isPush() | |
72 || pad->left.isHold()) { | |
73 #if 0 | |
74 SceneGraphPtr player_left; | |
75 player_left = sgroot->createSceneGraph(PLAYER_L); | |
76 player_left->set_move_collision(player_move_left, null_collision); | |
77 player_left->xyz[0] = node->xyz[0]; | |
78 player_left->xyz[1] = node->xyz[1]; | |
79 node->addChild(player_left); | |
80 node->flag_drawable = 1; | |
81 #endif | |
82 node->xyz[0] -= player_speed; | |
83 | |
84 if (node->xyz[0] - player_radius< 0) { | |
85 node->xyz[0] = player_radius; | |
86 } | |
87 } | |
88 | |
89 | |
90 if (pad->right.isPush() | |
91 || pad->right.isHold()) { | |
92 node->xyz[0] += player_speed; | |
93 | |
94 if (node->xyz[0] + player_radius > screen_w) { | |
95 node->xyz[0] = screen_w - player_radius; | |
96 } | |
97 } | |
98 | |
99 if (pad->up.isPush() | |
100 || pad->up.isHold()) { | |
101 node->xyz[1] -= player_speed; | |
102 | |
103 if (node->xyz[1] - player_radius < 0) { | |
104 node->xyz[1] = player_radius; | |
105 } | |
106 } | |
107 | |
108 if (pad->down.isPush() | |
109 || pad->down.isHold()) { | |
110 node->xyz[1] += player_speed; | |
111 | |
112 if (node->xyz[1] + player_radius > screen_h) { | |
113 node->xyz[1] = screen_h - player_radius; | |
114 } | |
115 } | |
116 | |
117 if (pad->circle.isPush()) { | |
118 SceneGraphPtr shot = sgroot->createSceneGraph(P_SHOT1); | |
119 shot->set_move_collision(shot_move, shot_collision); | |
120 shot->xyz[0] = node->xyz[0]; | |
121 shot->xyz[1] = node->xyz[1] - player_radius; | |
122 node->addBrother(shot); | |
123 } | |
124 } | |
125 | |
126 static void | |
127 player_collision(SceneGraphPtr node, int screen_w, int screen_h, | |
128 SceneGraphPtr tree) | |
129 { | |
130 //自機とボスのx,y座標での距離と2点間の距離 | |
131 static float x_distant, y_distant, distance; | |
132 //ボスの四角形の四隅の座標 | |
133 // static float boss_low_x, boss_low_y, boss_high_x, boss_high_y; | |
134 | |
135 SceneGraphIteratorPtr it = sgroot->getIterator(tree); | |
136 | |
137 | |
138 for (; it->hasNext(BOSS1);) { | |
139 it->next(BOSS1); | |
140 SceneGraphPtr enemy = it->get(); | |
141 | |
142 //各変数の初期化 | |
143 x_distant = node->xyz[0] - enemy->xyz[0]; | |
144 y_distant = node->xyz[1] - enemy->xyz[1]; | |
145 | |
146 //hypotfで2点間の距離を求める | |
147 distance = hypotf(x_distant, y_distant); | |
148 | |
149 /*四角形と円のcollision | |
150 if( (fabs( node->xyz[1] - ( boss_low_y ))) | |
151 */ | |
152 | |
153 //円同士のcollision | |
154 if(distance < (player_radius + boss_radius_y)) { | |
155 printf("!!!CAUTION!!!\n"); | |
156 } | |
157 } | |
158 } | |
159 | |
160 static void | |
161 shot_move(SceneGraphPtr node, int screen_w, int screen_h) | |
162 { | |
163 node->xyz[1] -= shot_speed; | |
164 | |
165 // 描画領域から抜けたら削除 | |
166 if (node->xyz[1] < 0) { | |
167 node->remove(); | |
168 } | |
169 } | |
170 | |
171 static void | |
172 shot_collision(SceneGraphPtr node, int screen_2, int screen_h, | |
173 SceneGraphPtr tree) | |
174 { | |
175 //自機とボスのx,y座標での距離と2点間の距離 | |
176 static float x_distant, y_distant, distance; | |
177 //ボスの四角形の四隅の座標 | |
178 // static float boss_low_x, boss_low_y, boss_high_x, boss_high_y; | |
179 | |
180 SceneGraphIteratorPtr it = sgroot->getIterator(tree); | |
181 | |
182 | |
183 for (; it->hasNext(BOSS1);) { | |
184 it->next(BOSS1); | |
185 SceneGraphPtr enemy = it->get(); | |
186 | |
187 x_distant = node->xyz[0] - enemy->xyz[0]; | |
188 y_distant = node->xyz[1] - enemy->xyz[1]; | |
189 | |
190 //hypotfで2点間の距離を求める | |
191 distance = hypotf(x_distant, y_distant); | |
192 | |
193 //円同士のcollision | |
194 if(distance < boss_radius_y) { | |
195 SceneGraphPtr blast = sgroot->createSceneGraph(BLAST1); | |
196 | |
197 blast->set_move_collision(blast_move, null_collision); | |
198 blast->xyz[0] = node->xyz[0]; | |
199 blast->xyz[1] = node->xyz[1]; | |
200 node->addBrother(blast); | |
201 node->remove(); | |
202 } | |
203 } | |
204 } | |
205 | |
557
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
206 extern Application * |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
207 application() { |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
208 return new ball_bound(); |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
209 } |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
210 |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
211 const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n"; |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
212 |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
213 |
539 | 214 static void |
215 blast_move(SceneGraphPtr node, int screen_w, int screen_h) | |
216 { | |
217 if(node->sgid > BLAST8) { | |
218 SceneGraphPtr blast = sgroot->createSceneGraph(node->sgid - 1); | |
219 blast->set_move_collision(blast_move, null_collision); | |
220 blast->xyz[0] = node->xyz[0]; | |
221 blast->xyz[1] = node->xyz[1]; | |
222 node->addBrother(blast); | |
223 } | |
224 | |
225 if (node->sgid == BLAST8) { | |
226 node->flag_drawable = 1; | |
227 } | |
228 | |
229 if((node->frame > 1)) { | |
230 node->remove(); | |
231 } | |
232 node->frame += 1; | |
233 } | |
234 | |
557
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
235 MainLoopPtr |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
236 bass1_action::boss1_init(Viewer *sgroot, int screen_w, int screen_h) |
539 | 237 { |
238 | |
239 sgroot->createFromXMLfile(manager, "xml_file/boss1.xml"); | |
240 sgroot->createFromXMLfile(manager, "xml_file/player1.xml"); | |
241 sgroot->createFromXMLfile(manager, "xml_file/p_shot.xml"); | |
242 sgroot->createFromXMLfile(manager, "xml_file/blast.xml"); | |
243 | |
244 //rootとなるSceneGraphを生成 | |
557
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
245 SceneGraphPtr root = sgroot->createSceneGraph(); |
539 | 246 |
247 //自機の初期化 | |
557
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
248 SceneGraphPtr player = sgroot->createSceneGraph(PLAYER); |
539 | 249 player->xyz[0] = screen_w/2; |
250 player->xyz[1] = screen_h - player_radius; | |
251 root->addChild(player); | |
252 | |
253 //ボスの初期化 | |
557
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
254 SceneGraphPtr boss1 = sgroot->createSceneGraph(BOSS1); |
539 | 255 boss1->xyz[0] = screen_w/2; |
256 boss1->xyz[1] = boss_radius_y; | |
257 // boss1->xyz[2] = first_boss1_depth; | |
258 boss1->stack_xyz[0] = first_boss1_speed; | |
259 root->addChild(boss1); | |
260 | |
261 //ボスの左右パーツを追加 | |
557
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
262 SceneGraphPtr left_parts = sgroot->createSceneGraph(BOSS1_L); |
539 | 263 boss1->addChild(left_parts); |
557
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
264 SceneGraphPtr right_parts = sgroot->createSceneGraph(BOSS1_R); |
539 | 265 boss1->addChild(right_parts); |
266 | |
267 //各機体の動きと当たり判定をセット | |
268 player->set_move_collision(player_move, player_collision); | |
269 boss1->set_move_collision(boss1_move_left, null_collision); | |
270 | |
271 //仕上げ | |
272 sgroot->setSceneData(root); | |
557
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
273 return sgroot; |
539 | 274 } |
557
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
275 |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
276 extern int init(TaskManager *manager, int argc, char *argv[]); |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
277 extern void task_initialize(); |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
278 static void TMend(TaskManager *manager); |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
279 |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
280 int |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
281 TMmain(TaskManager *manager, int argc, char *argv[]) |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
282 { |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
283 task_initialize(); |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
284 manager->set_TMend(TMend); |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
285 return init(manager, argc, argv); |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
286 |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
287 } |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
288 |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
289 void |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
290 TMend(TaskManager *manager) |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
291 { |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
292 printf("test_nogl end\n"); |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
293 } |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
294 |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
295 |