Mercurial > hg > Members > koba > t_dandy
annotate Dandy.cc @ 40:cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
author | koba <koba@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 12 Jan 2011 00:01:02 +0900 |
parents | 6626e451a09d |
children | 2c85322348cf |
rev | line source |
---|---|
0 | 1 #include "Dandy.h" |
2 #include <stdio.h> | |
3 #include <stdlib.h> | |
4 #include <string.h> | |
5 #include <ctype.h> | |
6 #include <math.h> | |
7 #include <time.h> | |
8 #include <SDL.h> | |
9 #include "SDL_opengl.h" | |
10 #include "object.h" | |
11 #include "tree_controll.h" | |
12 #include "xml.h" | |
13 #include "profile.h" | |
14 #include "syokika.h" | |
15 #include "sankaku.h" | |
16 #include "sgoex.h" | |
17 #include "sound.h" | |
18 #include "bool.h" | |
19 #include "bom.h" | |
20 #include "count2.h" | |
21 #include "tokuten.h" | |
22 #include "schedule.h" | |
23 #include "tama.h" | |
24 #include "debug.h" | |
25 #include "trace.h" | |
26 #include "LoadSprite.h" | |
27 #include <SDL_mixer.h> | |
28 #include "error.h" | |
29 #include "matrix_calc.h" | |
30 #include "Character.h" | |
31 #include "Character_state.h" | |
32 | |
33 int use_keybord = 0; | |
34 int cdp[20] = { 16, 16, 16, 17, 18, 0 }; | |
35 int d, i; | |
36 | |
37 int rswait = 0; | |
38 int cf = 0; | |
39 int cc = 0; | |
40 | |
41 //static SDL_Surface *screen; | |
42 // static Uint32 background; | |
43 // static char *pad_trace_file; | |
44 | |
45 extern void schedule(); | |
46 extern void tokuten(); | |
47 extern void Pad(); | |
48 extern void keybord(); | |
49 static int gamesyokika(int gamef); | |
50 static int game_pause(int); | |
4 | 51 |
40
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
52 static char *pad_trace_file; |
0 | 53 |
54 /** | |
55 * runmode: | |
56 * 0 - normal game | |
57 * 1 - capture mode | |
58 * program will capture all pad traces on a play and | |
59 * dump it into a file | |
60 * 2 - trace mode | |
61 * program will run with a trace file which is generated | |
62 * by capture-mode | |
63 */ | |
64 | |
65 SDL_Joystick *joy; | |
66 | |
40
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
67 #define SCMP_SIZ 8 |
0 | 68 |
69 const char *usr_help_str = "Usage: ./twice [-length data_length] [-count task_num]\n\ | |
70 -length Number of data (default DATA_NUM (Func.h))\n\ | |
71 -count Number of task (default 1)\n"; | |
72 | |
73 static Viewer *sgroot; | |
74 | |
1 | 75 TaskManager *tmanager; |
76 | |
0 | 77 static int screen_w; |
78 static int screen_h; | |
79 | |
80 MainLoopPtr | |
81 Dandy::init(Viewer *sgroot_, int w, int h) | |
82 { | |
83 screen_w = w; | |
84 screen_h = h; | |
85 sgroot = sgroot_; | |
1 | 86 tmanager = sgroot->manager; |
0 | 87 return sgroot; |
88 } | |
89 | |
90 Application * | |
91 application() { | |
92 return new Dandy(); | |
93 } | |
94 | |
40
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
95 static void print_usage(); |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
96 static int get_option(int argc, char *argv[]); |
0 | 97 static int opening(int gamef); |
98 static int dandy_closing(int gamef); | |
99 static int dandy_main_loop(int gamef); | |
100 static int dandy_main_init(int gamef); | |
101 extern int init(TaskManager *manager, int argc, char *argv[]); | |
102 extern void task_initialize(); | |
103 static void TMend(TaskManager *manager); | |
104 | |
105 bool | |
106 Dandy::app_loop(Viewer *viewer){ | |
107 // don't use allExecute | |
108 return 0; | |
109 }; | |
110 | |
111 static int gamef = 0; | |
112 | |
113 HTaskPtr | |
114 Dandy::application_task(HTaskPtr next, Viewer* viewer){ | |
115 // printf("gamef = %d\n",gamef); | |
116 switch (gamef) { | |
117 case 0: gamef= dandy_main_init(gamef); break; | |
118 case 1: gamef= gamesyokika(gamef); break; | |
119 case 2: gamef= opening(gamef); break; | |
120 case 3: gamef= dandy_main_loop(gamef); break; | |
121 case 4: gamef= dandy_closing(gamef); break; | |
122 } | |
123 return next; | |
1 | 124 }; |
0 | 125 |
6
9a92435eaee6
divide SG Dandy and Task Dandy.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
126 void |
9a92435eaee6
divide SG Dandy and Task Dandy.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
127 task_init() |
9a92435eaee6
divide SG Dandy and Task Dandy.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
128 { |
9a92435eaee6
divide SG Dandy and Task Dandy.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
129 |
9a92435eaee6
divide SG Dandy and Task Dandy.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
130 } |
9a92435eaee6
divide SG Dandy and Task Dandy.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
131 |
0 | 132 int |
133 TMmain(TaskManager *manager,int argc, char *argv[]) | |
134 { | |
135 task_init(); | |
136 task_initialize(); | |
137 manager->set_TMend(TMend); | |
40
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
138 if (get_option(argc, argv)) { |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
139 print_usage(); |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
140 } |
0 | 141 |
142 return init(manager,argc, argv); | |
143 } | |
144 | |
145 void | |
146 TMend(TaskManager *manager) | |
147 { | |
148 printf("game end\n"); | |
149 } | |
150 | |
151 static int light_sysswitch = 1; | |
152 static int light_num = 4; | |
153 | |
154 static void | |
1 | 155 _LightSysSwitch(Viewer *sgroot) { |
0 | 156 if (light_sysswitch == 1) { |
19 | 157 sgroot->OffLightSysSwitch(); |
0 | 158 for (int i = 0; i < light_num; i++) { |
159 SceneGraphPtr light = sgroot->getLight(i); | |
160 sgroot->OnLightSwitch(i); | |
161 light->xyz[0] = screen_w / 2; | |
162 light->xyz[1] = screen_h / 2; | |
163 light->xyz[2] = -100; | |
164 } | |
165 } else if (light_sysswitch == 0) { | |
166 sgroot->OffLightSysSwitch(); | |
167 } | |
168 } | |
169 | |
170 | |
40
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
171 static void |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
172 print_usage() |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
173 { |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
174 printf("usage: exe_file [-h|-help|--help][-capture filename][-trace filename]\n"); |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
175 } |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
176 |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
177 |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
178 static int |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
179 get_option(int argc, char *argv[]) |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
180 { |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
181 int i; |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
182 if (argc < 2) { |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
183 return 0; |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
184 } |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
185 for (i = 0; i < argc; i++) { |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
186 if (!strncmp(argv[i], "-capture", SCMP_SIZ)) { |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
187 if (++i >= argc) { |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
188 return 1; |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
189 } |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
190 printf("Start capture mode.\n"); |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
191 pad_trace_file = argv[i]; |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
192 runmode = 1; |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
193 return 0; |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
194 } else if (!strncmp(argv[i], "-trace", SCMP_SIZ)) { |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
195 if (++i >= argc) { |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
196 return 1; |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
197 } |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
198 printf("Start trace mode.\n"); |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
199 pad_trace_file = argv[i]; |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
200 runmode = 2; |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
201 return 0; |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
202 } else if (!strncmp(argv[i], "--help", SCMP_SIZ) || |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
203 !strncmp(argv[i], "-help", SCMP_SIZ) || |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
204 !strncmp(argv[i], "-h", SCMP_SIZ)) { |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
205 return 1; |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
206 } |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
207 } |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
208 return 1; |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
209 } |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
210 |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
211 |
0 | 212 static int |
213 dandy_main_init(int gamef) | |
214 { | |
215 //Timeprof timeprof_move; | |
216 //timeprof_move = timeprof_new(); | |
217 dbg_init("/dev/stdout"); | |
218 | |
219 /** | |
220 * timeprof があるんだけどね | |
221 */ | |
40
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
222 if ((runmode == 1)||(runmode == 2)) { |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
223 pad_file_open(pad_trace_file); |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
224 } |
0 | 225 |
226 sgroot->createFromXMLfile("xml/character.xml"); | |
227 sgroot->createFromXMLfile("xml/font.xml"); | |
228 sgroot->createFromXMLfile("xml/effect.xml"); | |
229 sgroot->createFromXMLfile("xml/boss.xml"); | |
230 | |
1 | 231 _LightSysSwitch(sgroot); |
0 | 232 |
233 init_sprite(0,0,0,0); | |
234 | |
235 __debug("syokikaが呼びだされました\n"); | |
236 joy=SDL_JoystickOpen(0); | |
237 if(!joy) { | |
238 fprintf(stderr,"failed to open joystick 0\n"); | |
239 use_keybord = 1; | |
240 } | |
241 | |
242 /** | |
243 * sound.c に移しました | |
244 * 代わりに InitSdlMixer(void); を使います。 | |
245 * まあ中身一緒なんだけどね | |
246 */ | |
247 /** | |
248 if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY,MIX_DEFAULT_FORMAT,2,1024) < 0) { | |
249 fprintf(stderr,"failed to initialize SDL_mixer.\n"); | |
250 SDL_Quit(); | |
251 exit(-1); | |
252 } | |
253 */ | |
254 | |
255 // SDL_mixer とかいろいろ初期化 | |
256 // もし Init に失敗したら | |
257 // 以後の Mixer 関連の関数を呼び出しても | |
258 // 中では何も行われないとかいう小細工を入れました。 | |
259 InitSdlMixer(); | |
260 | |
261 // 音楽ファイルの読み込み | |
262 LoadSdlMixer(); | |
263 | |
264 // ボリューム調整 | |
265 InitVolume(); | |
1 | 266 |
0 | 267 // 音出しテスト |
268 PlaySdlMixer(-1, BGM); | |
269 | |
270 if(!(init_chara_list(1024))){ | |
271 __debug("failed to init_chara_list\n"); | |
272 } | |
273 | |
274 __debug("finished init_chara_list\n"); | |
275 | |
276 return 1; | |
277 } | |
278 | |
279 SceneGraphPtr root; | |
280 | |
281 // extern void get_matrix(float *matrix, float *rxyz, float *txyz, float *scale, float *stack); | |
282 | |
283 static void | |
284 flip() | |
285 { | |
286 CameraPtr camera = sgroot->sgroot->getCamera(); | |
287 | |
288 sgroot->sgroot->flip(); | |
289 sgroot->sgroot->lightCalc(); | |
290 | |
291 root = sgroot->createSceneGraph(); | |
19 | 292 root->xyz[0] = 0; |
293 root->xyz[1] = 0; | |
0 | 294 root->xyz[2] = 30.0f; |
295 | |
296 /*親の回転、座標から、子の回転、座標を算出*/ | |
297 get_matrix(root->matrix, root->angle, root->xyz, root->scale, camera->matrix); | |
298 /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ | |
299 get_matrix(root->real_matrix, root->angle, root->xyz, root->scale, camera->real_matrix); | |
300 | |
301 sgroot->setSceneData(root); | |
302 } | |
303 | |
304 | |
305 static int | |
306 dandy_main_loop(int gamef) | |
307 { | |
308 if ((pad[0].l1 != 0) && (pad[0].r1 != 0) && | |
309 (pad[0].l2 != 0) && (pad[0].r2 != 0)) { | |
310 gamef = gamesyokika(gamef); | |
311 } | |
312 | |
313 if (pad[0].quit != 0) { | |
314 gamef = 4; | |
315 } | |
316 flip(); | |
317 | |
318 //SDL_FillRect(screen, NULL, background); | |
1 | 319 |
0 | 320 schedule(); |
321 enemyfaste = count; | |
322 | |
323 // timeprof_begin(timeprof_move); | |
324 //Move(); //enemy move | |
325 collision_detect(); | |
326 outofwindow(); | |
327 // timeprof_end(timeprof_move); | |
328 state_update(); | |
329 asteroidi = 0; | |
330 //charpatern(); | |
331 //bosguage(); | |
332 | |
333 if (jiki.bf == TRUE) { | |
334 Player(0); | |
335 count++; | |
336 PutSprite(count, jiki.x, jiki.y, jiki.ch); | |
337 } | |
338 | |
339 Putbom(); | |
340 tokuten(); | |
341 | |
342 count++; | |
343 //PutSprite(count, 0, 960 - 96, 10); | |
344 /*インフレゲージ */ | |
345 count++; | |
346 //PutSprite(count, 0, 0, 48); | |
347 | |
348 obj_draw(); | |
349 gamef = game_pause(gamef); | |
350 | |
40
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
351 switch (runmode) { |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
352 case 0: |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
353 if (use_keybord) { |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
354 keybord(); |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
355 } else { |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
356 Pad(joy); |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
357 } |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
358 break; |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
359 case 1: |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
360 if (use_keybord) { |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
361 keybord(); |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
362 } else { |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
363 Pad(joy); |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
364 } |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
365 capture_pad(); |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
366 break; |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
367 case 2: |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
368 if (!pad_file_read()) { |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
369 printf("can't trace file.\n"); |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
370 runmode = 0; |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
371 } |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
372 break; |
0 | 373 } |
40
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
374 |
0 | 375 filpcount++; |
376 count = 0; | |
377 | |
378 return gamef; | |
379 } | |
380 | |
381 static int | |
382 dandy_closing(int gamef) | |
383 { | |
40
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
384 pad_file_close(); |
0 | 385 |
386 //_______________________________________________ | |
387 // SDL_mixerの後始末 | |
388 Mix_CloseAudio(); | |
389 Mix_HaltMusic(); | |
390 FreeSdlMixer() ; | |
391 //_______________________________________________ | |
392 return 0; | |
393 } | |
394 | |
395 | |
396 static int | |
397 gamesyokika(int gamef) | |
398 { | |
399 laser_lv3[0].r = 62; | |
400 laser_lv3[0].r = 62; | |
401 for (i = 0; i < 3; i++) { | |
402 tlv3[i].y = -1; | |
403 } | |
404 filpcount = 0; | |
40
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
405 stage = 0; |
0 | 406 //for (i = 0; i < 300; i++) |
407 //enemy[i].f = FALSE; | |
408 jiki.zanki = 3; | |
409 jiki.x = 60; | |
410 jiki.y = 200; | |
411 jiki.ch = 3; | |
412 jiki.point = 0; | |
413 jiki.bf = FALSE; | |
414 jiki.muteki = 120; | |
415 enemycount = 0; | |
416 lg.stg = 4096; | |
417 pg.stg = 4096; | |
418 infg.stg = 0; | |
419 infg_level = 0; | |
420 //kyeenemyno = -1; | |
421 fastebos = 0; | |
422 jiki.ccount = 99; | |
423 p_extend = 200000; | |
424 pad[0].up=0; | |
425 pad[0].down=0; | |
426 pad[0].right=0; | |
427 pad[0].left=0; | |
428 pad[0].st=0; | |
429 pad[0].se=0; | |
430 | |
431 SoundStop(); | |
432 SoundPlay(7); | |
433 gamef = 2; | |
434 flip(); | |
435 return gamef; | |
436 } | |
437 | |
438 static int | |
439 opening(int gamef) | |
440 { | |
441 if(use_keybord == 1) { | |
442 keybord(); | |
443 } else { | |
444 Pad(joy); | |
445 } | |
446 | |
447 count = 1; | |
448 | |
449 PutSprite(count, 700, 480, 53); // put `push start' string on screen. | |
450 count++; | |
451 PutSprite(count, 224, 776, 119); // put `super dandy' | |
452 count++; | |
453 // PutSprite(count, 200, 64, 190); | |
454 // PutSpriteEx(count, 8192, 8192, 0); | |
455 PutSpriteEx(190, 800, 264, 2, 2, 5); | |
456 count++; | |
457 PutSprite(count, 396, 432, 191); | |
458 //PutSpriteEx(count, 8192, 8192, 0); | |
459 count++; | |
460 PutSprite(count, 640, 640, 192); | |
461 //PutSpriteEx(count, 8192, 8192, 0); | |
462 | |
463 if (pad[0].st > 1) { | |
464 jiki.bf = TRUE; | |
465 | |
466 //CdPlay(1,&cdp[0],0); | |
467 SoundStop(); | |
468 SoundPlay(0); | |
469 | |
470 gamef = 3; | |
471 pad[0].st = 1; | |
472 } else if ((pad[0].se > 0) && (pad[0].st > 0)) { | |
473 gamef = 2; | |
474 } | |
475 flip(); | |
476 return gamef; | |
477 } | |
478 | |
479 static int | |
480 game_pause(int gamef) | |
481 { | |
482 gamef = 3; | |
483 if (jiki.zanki != 0 && jiki.bf != FALSE) { | |
484 if (pad[0].se == 1) { | |
485 //Mix_Pause(BGM); | |
486 PauseSdlMixer(BGM); | |
487 while(1){ | |
488 if(use_keybord == 1) { | |
489 keybord(); | |
490 } else { | |
491 Pad(joy); | |
492 } | |
493 if(pad[0].st == 0) | |
494 continue; | |
495 pad[0].up=0; | |
496 pad[0].down=0; | |
497 pad[0].right=0; | |
498 pad[0].left=0; | |
499 pad[0].se=0; | |
500 pad[0].st=0; | |
501 //Mix_Resume(BGM); | |
502 ResumeSdlMixer(BGM); | |
503 break; | |
504 } | |
505 } | |
506 } | |
507 if (jiki.zanki == 0) { | |
508 // RECT *recp; | |
509 if ((jiki.ccount > 0) && (cf == 0)) { | |
510 cf = 1; | |
511 count++; | |
512 //cgcg(2); | |
513 PutSprite(2, 480, 480, 110); | |
514 count++; | |
515 //cgcg(1); | |
516 } | |
517 if ((jiki.ccount > 0) && (cf == 1)) { | |
518 while (1) { | |
519 if (pad[0].st > 0) { | |
520 cf = 0; | |
521 jiki.ccount--; | |
522 jiki.zanki = 3; | |
523 enemycount++; | |
524 cc = 0; | |
525 for (i = 0; i < 4; i++) { | |
526 clear_result[i] = 0; | |
527 } | |
528 goto f; | |
529 } | |
530 cc++; | |
531 if (29 - cc / 60 < 20) { | |
532 cc = 0; | |
533 cf = 3; | |
534 break; | |
535 } | |
536 SDL_Delay(100); | |
537 PutSprite(1, 640, 640, 29 - cc / 60); | |
538 // PutSpriteEx(1, 409 * ((cc % 60) + 1), 409 * ((cc % 60) + 1), 0); | |
539 | |
540 Pad(joy); | |
541 flip(); // this is not correct | |
542 } | |
543 } | |
544 if (rswait > 60 * 6) { | |
545 cf = 0; | |
546 rswait = 0; | |
547 gamef = gamesyokika(gamef); | |
548 } | |
549 rswait++; | |
550 count++; | |
551 //cgcg(1); | |
552 PutSprite(1, 480, 480, 19); | |
553 return gamef; | |
554 } | |
555 if (jiki.bf == FALSE) { | |
556 f: | |
557 if (rswait < 80) { | |
558 rswait++; | |
559 return gamef; | |
560 } else { | |
561 rswait = 0; | |
562 jiki.x = 60; | |
563 jiki.y = 200; | |
564 jiki.bf = TRUE; | |
565 | |
566 pad[0].st = 0; | |
567 lg.stg = 4096; | |
568 pg.stg = 4096; | |
569 laser_lv3[0].r = 62; | |
570 tlv3[0].r = 0; | |
571 tlv3[0].y = -1; | |
572 return gamef; | |
573 // sb_size = -1; | |
574 } | |
575 } | |
576 return gamef; | |
577 } | |
578 | |
579 | |
580 SpriteTable sptable[DEFOBJ]; | |
581 | |
582 | |
583 void | |
584 DefSpriteEx(int number, short middlex, short middley) | |
585 { | |
586 sptable[number].mx = middlex; | |
587 sptable[number].my = middley; | |
588 } | |
589 | |
590 | |
591 void | |
592 DefSprite(int number, const char *name, float w, float h, int color, OBJECT *obj) | |
593 { | |
594 SpriteTable *m = &sptable[number]; | |
595 m->w = w; | |
596 m->h = h; | |
597 m->color = (color & 32); | |
598 m->mx = w / 2; | |
599 m->my = h / 2; | |
33 | 600 m->tex_w = power_of_two(m->w); |
601 m->tex_h = power_of_two(m->h); | |
602 | |
0 | 603 m->texture = (int *)name; |
604 | |
605 } | |
606 | |
33 | 607 static float my_scale = 5; |
608 | |
0 | 609 void |
610 PutSprite(int zorder, short x, short y, int number) | |
611 { | |
612 SpriteTable *m = &sptable[number]; | |
613 char *name = (char *) m->texture; | |
33 | 614 if (!name) { |
615 printf("PutSprite %d unknown\n",number); | |
616 return; | |
617 } | |
0 | 618 SceneGraphPtr object = sgroot->createSceneGraph(name); |
33 | 619 object->xyz[0] = x - object->c_xyz[0]*my_scale; |
620 object->xyz[1] = y - object->c_xyz[1]*my_scale; | |
0 | 621 object->xyz[2] = 0; |
622 root->addChild(object); | |
623 | |
33 | 624 float scale[] = {my_scale,my_scale,1}; |
0 | 625 /*親の回転、座標から、子の回転、座標を算出*/ |
626 get_matrix(object->matrix, object->angle, object->xyz, scale, root->matrix); | |
627 /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ | |
628 get_matrix(object->real_matrix, object->angle, object->xyz, scale, root->real_matrix); | |
629 | |
630 } | |
631 | |
632 void | |
633 PutSpriteEx(int number, int x, int y, float scalex, float scaley, float angle) | |
634 { | |
635 SpriteTable *m = &sptable[number]; | |
636 char *name = (char *) m->texture; | |
637 if (!name) { | |
638 printf("PutSpriteEx %d unknown\n",number); | |
639 return; | |
640 } | |
641 SceneGraphPtr object = sgroot->createSceneGraph(name); | |
33 | 642 object->xyz[0] = x - object->c_xyz[0]*my_scale - m->w*my_scale; |
643 object->xyz[1] = y - object->c_xyz[0]*my_scale - m->w*my_scale; | |
0 | 644 object->xyz[2] = 0; |
645 object->c_xyz[0] = m->mx; | |
646 object->c_xyz[1] = m->my; | |
647 object->angle[3] = angle; | |
648 root->addChild(object); | |
649 | |
650 float scale[] = {5*scalex,5*scaley,1}; | |
651 /*親の回転、座標から、子の回転、座標を算出*/ | |
652 get_matrix(object->matrix, object->angle, object->xyz, scale, root->matrix); | |
653 /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ | |
654 get_matrix(object->real_matrix, object->angle, object->xyz, scale, root->real_matrix); | |
655 } | |
656 | |
657 | |
658 struct SGO_PAD pad[2]; | |
659 | |
660 | |
661 /* コントローラ状態の読み込み */ | |
662 void Pad(SDL_Joystick *joy) | |
663 { | |
664 Sint16 axis; | |
665 | |
666 SDL_JoystickUpdate(); | |
667 | |
668 if(SDL_JoystickGetButton(joy,PS2_CROSS)==SDL_PRESSED) | |
669 pad[0].k0++; | |
670 else | |
671 pad[0].k0=0; | |
672 | |
673 if(SDL_JoystickGetButton(joy,PS2_CIRCLE)==SDL_PRESSED) | |
674 pad[0].k1++; | |
675 else | |
676 pad[0].k1=0; | |
677 | |
678 if(SDL_JoystickGetButton(joy,PS2_SQUARE)==SDL_PRESSED) | |
679 pad[0].k3++; | |
680 else | |
681 pad[0].k3=0; | |
682 | |
683 if(SDL_JoystickGetButton(joy,PS2_TRIANGLE)==SDL_PRESSED) | |
684 pad[0].k4++; | |
685 else | |
686 pad[0].k4=0; | |
687 | |
688 if(SDL_JoystickGetButton(joy,PS2_L1)==SDL_PRESSED) | |
689 pad[0].l1++; | |
690 else | |
691 pad[0].l1=0; | |
692 | |
693 if(SDL_JoystickGetButton(joy,PS2_R1)==SDL_PRESSED) | |
694 pad[0].r1++; | |
695 else | |
696 pad[0].r1=0; | |
697 | |
698 if(SDL_JoystickGetButton(joy,PS2_L2)==SDL_PRESSED) | |
699 pad[0].l2++; | |
700 else | |
701 pad[0].l2=0; | |
702 | |
703 if(SDL_JoystickGetButton(joy,PS2_R2)==SDL_PRESSED) | |
704 pad[0].r2++; | |
705 else | |
706 pad[0].r2=0; | |
707 | |
708 if(SDL_JoystickGetButton(joy,PS2_START)==SDL_PRESSED) | |
709 pad[0].st++; | |
710 else | |
711 pad[0].st=0; | |
712 | |
713 if(SDL_JoystickGetButton(joy,PS2_SELECT)==SDL_PRESSED) | |
714 pad[0].se++; | |
715 else | |
716 pad[0].se=0; | |
717 | |
718 if(SDL_JoystickGetButton(joy,PS2_L3)==SDL_PRESSED) | |
719 pad[0].l3++; | |
720 else | |
721 pad[0].l3=0; | |
722 | |
723 if(SDL_JoystickGetButton(joy,PS2_R3)==SDL_PRESSED) | |
724 pad[0].r3++; | |
725 else | |
726 pad[0].r3=0; | |
727 //x | |
728 axis=SDL_JoystickGetAxis(joy,0); | |
729 if(axis>=3200){ | |
730 pad[0].left=0; | |
731 pad[0].right++; | |
732 } | |
733 else if(axis<=-3200){ | |
734 pad[0].right=0; | |
735 pad[0].left++; | |
736 } | |
737 else { | |
738 pad[0].right=0; | |
739 pad[0].left=0; | |
740 } | |
741 //y | |
742 axis=SDL_JoystickGetAxis(joy,1); | |
743 if(axis>=3200){ | |
744 pad[0].up=0; | |
745 pad[0].down++; | |
746 } | |
747 else if(axis<=-3200){ | |
748 pad[0].down=0; | |
749 pad[0].up++; | |
750 } | |
751 else { | |
752 pad[0].down=0; | |
753 pad[0].up=0; | |
754 } | |
755 | |
756 if ((pad[0].l1 != 0) && (pad[0].r1 != 0) && | |
757 (pad[0].l2 != 0) && (pad[0].r2 != 0) && | |
758 (pad[0].st != 0) && (pad[0].se != 0)) { | |
759 pad[0].quit = 1; | |
760 } else { | |
761 pad[0].quit = 0; | |
762 } | |
763 | |
764 } | |
765 | |
766 | |
767 void keybord() | |
768 { | |
769 SDL_PumpEvents(); | |
770 Uint8 *keys = SDL_GetKeyState(NULL); | |
771 | |
772 if (keys[SDLK_UP]) { | |
773 pad[0].up++; | |
774 } else { | |
775 pad[0].up = 0; | |
776 } | |
777 if (keys[SDLK_DOWN]) { | |
778 pad[0].down++; | |
779 } else { | |
780 pad[0].down = 0; | |
781 } | |
782 | |
783 if (keys[SDLK_RIGHT]) { | |
784 pad[0].right++; | |
785 } else { | |
786 pad[0].right = 0; | |
787 } | |
788 | |
789 if (keys[SDLK_LEFT]) { | |
790 pad[0].left++; | |
791 } else { | |
792 pad[0].left = 0; | |
793 } | |
794 | |
795 if (keys[SDLK_a]) { | |
796 pad[0].k0++; | |
797 } else { | |
798 pad[0].k0 = 0; | |
799 } | |
800 | |
801 if (keys[SDLK_z]) { | |
802 pad[0].k1++; | |
803 } else { | |
804 pad[0].k1 = 0; | |
805 } | |
806 | |
807 if (keys[SDLK_s]) { | |
808 pad[0].k3++; | |
809 } else { | |
810 pad[0].k3 = 0; | |
811 } | |
812 | |
813 if (keys[SDLK_x]) { | |
814 pad[0].k4++; | |
815 } else { | |
816 pad[0].k4 = 0; | |
817 } | |
818 | |
819 if (keys[SDLK_r]) { | |
820 pad[0].r2++; | |
821 } else { | |
822 pad[0].r2 = 0; | |
823 } | |
824 | |
825 if (keys[SDLK_e]) { | |
826 pad[0].r1++; | |
827 } else { | |
828 pad[0].r1 = 0; | |
829 } | |
830 | |
831 if (keys[SDLK_w]) { | |
832 pad[0].l1++; | |
833 } else { | |
834 pad[0].l1 = 0; | |
835 } | |
836 | |
837 if (keys[SDLK_q]) { | |
838 pad[0].l2++; | |
839 } else { | |
840 pad[0].l2 = 0; | |
841 } | |
842 | |
843 // START ボタンは Return が似合う気がする | |
844 //if(keys[SDLK_1]) | |
845 if (keys[SDLK_RETURN]) { | |
846 pad[0].st++; | |
847 } else { | |
848 pad[0].st = 0; | |
849 } | |
850 | |
851 if (keys[SDLK_2]) { | |
852 pad[0].se++; | |
853 } else { | |
854 pad[0].se = 0; | |
855 } | |
856 | |
857 if (keys[SDLK_ESCAPE]) { | |
40
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
858 pad_file_close(); |
cbe5bb9068c3
add trace mode to tree_dandy2(SceneGraph)
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
38
diff
changeset
|
859 |
0 | 860 SDL_Quit(); |
861 exit(1); | |
862 //pad[0].st = 1; | |
863 //pad[0].se = 1; | |
864 } | |
865 | |
866 if (keys[SDLK_0]) { | |
867 pad[0].quit = 1; | |
868 } else { | |
869 pad[0].quit = 0; | |
870 } | |
871 } | |
872 | |
873 | |
874 /* end */ |