Mercurial > hg > Members > kono > Cerium
annotate Renderer/Test/vacuum.cc @ 758:e615e552efa5
change Test/create_task
author | hiroki |
---|---|
date | Sat, 30 Jan 2010 19:33:16 +0900 |
parents | b7376415fa5f |
children | 4455e7b0caf3 |
rev | line source |
---|---|
507 | 1 #include <math.h> |
2 #include "vacuum.h" | |
3 #include "SceneGraphRoot.h" | |
4 #define ENCOUNT 55 | |
5 using namespace std; | |
6 | |
7 static float vacuum_speed = 10.0f; | |
8 | |
9 | |
10 /*オブジェクト毎にファイルを分けてみた | |
11 * | |
12 * | |
13 */ | |
14 | |
15 | |
16 | |
17 void | |
656
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
563
diff
changeset
|
18 no_move_idle(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) |
507 | 19 { |
20 | |
21 } | |
22 | |
23 void | |
656
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
563
diff
changeset
|
24 no_collision_idle(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h,SceneGraphPtr tree) |
507 | 25 { |
26 | |
27 } | |
28 | |
563
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
29 int redcube; |
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
30 int enemy; |
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
31 |
507 | 32 void |
656
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
563
diff
changeset
|
33 vacuum_coll(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, |
507 | 34 SceneGraphPtr tree) |
35 { | |
656
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
563
diff
changeset
|
36 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; |
507 | 37 Pad *pad = sgroot->getController(); |
38 | |
39 if(node->frame%ENCOUNT == ENCOUNT-1) { | |
40 if(random()%2) { | |
748 | 41 add_cubecollision_object(redcube,node,screen_w,screen_h, sgroot); |
507 | 42 } |
43 else { | |
748 | 44 add_cubecollision_object(enemy,node,screen_w,screen_h, sgroot); |
507 | 45 } |
46 } | |
47 | |
48 if (pad->cross.isHold()) { | |
49 SceneGraphIteratorPtr it = sgroot->getIterator(tree); | |
50 collision_red(it,node); | |
51 it = sgroot->getIterator(tree); | |
656
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
563
diff
changeset
|
52 collision_purple(it,node,screen_w,screen_h, sgroot); |
507 | 53 } |
54 | |
55 else if(pad->circle.isHold()) { | |
56 SceneGraphIteratorPtr it = sgroot->getIterator(tree); | |
656
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
563
diff
changeset
|
57 lock_attack(node, it, sgroot); |
507 | 58 } |
59 | |
60 } | |
61 | |
62 void | |
656
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
563
diff
changeset
|
63 lock_attack(SceneGraphPtr node,SceneGraphIteratorPtr it, SceneGraphRoot *sgroot) |
507 | 64 { |
65 | |
563
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
66 SceneGraphPtr e; |
507 | 67 SceneGraphPtr near_enemy = NULL; |
68 float dx,dy,r,range = 100; | |
69 // Pad *pad = sgroot->getController(); | |
70 | |
563
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
71 for(;it->hasNext(enemy);) { |
507 | 72 |
563
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
73 it->next(enemy); |
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
74 e = it->get(); |
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
75 dx = e->xyz[0] - node->xyz[0]; |
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
76 dy = e->xyz[1] - node->xyz[1]; |
507 | 77 r = sqrt(dx*dx+dy*dy); |
78 | |
563
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
79 if(range > r && e->stack_xyz[2] == 0) { |
507 | 80 range = r; |
563
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
81 near_enemy = e; |
507 | 82 } |
83 } | |
84 | |
85 | |
86 if(near_enemy != NULL) { | |
87 /*stack_xyz[2]をlockonフラグとして使うかな?*/ | |
88 SceneGraphPtr lockon; | |
89 // SceneGraphPtr near_enemy_common_move = near_enemy->parent; | |
90 near_enemy->stack_xyz[2] = 1; | |
563
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
91 lockon = sgroot->createSceneGraph("LOCK"); |
507 | 92 lockon->set_move_collision(no_move_idle,lockon_collision); |
93 //near_enemy_common_move->addChild(lockon); | |
94 near_enemy->addChild(lockon); | |
95 } | |
96 | |
97 } | |
98 | |
99 void | |
656
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
563
diff
changeset
|
100 lockon_collision(SceneGraphPtr node, void *sgroot_, int w, int h, SceneGraphPtr tree) { |
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
563
diff
changeset
|
101 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; |
507 | 102 Pad *pad = sgroot->getController(); |
103 SceneGraphPtr lockon_enemy = node->parent; | |
104 | |
105 /* node->angle[0] = -lockon_enemy->angle[0]; | |
106 node->angle[1] = -lockon_enemy->angle[1]; | |
107 node->angle[2] = -lockon_enemy->angle[2];*/ | |
108 | |
109 if(pad->circle.isRelease()) { | |
110 lockon_enemy->remove(); | |
111 } | |
112 | |
113 } | |
114 | |
115 | |
116 void | |
656
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
563
diff
changeset
|
117 vacuum_move(SceneGraphPtr node, void *sgroot_, int w, int h) |
507 | 118 { |
656
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
563
diff
changeset
|
119 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; |
507 | 120 Pad *pad = sgroot->getController(); |
121 | |
122 if (pad->right.isHold() && w > node->xyz[0]) { | |
123 node->xyz[0] += vacuum_speed; | |
124 node->angle[0] += 2; | |
125 } else if (pad->left.isHold() && 0 < node->xyz[0]) { | |
126 node->xyz[0] -= vacuum_speed; | |
127 node->angle[0] -= 2; | |
128 } | |
129 | |
130 if (pad->up.isHold() && 0 < node->xyz[1]) { | |
131 node->xyz[1] -= vacuum_speed; | |
132 node->angle[1] -= 2; | |
133 } else if (pad->down.isHold() && h > node->xyz[1]) { | |
134 node->xyz[1] += vacuum_speed; | |
135 node->angle[1] += 2; | |
136 } | |
137 | |
138 if (pad->start.isPush()) { | |
139 node->xyz[0] = w/2; | |
140 node->xyz[1] = h*0.8; | |
141 } | |
142 } | |
143 | |
144 | |
145 | |
146 /*cubeをランダムな場所に生成*/ | |
147 void | |
656
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
563
diff
changeset
|
148 add_cubecollision_object(int id,SceneGraphPtr root,int w,int h, SceneGraphRoot *sgroot) |
507 | 149 { |
150 SceneGraphPtr object; | |
151 SceneGraphPtr common_move; | |
152 | |
153 common_move = sgroot->createSceneGraph(); | |
154 object = sgroot->createSceneGraph(id); | |
155 object->xyz[0] = random()%w; | |
156 object->xyz[1] = random()%h; | |
157 object->set_move_collision(no_move_idle,cube_collision); | |
158 //common_move->addChild(object); | |
159 root->addBrother(object); | |
160 } | |
161 | |
162 | |
557
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
163 MainLoopPtr |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
164 vacuum::init(Viewer *sgroot, int w, int h) |
507 | 165 { |
166 SceneGraphPtr title; | |
167 | |
563
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
168 sgroot->createFromXMLfile( "xml_file/gamecube.xml"); |
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
169 sgroot->createFromXMLfile( "xml_file/title.xml"); |
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
170 sgroot->createFromXMLfile( "xml_file/gameover.xml"); |
507 | 171 |
563
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
172 title = sgroot->createSceneGraph("TITLE"); |
507 | 173 title->xyz[0] = w/2; |
174 title->xyz[1] = h/2; | |
175 title->set_move_collision(no_move_idle, title_collision); | |
176 | |
177 sgroot->setSceneData(title); | |
563
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
178 |
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
179 redcube = sgroot->getSgid("REDCUBE"); |
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
180 enemy = sgroot->getSgid("ENEMY"); |
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
181 |
557
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
182 return sgroot; |
507 | 183 } |
557
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
184 |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
185 extern Application * |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
186 application() { |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
187 return new vacuum(); |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
188 } |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
189 |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
190 const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n"; |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
191 |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
192 extern int init(TaskManager *manager, int argc, char *argv[]); |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
193 extern void task_initialize(); |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
194 static void TMend(TaskManager *manager); |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
195 |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
196 int |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
197 TMmain(TaskManager *manager, int argc, char *argv[]) |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
198 { |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
199 task_initialize(); |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
200 manager->set_TMend(TMend); |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
201 return init(manager, argc, argv); |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
202 |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
203 } |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
204 |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
205 void |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
206 TMend(TaskManager *manager) |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
207 { |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
208 printf("test_nogl end\n"); |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
209 } |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
210 |