Mercurial > hg > old > magoroku_racing.bad
comparison Magoroku.cc @ 106:0c4b7d74e292
add Magoroku.cc & .h (Dandy.cc & .h)
author | Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 08 Jun 2011 13:16:25 +0900 |
parents | |
children | 8a525ec378fc |
comparison
equal
deleted
inserted
replaced
105:ef64f1182dc8 | 106:0c4b7d74e292 |
---|---|
1 #include "Magoroku.h" | |
2 #include "SgoexCerium.h" | |
3 #include <stdio.h> | |
4 #include <stdlib.h> | |
5 #include <string.h> | |
6 #include <ctype.h> | |
7 #include <math.h> | |
8 #include <time.h> | |
9 #include <SDL.h> | |
10 #include "SDL_opengl.h" | |
11 #include "object.h" | |
12 #include "tree_controll.h" | |
13 #include "xml.h" | |
14 #include "profile.h" | |
15 #include "syokika.h" | |
16 #include "sankaku.h" | |
17 #include "sgoex.h" | |
18 #include "sound.h" | |
19 #include "bool.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 #include "error.h" | |
30 #include "matrix_calc.h" | |
31 | |
32 #include "Character.h" | |
33 #include "Character_state.h" | |
34 | |
35 static int use_keybord = 0; | |
36 // static int cdp[20] = { 16, 16, 16, 17, 18, 0 }; | |
37 static int i; | |
38 | |
39 static int rswait = 0; | |
40 static int cf = 0; | |
41 static int cc = 0; | |
42 | |
43 static int test_mode = 0; | |
44 static const char *test_object = "" ; | |
45 | |
46 //static SDL_Surface *screen; | |
47 // static Uint32 background; | |
48 // static char *pad_trace_file; | |
49 | |
50 extern void schedule(); | |
51 extern void tokuten(); | |
52 extern void Pad(); | |
53 extern void keybord(); | |
54 static int gamesyokika(int gamef); | |
55 static int game_pause(int); | |
56 //static char *pad_trace_file; | |
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 int runmode; | |
69 | |
70 SDL_Joystick *joy; | |
71 | |
72 | |
73 | |
74 const char *usr_help_str = "Usage: ./twice [-length data_length] [-count task_num]\n\ | |
75 -length Number of data (default DATA_NUM (Func.h))\n\ | |
76 -count Number of task (default 1)\n"; | |
77 | |
78 Viewer *droot; | |
79 | |
80 static int screen_w; | |
81 static int screen_h; | |
82 | |
83 //ウィンドウのサイズとかを指定? | |
84 MainLoopPtr | |
85 Magoroku::init(Viewer *sgroot_, int w, int h) | |
86 { | |
87 screen_w = w; | |
88 screen_h = h; | |
89 droot = sgroot_; | |
90 return droot; | |
91 } | |
92 | |
93 Application * | |
94 application() { | |
95 return new Magoroku(); | |
96 } | |
97 | |
98 | |
99 static int opening(int gamef); | |
100 static int dandy_closing(int gamef); | |
101 static int dandy_main_loop(int gamef); | |
102 static int dandy_main_init(int gamef); | |
103 extern int init(TaskManager *manager, int argc, char *argv[]); | |
104 extern void task_initialize(); | |
105 static void TMend(TaskManager *manager); | |
106 | |
107 //class Application の中の virtual bool app_loop( return 1 だけの関数?) を継承 | |
108 bool | |
109 Magoroku::app_loop(Viewer *viewer){ | |
110 // don't use allExecute | |
111 return 0; | |
112 }; | |
113 | |
114 //ゲームの分岐に使用 | |
115 static int gamef = 0; | |
116 | |
117 //ゲームの分岐っぽそう。magoroku の schedule の処理と同等と考えてオッケーかな? | |
118 HTaskPtr | |
119 Magoroku::application_task(HTaskPtr next, Viewer* viewer){ | |
120 // printf("gamef = %d\n",gamef); | |
121 switch (gamef) { | |
122 case 0: gamef= dandy_main_init(gamef); break; | |
123 case 1: gamef= gamesyokika(gamef); break; | |
124 case 2: gamef= opening(gamef); break; | |
125 case 3: gamef= dandy_main_loop(gamef); break; | |
126 case 4: gamef= dandy_closing(gamef); break; | |
127 } | |
128 return next; | |
129 }; | |
130 | |
131 | |
132 | |
133 | |
134 static void | |
135 task_init() | |
136 { | |
137 } | |
138 | |
139 int | |
140 TMmain(TaskManager *manager,int argc, char *argv[]) | |
141 { | |
142 for(int i = 1; i<argc ; i++) { | |
143 if (strcmp(argv[i],"-t")) { | |
144 test_mode=1; | |
145 if (i+1<argc && argv[i+1]) { | |
146 i++; | |
147 test_object=argv[i]; | |
148 } | |
149 } | |
150 } | |
151 | |
152 task_init(); | |
153 task_initialize(); | |
154 manager->set_TMend(TMend); | |
155 | |
156 return init(manager,argc, argv); | |
157 } | |
158 | |
159 void | |
160 TMend(TaskManager *manager) | |
161 { | |
162 printf("game end\n"); | |
163 } | |
164 | |
165 static int light_sysswitch = 0; | |
166 static int light_num = 4; | |
167 | |
168 static void | |
169 LightSysSwitch(Viewer *sgroot) { | |
170 if (light_sysswitch == 1) { | |
171 sgroot->OnLightSysSwitch(); | |
172 for (int i = 0; i < light_num; i++) { | |
173 SceneGraphPtr light = sgroot->getLight(i); | |
174 sgroot->OnLightSwitch(i); | |
175 light->xyz[0] = screen_w / 2; | |
176 light->xyz[1] = screen_h / 2; | |
177 light->xyz[2] = -100; | |
178 } | |
179 } else if (light_sysswitch == 0) { | |
180 sgroot->OffLightSysSwitch(); | |
181 } | |
182 } | |
183 | |
184 | |
185 static int | |
186 dandy_main_init(int gamef) | |
187 { | |
188 //Timeprof timeprof_move; | |
189 //timeprof_move = timeprof_new(); | |
190 dbg_init("/dev/stdout"); | |
191 | |
192 /** | |
193 * timeprof があるんだけどね | |
194 */ | |
195 | |
196 droot->createFromXMLfile("xml/character.xml"); | |
197 droot->createFromXMLfile("xml/font.xml"); | |
198 droot->createFromXMLfile("xml/effect.xml"); | |
199 droot->createFromXMLfile("xml/boss.xml"); | |
200 | |
201 LightSysSwitch(droot); | |
202 | |
203 | |
204 init_sprite(0,0,0,0); | |
205 | |
206 __debug("syokikaが呼びだされました\n"); | |
207 joy=SDL_JoystickOpen(0); | |
208 if(!joy) { | |
209 fprintf(stderr,"failed to open joystick 0\n"); | |
210 use_keybord = 1; | |
211 } | |
212 | |
213 /** | |
214 * sound.c に移しました | |
215 * 代わりに InitSdlMixer(void); を使います。 | |
216 * まあ中身一緒なんだけどね | |
217 */ | |
218 /** | |
219 if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY,MIX_DEFAULT_FORMAT,2,1024) < 0) { | |
220 fprintf(stderr,"failed to initialize SDL_mixer.\n"); | |
221 SDL_Quit(); | |
222 exit(-1); | |
223 } | |
224 */ | |
225 | |
226 // SDL_mixer とかいろいろ初期化 | |
227 // もし Init に失敗したら | |
228 // 以後の Mixer 関連の関数を呼び出しても | |
229 // 中では何も行われないとかいう小細工を入れました。 | |
230 InitSdlMixer(); | |
231 | |
232 // 音楽ファイルの読み込み | |
233 LoadSdlMixer(); | |
234 | |
235 // ボリューム調整 | |
236 InitVolume(); | |
237 | |
238 // 音出しテスト | |
239 PlaySdlMixer(-1, BGM); | |
240 | |
241 if(!(init_chara_list(1024))){ | |
242 __debug("failed to init_chara_list\n"); | |
243 } | |
244 | |
245 __debug("finished init_chara_list\n"); | |
246 | |
247 return 1; | |
248 } | |
249 | |
250 | |
251 static int | |
252 dandy_main_loop(int gamef) | |
253 { | |
254 | |
255 | |
256 if ((pad[0].l1 != 0) && (pad[0].r1 != 0) && | |
257 (pad[0].l2 != 0) && (pad[0].r2 != 0)) { | |
258 gamef = gamesyokika(gamef); | |
259 } | |
260 | |
261 if (pad[0].quit != 0) { | |
262 gamef = 4; | |
263 } | |
264 flip(); | |
265 | |
266 //SDL_FillRect(screen, NULL, background); | |
267 | |
268 schedule(); | |
269 enemyfaste = count; | |
270 | |
271 // timeprof_begin(timeprof_move); | |
272 //Move(); //enemy move | |
273 collision_detect(); | |
274 outofwindow(); | |
275 // timeprof_end(timeprof_move); | |
276 state_update(); | |
277 asteroidi = 0; | |
278 //charpatern(); | |
279 //bosguage(); | |
280 | |
281 if (jiki.bf == TRUE) { | |
282 Player(0); | |
283 count++; | |
284 PutSprite(count, jiki.x, jiki.y, jiki.ch); | |
285 } | |
286 | |
287 Putbom(); | |
288 tokuten(); | |
289 | |
290 count++; | |
291 //PutSprite(count, 0, 960 - 96, 10); | |
292 /*インフレゲージ */ | |
293 count++; | |
294 //PutSprite(count, 0, 0, 48); | |
295 | |
296 obj_draw(); | |
297 gamef = game_pause(gamef); | |
298 | |
299 if (use_keybord) { | |
300 keybord(); | |
301 } else { | |
302 Pad(joy); | |
303 } | |
304 filpcount++; | |
305 count = 0; | |
306 | |
307 return gamef; | |
308 } | |
309 | |
310 static int | |
311 dandy_closing(int gamef) | |
312 { | |
313 | |
314 //_______________________________________________ | |
315 // SDL_mixerの後始末 | |
316 Mix_CloseAudio(); | |
317 Mix_HaltMusic(); | |
318 FreeSdlMixer() ; | |
319 //_______________________________________________ | |
320 return 0; | |
321 } | |
322 | |
323 | |
324 static int | |
325 gamesyokika(int gamef) | |
326 { | |
327 laser_lv3[0].r = 62; | |
328 laser_lv3[0].r = 62; | |
329 for (i = 0; i < 3; i++) { | |
330 tlv3[i].y = -1; | |
331 } | |
332 filpcount = 0; | |
333 stage = 0; | |
334 //for (i = 0; i < 300; i++) | |
335 //enemy[i].f = FALSE; | |
336 jiki.zanki = 3; | |
337 jiki.x = 60; | |
338 jiki.y = 200; | |
339 jiki.ch = 3; | |
340 jiki.point = 0; | |
341 jiki.bf = FALSE; | |
342 jiki.muteki = 120; | |
343 enemycount = 0; | |
344 lg.stg = 4096; | |
345 pg.stg = 4096; | |
346 infg.stg = 0; | |
347 infg_level = 0; | |
348 //kyeenemyno = -1; | |
349 fastebos = 0; | |
350 jiki.ccount = 99; | |
351 p_extend = 200000; | |
352 pad[0].up=0; | |
353 pad[0].down=0; | |
354 pad[0].right=0; | |
355 pad[0].left=0; | |
356 pad[0].st=0; | |
357 pad[0].se=0; | |
358 | |
359 SoundStop(); | |
360 SoundPlay(7); | |
361 gamef = 2; | |
362 flip(); | |
363 return gamef; | |
364 } | |
365 | |
366 static int | |
367 opening(int gamef) | |
368 { | |
369 if(use_keybord == 1) { | |
370 keybord(); | |
371 } else { | |
372 Pad(joy); | |
373 } | |
374 | |
375 count = 1; | |
376 | |
377 PutSprite(count, 700, 480, 53); // put `push start' string on screen. | |
378 count++; | |
379 PutSprite(count, 224, 776, 119); // put `super dandy' | |
380 count++; | |
381 // PutSprite(count, 200, 64, 190); | |
382 // PutSpriteEx(count, 8192, 8192, 0); | |
383 PutSpriteEx(190, 800, 264, 2, 2, 5); | |
384 count++; | |
385 PutSprite(count, 396, 432, 191); | |
386 //PutSpriteEx(count, 8192, 8192, 0); | |
387 count++; | |
388 PutSprite(count, 640, 640, 192); | |
389 //PutSpriteEx(count, 8192, 8192, 0); | |
390 | |
391 if (pad[0].st > 1) { | |
392 jiki.bf = TRUE; | |
393 | |
394 //CdPlay(1,&cdp[0],0); | |
395 SoundStop(); | |
396 SoundPlay(0); | |
397 | |
398 gamef = 3; | |
399 pad[0].st = 1; | |
400 } else if ((pad[0].se > 0) && (pad[0].st > 0)) { | |
401 gamef = 2; | |
402 } | |
403 flip(); | |
404 return gamef; | |
405 } | |
406 | |
407 static int | |
408 game_pause(int gamef) | |
409 { | |
410 gamef = 3; | |
411 if (jiki.zanki != 0 && jiki.bf != FALSE) { | |
412 if (pad[0].se == 1) { | |
413 //Mix_Pause(BGM); | |
414 PauseSdlMixer(BGM); | |
415 while(1){ | |
416 if(use_keybord == 1) { | |
417 keybord(); | |
418 } else { | |
419 Pad(joy); | |
420 } | |
421 if(pad[0].st == 0) | |
422 continue; | |
423 pad[0].up=0; | |
424 pad[0].down=0; | |
425 pad[0].right=0; | |
426 pad[0].left=0; | |
427 pad[0].se=0; | |
428 pad[0].st=0; | |
429 //Mix_Resume(BGM); | |
430 ResumeSdlMixer(BGM); | |
431 break; | |
432 } | |
433 } | |
434 } | |
435 if (jiki.zanki == 0) { | |
436 // RECT *recp; | |
437 if ((jiki.ccount > 0) && (cf == 0)) { | |
438 cf = 1; | |
439 count++; | |
440 //cgcg(2); | |
441 PutSprite(count, 480, 480, 110); | |
442 count++; | |
443 //cgcg(1); | |
444 } | |
445 if ((jiki.ccount > 0) && (cf == 1)) { | |
446 while (1) { | |
447 if (pad[0].st > 0) { | |
448 cf = 0; | |
449 jiki.ccount--; | |
450 jiki.zanki = 3; | |
451 enemycount++; | |
452 cc = 0; | |
453 for (i = 0; i < 4; i++) { | |
454 clear_result[i] = 0; | |
455 } | |
456 goto f; | |
457 } | |
458 cc++; | |
459 if (29 - cc / 60 < 20) { | |
460 cc = 0; | |
461 cf = 3; | |
462 break; | |
463 } | |
464 SDL_Delay(100); | |
465 PutSprite(1, 640, 640, 29 - cc / 60); | |
466 // PutSpriteEx(1, 409 * ((cc % 60) + 1), 409 * ((cc % 60) + 1), 0); | |
467 | |
468 Pad(joy); | |
469 flip(); // this is not correct | |
470 } | |
471 } | |
472 if (rswait > 60 * 6) { | |
473 cf = 0; | |
474 rswait = 0; | |
475 gamef = gamesyokika(gamef); | |
476 } | |
477 rswait++; | |
478 count++; | |
479 //cgcg(1); | |
480 PutSprite(1, 480, 480, 19); | |
481 return gamef; | |
482 } | |
483 if (jiki.bf == FALSE) { | |
484 f: | |
485 if (rswait < 80) { | |
486 rswait++; | |
487 return gamef; | |
488 } else { | |
489 rswait = 0; | |
490 jiki.x = 60; | |
491 jiki.y = 200; | |
492 jiki.bf = TRUE; | |
493 | |
494 pad[0].st = 0; | |
495 lg.stg = 4096; | |
496 pg.stg = 4096; | |
497 laser_lv3[0].r = 62; | |
498 tlv3[0].r = 0; | |
499 tlv3[0].y = -1; | |
500 return gamef; | |
501 // sb_size = -1; | |
502 } | |
503 } | |
504 return gamef; | |
505 } | |
506 | |
507 | |
508 | |
509 /* end */ |