Mercurial > hg > Game > Cerium
annotate Renderer/Test/boss1_action.cc @ 562:d65f21b18165 draft
name search
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 22 Oct 2009 22:22:31 +0900 |
parents | 00428ba0ba03 |
children | 7a311860a76e |
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()) { | |
562 | 118 SceneGraphPtr shot = sgroot->createSceneGraph("P_SHOT1"); |
539 | 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 | |
562 | 126 static int boss1sgid; |
127 | |
539 | 128 static void |
129 player_collision(SceneGraphPtr node, int screen_w, int screen_h, | |
130 SceneGraphPtr tree) | |
131 { | |
132 //自機とボスのx,y座標での距離と2点間の距離 | |
133 static float x_distant, y_distant, distance; | |
134 //ボスの四角形の四隅の座標 | |
135 // static float boss_low_x, boss_low_y, boss_high_x, boss_high_y; | |
136 | |
137 SceneGraphIteratorPtr it = sgroot->getIterator(tree); | |
138 | |
139 | |
562 | 140 for (; it->hasNext(boss1sgid);) { |
141 it->next(boss1sgid); | |
539 | 142 SceneGraphPtr enemy = it->get(); |
143 | |
144 //各変数の初期化 | |
145 x_distant = node->xyz[0] - enemy->xyz[0]; | |
146 y_distant = node->xyz[1] - enemy->xyz[1]; | |
147 | |
148 //hypotfで2点間の距離を求める | |
149 distance = hypotf(x_distant, y_distant); | |
150 | |
151 /*四角形と円のcollision | |
152 if( (fabs( node->xyz[1] - ( boss_low_y ))) | |
153 */ | |
154 | |
155 //円同士のcollision | |
156 if(distance < (player_radius + boss_radius_y)) { | |
157 printf("!!!CAUTION!!!\n"); | |
158 } | |
159 } | |
160 } | |
161 | |
162 static void | |
163 shot_move(SceneGraphPtr node, int screen_w, int screen_h) | |
164 { | |
165 node->xyz[1] -= shot_speed; | |
166 | |
167 // 描画領域から抜けたら削除 | |
168 if (node->xyz[1] < 0) { | |
169 node->remove(); | |
170 } | |
171 } | |
172 | |
173 static void | |
174 shot_collision(SceneGraphPtr node, int screen_2, int screen_h, | |
175 SceneGraphPtr tree) | |
176 { | |
177 //自機とボスのx,y座標での距離と2点間の距離 | |
178 static float x_distant, y_distant, distance; | |
179 //ボスの四角形の四隅の座標 | |
180 // static float boss_low_x, boss_low_y, boss_high_x, boss_high_y; | |
181 | |
182 SceneGraphIteratorPtr it = sgroot->getIterator(tree); | |
183 | |
184 | |
562 | 185 for (; it->hasNext(boss1sgid);) { |
186 it->next(boss1sgid); | |
539 | 187 SceneGraphPtr enemy = it->get(); |
188 | |
189 x_distant = node->xyz[0] - enemy->xyz[0]; | |
190 y_distant = node->xyz[1] - enemy->xyz[1]; | |
191 | |
192 //hypotfで2点間の距離を求める | |
193 distance = hypotf(x_distant, y_distant); | |
194 | |
195 //円同士のcollision | |
196 if(distance < boss_radius_y) { | |
562 | 197 SceneGraphPtr blast = sgroot->createSceneGraph("BLAST1"); |
539 | 198 |
199 blast->set_move_collision(blast_move, null_collision); | |
200 blast->xyz[0] = node->xyz[0]; | |
201 blast->xyz[1] = node->xyz[1]; | |
202 node->addBrother(blast); | |
203 node->remove(); | |
204 } | |
205 } | |
206 } | |
207 | |
557
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
208 extern Application * |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
209 application() { |
558 | 210 return new boss1_action(); |
557
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
211 } |
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 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
|
214 |
562 | 215 static int blast8; |
557
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
216 |
539 | 217 static void |
218 blast_move(SceneGraphPtr node, int screen_w, int screen_h) | |
219 { | |
562 | 220 if(node->sgid > blast8) { |
539 | 221 SceneGraphPtr blast = sgroot->createSceneGraph(node->sgid - 1); |
222 blast->set_move_collision(blast_move, null_collision); | |
223 blast->xyz[0] = node->xyz[0]; | |
224 blast->xyz[1] = node->xyz[1]; | |
225 node->addBrother(blast); | |
226 } | |
227 | |
562 | 228 if (node->sgid == blast8) { |
539 | 229 node->flag_drawable = 1; |
230 } | |
231 | |
232 if((node->frame > 1)) { | |
233 node->remove(); | |
234 } | |
235 node->frame += 1; | |
236 } | |
237 | |
557
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
238 MainLoopPtr |
558 | 239 boss1_action::init(Viewer *sgroot, int screen_w, int screen_h) |
539 | 240 { |
241 | |
558 | 242 sgroot->createFromXMLfile("xml_file/boss1.xml"); |
243 sgroot->createFromXMLfile("xml_file/player1.xml"); | |
244 sgroot->createFromXMLfile("xml_file/p_shot.xml"); | |
245 sgroot->createFromXMLfile("xml_file/blast.xml"); | |
562 | 246 |
247 blast8 = sgroot->getSgid("BLAST8"); | |
248 | |
539 | 249 //rootとなるSceneGraphを生成 |
557
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
250 SceneGraphPtr root = sgroot->createSceneGraph(); |
539 | 251 |
252 //自機の初期化 | |
562 | 253 SceneGraphPtr player = sgroot->createSceneGraph("PLAYER"); |
539 | 254 player->xyz[0] = screen_w/2; |
255 player->xyz[1] = screen_h - player_radius; | |
256 root->addChild(player); | |
257 | |
258 //ボスの初期化 | |
562 | 259 SceneGraphPtr boss1 = sgroot->createSceneGraph("BOSS1"); |
260 boss1sgid = boss1->sgid; | |
261 | |
539 | 262 boss1->xyz[0] = screen_w/2; |
263 boss1->xyz[1] = boss_radius_y; | |
264 // boss1->xyz[2] = first_boss1_depth; | |
265 boss1->stack_xyz[0] = first_boss1_speed; | |
266 root->addChild(boss1); | |
267 | |
268 //ボスの左右パーツを追加 | |
562 | 269 SceneGraphPtr left_parts = sgroot->createSceneGraph("BOSS1_L"); |
539 | 270 boss1->addChild(left_parts); |
562 | 271 SceneGraphPtr right_parts = sgroot->createSceneGraph("BOSS1_R"); |
539 | 272 boss1->addChild(right_parts); |
273 | |
274 //各機体の動きと当たり判定をセット | |
275 player->set_move_collision(player_move, player_collision); | |
276 boss1->set_move_collision(boss1_move_left, null_collision); | |
277 | |
278 //仕上げ | |
279 sgroot->setSceneData(root); | |
557
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
280 return sgroot; |
539 | 281 } |
557
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 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
|
284 extern void task_initialize(); |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
285 static void TMend(TaskManager *manager); |
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 int |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
288 TMmain(TaskManager *manager, int argc, char *argv[]) |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
289 { |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
290 task_initialize(); |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
291 manager->set_TMend(TMend); |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
292 return init(manager, argc, argv); |
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 |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
296 void |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
297 TMend(TaskManager *manager) |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
298 { |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
299 printf("test_nogl end\n"); |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
300 } |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
301 |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
302 |