comparison TaskManager/Test/test_render/vacuum.cpp @ 376:4fb99cd5d13f draft

chain.cpp added
author kazz@kazzone.cr.ie.u-ryukyu.ac.jp
date Fri, 31 Jul 2009 18:21:24 +0900
parents 4fad8f9329ac 205e4a4af635
children bdeb7a73285b
comparison
equal deleted inserted replaced
375:2ae25549dd6a 376:4fb99cd5d13f
1 #include <math.h> 1 #include <math.h>
2 #include "vacuum.h"
2 #include "SceneGraphRoot.h" 3 #include "SceneGraphRoot.h"
3 #include "SGList.h" 4 #include "SGList.h"
4 5 #define ENCOUNT 55
6 using namespace std;
7
8 <<<<<<< local
5 static void cube_move_left(SceneGraphPtr node, int screen_w, int screen_h); 9 static void cube_move_left(SceneGraphPtr node, int screen_w, int screen_h);
6 static void cube_move_right(SceneGraphPtr node, int screen_w, int screen_h); 10 static void cube_move_right(SceneGraphPtr node, int screen_w, int screen_h);
7 static void cube_move_idle(SceneGraphPtr node, int screen_w, int screen_h); 11 static void cube_move_idle(SceneGraphPtr node, int screen_w, int screen_h);
8 static void cube_collision(SceneGraphPtr node, int screen_w, int screen_h, 12 static void cube_collision(SceneGraphPtr node, int screen_w, int screen_h,
9 SceneGraphPtr tree); 13 SceneGraphPtr tree);
10 static void cube_split(SceneGraphPtr root); 14 static void cube_split(SceneGraphPtr root);
11 15 =======
12 static void vacuum_move(SceneGraphPtr node, int w, int h); 16 static float vacuum_speed = 10.0f;
13 static void vacuum_coll(SceneGraphPtr node, int w, int h); 17 >>>>>>> other
14 18
15 static float vacuum_speed = 3.0f; 19
16 20 /*オブジェクト毎にファイルを分けてみた
17 static void 21 *
18 cube_move_left(SceneGraphPtr node, int screen_w, int screen_h) 22 *
19 { 23 */
20 node->xyz[0] -= node->stack_xyz[0]; 24
21 #if 0 25
22 node->xyz[1] -= node->stack_xyz[0] * node->stack_xyz[1]; 26
23 node->xyz[2] -= node->stack_xyz[0] * node->stack_xyz[2]; 27 void
24 #else 28 no_move_idle(SceneGraphPtr node, int screen_w, int screen_h)
25 node->xyz[1] += node->stack_xyz[1]; 29 {
26 //node->xyz[2] -= node->stack_xyz[2]; 30
27 #endif 31 <<<<<<< local
28
29 if (node->xyz[0] < 0) { 32 if (node->xyz[0] < 0) {
30 node->set_move_collision(cube_move_right, cube_collision); 33 node->set_move_collision(cube_move_right, cube_collision);
31 } 34 }
32 35
33 if (node->xyz[1] < 0 || node->xyz[1] > screen_h) { 36 if (node->xyz[1] < 0 || node->xyz[1] > screen_h) {
39 //node->angle[2] += 2.0f * node->stack_xyz[2]; 42 //node->angle[2] += 2.0f * node->stack_xyz[2];
40 43
41 if (++node->frame > 60) { 44 if (++node->frame > 60) {
42 cube_split(node); 45 cube_split(node);
43 } 46 }
44 } 47 =======
45 48 >>>>>>> other
46 static void 49 }
47 cube_move_right(SceneGraphPtr node, int screen_w, int screen_h) 50
48 { 51 void
52 no_collision_idle(SceneGraphPtr node, int screen_w, int screen_h,SceneGraphPtr tree)
53 {
54 <<<<<<< local
49 node->xyz[0] += node->stack_xyz[0]; 55 node->xyz[0] += node->stack_xyz[0];
50 #if 0 56 #if 0
51 node->xyz[1] -= node->stack_xyz[0] * node->stack_xyz[1]; 57 node->xyz[1] -= node->stack_xyz[0] * node->stack_xyz[1];
52 node->xyz[2] -= node->stack_xyz[0] * node->stack_xyz[2]; 58 node->xyz[2] -= node->stack_xyz[0] * node->stack_xyz[2];
53 #else 59 #else
55 #endif 61 #endif
56 62
57 if (node->xyz[0] > screen_w) { 63 if (node->xyz[0] > screen_w) {
58 node->set_move_collision(cube_move_left, cube_collision); 64 node->set_move_collision(cube_move_left, cube_collision);
59 } 65 }
60 66 =======
67 >>>>>>> other
68
69 <<<<<<< local
61 if (node->xyz[1] < 0 || node->xyz[1] > screen_h) { 70 if (node->xyz[1] < 0 || node->xyz[1] > screen_h) {
62 node->stack_xyz[1] = -node->stack_xyz[1]; 71 node->stack_xyz[1] = -node->stack_xyz[1];
63 } 72 }
64 73
65 //node->angle[0] += 2.0f; 74 //node->angle[0] += 2.0f;
67 //node->angle[2] += 2.0f * node->stack_xyz[2]; 76 //node->angle[2] += 2.0f * node->stack_xyz[2];
68 77
69 if (++node->frame > 60) { 78 if (++node->frame > 60) {
70 cube_split(node); 79 cube_split(node);
71 } 80 }
72 } 81 =======
73 82 >>>>>>> other
74 static void 83 }
75 cube_split(SceneGraphPtr root) 84
76 { 85 void
77 SceneGraphPtr p = root->clone(); 86 vacuum_coll(SceneGraphPtr node, int screen_w, int screen_h,
78 root->addBrother(p); 87 SceneGraphPtr tree)
79
80 root->set_move_collision(cube_move_left, cube_collision);
81 p->set_move_collision(cube_move_right, cube_collision);
82
83 root->frame = 0;
84 p->frame = 0;
85
86 p->xyz[0] = root->xyz[0] + 2;
87 p->xyz[1] = root->xyz[1];
88 p->xyz[2] = root->xyz[2];
89
90 p->stack_xyz[0] = 2.0f;
91 p->stack_xyz[1] = random()%3-1;
92 p->stack_xyz[2] = random()%3-1;
93
94 root->xyz[0] -= 2;
95 root->stack_xyz[0] = 2.0f;
96 root->stack_xyz[1] = random()%3-1;
97 root->stack_xyz[2] = 0.0f;
98 //root->stack_xyz[2] = random()%3-1;
99 }
100
101
102 static void
103 cube_move_idle(SceneGraphPtr node, int screen_w, int screen_h)
104 { 88 {
105 Pad *pad = sgroot->getController(); 89 Pad *pad = sgroot->getController();
106 90
91 <<<<<<< local
107 if (pad->circle.isPush()) { 92 if (pad->circle.isPush()) {
108 cube_split(node); 93 cube_split(node);
109 } 94 =======
110 } 95 if(node->frame%ENCOUNT == ENCOUNT-1) {
111 96 if(random()%2) {
97 add_cubecollision_object(REDCUBE,node,screen_w,screen_h);
98 }
99 else {
100 add_cubecollision_object(ENEMY,node,screen_w,screen_h);
101 }
102 >>>>>>> other
103 }
104
105 if (pad->cross.isHold()) {
106 SceneGraphIteratorPtr it = sgroot->getIterator(tree);
107 collision_red(it,node);
108 it = sgroot->getIterator(tree);
109 collision_purple(it,node,screen_w,screen_h);
110 }
111
112 else if(pad->circle.isHold()) {
113 SceneGraphIteratorPtr it = sgroot->getIterator(tree);
114 lock_attack(node,it);
115 }
116
117 }
118
119 <<<<<<< local
112 static void 120 static void
113 cube_collision(SceneGraphPtr node, int screen_w, int screen_h, 121 cube_collision(SceneGraphPtr node, int screen_w, int screen_h,
114 SceneGraphPtr tree) 122 SceneGraphPtr tree)
115 { 123 =======
116 } 124 void
117 125 lock_attack(SceneGraphPtr node,SceneGraphIteratorPtr it)
126 >>>>>>> other
127 {
128
129 SceneGraphPtr enemy;
130 SceneGraphPtr near_enemy = NULL;
131 float dx,dy,r,range = 100;
132 // Pad *pad = sgroot->getController();
133
134 for(;it->hasNext(ENEMY);) {
135
136 it->next(ENEMY);
137 enemy = it->get();
138 dx = enemy->xyz[0] - node->xyz[0];
139 dy = enemy->xyz[1] - node->xyz[1];
140 r = sqrt(dx*dx+dy*dy);
141
142 if(range > r && enemy->stack_xyz[2] == 0) {
143 range = r;
144 near_enemy = enemy;
145 }
146 }
147
148
149 if(near_enemy != NULL) {
150 /*stack_xyz[2]をlockonフラグとして使うかな?*/
151 SceneGraphPtr lockon;
152 // SceneGraphPtr near_enemy_common_move = near_enemy->parent;
153 near_enemy->stack_xyz[2] = 1;
154 lockon = sgroot->createSceneGraph(LOCK);
155 lockon->set_move_collision(no_move_idle,lockon_collision);
156 //near_enemy_common_move->addChild(lockon);
157 near_enemy->addChild(lockon);
158 }
159
160 }
161
162 <<<<<<< local
118 static void 163 static void
119 vacuum_coll(SceneGraphPtr node, int screen_w, int screen_h, 164 vacuum_coll(SceneGraphPtr node, int screen_w, int screen_h,
120 SceneGraphPtr tree) 165 SceneGraphPtr tree)
121 { 166 {
122 SceneGraphIteratorPtr it = sgroot->getIterator(); 167 SceneGraphIteratorPtr it = sgroot->getIterator();
123 SceneGraphPtr bigm; 168 SceneGraphPtr bigm;
124 Pad *pad = sgroot->getController(); 169 Pad *pad = sgroot->getController();
125 float dx, dy, r; 170 float dx, dy, r;
126 float q = 0; 171 float q = 0;
127 172 =======
173 void
174 lockon_collision(SceneGraphPtr node,int w,int h,SceneGraphPtr tree) {
175 >>>>>>> other
176
177 <<<<<<< local
128 if (pad->cross.isRelease()) { 178 if (pad->cross.isRelease()) {
129 return; 179 return;
130 } 180 }
131 181 =======
132 return; 182 Pad *pad = sgroot->getController();
133 183 SceneGraphPtr lockon_enemy = node->parent;
184 >>>>>>> other
185
186 /* node->angle[0] = -lockon_enemy->angle[0];
187 node->angle[1] = -lockon_enemy->angle[1];
188 node->angle[2] = -lockon_enemy->angle[2];*/
189
190 <<<<<<< local
134 for (; it->hasNext(MCUBE);) { 191 for (; it->hasNext(MCUBE);) {
135 it->next(MCUBE); 192 it->next(MCUBE);
136 SceneGraphPtr mcube = it->get(); 193 SceneGraphPtr mcube = it->get();
137 194 =======
195 if(pad->circle.isRelease()) {
196 lockon_enemy->remove();
197 }
198 >>>>>>> other
199
200 <<<<<<< local
138 dx = node->xyz[0] - mcube->xyz[0]; 201 dx = node->xyz[0] - mcube->xyz[0];
139 dy = node->xyz[1] - mcube->xyz[1]; 202 dy = node->xyz[1] - mcube->xyz[1];
140 203
141 r = sqrt(dx*dx + dy*dy); 204 r = sqrt(dx*dx + dy*dy);
142 205
165 mcube->stack_xyz[0] = -q*cos(atan(dy/dx)); 228 mcube->stack_xyz[0] = -q*cos(atan(dy/dx));
166 mcube->stack_xyz[1] = -q*sin(atan(dy/dx)); 229 mcube->stack_xyz[1] = -q*sin(atan(dy/dx));
167 } 230 }
168 } 231 }
169 } 232 }
170 } 233 =======
171 234 >>>>>>> other
172 static void 235 }
236
237
238 void
173 vacuum_move(SceneGraphPtr node , int w, int h) 239 vacuum_move(SceneGraphPtr node , int w, int h)
174 { 240 {
175 Pad *pad = sgroot->getController(); 241 Pad *pad = sgroot->getController();
176 242
243 <<<<<<< local
177 if (pad->right.isHold()) { 244 if (pad->right.isHold()) {
178 node->xyz[0] += vacuum_speed; 245 node->xyz[0] += vacuum_speed;
179 } else if (pad->left.isHold()) { 246 } else if (pad->left.isHold()) {
180 node->xyz[0] -= vacuum_speed; 247 node->xyz[0] -= vacuum_speed;
181 } 248 =======
182 249 if (pad->right.isHold() && w > node->xyz[0]) {
250 node->xyz[0] += vacuum_speed;
251 node->angle[0] += 2;
252 } else if (pad->left.isHold() && 0 < node->xyz[0]) {
253 node->xyz[0] -= vacuum_speed;
254 node->angle[0] -= 2;
255 >>>>>>> other
256 }
257
258 <<<<<<< local
183 if (pad->up.isHold()) { 259 if (pad->up.isHold()) {
184 node->xyz[1] -= vacuum_speed; 260 node->xyz[1] -= vacuum_speed;
185 } else if (pad->down.isHold()) { 261 } else if (pad->down.isHold()) {
186 node->xyz[1] += vacuum_speed; 262 node->xyz[1] += vacuum_speed;
263 =======
264 if (pad->up.isHold() && 0 < node->xyz[1]) {
265 node->xyz[1] -= vacuum_speed;
266 node->angle[1] -= 2;
267 } else if (pad->down.isHold() && h > node->xyz[1]) {
268 node->xyz[1] += vacuum_speed;
269 node->angle[1] += 2;
270 >>>>>>> other
187 } 271 }
188 272
189 if (pad->start.isPush()) { 273 if (pad->start.isPush()) {
274 <<<<<<< local
190 node->xyz[0] = w/2; 275 node->xyz[0] = w/2;
191 node->xyz[1] = h*0.8; 276 node->xyz[1] = h*0.8;
192 } 277 =======
193 } 278 node->xyz[0] = w/2;
194 279 node->xyz[1] = h*0.8;
195 void 280 >>>>>>> other
196 vacuum_init(int w, int h) 281 }
197 { 282 }
198 SceneGraphPtr cube; 283
199 SceneGraphPtr vacuum; 284
200 SceneGraphPtr back; 285
201 286 /*cubeをランダムな場所に生成*/
202 sgroot->createFromXMLfile("xml_file/mcube.xml"); 287 void
203 288 add_cubecollision_object(int id,SceneGraphPtr root,int w,int h)
204 cube = sgroot->createSceneGraph(MCUBE); 289 {
205 cube->xyz[0] = w/2; 290 SceneGraphPtr object;
206 cube->xyz[1] = h/2; 291 SceneGraphPtr common_move;
207 cube->xyz[2] = 0.0f; 292
208 cube->set_move_collision(cube_move_idle, cube_collision); 293 common_move = sgroot->createSceneGraph();
209 294 object = sgroot->createSceneGraph(id);
210 vacuum = sgroot->createSceneGraph(BIGMCUBE); 295 object->xyz[0] = random()%w;
211 vacuum->xyz[0] = w/2; 296 object->xyz[1] = random()%h;
212 vacuum->xyz[1] = h*0.8; 297 object->set_move_collision(no_move_idle,cube_collision);
213 vacuum->set_move_collision(vacuum_move, vacuum_coll); 298 //common_move->addChild(object);
214 299 root->addBrother(object);
215 back = sgroot->createSceneGraph(); 300 }
216 back->addChild(vacuum); 301
217 back->addChild(cube); 302
218 303 void
219 sgroot->setSceneData(back); 304 vacuum_init2(int w, int h)
220 } 305 {
306 SceneGraphPtr title;
307
308 sgroot->createFromXMLfile("xml_file/gamecube.xml");
309 sgroot->createFromXMLfile("xml_file/title.xml");
310 sgroot->createFromXMLfile("xml_file/gameover.xml");
311
312 title = sgroot->createSceneGraph(TITLE);
313 title->xyz[0] = w/2;
314 title->xyz[1] = h/2;
315 title->set_move_collision(no_move_idle, title_collision);
316
317 sgroot->setSceneData(title);
318 }