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