0
|
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
|
|
18 no_move_idle(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
|
|
19 {
|
|
20
|
|
21 }
|
|
22
|
|
23 void
|
|
24 no_collision_idle(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h,SceneGraphPtr tree)
|
|
25 {
|
|
26
|
|
27 }
|
|
28
|
|
29 int redcube;
|
|
30 int enemy;
|
|
31
|
|
32 void
|
|
33 vacuum_coll(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h,
|
|
34 SceneGraphPtr tree)
|
|
35 {
|
|
36 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
|
|
37 Pad *pad = sgroot->getController();
|
|
38
|
|
39 if(node->frame%ENCOUNT == ENCOUNT-1) {
|
|
40 if(random()%2) {
|
|
41 add_cubecollision_object(redcube,node,screen_w,screen_h, sgroot);
|
|
42 }
|
|
43 else {
|
|
44 add_cubecollision_object(enemy,node,screen_w,screen_h, sgroot);
|
|
45 }
|
|
46 }
|
|
47
|
|
48 if (pad->cross.isHold()) {
|
|
49 SceneGraphIteratorPtr it = sgroot->getIterator(tree);
|
|
50 collision_red(it,node);
|
|
51 it = sgroot->getIterator(tree);
|
|
52 collision_purple(it,node,screen_w,screen_h, sgroot);
|
|
53 }
|
|
54
|
|
55 else if(pad->circle.isHold()) {
|
|
56 SceneGraphIteratorPtr it = sgroot->getIterator(tree);
|
|
57 lock_attack(node, it, sgroot);
|
|
58 }
|
|
59
|
|
60 }
|
|
61
|
|
62 void
|
|
63 lock_attack(SceneGraphPtr node,SceneGraphIteratorPtr it, SceneGraphRoot *sgroot)
|
|
64 {
|
|
65
|
|
66 SceneGraphPtr e;
|
|
67 SceneGraphPtr near_enemy = NULL;
|
|
68 float dx,dy,r,range = 100;
|
|
69 // Pad *pad = sgroot->getController();
|
|
70
|
|
71 for(;it->hasNext(enemy);) {
|
|
72
|
|
73 it->next(enemy);
|
|
74 e = it->get();
|
|
75 dx = e->xyz[0] - node->xyz[0];
|
|
76 dy = e->xyz[1] - node->xyz[1];
|
|
77 r = sqrt(dx*dx+dy*dy);
|
|
78
|
|
79 if(range > r && e->stack_xyz[2] == 0) {
|
|
80 range = r;
|
|
81 near_enemy = e;
|
|
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;
|
|
91 lockon = sgroot->createSceneGraph("LOCK");
|
|
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
|
|
100 lockon_collision(SceneGraphPtr node, void *sgroot_, int w, int h, SceneGraphPtr tree) {
|
|
101 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
|
|
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
|
|
117 vacuum_move(SceneGraphPtr node, void *sgroot_, int w, int h)
|
|
118 {
|
|
119 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
|
|
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
|
|
148 add_cubecollision_object(int id,SceneGraphPtr root,int w,int h, SceneGraphRoot *sgroot)
|
|
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
|
|
163 MainLoopPtr
|
|
164 vacuum::init(Viewer *sgroot, int w, int h)
|
|
165 {
|
|
166 SceneGraphPtr title;
|
|
167
|
|
168 sgroot->createFromXMLfile( "xml_file/gamecube.xml");
|
|
169 sgroot->createFromXMLfile( "xml_file/title.xml");
|
|
170 sgroot->createFromXMLfile( "xml_file/gameover.xml");
|
|
171
|
|
172 title = sgroot->createSceneGraph("TITLE");
|
|
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);
|
|
178
|
|
179 redcube = sgroot->getSgid("REDCUBE");
|
|
180 enemy = sgroot->getSgid("ENEMY");
|
|
181
|
|
182 return sgroot;
|
|
183 }
|
|
184
|
|
185 extern Application *
|
|
186 application() {
|
|
187 return new vacuum();
|
|
188 }
|
|
189
|
|
190 const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n";
|
|
191
|
|
192 extern int init(TaskManager *manager, int argc, char *argv[]);
|
|
193 extern void task_initialize();
|
|
194 static void TMend(TaskManager *manager);
|
|
195
|
|
196 int
|
|
197 TMmain(TaskManager *manager, int argc, char *argv[])
|
|
198 {
|
|
199 task_initialize();
|
|
200 manager->set_TMend(TMend);
|
|
201 return init(manager, argc, argv);
|
|
202
|
|
203 }
|
|
204
|
|
205 void
|
|
206 TMend(TaskManager *manager)
|
|
207 {
|
|
208 printf("test_nogl end\n");
|
|
209 }
|
|
210
|