Mercurial > hg > Members > koba > t_dandy
annotate main.c @ 47:f5e112bffe26
fix old version.
author | koba <koba@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 18 Jan 2011 19:35:58 +0900 |
parents | 2c85322348cf |
children | fce767bb5e25 |
rev | line source |
---|---|
0 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include <ctype.h> | |
5 #include <math.h> | |
6 #include <time.h> | |
7 #include <SDL.h> | |
8 #include "SDL_opengl.h" | |
9 #include "object.h" | |
10 #include "tree_controll.h" | |
11 #include "xml.h" | |
12 #include "profile.h" | |
13 #include "syokika.h" | |
14 #include "sankaku.h" | |
15 #include "sgoex.h" | |
16 #include "sound.h" | |
17 #include "bool.h" | |
18 #include "Character.h" | |
19 #include "Character_state.h" | |
20 #include "bom.h" | |
21 #include "count2.h" | |
22 #include "tokuten.h" | |
23 #include "schedule.h" | |
24 #include "tama.h" | |
25 #include "debug.h" | |
26 #include "trace.h" | |
27 #include "LoadSprite.h" | |
28 #include <SDL_mixer.h> | |
29 | |
30 #include "error.h" | |
31 | |
44 | 32 static int runmode = 0; |
0 | 33 static int gamef = 0; |
34 static int use_keybord = 0; | |
35 static int i; | |
36 | |
37 static int rswait = 0; | |
38 static int cf = 0; | |
39 static int cc = 0; | |
40 | |
41 static Uint32 background; | |
43 | 42 static TraceBuffPtr t_buff; |
39
5484b8606e8e
add trace mode to tree_dandy2(GL).
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
34
diff
changeset
|
43 static char *pad_trace_file; |
0 | 44 |
45 extern void schedule(); | |
46 extern void tokuten(); | |
47 extern void keybord(); | |
48 //extern void PutSpriteEx(int number, int x, int y, GLfloat scalex, GLfloat scaley, GLfloat angle); | |
49 //GLuint texture[250] = {0}; | |
50 static void gamesyokika(SDL_Joystick *joy); | |
51 static void opening(SDL_Joystick *joy); | |
52 static void pause(SDL_Joystick *joy); | |
44 | 53 static void KeyAssign(int runmode, TraceBuffPtr buff, SDL_Joystick *joy, SGO_PAD *pad); |
43 | 54 |
0 | 55 extern void SDL_GL_Enter2DMode(); |
56 extern void SDL_GL_Leave2DMode(); | |
57 | |
58 /** | |
59 * runmode: | |
60 * 0 - normal game | |
61 * 1 - capture mode | |
62 * program will capture all pad traces on a play and | |
63 * dump it into a file | |
64 * 2 - trace mode | |
65 * program will run with a trace file which is generated | |
66 * by capture-mode | |
67 */ | |
68 | |
39
5484b8606e8e
add trace mode to tree_dandy2(GL).
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
34
diff
changeset
|
69 |
0 | 70 #define SCMP_SIZ 8 |
71 | |
72 | |
39
5484b8606e8e
add trace mode to tree_dandy2(GL).
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
34
diff
changeset
|
73 static void |
5484b8606e8e
add trace mode to tree_dandy2(GL).
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
34
diff
changeset
|
74 print_usage() |
0 | 75 { |
44 | 76 printf("usage: ./exe_file [-h|-help|--help][-capture filename][-trace filename]\n"); |
0 | 77 } |
78 | |
79 | |
39
5484b8606e8e
add trace mode to tree_dandy2(GL).
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
34
diff
changeset
|
80 static int |
5484b8606e8e
add trace mode to tree_dandy2(GL).
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
34
diff
changeset
|
81 get_option(int argc, char *argv[]) |
0 | 82 { |
83 int i; | |
84 if (argc < 2) { | |
43 | 85 runmode = 0; |
86 return 0; | |
0 | 87 } |
88 for (i = 0; i < argc; i++) { | |
43 | 89 if (!strncmp(argv[i], "-capture", SCMP_SIZ)) { |
90 if (++i >= argc) { | |
91 return 1; | |
92 } | |
93 printf("Start Capture mode.\n"); | |
94 t_buff = (TraceBuffPtr)malloc(sizeof(TraceBuff)); | |
95 t_buff->next = NULL; | |
96 pad_trace_file = argv[i]; | |
97 runmode = 1; | |
98 return 0; | |
99 } else if (!strncmp(argv[i], "-trace", SCMP_SIZ)) { | |
100 if (++i >= argc) { | |
101 return 1; | |
0 | 102 } |
43 | 103 printf("Start Trace mode.\n"); |
104 t_buff = (TraceBuffPtr)malloc(sizeof(TraceBuff)); | |
105 t_buff->next = NULL; | |
106 pad_trace_file = argv[i]; | |
107 runmode = 2; | |
108 return 0; | |
109 } else if (!strncmp(argv[i], "--help", SCMP_SIZ) || | |
110 !strncmp(argv[i], "-help", SCMP_SIZ) || | |
111 !strncmp(argv[i], "-h", SCMP_SIZ)) { | |
112 return 1; | |
113 } | |
0 | 114 } |
43 | 115 |
0 | 116 return 1; |
117 } | |
118 | |
119 | |
120 int main(int argc, char *argv[]) | |
121 { | |
122 Timeprof timeprof_move; | |
123 timeprof_move = timeprof_new(); | |
124 dbg_init("/dev/stdout"); | |
125 | |
126 /** | |
127 * timeprof があるんだけどね | |
128 */ | |
129 int frames = 0; | |
130 int start_time = 0, stop_time = 0; | |
131 | |
132 if (get_option(argc, argv)) { | |
39
5484b8606e8e
add trace mode to tree_dandy2(GL).
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
34
diff
changeset
|
133 print_usage(); |
43 | 134 return 0; |
0 | 135 } |
43 | 136 |
44 | 137 TraceBuffPtr first; |
43 | 138 if ((runmode == 1)||(runmode ==2)) { |
139 if (!PadfileOpen(pad_trace_file)) { | |
140 runmode = 0; | |
141 } else if(runmode == 2) { | |
142 PadfileRead(t_buff); | |
143 } | |
144 first = t_buff; | |
0 | 145 } |
43 | 146 |
39
5484b8606e8e
add trace mode to tree_dandy2(GL).
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
34
diff
changeset
|
147 /* |
5484b8606e8e
add trace mode to tree_dandy2(GL).
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
34
diff
changeset
|
148 if(myrand_open_file("rand_trace")) { |
5484b8606e8e
add trace mode to tree_dandy2(GL).
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
34
diff
changeset
|
149 perror("main"); |
5484b8606e8e
add trace mode to tree_dandy2(GL).
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
34
diff
changeset
|
150 retun 1; |
0 | 151 } |
39
5484b8606e8e
add trace mode to tree_dandy2(GL).
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
34
diff
changeset
|
152 */ |
0 | 153 |
154 //SDL_Joystick *joy=SDL_JoystickOpen(0); | |
155 | |
156 syokika(argc, argv); | |
157 __debug("syokikaが呼びだされました\n"); | |
158 SDL_Joystick *joy=SDL_JoystickOpen(0); | |
159 if(!joy) { | |
160 fprintf(stderr,"failed to open joystick 0\n"); | |
161 use_keybord = 1; | |
162 } | |
163 background = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00); | |
164 SDL_FillRect(screen, NULL, background); | |
165 SDL_GL_Enter2DMode(); | |
166 | |
167 opening(joy); | |
168 | |
169 __debug("openingがよびだされました\n"); | |
170 | |
171 /** | |
172 * sound.c に移しました | |
173 * 代わりに InitSdlMixer(void); を使います。 | |
174 * まあ中身一緒なんだけどね | |
175 */ | |
176 /** | |
177 if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY,MIX_DEFAULT_FORMAT,2,1024) < 0) { | |
178 fprintf(stderr,"failed to initialize SDL_mixer.\n"); | |
179 SDL_Quit(); | |
180 exit(-1); | |
181 } | |
182 */ | |
183 | |
184 // SDL_mixer とかいろいろ初期化 | |
185 // もし Init に失敗したら | |
186 // 以後の Mixer 関連の関数を呼び出しても | |
187 // 中では何も行われないとかいう小細工を入れました。 | |
188 InitSdlMixer(); | |
189 | |
190 // 音楽ファイルの読み込み | |
191 LoadSdlMixer(); | |
192 | |
193 // ボリューム調整 | |
194 InitVolume(); | |
195 | |
196 // 音出しテスト | |
197 PlaySdlMixer(-1, BGM); | |
198 | |
199 if(!(init_chara_list(1024))){ | |
200 __debug("failed to init_chara_list\n"); | |
201 } | |
202 | |
203 __debug("finished init_chara_list\n"); | |
204 | |
205 start_time = SDL_GetTicks(); | |
206 | |
207 while (gamef) { | |
43 | 208 if ((pad[0].l1 != 0) && (pad[0].r1 != 0) && |
0 | 209 (pad[0].l2 != 0) && (pad[0].r2 != 0)) { |
210 glFlush(); | |
211 SDL_GL_SwapBuffers( ); | |
212 gamesyokika(joy); | |
213 } | |
214 | |
215 if (pad[0].quit != 0) { | |
216 gamef = 0; | |
217 } | |
218 | |
219 //SDL_FillRect(screen, NULL, background); | |
220 glClear( GL_COLOR_BUFFER_BIT); | |
221 | |
222 schedule(); | |
223 enemyfaste = count; | |
224 | |
225 timeprof_begin(timeprof_move); | |
226 //Move(); //enemy move | |
227 collision_detect(); | |
228 outofwindow(); | |
229 timeprof_end(timeprof_move); | |
230 state_update(); | |
231 asteroidi = 0; | |
232 //charpatern(); | |
233 //bosguage(); | |
234 | |
235 if (jiki.bf == TRUE) { | |
236 Player(0); | |
237 count++; | |
238 PutSprite(count, jiki.x, jiki.y, jiki.ch); | |
239 } | |
240 | |
241 Putbom(); | |
242 tokuten(); | |
243 | |
244 count++; | |
245 //PutSprite(count, 0, 960 - 96, 10); | |
246 /*インフレゲージ */ | |
247 count++; | |
248 //PutSprite(count, 0, 0, 48); | |
249 obj_draw(); | |
250 pause(joy); | |
251 | |
44 | 252 KeyAssign(runmode, t_buff, joy, pad); |
0 | 253 |
254 glFlush(); | |
255 SDL_GL_SwapBuffers( ); | |
256 filpcount++; | |
257 SDL_Delay(10); | |
258 count = 0; | |
259 | |
260 | |
261 frames++; | |
262 } | |
263 | |
264 stop_time = SDL_GetTicks(); | |
265 | |
266 { | |
267 char buf[128]; | |
268 timeprof_sprint(buf, "move", timeprof_move); | |
269 dbg_printf("%s\n", buf); | |
270 } | |
271 | |
272 printf("%f FPS\n", ((float)frames)/(stop_time-start_time)*1000.0); | |
273 | |
274 SDL_GL_Leave2DMode(); | |
275 SDL_FreeSurface(sprite); | |
276 | |
277 SDL_JoystickClose(joy); | |
278 | |
279 //_______________________________________________ | |
280 // SDL_mixerの後始末 | |
281 Mix_CloseAudio(); | |
282 Mix_HaltMusic(); | |
283 FreeSdlMixer() ; | |
284 //_______________________________________________ | |
285 | |
43 | 286 if (runmode == 1) { |
287 PadfileWrite(first); | |
288 PadfileClose(first); | |
289 } else if (runmode == 2) { | |
290 PadfileClose(first); | |
291 } | |
0 | 292 |
293 SDL_Quit(); | |
294 return(0); | |
295 } | |
296 | |
297 | |
44 | 298 static void |
299 gamesyokika(SDL_Joystick *joy) | |
0 | 300 { |
301 laser_lv3[0].r = 62; | |
302 laser_lv3[0].r = 62; | |
303 for (i = 0; i < 3; i++) { | |
304 tlv3[i].y = -1; | |
305 } | |
306 filpcount = 0; | |
34 | 307 stage = 1; |
0 | 308 //for (i = 0; i < 300; i++) |
309 //enemy[i].f = FALSE; | |
310 jiki.zanki = 3; | |
311 jiki.x = 60; | |
312 jiki.y = 200; | |
313 jiki.ch = 3; | |
314 jiki.point = 0; | |
315 jiki.bf = FALSE; | |
316 jiki.muteki = 120; | |
317 enemycount = 0; | |
318 lg.stg = 4096; | |
319 pg.stg = 4096; | |
320 infg.stg = 0; | |
321 infg_level = 0; | |
322 //kyeenemyno = -1; | |
323 fastebos = 0; | |
324 jiki.ccount = 99; | |
325 p_extend = 200000; | |
326 pad[0].up=0; | |
327 pad[0].down=0; | |
328 pad[0].right=0; | |
329 pad[0].left=0; | |
330 pad[0].st=0; | |
331 pad[0].se=0; | |
332 opening(joy); | |
333 } | |
334 | |
335 | |
44 | 336 static void |
337 opening(SDL_Joystick *joy) | |
0 | 338 { |
339 //for (i = 0; i < 300; i++) { | |
340 //}; | |
341 | |
342 SoundStop(); | |
343 SoundPlay(7); | |
344 | |
345 while (1) { | |
346 if(use_keybord == 1) { | |
347 keybord(); | |
348 } else { | |
349 Pad(joy); | |
350 } | |
351 | |
352 count = 1; | |
353 | |
354 PutSprite(count, 700, 480, 53); // put `push start' string on screen. | |
355 count++; | |
356 PutSprite(count, 224, 776, 119); // put `super dandy' | |
357 count++; | |
358 // PutSprite(count, 200, 64, 190); | |
359 // PutSpriteEx(count, 8192, 8192, 0); | |
360 PutSpriteEx(190, 800, 264, 2, 2, 5); | |
361 count++; | |
362 PutSprite(count, 396, 432, 191); | |
363 //PutSpriteEx(count, 8192, 8192, 0); | |
364 count++; | |
365 PutSprite(count, 640, 640, 192); | |
366 //PutSpriteEx(count, 8192, 8192, 0); | |
367 | |
368 if (pad[0].st > 1) { | |
369 jiki.bf = TRUE; | |
370 | |
371 //CdPlay(1,&cdp[0],0); | |
372 SoundStop(); | |
373 SoundPlay(0); | |
374 | |
375 gamef = 1; | |
376 pad[0].st = 1; | |
377 return; | |
378 } | |
379 if ((pad[0].se > 0) && (pad[0].st > 0)) { | |
380 gamef = 0; | |
381 break; | |
382 } | |
383 | |
384 | |
385 SDL_GL_SwapBuffers( ); | |
386 } | |
387 } | |
388 | |
44 | 389 static void |
0 | 390 pause(SDL_Joystick *joy) |
391 { | |
392 if (jiki.zanki != 0 && jiki.bf != FALSE) { | |
393 if (pad[0].se == 1) { | |
394 //Mix_Pause(BGM); | |
395 PauseSdlMixer(BGM); | |
396 while(1){ | |
397 if(use_keybord == 1) { | |
398 keybord(); | |
399 } else { | |
400 Pad(joy); | |
401 } | |
402 if(pad[0].st == 0) | |
403 continue; | |
404 pad[0].up=0; | |
405 pad[0].down=0; | |
406 pad[0].right=0; | |
407 pad[0].left=0; | |
408 pad[0].se=0; | |
409 pad[0].st=0; | |
410 //Mix_Resume(BGM); | |
411 ResumeSdlMixer(BGM); | |
412 break; | |
413 } | |
414 } | |
415 } | |
416 if (jiki.zanki == 0) { | |
417 // RECT *recp; | |
418 if ((jiki.ccount > 0) && (cf == 0)) { | |
419 cf = 1; | |
420 count++; | |
421 //cgcg(2); | |
422 PutSprite(2, 480, 480, 110); | |
423 count++; | |
424 //cgcg(1); | |
425 } | |
426 if ((jiki.ccount > 0) && (cf == 1)) { | |
427 while (1) { | |
428 if (pad[0].st > 0) { | |
429 cf = 0; | |
430 jiki.ccount--; | |
431 jiki.zanki = 3; | |
432 enemycount++; | |
433 cc = 0; | |
434 for (i = 0; i < 4; i++) { | |
435 clear_result[i] = 0; | |
436 } | |
437 goto f; | |
438 } | |
439 cc++; | |
440 if (29 - cc / 60 < 20) { | |
441 cc = 0; | |
442 cf = 3; | |
443 break; | |
444 } | |
445 SDL_Delay(100); | |
446 PutSprite(1, 640, 640, 29 - cc / 60); | |
447 // PutSpriteEx(1, 409 * ((cc % 60) + 1), 409 * ((cc % 60) + 1), 0); | |
448 | |
449 Pad(joy); | |
450 SDL_GL_SwapBuffers( ); | |
451 } | |
452 } | |
453 if (rswait > 60 * 6) { | |
454 cf = 0; | |
455 rswait = 0; | |
456 gamesyokika(joy); | |
457 } | |
458 rswait++; | |
459 count++; | |
460 //cgcg(1); | |
461 PutSprite(1, 480, 480, 19); | |
462 return; | |
463 } | |
464 if (jiki.bf == FALSE) { | |
465 f: | |
466 if (rswait < 80) { | |
467 rswait++; | |
468 return; | |
469 } else { | |
470 rswait = 0; | |
471 jiki.x = 60; | |
472 jiki.y = 200; | |
473 jiki.bf = TRUE; | |
474 | |
475 pad[0].st = 0; | |
476 lg.stg = 4096; | |
477 pg.stg = 4096; | |
478 laser_lv3[0].r = 62; | |
479 tlv3[0].r = 0; | |
480 tlv3[0].y = -1; | |
481 return; | |
482 // sb_size = -1; | |
483 } | |
484 } | |
485 } | |
44 | 486 |
487 | |
488 static void | |
489 KeyAssign(int runmode, TraceBuffPtr buff, SDL_Joystick *joy, SGO_PAD *pad) | |
490 { | |
491 switch (runmode) { | |
492 case 0: | |
493 if (use_keybord) { | |
494 keybord(); | |
495 } else { | |
496 Pad(joy); | |
497 } | |
498 break; | |
499 case 1: | |
500 if (use_keybord) { | |
501 keybord(); | |
502 } else { | |
503 Pad(joy); | |
504 } | |
505 t_buff = CapturePad(t_buff, pad); | |
506 break; | |
507 case 2: | |
508 t_buff = TracePad(t_buff, pad); | |
509 break; | |
510 } | |
511 } |