comparison Renderer/Application/boss1_action.cc @ 507:735f76483bb2

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