Mercurial > hg > Game > Cerium
annotate Renderer/Test/vacuum.cc @ 2022:fac44ad2867d draft
make a sound
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 16 Jul 2014 02:50:32 +0900 |
parents | 7763f03a94e1 |
children |
rev | line source |
---|---|
539 | 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 | |
653
7a311860a76e
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) |
539 | 19 { |
20 | |
21 } | |
22 | |
23 void | |
653
7a311860a76e
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) |
539 | 25 { |
26 | |
27 } | |
28 | |
563
338ad9c856fc
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
29 int redcube; |
338ad9c856fc
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
30 int enemy; |
338ad9c856fc
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
31 |
539 | 32 void |
653
7a311860a76e
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, |
539 | 34 SceneGraphPtr tree) |
35 { | |
653
7a311860a76e
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_; |
539 | 37 Pad *pad = sgroot->getController(); |
38 | |
39 if(node->frame%ENCOUNT == ENCOUNT-1) { | |
40 if(random()%2) { | |
747 | 41 add_cubecollision_object(redcube,node,screen_w,screen_h, sgroot); |
539 | 42 } |
43 else { | |
747 | 44 add_cubecollision_object(enemy,node,screen_w,screen_h, sgroot); |
539 | 45 } |
46 } | |
47 | |
48 if (pad->cross.isHold()) { | |
49 SceneGraphIteratorPtr it = sgroot->getIterator(tree); | |
50 collision_red(it,node); | |
51 it = sgroot->getIterator(tree); | |
653
7a311860a76e
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); |
539 | 53 } |
54 | |
55 else if(pad->circle.isHold()) { | |
56 SceneGraphIteratorPtr it = sgroot->getIterator(tree); | |
653
7a311860a76e
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); |
539 | 58 } |
59 | |
60 } | |
61 | |
62 void | |
653
7a311860a76e
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) |
539 | 64 { |
65 | |
563
338ad9c856fc
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
66 SceneGraphPtr e; |
539 | 67 SceneGraphPtr near_enemy = NULL; |
68 float dx,dy,r,range = 100; | |
69 // Pad *pad = sgroot->getController(); | |
70 | |
563
338ad9c856fc
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
71 for(;it->hasNext(enemy);) { |
539 | 72 |
563
338ad9c856fc
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
73 it->next(enemy); |
338ad9c856fc
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
74 e = it->get(); |
338ad9c856fc
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]; |
338ad9c856fc
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]; |
539 | 77 r = sqrt(dx*dx+dy*dy); |
78 | |
563
338ad9c856fc
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) { |
539 | 80 range = r; |
563
338ad9c856fc
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
81 near_enemy = e; |
539 | 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
338ad9c856fc
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
91 lockon = sgroot->createSceneGraph("LOCK"); |
539 | 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 | |
653
7a311860a76e
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) { |
7a311860a76e
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_; |
539 | 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 | |
653
7a311860a76e
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) |
539 | 118 { |
653
7a311860a76e
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_; |
539 | 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 | |
653
7a311860a76e
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) |
539 | 149 { |
150 SceneGraphPtr object; | |
1211 | 151 // SceneGraphPtr common_move; |
539 | 152 |
1136 | 153 //common_move = sgroot->createSceneGraph(); |
539 | 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
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
163 MainLoopPtr |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
164 vacuum::init(Viewer *sgroot, int w, int h) |
539 | 165 { |
166 SceneGraphPtr title; | |
167 | |
563
338ad9c856fc
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"); |
338ad9c856fc
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"); |
338ad9c856fc
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"); |
539 | 171 |
563
338ad9c856fc
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
172 title = sgroot->createSceneGraph("TITLE"); |
539 | 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
338ad9c856fc
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
178 |
338ad9c856fc
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
179 redcube = sgroot->getSgid("REDCUBE"); |
338ad9c856fc
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
180 enemy = sgroot->getSgid("ENEMY"); |
338ad9c856fc
all exmple on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
557
diff
changeset
|
181 |
557
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
182 return sgroot; |
539 | 183 } |
557
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
184 |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
185 extern Application * |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
186 application() { |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
187 return new vacuum(); |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
188 } |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
189 |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
190 const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n"; |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
191 |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
192 extern int init(TaskManager *manager, int argc, char *argv[]); |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
193 extern void task_initialize(); |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
194 static void TMend(TaskManager *manager); |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
195 |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
196 int |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
197 TMmain(TaskManager *manager, int argc, char *argv[]) |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
198 { |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
199 task_initialize(); |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
200 manager->set_TMend(TMend); |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
201 return init(manager, argc, argv); |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
202 |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
203 } |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
204 |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
205 void |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
206 TMend(TaskManager *manager) |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
207 { |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
208 printf("test_nogl end\n"); |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
209 } |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
540
diff
changeset
|
210 |