comparison Renderer/test_render/boss1_action.cpp @ 283:15bfacccde99 draft

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