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