comparison Renderer/Test/vacuum.cc @ 563:b21a013051a2

all exmple on Mac OS X
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 22 Oct 2009 23:05:16 +0900
parents ec72b601b71f
children d0b8860c17f8
comparison
equal deleted inserted replaced
562:a5fda4e51498 563:b21a013051a2
1 #include <math.h> 1 #include <math.h>
2 #include "vacuum.h" 2 #include "vacuum.h"
3 #include "SceneGraphRoot.h" 3 #include "SceneGraphRoot.h"
4 #include "SGList.h"
5 #define ENCOUNT 55 4 #define ENCOUNT 55
6 using namespace std; 5 using namespace std;
7 6
8 static float vacuum_speed = 10.0f; 7 static float vacuum_speed = 10.0f;
9 8
25 no_collision_idle(SceneGraphPtr node, int screen_w, int screen_h,SceneGraphPtr tree) 24 no_collision_idle(SceneGraphPtr node, int screen_w, int screen_h,SceneGraphPtr tree)
26 { 25 {
27 26
28 } 27 }
29 28
29 int redcube;
30 int enemy;
31
30 void 32 void
31 vacuum_coll(SceneGraphPtr node, int screen_w, int screen_h, 33 vacuum_coll(SceneGraphPtr node, int screen_w, int screen_h,
32 SceneGraphPtr tree) 34 SceneGraphPtr tree)
33 { 35 {
34 Pad *pad = sgroot->getController(); 36 Pad *pad = sgroot->getController();
35 37
36 if(node->frame%ENCOUNT == ENCOUNT-1) { 38 if(node->frame%ENCOUNT == ENCOUNT-1) {
37 if(random()%2) { 39 if(random()%2) {
38 add_cubecollision_object(REDCUBE,node,screen_w,screen_h); 40 add_cubecollision_object(redcube,node,screen_w,screen_h);
39 } 41 }
40 else { 42 else {
41 add_cubecollision_object(ENEMY,node,screen_w,screen_h); 43 add_cubecollision_object(enemy,node,screen_w,screen_h);
42 } 44 }
43 } 45 }
44 46
45 if (pad->cross.isHold()) { 47 if (pad->cross.isHold()) {
46 SceneGraphIteratorPtr it = sgroot->getIterator(tree); 48 SceneGraphIteratorPtr it = sgroot->getIterator(tree);
58 60
59 void 61 void
60 lock_attack(SceneGraphPtr node,SceneGraphIteratorPtr it) 62 lock_attack(SceneGraphPtr node,SceneGraphIteratorPtr it)
61 { 63 {
62 64
63 SceneGraphPtr enemy; 65 SceneGraphPtr e;
64 SceneGraphPtr near_enemy = NULL; 66 SceneGraphPtr near_enemy = NULL;
65 float dx,dy,r,range = 100; 67 float dx,dy,r,range = 100;
66 // Pad *pad = sgroot->getController(); 68 // Pad *pad = sgroot->getController();
67 69
68 for(;it->hasNext(ENEMY);) { 70 for(;it->hasNext(enemy);) {
69 71
70 it->next(ENEMY); 72 it->next(enemy);
71 enemy = it->get(); 73 e = it->get();
72 dx = enemy->xyz[0] - node->xyz[0]; 74 dx = e->xyz[0] - node->xyz[0];
73 dy = enemy->xyz[1] - node->xyz[1]; 75 dy = e->xyz[1] - node->xyz[1];
74 r = sqrt(dx*dx+dy*dy); 76 r = sqrt(dx*dx+dy*dy);
75 77
76 if(range > r && enemy->stack_xyz[2] == 0) { 78 if(range > r && e->stack_xyz[2] == 0) {
77 range = r; 79 range = r;
78 near_enemy = enemy; 80 near_enemy = e;
79 } 81 }
80 } 82 }
81 83
82 84
83 if(near_enemy != NULL) { 85 if(near_enemy != NULL) {
84 /*stack_xyz[2]をlockonフラグとして使うかな?*/ 86 /*stack_xyz[2]をlockonフラグとして使うかな?*/
85 SceneGraphPtr lockon; 87 SceneGraphPtr lockon;
86 // SceneGraphPtr near_enemy_common_move = near_enemy->parent; 88 // SceneGraphPtr near_enemy_common_move = near_enemy->parent;
87 near_enemy->stack_xyz[2] = 1; 89 near_enemy->stack_xyz[2] = 1;
88 lockon = sgroot->createSceneGraph(LOCK); 90 lockon = sgroot->createSceneGraph("LOCK");
89 lockon->set_move_collision(no_move_idle,lockon_collision); 91 lockon->set_move_collision(no_move_idle,lockon_collision);
90 //near_enemy_common_move->addChild(lockon); 92 //near_enemy_common_move->addChild(lockon);
91 near_enemy->addChild(lockon); 93 near_enemy->addChild(lockon);
92 } 94 }
93 95
159 MainLoopPtr 161 MainLoopPtr
160 vacuum::init(Viewer *sgroot, int w, int h) 162 vacuum::init(Viewer *sgroot, int w, int h)
161 { 163 {
162 SceneGraphPtr title; 164 SceneGraphPtr title;
163 165
164 sgroot->createFromXMLfile(manager, "xml_file/gamecube.xml"); 166 sgroot->createFromXMLfile( "xml_file/gamecube.xml");
165 sgroot->createFromXMLfile(manager, "xml_file/title.xml"); 167 sgroot->createFromXMLfile( "xml_file/title.xml");
166 sgroot->createFromXMLfile(manager, "xml_file/gameover.xml"); 168 sgroot->createFromXMLfile( "xml_file/gameover.xml");
167 169
168 title = sgroot->createSceneGraph(TITLE); 170 title = sgroot->createSceneGraph("TITLE");
169 title->xyz[0] = w/2; 171 title->xyz[0] = w/2;
170 title->xyz[1] = h/2; 172 title->xyz[1] = h/2;
171 title->set_move_collision(no_move_idle, title_collision); 173 title->set_move_collision(no_move_idle, title_collision);
172 174
173 sgroot->setSceneData(title); 175 sgroot->setSceneData(title);
176
177 redcube = sgroot->getSgid("REDCUBE");
178 enemy = sgroot->getSgid("ENEMY");
179
174 return sgroot; 180 return sgroot;
175 } 181 }
176 182
177 extern Application * 183 extern Application *
178 application() { 184 application() {