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