Mercurial > hg > Members > kono > Cerium
annotate Renderer/Test/ieshoot.cc @ 758:e615e552efa5
change Test/create_task
author | hiroki |
---|---|
date | Sat, 30 Jan 2010 19:33:16 +0900 |
parents | b7376415fa5f |
children |
rev | line source |
---|---|
507 | 1 #include "SceneGraphRoot.h" |
563
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
2 #include "ieshoot.h" |
507 | 3 |
4 static const float jiki_speed = 6.0f; | |
5 static const float jiki_radius = 32.0f; | |
6 | |
7 static const float tama_speed = 10.0f; | |
8 static const float tama_radius = 16.0f; | |
9 | |
10 static const float boss_radius_x = 64.0f; | |
11 static const float boss_radius_y = 128.0f; | |
12 | |
13 static const float iebosstama_speed = 15.0f; | |
14 | |
15 static 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
|
16 ieboss_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, |
507 | 17 SceneGraphPtr tree); |
18 static 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
|
19 ieboss_collision_invincibil(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_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
|
20 static void ieboss_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h); |
507 | 21 |
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
|
22 static void iebosstama_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h); |
507 | 23 |
24 | |
25 static 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
|
26 iejiki_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, |
507 | 27 SceneGraphPtr tree) |
28 { | |
29 } | |
30 | |
31 static 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
|
32 ietama_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, |
507 | 33 SceneGraphPtr tree) |
34 { | |
35 } | |
36 | |
37 static 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
|
38 ieboss_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, |
507 | 39 SceneGraphPtr tree) |
40 { | |
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
|
41 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; |
507 | 42 SceneGraphIteratorPtr it = sgroot->getIterator(tree); |
43 static int damage = 0; | |
563
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
44 int ietama = sgroot->getSgid("IETAMA"); |
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
45 for (; it->hasNext(ietama);) { |
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
46 it->next(ietama); |
507 | 47 SceneGraphPtr tama = it->get(); |
48 | |
49 if (node->xyz[0] - boss_radius_x < tama->xyz[0] + tama_radius | |
50 && node->xyz[0] + boss_radius_x > tama->xyz[0] - tama_radius | |
51 && node->xyz[1] + boss_radius_y > tama->xyz[1] - tama_radius) { | |
52 tama->remove(); | |
53 | |
54 node->set_move_collision(ieboss_move, ieboss_collision_invincibil); | |
55 | |
563
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
56 SceneGraphPtr iebosstama = sgroot->createSceneGraph("Earth"); |
507 | 57 iebosstama->set_move_collision(iebosstama_move, ietama_collision); |
58 iebosstama->xyz[0] = node->xyz[0]; | |
59 iebosstama->xyz[1] = node->xyz[1] + boss_radius_y; | |
60 //iebosstama->xyz[2] = 50.0f; | |
61 node->addBrother(iebosstama); | |
62 | |
63 damage++; | |
64 } | |
65 } | |
66 | |
67 if (damage > 10) { | |
68 node->remove(); | |
69 } | |
70 } | |
71 | |
72 static 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
|
73 ieboss_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) |
507 | 74 { |
75 /** | |
76 * TODO | |
77 * Boss が複数居た場合、これじゃ駄目 | |
78 */ | |
79 static float x_speed = 5.0f; | |
80 static float z_speed = 5.0f; | |
81 | |
82 node->xyz[0] += x_speed; | |
83 | |
84 if (node->xyz[0] - boss_radius_x < 0) { | |
85 x_speed = -x_speed; | |
86 node->xyz[0] = boss_radius_x; | |
87 } else if (node->xyz[0] + boss_radius_x > screen_w) { | |
88 x_speed = -x_speed; | |
89 node->xyz[0] = screen_w - boss_radius_x; | |
90 } | |
91 | |
92 //node->xyz[2] += z_speed; | |
93 if (node->xyz[2] >= 100.0f) { | |
94 node->xyz[2] = 99.99f; | |
95 z_speed = -z_speed; | |
96 } else if (node->xyz[2] <= -100.0f) { | |
97 node->xyz[2] = -99.99f; | |
98 z_speed = -z_speed; | |
99 } | |
100 } | |
101 | |
102 static 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
|
103 ieboss_collision_invincibil(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, |
507 | 104 SceneGraphPtr tree) |
105 { | |
106 static int frame = 0; | |
107 | |
108 frame++; | |
109 | |
110 node->flag_drawable ^= 1; | |
111 | |
112 if (frame > 60) { | |
113 frame = 0; | |
114 node->flag_drawable = 1; | |
115 node->set_move_collision(ieboss_move, ieboss_collision); | |
116 } | |
117 } | |
118 | |
119 static 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
|
120 iebosstama_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) |
507 | 121 { |
122 node->xyz[1] += iebosstama_speed; | |
123 | |
124 // 描画領域から抜けたら削除 | |
125 if (node->xyz[1] > screen_h) { | |
126 node->remove(); | |
127 } | |
128 } | |
129 | |
130 static 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
|
131 ietama_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) |
507 | 132 { |
133 node->xyz[1] -= tama_speed; | |
134 | |
135 // 描画領域から抜けたら削除 | |
136 if (node->xyz[1] < 0) { | |
137 node->remove(); | |
138 } | |
139 } | |
140 | |
141 static 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
|
142 iejiki_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) |
507 | 143 { |
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
|
144 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; |
507 | 145 Pad *pad = sgroot->getController(); |
146 | |
147 if (pad->left.isPush() | |
148 || pad->left.isHold()) { | |
149 node->xyz[0] -= jiki_speed; | |
150 | |
151 if (node->xyz[0] - jiki_radius< 0) { | |
152 node->xyz[0] = jiki_radius; | |
153 } | |
154 } | |
155 | |
156 if (pad->right.isPush() | |
157 || pad->right.isHold()) { | |
158 node->xyz[0] += jiki_speed; | |
159 | |
160 if (node->xyz[0] + jiki_radius > screen_w) { | |
161 node->xyz[0] = screen_w - jiki_radius; | |
162 } | |
163 } | |
164 | |
165 if (pad->up.isPush() | |
166 || pad->up.isHold()) { | |
167 node->xyz[1] -= jiki_speed; | |
168 | |
169 if (node->xyz[1] - jiki_radius < 0) { | |
170 node->xyz[1] = jiki_radius; | |
171 } | |
172 } | |
173 | |
174 if (pad->down.isPush() | |
175 || pad->down.isHold()) { | |
176 node->xyz[1] += jiki_speed; | |
177 | |
178 if (node->xyz[1] + jiki_radius > screen_h) { | |
179 node->xyz[1] = screen_h - jiki_radius; | |
180 } | |
181 } | |
182 | |
183 if (pad->circle.isPush()) { | |
563
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
184 SceneGraphPtr ietama = sgroot->createSceneGraph("IETAMA"); |
507 | 185 ietama->set_move_collision(ietama_move, ietama_collision); |
186 ietama->xyz[0] = node->xyz[0]; | |
187 ietama->xyz[1] = node->xyz[1]; | |
188 node->addBrother(ietama); | |
189 } | |
190 } | |
191 | |
192 | |
557
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
193 MainLoopPtr |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
194 ieshoot::init(Viewer *sgroot, int w, int h) |
507 | 195 { |
196 SceneGraphPtr iejiki; | |
197 SceneGraphPtr enemy; | |
198 SceneGraphPtr back; | |
199 | |
563
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
200 sgroot->createFromXMLfile( "xml_file/ietama.xml"); |
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
201 sgroot->createFromXMLfile( "xml_file/ieboss.xml"); |
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
202 sgroot->createFromXMLfile( "xml_file/iejiki.xml"); |
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
203 sgroot->createFromXMLfile( "xml_file/universe.xml"); |
507 | 204 |
205 back = sgroot->createSceneGraph(); | |
206 | |
563
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
207 iejiki = sgroot->createSceneGraph("IEJIKI"); |
507 | 208 iejiki->set_move_collision(iejiki_move, iejiki_collision); |
209 iejiki->xyz[2] = 20; | |
210 back->addChild(iejiki); | |
211 | |
563
b21a013051a2
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
212 enemy = sgroot->createSceneGraph("IEBOSS"); |
507 | 213 enemy->set_move_collision(ieboss_move, ieboss_collision); |
214 enemy->xyz[1] = boss_radius_y; | |
215 back->addChild(enemy); | |
216 | |
217 sgroot->setSceneData(back); | |
557
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
218 return sgroot; |
507 | 219 } |
557
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
220 |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
221 extern Application * |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
222 application() { |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
223 return new ieshoot(); |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
224 } |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
225 |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
226 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
|
227 |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
228 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
|
229 extern void task_initialize(); |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
230 static void TMend(TaskManager *manager); |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
231 |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
232 int |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
233 TMmain(TaskManager *manager, int argc, char *argv[]) |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
234 { |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
235 task_initialize(); |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
236 manager->set_TMend(TMend); |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
237 return init(manager, argc, argv); |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
238 |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
239 } |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
240 |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
241 void |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
242 TMend(TaskManager *manager) |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
243 { |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
244 printf("test_nogl end\n"); |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
245 } |
ec72b601b71f
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
508
diff
changeset
|
246 |