507
|
1 #include <math.h>
|
|
2 #include "vacuum.h"
|
|
3 #include "SceneGraphRoot.h"
|
|
4 #include "SGList.h"
|
|
5 #define ENCOUNT 55
|
|
6 using namespace std;
|
|
7
|
|
8 static float vacuum_speed = 10.0f;
|
|
9
|
|
10
|
|
11 /*オブジェクト毎にファイルを分けてみた
|
|
12 *
|
|
13 *
|
|
14 */
|
|
15
|
|
16
|
|
17
|
|
18 void
|
|
19 no_move_idle(SceneGraphPtr node, int screen_w, int screen_h)
|
|
20 {
|
|
21
|
|
22 }
|
|
23
|
|
24 void
|
|
25 no_collision_idle(SceneGraphPtr node, int screen_w, int screen_h,SceneGraphPtr tree)
|
|
26 {
|
|
27
|
|
28 }
|
|
29
|
|
30 void
|
|
31 vacuum_coll(SceneGraphPtr node, int screen_w, int screen_h,
|
|
32 SceneGraphPtr tree)
|
|
33 {
|
|
34 Pad *pad = sgroot->getController();
|
|
35
|
|
36 if(node->frame%ENCOUNT == ENCOUNT-1) {
|
|
37 if(random()%2) {
|
|
38 add_cubecollision_object(REDCUBE,node,screen_w,screen_h);
|
|
39 }
|
|
40 else {
|
|
41 add_cubecollision_object(ENEMY,node,screen_w,screen_h);
|
|
42 }
|
|
43 }
|
|
44
|
|
45 if (pad->cross.isHold()) {
|
|
46 SceneGraphIteratorPtr it = sgroot->getIterator(tree);
|
|
47 collision_red(it,node);
|
|
48 it = sgroot->getIterator(tree);
|
|
49 collision_purple(it,node,screen_w,screen_h);
|
|
50 }
|
|
51
|
|
52 else if(pad->circle.isHold()) {
|
|
53 SceneGraphIteratorPtr it = sgroot->getIterator(tree);
|
|
54 lock_attack(node,it);
|
|
55 }
|
|
56
|
|
57 }
|
|
58
|
|
59 void
|
|
60 lock_attack(SceneGraphPtr node,SceneGraphIteratorPtr it)
|
|
61 {
|
|
62
|
|
63 SceneGraphPtr enemy;
|
|
64 SceneGraphPtr near_enemy = NULL;
|
|
65 float dx,dy,r,range = 100;
|
|
66 // Pad *pad = sgroot->getController();
|
|
67
|
|
68 for(;it->hasNext(ENEMY);) {
|
|
69
|
|
70 it->next(ENEMY);
|
|
71 enemy = it->get();
|
|
72 dx = enemy->xyz[0] - node->xyz[0];
|
|
73 dy = enemy->xyz[1] - node->xyz[1];
|
|
74 r = sqrt(dx*dx+dy*dy);
|
|
75
|
|
76 if(range > r && enemy->stack_xyz[2] == 0) {
|
|
77 range = r;
|
|
78 near_enemy = enemy;
|
|
79 }
|
|
80 }
|
|
81
|
|
82
|
|
83 if(near_enemy != NULL) {
|
|
84 /*stack_xyz[2]をlockonフラグとして使うかな?*/
|
|
85 SceneGraphPtr lockon;
|
|
86 // SceneGraphPtr near_enemy_common_move = near_enemy->parent;
|
|
87 near_enemy->stack_xyz[2] = 1;
|
|
88 lockon = sgroot->createSceneGraph(LOCK);
|
|
89 lockon->set_move_collision(no_move_idle,lockon_collision);
|
|
90 //near_enemy_common_move->addChild(lockon);
|
|
91 near_enemy->addChild(lockon);
|
|
92 }
|
|
93
|
|
94 }
|
|
95
|
|
96 void
|
|
97 lockon_collision(SceneGraphPtr node,int w,int h,SceneGraphPtr tree) {
|
|
98
|
|
99 Pad *pad = sgroot->getController();
|
|
100 SceneGraphPtr lockon_enemy = node->parent;
|
|
101
|
|
102 /* node->angle[0] = -lockon_enemy->angle[0];
|
|
103 node->angle[1] = -lockon_enemy->angle[1];
|
|
104 node->angle[2] = -lockon_enemy->angle[2];*/
|
|
105
|
|
106 if(pad->circle.isRelease()) {
|
|
107 lockon_enemy->remove();
|
|
108 }
|
|
109
|
|
110 }
|
|
111
|
|
112
|
|
113 void
|
|
114 vacuum_move(SceneGraphPtr node , int w, int h)
|
|
115 {
|
|
116 Pad *pad = sgroot->getController();
|
|
117
|
|
118 if (pad->right.isHold() && w > node->xyz[0]) {
|
|
119 node->xyz[0] += vacuum_speed;
|
|
120 node->angle[0] += 2;
|
|
121 } else if (pad->left.isHold() && 0 < node->xyz[0]) {
|
|
122 node->xyz[0] -= vacuum_speed;
|
|
123 node->angle[0] -= 2;
|
|
124 }
|
|
125
|
|
126 if (pad->up.isHold() && 0 < node->xyz[1]) {
|
|
127 node->xyz[1] -= vacuum_speed;
|
|
128 node->angle[1] -= 2;
|
|
129 } else if (pad->down.isHold() && h > node->xyz[1]) {
|
|
130 node->xyz[1] += vacuum_speed;
|
|
131 node->angle[1] += 2;
|
|
132 }
|
|
133
|
|
134 if (pad->start.isPush()) {
|
|
135 node->xyz[0] = w/2;
|
|
136 node->xyz[1] = h*0.8;
|
|
137 }
|
|
138 }
|
|
139
|
|
140
|
|
141
|
|
142 /*cubeをランダムな場所に生成*/
|
|
143 void
|
|
144 add_cubecollision_object(int id,SceneGraphPtr root,int w,int h)
|
|
145 {
|
|
146 SceneGraphPtr object;
|
|
147 SceneGraphPtr common_move;
|
|
148
|
|
149 common_move = sgroot->createSceneGraph();
|
|
150 object = sgroot->createSceneGraph(id);
|
|
151 object->xyz[0] = random()%w;
|
|
152 object->xyz[1] = random()%h;
|
|
153 object->set_move_collision(no_move_idle,cube_collision);
|
|
154 //common_move->addChild(object);
|
|
155 root->addBrother(object);
|
|
156 }
|
|
157
|
|
158
|
|
159 void
|
|
160 vacuum_init2(TaskManager *manager, int w, int h)
|
|
161 {
|
|
162 SceneGraphPtr title;
|
|
163
|
|
164 sgroot->createFromXMLfile(manager, "xml_file/gamecube.xml");
|
|
165 sgroot->createFromXMLfile(manager, "xml_file/title.xml");
|
|
166 sgroot->createFromXMLfile(manager, "xml_file/gameover.xml");
|
|
167
|
|
168 title = sgroot->createSceneGraph(TITLE);
|
|
169 title->xyz[0] = w/2;
|
|
170 title->xyz[1] = h/2;
|
|
171 title->set_move_collision(no_move_idle, title_collision);
|
|
172
|
|
173 sgroot->setSceneData(title);
|
|
174 }
|