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